MediaWiki:Common.js: Difference between revisions
m Fix global collapsible controls |
m Avoid reinitializing standard collapsible tables |
||
| Line 17: | Line 17: | ||
(function () { | (function () { | ||
function normalizeLegacyCollapsibles($root) { | function normalizeLegacyCollapsibles($root) { | ||
$root.find('table.collapsible, div.collapsible, ul.collapsible, ol.collapsible').each(function () { | var $legacy = $root.find('table.collapsible, div.collapsible, ul.collapsible, ol.collapsible') | ||
.not('.mw-collapsible'); | |||
$legacy.each(function () { | |||
var $element = $(this); | var $element = $(this); | ||
| Line 25: | Line 28: | ||
} | } | ||
}); | }); | ||
$legacy.makeCollapsible(); | |||
} | } | ||
| Line 72: | Line 65: | ||
} | } | ||
function | function attachControls($root) { | ||
if ($('#muhro-collapse-controls').length || !findCollapsibles($root).length) { | |||
return false; | |||
if ($('#muhro-collapse-controls').length || !$ | |||
return; | |||
} | } | ||
| Line 117: | Line 101: | ||
updateButtons($root, $expand, $collapse); | updateButtons($root, $expand, $collapse); | ||
$('body').append($controls); | $('body').append($controls); | ||
return true; | |||
} | |||
function addCollapsibleControls($content) { | |||
var $root = $content.find('.mw-parser-output').first(); | |||
var attempts = 0; | |||
if (!$root.length) { | |||
$root = $content; | |||
} | |||
normalizeLegacyCollapsibles($root); | |||
function tryAttach() { | |||
attempts++; | |||
if (attachControls($root) || attempts >= 20) { | |||
return; | |||
} | |||
window.setTimeout(tryAttach, 250); | |||
} | |||
tryAttach(); | |||
} | } | ||