/*!
 * scrolling.js
 *
 * Copyright © 2016 Jorge M. Peláez | MIT license
 * http://j-pel.github.io/dynamize
 * 
 */

(function() {

  'use strict';

  var elements = document.getElementsByClassName('scrollable');
  for (var i = 0; i < elements.length; i++) {
    var table = elements[i];
    var thead = elements[i].tHead;
    var page = table.parentNode;
    var header = document.createElement("div");
    var headert = document.createElement("table");
    var scroller = document.createElement("div");
    thead.classList.add('top-fixed');
    table.removeChild(thead);
    page.insertBefore(header,table);
    header.appendChild(headert);
    headert.appendChild(thead);
    page.insertBefore(scroller,table);
    page.removeChild(table);
    scroller.style.display = "block";
    ["position","width","height","maxWidth","maxHeight","minWidth","minHeight",
    "top","left","bottom","right"].forEach(function(prop){
      scroller.style[prop] = table.style[prop];
    });
    ["movable","rotable","sizable"].forEach(function(cls){
			if(table.classList.contains(cls)) {
				scroller.classList.add(cls);
				table.classList.remove(cls);
			}
		});
    table.style.width = "100%";
    scroller.style.overflow = "scroll";
    scroller.appendChild(table);
  }

  var elements = document.getElementsByClassName('fix-top');
  for (var i = elements.length-1; elements.length > 0;i = elements.length-1) {
    var table = elements[i].parentNode;
    var head = elements[i].cloneNode(true);
    table.removeChild(thead);
    var theadt = document.createElement("table");
    theadt.appendChild(thead);
    head.classList.remove('fix-top');
    var fixed = table.parentNode.insertBefore(document.createElement("table"),table);
    fixed.classList.add('top-fixed');
    fixed.appendChild(head);
    fixed.style.position = "sticky";
    fixed.style.top = "0px";
    fixed.style.width = "100%";
    table.removeChild(elements[i]);
  }
  window.addEventListener('resize', onResize, false);
  onResize();

  function onResize() {
    var elements = document.getElementsByClassName('top-fixed');
    for (var e = 0; e < elements.length; e++) {
      var head = elements[e].rows[0].cells;
      var body = elements[e].parentNode.parentNode.nextSibling.firstChild.tBodies[0]
      if (body.rows.length==0) return(0);
      body = body.rows[0].cells;
      for (var i=0;i<body.length;i++) {
        head[i].style.minWidth = body[i].clientWidth + "px";
      }
    }
  }

})();

@@ -120,16 +120,23 @@
 unction(
+exports
 ) %7B%0A%0A  '
@@ -149,16 +149,1073 @@
 rict';%0A%0A
+  /*!%0A   * refresh()%0A   * Resizes the fixed headers for all columns in accordance to%0A   * the table contents.%0A   * %0A   * @api public%0A   */%0A  var refresh = exports.refresh = function() %7B%0A    var elements = document.getElementsByClassName('top-fixed');%0A    for (var e = 0; e %3C elements.length; e++) %7B%0A      var head = elements%5Be%5D.rows%5B0%5D.cells;%0A      var body = elements%5Be%5D.parentNode.parentNode.nextSibling.firstChild.tBodies%5B0%5D%0A      if (body.rows.length==0) return(0);%0A      if (body.rows%5B0%5D.cells.length%3E=head.length) %7B%0A        if (body.parentNode.parentNode.offsetWidth%3Ebody.offsetWidth) %7B%0A          var scroll_spacer = elements%5Be%5D.firstChild.appendChild(document.createElement(%22th%22));%0A          scroll_spacer.style.minWidth = (body.parentNode.parentNode.offsetWidth - body.offsetWidth)+%22px%22;%0A        %7D%0A      %7D%0A      body = body.rows%5B0%5D.cells;%0A      for (var i=0;i%3Cbody.length;i++) %7B%0A        head%5Bi%5D.style.minWidth = (body%5Bi%5D.clientWidth-2) + %22px%22;%0A      %7D%0A    %7D%0A  %7D%0A%0A  /*%0A   * Private utils to modify the DOM in order to create the fixed headers%0A   */%0A%0A
   var el
@@ -3039,22 +3039,8 @@
 se);
-%0A  onResize();
 %0A%0A  
@@ -3069,443 +3069,292 @@
     
-var elements = document.getElementsByClassName('top-fixed');%0A    for (var e = 0; e %3C elements.length; e++) %7B%0A      var head = elements%5Be%5D.rows%5B0%5D.cells;%0A      var body = elements%5Be%5D.parentNode.parentNode.nextSibling.firstChild.tBodies%5B0%5D%0A      if (body.rows.length==0) return(0);%0A      body = body.rows%5B0%5D.cells;%0A      for (var i=0;i%3Cbody.length;i++) %7B%0A        head%5Bi%5D.style.minWidth = body%5Bi%5D.clientWidth + %22px%22;%0A      %7D%0A    %7D%0A  %7D%0A%0A%7D)(
+refresh();%0A  %7D%0A%0A/* NOTE: for triggering the resize event, in all browsers, use:%0A  var evt = window.document.createEvent('UIEvents'); %0A  evt.initUIEvent('resize', true, false, window, 0); %0A  window.dispatchEvent(evt);%0A*/%0A%0A%7D)(typeof exports === 'undefined'? this%5B'scrolling'%5D=%7B%7D: exports
 );%0A

refresh call in scrolling.js for header resize