diff --git a/dist/stackonly/tablesaw.stackonly.css b/dist/stackonly/tablesaw.stackonly.css index 363b3eb..2c4de1e 100644 --- a/dist/stackonly/tablesaw.stackonly.css +++ b/dist/stackonly/tablesaw.stackonly.css @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ diff --git a/dist/stackonly/tablesaw.stackonly.jquery.js b/dist/stackonly/tablesaw.stackonly.jquery.js index 250b8c8..ae27d07 100644 --- a/dist/stackonly/tablesaw.stackonly.jquery.js +++ b/dist/stackonly/tablesaw.stackonly.jquery.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ // UMD module definition @@ -111,6 +111,14 @@ if (Tablesaw.mustard) { }; Table.prototype.init = function() { + if (!this.$thead.length) { + throw new Error("tablesaw: a is required, but none was found."); + } + + if (!this.$thead.find("th").length) { + throw new Error("tablesaw: no header cells found. Are you using inside of ?"); + } + // assign an id if there is none if (!this.$table.attr("id")) { this.$table.attr("id", pluginName + "-" + Math.round(Math.random() * 10000)); diff --git a/dist/stackonly/tablesaw.stackonly.js b/dist/stackonly/tablesaw.stackonly.js index 4ecbec7..93af0da 100644 --- a/dist/stackonly/tablesaw.stackonly.js +++ b/dist/stackonly/tablesaw.stackonly.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ /*! Shoestring - v2.0.0 - 2017-02-14 @@ -1818,6 +1818,14 @@ if (Tablesaw.mustard) { }; Table.prototype.init = function() { + if (!this.$thead.length) { + throw new Error("tablesaw: a is required, but none was found."); + } + + if (!this.$thead.find("th").length) { + throw new Error("tablesaw: no header cells found. Are you using inside of ?"); + } + // assign an id if there is none if (!this.$table.attr("id")) { this.$table.attr("id", pluginName + "-" + Math.round(Math.random() * 10000)); diff --git a/dist/stackonly/tablesaw.stackonly.scss b/dist/stackonly/tablesaw.stackonly.scss index facd1f4..99d7c33 100644 --- a/dist/stackonly/tablesaw.stackonly.scss +++ b/dist/stackonly/tablesaw.stackonly.scss @@ -1,7 +1,7 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ diff --git a/dist/tablesaw-init.js b/dist/tablesaw-init.js index b466826..740953b 100644 --- a/dist/tablesaw-init.js +++ b/dist/tablesaw-init.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ (function(win) { diff --git a/dist/tablesaw.css b/dist/tablesaw.css index 82f506e..1f3802a 100644 --- a/dist/tablesaw.css +++ b/dist/tablesaw.css @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ @@ -340,15 +340,15 @@ a.tablesaw-btn { margin: .59375em 0; } -.tablesaw-swipe .tablesaw-cell-persist { +.tablesaw-swipe .tablesaw-swipe-cellpersist { border-right: 2px solid #e4e1de; } -.tablesaw-swipe-shadow .tablesaw-cell-persist { +.tablesaw-swipe-shadow .tablesaw-swipe-cellpersist { border-right-width: 1px; } -.tablesaw-swipe-shadow .tablesaw-cell-persist { +.tablesaw-swipe-shadow .tablesaw-swipe-cellpersist { box-shadow: 3px 0 4px -1px #e4e1de; } @@ -491,8 +491,8 @@ a.tablesaw-btn { @media only all { /* Unchecked manually: Always hide */ - .tablesaw-swipe th.tablesaw-cell-hidden, - .tablesaw-swipe td.tablesaw-cell-hidden { + .tablesaw-swipe th.tablesaw-swipe-cellhidden, + .tablesaw-swipe td.tablesaw-swipe-cellhidden { display: none; } } @@ -650,15 +650,15 @@ a.tablesaw-btn { @media only all { /* Unchecked manually: Always hide */ - .tablesaw-columntoggle th.tablesaw-cell-hidden, - .tablesaw-columntoggle td.tablesaw-cell-hidden { + .tablesaw-columntoggle th.tablesaw-toggle-cellhidden, + .tablesaw-columntoggle td.tablesaw-toggle-cellhidden { display: none; } /* Checked manually: Always show */ - .tablesaw-columntoggle th.tablesaw-cell-visible, - .tablesaw-columntoggle td.tablesaw-cell-visible { + .tablesaw-columntoggle th.tablesaw-toggle-cellvisible, + .tablesaw-columntoggle td.tablesaw-toggle-cellvisible { display: table-cell; } } diff --git a/dist/tablesaw.jquery.js b/dist/tablesaw.jquery.js index 7cef1db..e2c781f 100644 --- a/dist/tablesaw.jquery.js +++ b/dist/tablesaw.jquery.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ // UMD module definition @@ -111,6 +111,14 @@ if (Tablesaw.mustard) { }; Table.prototype.init = function() { + if (!this.$thead.length) { + throw new Error("tablesaw: a is required, but none was found."); + } + + if (!this.$thead.find("th").length) { + throw new Error("tablesaw: no header cells found. Are you using inside of ?"); + } + // assign an id if there is none if (!this.$table.attr("id")) { this.$table.attr("id", pluginName + "-" + Math.round(Math.random() * 10000)); @@ -691,8 +699,8 @@ if (Tablesaw.mustard) { var header = self.getHeaderFromCheckbox(checkbox); var $cells = self.$getCells(header); - $cells[!checked ? "addClass" : "removeClass"]("tablesaw-cell-hidden"); - $cells[checked ? "addClass" : "removeClass"]("tablesaw-cell-visible"); + $cells[!checked ? "addClass" : "removeClass"]("tablesaw-toggle-cellhidden"); + $cells[checked ? "addClass" : "removeClass"]("tablesaw-toggle-cellvisible"); self.updateColspanIgnoredRows(checked, $(header).add(header.cells)); @@ -873,7 +881,7 @@ if (Tablesaw.mustard) { this.$table.removeClass(this.classes.columnToggleTable); this.$table.find("th, td").each(function() { var $cell = $(this); - $cell.removeClass("tablesaw-cell-hidden").removeClass("tablesaw-cell-visible"); + $cell.removeClass("tablesaw-toggle-cellhidden").removeClass("tablesaw-toggle-cellvisible"); this.className = this.className.replace(/\bui\-table\-priority\-\d\b/g, ""); }); @@ -1272,10 +1280,14 @@ if (Tablesaw.mustard) { var classes = { hideBtn: "disabled", persistWidths: "tablesaw-fix-persist", + hiddenCol: "tablesaw-swipe-cellhidden", + persistCol: "tablesaw-swipe-cellpersist", allColumnsVisible: "tablesaw-all-cols-visible" }; var attrs = { - disableTouchEvents: "data-tablesaw-no-touch" + disableTouchEvents: "data-tablesaw-no-touch", + ignorerow: "data-tablesaw-ignorerow", + subrow: "data-tablesaw-subrow" }; function createSwipeTable(tbl, $table) { @@ -1302,13 +1314,13 @@ if (Tablesaw.mustard) { var tableId = $table.attr("id"); if (!$headerCells.length) { - throw new Error( - "tablesaw swipe: no header cells found. Are you using inside of ?" - ); + throw new Error("tablesaw swipe: no header cells found."); } $table.addClass("tablesaw-swipe"); + $table.find("." + classes.hiddenCol).removeClass(classes.hiddenCol); + // Calculate initial widths $headerCells.each(function() { var width = this.offsetWidth; @@ -1323,25 +1335,53 @@ if (Tablesaw.mustard) { } function $getCells(headerCell) { - return $(headerCell.cells).add(headerCell); + return $(headerCell.cells).add(headerCell).filter(function() { + return !$(this).parent().is("[" + attrs.ignorerow + "],[" + attrs.subrow + "]"); + }); } function showColumn(headerCell) { - $getCells(headerCell).removeClass("tablesaw-cell-hidden"); + $getCells(headerCell).removeClass(classes.hiddenCol); } function hideColumn(headerCell) { - $getCells(headerCell).addClass("tablesaw-cell-hidden"); + $getCells(headerCell).addClass(classes.hiddenCol); } function persistColumn(headerCell) { - $getCells(headerCell).addClass("tablesaw-cell-persist"); + $getCells(headerCell).addClass(classes.persistCol); } function isPersistent(headerCell) { return $(headerCell).is('[data-tablesaw-priority="persist"]'); } + function countVisibleColspan() { + var count = 0; + $headerCells.each(function() { + var $t = $(this); + if ($t.is("." + classes.hiddenCol)) { + return; + } + count += parseInt($t.attr("colspan") || 1, 10); + }); + return count; + } + + function updateColspanOnIgnoredRows(newColspan) { + if (!newColspan) { + newColspan = countVisibleColspan(); + } + $table + .find("[" + attrs.ignorerow + "],[" + attrs.subrow + "]") + .find("td[colspan]") + .each(function() { + var $t = $(this); + var colspan = parseInt($t.attr("colspan"), 10); + $t.attr("colspan", newColspan); + }); + } + function unmaintainWidths() { $table.removeClass(classes.persistWidths); $("#" + tableId + "-persist").remove(); @@ -1364,7 +1404,9 @@ if (Tablesaw.mustard) { hash.push(index + "-" + width); styles.push( prefix + - " .tablesaw-cell-persist:nth-child(" + + " ." + + classes.persistCol + + ":nth-child(" + (index + 1) + ") { width: " + width + @@ -1397,7 +1439,7 @@ if (Tablesaw.mustard) { $headerCellsNoPersist.each(function(i) { var $t = $(this), - isHidden = $t.css("display") === "none" || $t.is(".tablesaw-cell-hidden"); + isHidden = $t.css("display") === "none" || $t.is("." + classes.hiddenCol); if (!isHidden && !checkFound) { checkFound = true; @@ -1457,15 +1499,19 @@ if (Tablesaw.mustard) { // We need at least one column to swipe. var needsNonPersistentColumn = visibleNonPersistantCount === 0; + var visibleColumnCount = 0; $headerCells.each(function(index) { + var colspan = parseInt($(this).attr("colspan") || 1, 10); if (persist[index]) { + visibleColumnCount += colspan; // for visual box-shadow persistColumn(this); return; } if (sums[index] <= containerWidth || needsNonPersistentColumn) { + visibleColumnCount += colspan; needsNonPersistentColumn = false; showColumn(this); } else { @@ -1473,7 +1519,9 @@ if (Tablesaw.mustard) { } }); + updateColspanOnIgnoredRows(visibleColumnCount); unmaintainWidths(); + $table.trigger("tablesawcolumns"); } @@ -1492,6 +1540,7 @@ if (Tablesaw.mustard) { hideColumn($headerCellsNoPersist.get(pair[0])); showColumn($headerCellsNoPersist.get(pair[1])); + updateColspanOnIgnoredRows(); $table.trigger("tablesawcolumns"); } diff --git a/dist/tablesaw.js b/dist/tablesaw.js index 3f49e65..a46ff37 100644 --- a/dist/tablesaw.js +++ b/dist/tablesaw.js @@ -1,4 +1,4 @@ -/*! Tablesaw - v3.0.2 - 2017-07-07 +/*! Tablesaw - v3.0.3 - 2017-07-13 * https://github.com/filamentgroup/tablesaw * Copyright (c) 2017 Filament Group; Licensed MIT */ /*! Shoestring - v2.0.0 - 2017-02-14 @@ -1818,6 +1818,14 @@ if (Tablesaw.mustard) { }; Table.prototype.init = function() { + if (!this.$thead.length) { + throw new Error("tablesaw: a is required, but none was found."); + } + + if (!this.$thead.find("th").length) { + throw new Error("tablesaw: no header cells found. Are you using inside of ?"); + } + // assign an id if there is none if (!this.$table.attr("id")) { this.$table.attr("id", pluginName + "-" + Math.round(Math.random() * 10000)); @@ -2398,8 +2406,8 @@ if (Tablesaw.mustard) { var header = self.getHeaderFromCheckbox(checkbox); var $cells = self.$getCells(header); - $cells[!checked ? "addClass" : "removeClass"]("tablesaw-cell-hidden"); - $cells[checked ? "addClass" : "removeClass"]("tablesaw-cell-visible"); + $cells[!checked ? "addClass" : "removeClass"]("tablesaw-toggle-cellhidden"); + $cells[checked ? "addClass" : "removeClass"]("tablesaw-toggle-cellvisible"); self.updateColspanIgnoredRows(checked, $(header).add(header.cells)); @@ -2580,7 +2588,7 @@ if (Tablesaw.mustard) { this.$table.removeClass(this.classes.columnToggleTable); this.$table.find("th, td").each(function() { var $cell = $(this); - $cell.removeClass("tablesaw-cell-hidden").removeClass("tablesaw-cell-visible"); + $cell.removeClass("tablesaw-toggle-cellhidden").removeClass("tablesaw-toggle-cellvisible"); this.className = this.className.replace(/\bui\-table\-priority\-\d\b/g, ""); }); @@ -2979,10 +2987,14 @@ if (Tablesaw.mustard) { var classes = { hideBtn: "disabled", persistWidths: "tablesaw-fix-persist", + hiddenCol: "tablesaw-swipe-cellhidden", + persistCol: "tablesaw-swipe-cellpersist", allColumnsVisible: "tablesaw-all-cols-visible" }; var attrs = { - disableTouchEvents: "data-tablesaw-no-touch" + disableTouchEvents: "data-tablesaw-no-touch", + ignorerow: "data-tablesaw-ignorerow", + subrow: "data-tablesaw-subrow" }; function createSwipeTable(tbl, $table) { @@ -3009,13 +3021,13 @@ if (Tablesaw.mustard) { var tableId = $table.attr("id"); if (!$headerCells.length) { - throw new Error( - "tablesaw swipe: no header cells found. Are you using inside of ?" - ); + throw new Error("tablesaw swipe: no header cells found."); } $table.addClass("tablesaw-swipe"); + $table.find("." + classes.hiddenCol).removeClass(classes.hiddenCol); + // Calculate initial widths $headerCells.each(function() { var width = this.offsetWidth; @@ -3030,25 +3042,53 @@ if (Tablesaw.mustard) { } function $getCells(headerCell) { - return $(headerCell.cells).add(headerCell); + return $(headerCell.cells).add(headerCell).filter(function() { + return !$(this).parent().is("[" + attrs.ignorerow + "],[" + attrs.subrow + "]"); + }); } function showColumn(headerCell) { - $getCells(headerCell).removeClass("tablesaw-cell-hidden"); + $getCells(headerCell).removeClass(classes.hiddenCol); } function hideColumn(headerCell) { - $getCells(headerCell).addClass("tablesaw-cell-hidden"); + $getCells(headerCell).addClass(classes.hiddenCol); } function persistColumn(headerCell) { - $getCells(headerCell).addClass("tablesaw-cell-persist"); + $getCells(headerCell).addClass(classes.persistCol); } function isPersistent(headerCell) { return $(headerCell).is('[data-tablesaw-priority="persist"]'); } + function countVisibleColspan() { + var count = 0; + $headerCells.each(function() { + var $t = $(this); + if ($t.is("." + classes.hiddenCol)) { + return; + } + count += parseInt($t.attr("colspan") || 1, 10); + }); + return count; + } + + function updateColspanOnIgnoredRows(newColspan) { + if (!newColspan) { + newColspan = countVisibleColspan(); + } + $table + .find("[" + attrs.ignorerow + "],[" + attrs.subrow + "]") + .find("td[colspan]") + .each(function() { + var $t = $(this); + var colspan = parseInt($t.attr("colspan"), 10); + $t.attr("colspan", newColspan); + }); + } + function unmaintainWidths() { $table.removeClass(classes.persistWidths); $("#" + tableId + "-persist").remove(); @@ -3071,7 +3111,9 @@ if (Tablesaw.mustard) { hash.push(index + "-" + width); styles.push( prefix + - " .tablesaw-cell-persist:nth-child(" + + " ." + + classes.persistCol + + ":nth-child(" + (index + 1) + ") { width: " + width + @@ -3104,7 +3146,7 @@ if (Tablesaw.mustard) { $headerCellsNoPersist.each(function(i) { var $t = $(this), - isHidden = $t.css("display") === "none" || $t.is(".tablesaw-cell-hidden"); + isHidden = $t.css("display") === "none" || $t.is("." + classes.hiddenCol); if (!isHidden && !checkFound) { checkFound = true; @@ -3164,15 +3206,19 @@ if (Tablesaw.mustard) { // We need at least one column to swipe. var needsNonPersistentColumn = visibleNonPersistantCount === 0; + var visibleColumnCount = 0; $headerCells.each(function(index) { + var colspan = parseInt($(this).attr("colspan") || 1, 10); if (persist[index]) { + visibleColumnCount += colspan; // for visual box-shadow persistColumn(this); return; } if (sums[index] <= containerWidth || needsNonPersistentColumn) { + visibleColumnCount += colspan; needsNonPersistentColumn = false; showColumn(this); } else { @@ -3180,7 +3226,9 @@ if (Tablesaw.mustard) { } }); + updateColspanOnIgnoredRows(visibleColumnCount); unmaintainWidths(); + $table.trigger("tablesawcolumns"); } @@ -3199,6 +3247,7 @@ if (Tablesaw.mustard) { hideColumn($headerCellsNoPersist.get(pair[0])); showColumn($headerCellsNoPersist.get(pair[1])); + updateColspanOnIgnoredRows(); $table.trigger("tablesawcolumns"); } diff --git a/package.json b/package.json index 4bfb79d..f8feb07 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "tablesaw", "title": "Tablesaw", "description": "A set of plugins for responsive tables.", - "version": "3.0.2", + "version": "3.0.3", "homepage": "https://github.com/filamentgroup/tablesaw", "author": { "name": "Zach Leatherman",