aboutsummaryrefslogtreecommitdiffstats
path: root/guides/assets/javascripts/responsive-tables.js
diff options
context:
space:
mode:
Diffstat (limited to 'guides/assets/javascripts/responsive-tables.js')
-rw-r--r--guides/assets/javascripts/responsive-tables.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/guides/assets/javascripts/responsive-tables.js b/guides/assets/javascripts/responsive-tables.js
index 3c90ba758c..24906dddeb 100644
--- a/guides/assets/javascripts/responsive-tables.js
+++ b/guides/assets/javascripts/responsive-tables.js
@@ -1,18 +1,25 @@
(function() {
"use strict";
+
var switched = false;
- document.querySelectorAll(":not(.syntaxhighlighter)>table").forEach(function(element) {
+ // 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) {
element.classList.add("responsive");
});
var updateTables = function() {
if (document.documentElement.clientWidth < 767 && !switched) {
switched = true;
- document.querySelectorAll("table.responsive").forEach(splitTable);
+ each(document.querySelectorAll("table.responsive"), splitTable);
} else {
switched = false;
- document.querySelectorAll(".table-wrapper table.responsive").forEach(unsplitTable);
+ each(document.querySelectorAll(".table-wrapper table.responsive"), unsplitTable);
}
}
@@ -22,19 +29,19 @@
var splitTable = function(original) {
wrap(original, createElement("div", "table-wrapper"));
- var $copy = original.cloneNode(true);
- $copy.querySelectorAll("td:not(:first-child), th:not(:first-child)").forEach(function(element) {
+ var copy = original.cloneNode(true);
+ each(copy.querySelectorAll("td:not(:first-child), th:not(:first-child)"), function(element) {
element.style.display = "none";
});
- $copy.classList.remove("responsive");
+ copy.classList.remove("responsive");
- original.parentNode.append($copy);
- wrap($copy, createElement("div", "pinned"))
+ original.parentNode.append(copy);
+ wrap(copy, createElement("div", "pinned"))
wrap(original, createElement("div", "scrollable"));
}
var unsplitTable = function(original) {
- document.querySelectorAll(".table-wrapper .pinned").forEach(function(element) {
+ each(document.querySelectorAll(".table-wrapper .pinned"), function(element) {
element.parentNode.removeChild(element);
});
unwrap(original.parentNode);