MediaWiki:Common.js: Difference between revisions
From Metroid Wiki
no edit summary
Melchizedek (talk | contribs) (Created page with '→Any JavaScript here will be loaded for all users on every page load.: // -------------------------------------------------------- // Collapsible tables // Description: Allo…') |
Melchizedek (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
// -------------------------------------------------------- | // -------------------------------------------------------- | ||
// Collapsible tables | // Collapsible tables | ||
Line 189: | Line 188: | ||
addOnloadHook( createNavigationBarToggleButton ); | addOnloadHook( createNavigationBarToggleButton ); | ||
// -------------------------------------------------------- | |||
// Test if an element has a certain class | |||
// Description: Uses regular expressions and caching for better performance. | |||
// Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]] | |||
// -------------------------------------------------------- | |||
var hasClass = (function () { | |||
var reCache = {}; | |||
return function (element, className) { | |||
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className); | |||
}; | |||
})(); | |||
// -------------------------------------------------------- | |||
// addPurge | |||
// adds a "purge" tab (after "watch") | |||
// -------------------------------------------------------- | |||
addOnloadHook(function () { | |||
if (wgAction != 'edit' && wgCanonicalNamespace != 'Special' && wgAction != 'history' && wgAction != 'delete' && wgAction != 'watch' && wgAction | |||
!= 'unwatch' && wgAction != 'protect' && wgAction != 'markpatrolled' && wgAction != 'rollback' && document.URL.indexOf('diff=') <= 0 | |||
&& document.URL.indexOf('oldid=') <=0) | |||
{ var hist; var url; | |||
if (!(hist = document.getElementById('ca-history') )) return; | |||
if (!(url = hist.getElementsByTagName('a')[0] )) return; | |||
if (!(url = url.href )) return; | |||
addPortletLink('p-cactions', url.replace(/([?&]action=)history([&#]|$)/, '$1purge$2'), | |||
'purge', 'ca-purge', 'Purge server cache for this page', '0'); | |||
} | |||
}); | |||
// | |||
// -------------------------------------------------------- | |||
// addSubpages | |||
// adds a 'subpages' link to the toolbox bar (excludes File, MediaWiki and Category namespaces) | |||
// -------------------------------------------------------- | |||
addOnloadHook(function () { | |||
var NSWithoutSubpages = new Array(-1, 6, 8, 14); | |||
if (document.getElementById('p-tb') && NSWithoutSubpages.indexOf(wgNamespaceNumber) == -1) | |||
{ | |||
var linkSubpages = '/Special:PrefixIndex/' + wgPageName + '/'; | |||
addPortletLink('p-tb', linkSubpages, 'Subpages', 't-subpages', 'Subpages of this page'); | |||
} | |||
}); | |||
// |