2018-04-21 04:59:30 -04:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
2018-04-22 15:02:38 -04:00
|
|
|
|
2012-04-05 00:53:10 -04:00
|
|
|
var switched = false;
|
2018-04-21 04:59:30 -04:00
|
|
|
|
2018-04-22 15:02:38 -04:00
|
|
|
// For old browsers
|
|
|
|
var each = function(node, callback) {
|
|
|
|
var array = Array.prototype.slice.call(node);
|
|
|
|
for(var i = 0; i < array.length; i++) callback(array[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
each(document.querySelectorAll(":not(.syntaxhighlighter)>table"), function(element) {
|
2018-04-21 04:59:30 -04:00
|
|
|
element.classList.add("responsive");
|
|
|
|
});
|
|
|
|
|
2012-04-05 00:53:10 -04:00
|
|
|
var updateTables = function() {
|
2018-04-21 04:59:30 -04:00
|
|
|
if (document.documentElement.clientWidth < 767 && !switched) {
|
2012-04-05 00:53:10 -04:00
|
|
|
switched = true;
|
2018-04-22 15:02:38 -04:00
|
|
|
each(document.querySelectorAll("table.responsive"), splitTable);
|
2018-04-21 04:59:30 -04:00
|
|
|
} else {
|
2012-04-05 00:53:10 -04:00
|
|
|
switched = false;
|
2018-04-22 15:02:38 -04:00
|
|
|
each(document.querySelectorAll(".table-wrapper table.responsive"), unsplitTable);
|
2012-04-05 00:53:10 -04:00
|
|
|
}
|
2018-04-21 04:59:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", updateTables);
|
|
|
|
window.addEventListener("resize", updateTables);
|
|
|
|
|
|
|
|
var splitTable = function(original) {
|
|
|
|
wrap(original, createElement("div", "table-wrapper"));
|
|
|
|
|
2018-04-22 15:02:38 -04:00
|
|
|
var copy = original.cloneNode(true);
|
|
|
|
each(copy.querySelectorAll("td:not(:first-child), th:not(:first-child)"), function(element) {
|
2018-04-21 04:59:30 -04:00
|
|
|
element.style.display = "none";
|
|
|
|
});
|
2018-04-22 15:02:38 -04:00
|
|
|
copy.classList.remove("responsive");
|
2018-04-21 04:59:30 -04:00
|
|
|
|
2018-04-22 15:02:38 -04:00
|
|
|
original.parentNode.append(copy);
|
|
|
|
wrap(copy, createElement("div", "pinned"))
|
2018-04-21 04:59:30 -04:00
|
|
|
wrap(original, createElement("div", "scrollable"));
|
|
|
|
}
|
2012-04-05 00:53:10 -04:00
|
|
|
|
2018-04-21 04:59:30 -04:00
|
|
|
var unsplitTable = function(original) {
|
2018-04-22 15:02:38 -04:00
|
|
|
each(document.querySelectorAll(".table-wrapper .pinned"), function(element) {
|
2018-04-21 04:59:30 -04:00
|
|
|
element.parentNode.removeChild(element);
|
|
|
|
});
|
|
|
|
unwrap(original.parentNode);
|
|
|
|
unwrap(original);
|
|
|
|
}
|
|
|
|
}).call(this);
|