MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(11 intermediate revisions by 3 users not shown)
Line 2: Line 2:
mw.loader.load('https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css', 'text/css');
mw.loader.load('https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css', 'text/css');


// JS laden und initialisieren nach vollständigem Seitenaufbau
// DataTables JS laden und initialisieren
mw.loader.getScript('https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js')
mw.loader.getScript('https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js')
   .then(function () {
   .then(function () {
     $(function () {
     $(function () {
       var table = document.getElementById('illust-table');
       var table = $('#example');
       if (table) {
 
         console.log('Initialisiere DataTables für #illust-table …');
       if (table.length) {
        $('#illust-table').DataTable();
         // Füge zusätzliche Kopfzeile mit Input-Feldern hinzu
      } else {
        $('#example thead').append('<tr></tr>');
         console.warn('Tabelle mit ID "illust-table" nicht gefunden.');
        $('#example thead tr:eq(0) th').each(function () {
          var title = $(this).text();
          $('#example thead tr:eq(1)').append('<th><input type="text" placeholder="Suche ' + title + '" /></th>');
        });
 
        // DataTable initialisieren
        var dataTable = table.DataTable();
 
         // Spaltensuche aktivieren
        dataTable.columns().every(function () {
          var that = this;
          $('input', this.header()).on('keyup change clear', function () {
            if (that.search() !== this.value) {
              that.search(this.value).draw();
            }
          });
        });
       }
       }
     });
     });
   });
   });
 
$(document).ready(function () {
  var table = $('#example').DataTable();


  // Spaltensuche aktivieren
/* Move Edittools directly below the edit field. */
  $('#example thead tr:eq(1) th').each(function (i) {
mw.loader.load("https://twainframe.org/index.php?title=MediaWiki:MoveEdittools.js&action=raw&ctype=text/javascript");
    $('input', this).on('keyup change', function () {
      if (table.column(i).search() !== this.value) {
        table.column(i).search(this.value).draw();
      }
    });
  });
});