MediaWiki:Common.js
MediaWiki interface page
More actions
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */// Load DataTables library
mw.loader.using( 'jquery' ).done( function () {
$.getScript("https://cdn.datatables.net/1.13.8/js/jquery.dataTables.min.js", function () {
// Activate DataTables on any table with class="datatable"
$(document).ready(function () {
$("table.datatable").DataTable({
paging: true, // Adds pagination
searching: true, // Adds search box
ordering: true, // Enables column sorting
info: true // Shows "Showing 1 to 10 of X entries"
});
});
});
});
mw.hook('wikipage.content').add(function ($content) {
var $tbl = $content.find('#dungeons');
if ($tbl.length && !$tbl.hasClass('dt-initialized')) {
// Load DataTables if not already present
var loadDT = function () {
if ($.fn.dataTable) {
$tbl.addClass('dt-initialized').DataTable({
paging: true,
searching: true,
ordering: true,
info: true
});
} else {
// Fallback: load from CDN once
$.when(
$.getScript('https://cdn.datatables.net/1.13.8/js/jquery.dataTables.min.js')
).done(function () {
$('<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.8/css/jquery.dataTables.min.css">').appendTo('head');
$tbl.addClass('dt-initialized').DataTable({
paging: true,
searching: true,
ordering: true,
info: true
});
});
}
};
loadDT();
}
});