| Line 243: |
Line 243: |
| | // 1) table with "header-fixed" class | | // 1) table with "header-fixed" class |
| | // 2) a table row with "header-row" class | | // 2) a table row with "header-row" class |
| − | console.debug('FixedHeader: before jquery.tablesorter')
| |
| | mw.loader.using('jquery.tablesorter', function() { | | mw.loader.using('jquery.tablesorter', function() { |
| − |
| |
| − | console.debug('FixedHeader: after jquery.tablesorter')
| |
| − |
| |
| − | var ts = $.fn.tablesorter;
| |
| − | $.fn.tablesorter = function() {
| |
| − | ts.apply(this, arguments);
| |
| − | initializeStickyHeader();
| |
| − | }
| |
| − |
| |
| | function initializeStickyHeader() { | | function initializeStickyHeader() { |
| | var tables = []; | | var tables = []; |
| | var $tables = $('.header-fixed'); | | var $tables = $('.header-fixed'); |
| | + | |
| | + | console.debug('FixedHeader: ' + $tables.length) |
| | | | |
| | if ($tables.length == 0) return; | | if ($tables.length == 0) return; |
| − |
| + | |
| | $tables.each(function() { | | $tables.each(function() { |
| | // If this table is under tabber AND is hidden, | | // If this table is under tabber AND is hidden, |
| Line 270: |
Line 262: |
| | tabberTabParent.style.display = "block"; | | tabberTabParent.style.display = "block"; |
| | } | | } |
| − |
| + | |
| | // Build fixed-header-table content | | // Build fixed-header-table content |
| | var $headerRow = $(this).find('.header-row'); | | var $headerRow = $(this).find('.header-row'); |
| | var $newHeaderContent = $('<tbody>'); | | var $newHeaderContent = $('<tbody>'); |
| | $newHeaderContent.append($headerRow.clone()); | | $newHeaderContent.append($headerRow.clone()); |
| − |
| + | |
| | // Add fixed-header-table colgroup to fix width | | // Add fixed-header-table colgroup to fix width |
| | var $columnsOld = $headerRow.find('td:not([colspan]),th:not([colspan])'); | | var $columnsOld = $headerRow.find('td:not([colspan]),th:not([colspan])'); |
| | var $newHeaderColgroup = $('<colgroup>'); | | var $newHeaderColgroup = $('<colgroup>'); |
| − |
| + | |
| | for (var i = 0; i < $columnsOld.length; i++) { | | for (var i = 0; i < $columnsOld.length; i++) { |
| | var width = $columnsOld[i].getBoundingClientRect().width; | | var width = $columnsOld[i].getBoundingClientRect().width; |
| Line 286: |
Line 278: |
| | ); | | ); |
| | } | | } |
| − |
| + | |
| | $(this).before( | | $(this).before( |
| | $('<table>') | | $('<table>') |
| Line 307: |
Line 299: |
| | }); | | }); |
| | $(this.previousSibling).css('width', $(this).width() + 1); | | $(this.previousSibling).css('width', $(this).width() + 1); |
| − |
| + | |
| | // Restore original tab display status | | // Restore original tab display status |
| | // if this table was under tabber and hidden | | // if this table was under tabber and hidden |
| Line 315: |
Line 307: |
| | } | | } |
| | }); | | }); |
| − |
| + | |
| | $(window).on('scroll', function() { | | $(window).on('scroll', function() { |
| | var scrollOffset = $(this).scrollTop(); | | var scrollOffset = $(this).scrollTop(); |
| Line 330: |
Line 322: |
| | } | | } |
| | }); | | }); |
| | + | } |
| | + | |
| | + | var ts = $.fn.tablesorter; |
| | + | $.fn.tablesorter = function() { |
| | + | ts.apply(this, arguments); |
| | + | initializeStickyHeader(); |
| | } | | } |
| | }) | | }) |
| | }); | | }); |