Difference between revisions of "MediaWiki:Common.js"
Line 2: | Line 2: | ||
/* Add icons to expandable entries in TOC */ |
/* Add icons to expandable entries in TOC */ |
||
− | + | $(document).ready(function(){ |
|
− | + | $('#toc li a').each(function(a,b){ |
|
− | + | var numSiblings = $(this).siblings('ul:hidden').size(); |
|
− | + | if (numSiblings > 0) { |
|
− | + | $(this).before(' <span class="toggleicon">[]</span> '); |
|
− | + | updateIcons(); |
|
− | + | } |
|
− | + | }); |
|
− | //}); |
||
+ | $('#toc span.toggleicon').click(function(){ |
||
+ | $(this).siblings('ul').toggle({ |
||
+ | duration: 200, |
||
+ | complete: updateIcons |
||
+ | }); |
||
+ | }); |
||
+ | }); |
||
− | //$('#toc span.toggleicon').click(function(){ |
||
− | // $(this).siblings('ul').toggle({ |
||
− | // duration: 200, |
||
− | // complete: updateIcons |
||
− | // }); |
||
− | //}); |
||
+ | function updateIcons() { |
||
− | |||
+ | $('#toc span.toggleicon').each(function(){ |
||
− | //function updateIcons() { |
||
+ | if ($(this).siblings('ul').first().is(':hidden')) { |
||
− | // $('#toc span.toggleicon').each(function(){ |
||
− | + | $(this).html('[+]'); |
|
+ | } else { |
||
− | // $(this).html('[+]'); |
||
+ | $(this).html('[−]'); |
||
− | // } else { |
||
+ | } |
||
− | // $(this).html('[−]'); |
||
− | + | }) |
|
+ | } |
||
− | // }) |
||
+ | /* Add icons to expandable entries in TOC - End */ |
||
− | //} |
Revision as of 10:12, 1 April 2019
/* Any JavaScript here will be loaded for all users on every page load. */
/* Add icons to expandable entries in TOC */
$(document).ready(function(){
$('#toc li a').each(function(a,b){
var numSiblings = $(this).siblings('ul:hidden').size();
if (numSiblings > 0) {
$(this).before(' <span class="toggleicon">[]</span> ');
updateIcons();
}
});
$('#toc span.toggleicon').click(function(){
$(this).siblings('ul').toggle({
duration: 200,
complete: updateIcons
});
});
});
function updateIcons() {
$('#toc span.toggleicon').each(function(){
if ($(this).siblings('ul').first().is(':hidden')) {
$(this).html('[+]');
} else {
$(this).html('[−]');
}
})
}
/* Add icons to expandable entries in TOC - End */