Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 12: Line 12:
         });
         });
     });
     });
});
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();
  }
});
});

Revision as of 00:28, 3 September 2025

/* 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();
  }
});