MediaWiki:Gadget-CollapsibleTemplates.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
This user script seems to have a documentation page at MediaWiki:Gadget-CollapsibleTemplates and an accompanying .css page at MediaWiki:Gadget-CollapsibleTemplates.css. |
/* jshint curly:false */
/* global jQuery:false, mediaWiki:false*/
(function ($, mw) {
'use strict';
function toggleTemplate($element) {
if ($element.is('tr')) {
$element
.parent().parent()
.toggleClass('collapsed');
$element.nextAll('tr')
.toggleClass('hidden');
} else {
$element
.parent()
.toggleClass('expanded')
.toggleClass('collapsed')
.find('div.body')
.slideToggle((mw.config.get('skin') === 'vector') ? 150 : 0);
}
}
function launch($content) {
var $tableTmp = $content.find('table.collapsible');
$content = $content.find('div.collapsibletemplate')
.each(function (i, el) {
el = $(el)
.attr('dir', document.documentElement.getAttribute('dir'))
.find('.body');
if (el[0]) {
if ($(this).hasClass('collapsed')) el.hide();
el.removeClass('show-on-commons');
}
});
$tableTmp = $tableTmp.map(function (i, el) {
el = $(el).find('> tbody > tr');
if (el[0]) {
if ($(this).hasClass('collapsed')) el.not(':first-child').toggleClass('hidden');
return el[0];
}
});
$($content.find('div.collapsibleheader').show().add($tableTmp))
.on('mousedown', function (e) {
var $t = $(e.target);
if ($t.is('a') || $t.parents('a').length)
return true;
toggleTemplate($(e.currentTarget));
return false;
});
}
mw.hook('wikipage.content').add(launch);
}(jQuery, mediaWiki));