Changes

m
no edit summary
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')
+
// TODO: tablesorter, tabbertab, resize
mw.loader.using('jquery.tablesorter', function() {
+
// mw.loader.using('jquery.tablesorter', function() {
 +
var tables = [];
   −
console.debug('FixedHeader: after jquery.tablesorter')
+
function initializeStickyHeader() {
 +
var $tables = $('.header-fixed');
   −
var ts = $.fn.tablesorter;
+
if ($tables.length == 0) return;
$.fn.tablesorter = function() {
+
 
  ts.apply(this, arguments);
+
$tables.each(function(n) {
  initializeStickyHeader();
+
  if ($(this).hasClass('header-fixed-done')) return;
 +
  if ($(this).hasClass('mw-collapsed')) {
 +
  console.debug('header-fixed: collapsed: ' + n)
 +
  $(this).find('.mw-collapsible-text').click(function() {
 +
  console.debug('header-fixed: click: ' + n)
 +
  setTimeout(function() { initializeStickyHeader(); }, 1000);
 +
  })
 +
  return;
 +
  }
 +
/*
 +
    var tabberTabParent = $(this).parent(".tabbertab")[0];
 +
    var originalStyleDisplay;
 +
    if (tabberTabParent) {
 +
    originalStyleDisplay = tabberTabParent.style.display;
 +
    tabberTabParent.style.visibility = "hidden";
 +
    tabberTabParent.style.display = "block";
 +
    }
 +
*/
 +
    var $headerRow = $(this).find('.header-row');
 +
    var $newHeaderContent = $('<tbody>');
 +
    $newHeaderContent.append($headerRow.clone());
 +
 
 +
    var $columnsOld = $headerRow.find('td:not([colspan]),th:not([colspan])');
 +
    var $newHeaderColgroup = $('<colgroup>');
 +
    for (var i = 0; i < $columnsOld.length; i++) {
 +
    $newHeaderColgroup.append($('<col>').css('width', $columnsOld[i].getBoundingClientRect().width));
 +
    }
 +
 
 +
    $(this).before(
 +
    $('<table>')
 +
        .addClass('header-fixed-helper')
 +
        .addClass('wikitable')
 +
        .css('position', 'sticky')
 +
        .css('top', '0')
 +
        .css('z-index', '9')
 +
        .css('display', 'none')
 +
        .css('background-color', '#fff')
 +
        .css('margin-top', '0')
 +
        .css('margin-bottom', '0')
 +
        .css('table-layout', 'fixed')
 +
        .append($newHeaderColgroup)
 +
        .append($newHeaderContent)
 +
    );
 +
    tables.push({ table: this, helper: this.previousSibling });
 +
    $(this.previousSibling).css('width', $(this).width() + 1);
 +
/*
 +
    if (tabberTabParent) {
 +
    tabberTabParent.style.visibility = "";
 +
    tabberTabParent.style.display = originalStyleDisplay;
 +
    }
 +
    */
 +
    $(this).addClass('header-fixed-done');
 +
    console.debug('header-fixed: fixed: ' + n)
 +
});
 +
}
 +
 
 +
$(window).on('scroll', function() {
 +
var scrollOffset = $(this).scrollTop();
 +
for (var i = 0; i < tables.length; i++) {
 +
var tableOffset = $(tables[i].table).offset().top;
 +
var tableHeight = $(tables[i].table).height();
 +
var helperHeight = $(tables[i].helper).height();
 +
if ((scrollOffset > tableOffset) && (scrollOffset < (tableOffset + tableHeight - helperHeight))) {
 +
    if ($(tables[i].helper).is(':hidden')) {
 +
    $(tables[i].helper).show();
 +
    }
 +
} else {
 +
    $(tables[i].helper).hide();
 +
}
 
}
 
}
+
});
function initializeStickyHeader() {
+
 
  var tables = [];
+
/*
  var $tables = $('.header-fixed');
+
var ts = $.fn.tablesorter;
+
$.fn.tablesorter = function() {
  if ($tables.length == 0) return;
+
  ts.apply(this, arguments);
+
  initializeStickyHeader();
  $tables.each(function() {
+
}
    // If this table is under tabber AND is hidden,
+
*/
    // temporarily make element visible so we can pull its width data later
+
setTimeout(function() { initializeStickyHeader(); }, 1000);
    var tabberTabParent = $(this).parent(".tabbertab")[0];
+
//})
    var originalStyleDisplay;
+
 
    if (tabberTabParent) {
+
// Basic video support using <img> and <video> elements
      originalStyleDisplay = tabberTabParent.style.display;
+
 
      tabberTabParent.style.visibility = "hidden";
+
$('.video').each(function () {
      tabberTabParent.style.display = "block";
+
var src = $(this).data('src') || '';
    }
+
var parts = src.split('.');
+
var ext = parts[parts.length - 1] || '';
    // Build fixed-header-table content
+
if (ext === 'webp') {
    var $headerRow = $(this).find('.header-row');
+
var a = $('<a>').addClass('image').attr('href', '/File:' + src);
    var $newHeaderContent = $('<tbody>');
+
var img = $('<img>');
    $newHeaderContent.append($headerRow.clone());
+
for (var attr in $(this).data()) {
+
img.attr(attr, (attr === 'src' ? 'https://en.kancollewiki.net/Special:Filepath/' : '') + $(this).data(attr));
    // Add fixed-header-table colgroup to fix width
+
}
    var $columnsOld = $headerRow.find('td:not([colspan]),th:not([colspan])');
+
a.append(img);
    var $newHeaderColgroup = $('<colgroup>');
+
      $(this).append(a);
+
} else {
    for (var i = 0; i < $columnsOld.length; i++) {
+
var video = $('<video>').attr('controls', '');
      var width = $columnsOld[i].getBoundingClientRect().width;
+
var source = $('<source>').attr('type', 'video/' + ext);
      $newHeaderColgroup.append(
+
for (var attr in $(this).data()) {
        $('<col>').css('width', width)
+
var el = attr === 'src' || attr === 'type' ? source : video;
      );
+
el.attr(attr, (attr === 'src' ? 'https://en.kancollewiki.net/Special:Filepath/' : '') + $(this).data(attr));
    }
+
}
+
video.append(source);
    $(this).before(
+
      $(this).append(video);
      $('<table>')
  −
        .addClass('header-fixed-helper')
  −
        .addClass('wikitable')
  −
        .css('position', 'sticky')
  −
        .css('top', '0')
  −
        .css('z-index', '9')
  −
        .css('display', 'none')
  −
        .css('background-color', '#fff')
  −
        .css('margin-top', '0')
  −
        .css('margin-bottom', '0')
  −
        .css('table-layout', 'fixed')
  −
        .append($newHeaderColgroup)
  −
        .append($newHeaderContent)
  −
    );
  −
    tables.push({
  −
      table: this,
  −
      helper: this.previousSibling
  −
    });
  −
    $(this.previousSibling).css('width', $(this).width() + 1);
  −
  −
    // Restore original tab display status
  −
    // if this table was under tabber and hidden
  −
    if (tabberTabParent) {
  −
      tabberTabParent.style.visibility = "";
  −
      tabberTabParent.style.display = originalStyleDisplay;
  −
    }
  −
  });
  −
  −
  $(window).on('scroll', function() {
  −
    var scrollOffset = $(this).scrollTop();
  −
    for (var i = 0; i < tables.length; i++) {
  −
      var tableOffset = $(tables[i].table).offset().top;
  −
      var tableHeight = $(tables[i].table).height();
  −
      var helperHeight = $(tables[i].helper).height();
  −
      if ((scrollOffset > tableOffset) && (scrollOffset < (tableOffset + tableHeight - helperHeight))) {
  −
        if ($(tables[i].helper).is(':hidden'))
  −
          $(tables[i].helper).show();
  −
      } else {
  −
        $(tables[i].helper).hide();
  −
      }
  −
    }
  −
  });
   
}
 
}
})
+
});
 +
 
 
});
 
});
cssedit, gkautomate
6,926

edits