Jump to content

MediaWiki:Common.js: Difference between revisions

From TwainFrame
No edit summary
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
/* Das folgende JavaScript wird für alle Benutzer geladen. */
// DataTables CSS laden
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.load('https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css', 'text/css');


// DataTables JS laden und initialisieren
mw.loader.getScript('https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js')
  .then(function () {
    $(function () {
      var table = $('#example');


console.log('DataTables-Skript wird geladen...');
      if (table.length) {
        // Füge zusätzliche Kopfzeile mit Input-Feldern hinzu
        $('#example thead').append('<tr></tr>');
        $('#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>');
        });


// DataTables JS nachladen und dann initialisieren
        // DataTable initialisieren
mw.loader.getScript('https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js')
        var dataTable = table.DataTable();
.then(function() {
 
    console.log('DataTables erfolgreich geladen! Initialisiere Tabelle...');
         // Spaltensuche aktivieren
    $(document).ready(function() {
        dataTable.columns().every(function () {
         $('#catalog').DataTable({
          var that = this;
            paging: true,
          $('input', this.header()).on('keyup change clear', function () {
            pageLength: 100,
            if (that.search() !== this.value) {
            searching: true,
              that.search(this.value).draw();
            ordering: true,
            lengthMenu: [ [10, 25, 50, 100, 200, 600], [10, 25, 50, 100, 200, 600] ],
            order: [[1, 'asc']],
            language: {
                search: "Suche:",
                lengthMenu: "Show _MENU_ Entries",
                zeroRecords: "No Matches",
                info: "Page _PAGE_ of _PAGES_",
                infoEmpty: "Empty",
                infoFiltered: "(out of _MAX_ total entries)"
            },
            initComplete: function () {
                // Fügt für jede Spalte ein Suchfeld hinzu
                this.api().columns().every(function () {
                    var column = this;
                    var header = $(column.header());
                    var columnTitle = header.text(); // Spaltentitel extrahieren
                    var input = $('<input type="text" placeholder="' + columnTitle + ' ..." style="width: 100%; padding: 5px;"/>')
                        .appendTo($(header).empty()) // Leert die Headerzelle und fügt das Eingabefeld ein
                        .on('keyup change', function () {
                            column.search(this.value).draw();  // Filtert die Spalte nach Eingabewerten
                        })
                        .on('click', function(e) {
                            e.stopPropagation(); // Verhindert, dass der Klick die Sortierung beeinflusst
                        });
                });
             }
             }
          });
         });
         });
      }
     });
     });
})
  });
.catch(function(err) {
 
    console.error('Fehler beim Laden von DataTables:', err);
/* Move Edittools directly below the edit field. */
});
mw.loader.load("https://twainframe.org/index.php?title=MediaWiki:MoveEdittools.js&action=raw&ctype=text/javascript");

Latest revision as of 16:09, 25 June 2025

// DataTables CSS laden
mw.loader.load('https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css', 'text/css');

// DataTables JS laden und initialisieren
mw.loader.getScript('https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js')
  .then(function () {
    $(function () {
      var table = $('#example');

      if (table.length) {
        // Füge zusätzliche Kopfzeile mit Input-Feldern hinzu
        $('#example thead').append('<tr></tr>');
        $('#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();
            }
          });
        });
      }
    });
  });

/* Move Edittools directly below the edit field. */
mw.loader.load("https://twainframe.org/index.php?title=MediaWiki:MoveEdittools.js&action=raw&ctype=text/javascript");