Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Fixes #304
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 16, 2017
1 parent 0972854 commit f84d4f6
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
@@ -0,0 +1,3 @@
src/tables.intro.jquery.js
src/tables.intro.shoestring.js
src/tables.outro.js
11 changes: 8 additions & 3 deletions Gruntfile.js
Expand Up @@ -127,7 +127,12 @@ module.exports = function(grunt) {
}
},
qunit: {
files: ['test/**/*.html']
files: ['test-qunit/**/*.html']
},
run: {
ava: {
exec: "./node_modules/.bin/ava"
}
},
watch: {
src: {
Expand Down Expand Up @@ -197,13 +202,13 @@ module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

// Default task.
grunt.registerTask('travis', ['qunit']);
grunt.registerTask('test', ['qunit', 'run:ava']);
grunt.registerTask('concat-pre', ['concat:jsautoinit', 'concat:jsall', 'concat:jsjquery', 'concat:jsstack', 'concat:jsstackjquery', 'concat:cssall', 'concat:cssstack', 'concat:cssstackmixinpre']);
grunt.registerTask('concat-post', ['concat:cssstackmixinpost']);
grunt.registerTask('src', ['concat-pre', 'myth', 'concat-post', 'clean:dependencies', 'copy', 'clean:post']);
grunt.registerTask('filesize', ['uglify', 'cssmin', 'bytesize', 'clean:post']);

grunt.registerTask('default', ['src', 'qunit', 'filesize']);
grunt.registerTask('default', ['src', 'test', 'filesize']);

// Deploy
grunt.registerTask('deploy', ['default', 'gh-pages']);
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -19,7 +19,7 @@ A set of plugins for responsive tables.
* [Check All](#check-all)
* [Internationalization i18n](#internationalization-i18n)
* [Limitations](#limitations)
* [Run Tests](http://filamentgroup.github.io/tablesaw/test/tablesaw.html)
* [Run Tests](http://filamentgroup.github.io/tablesaw/test-qunit/tablesaw.html)
* [Browser Support](#browser-support)

## Stack Mode
Expand Down Expand Up @@ -363,7 +363,7 @@ Some of the more intrusive default styles have instead moved to opt-in classes y
| `rowspan` | _Not yet supported_ ([#247](https://github.com/filamentgroup/tablesaw/issues/247)) | Supported | Supported | _Not yet supported_ ([#268](https://github.com/filamentgroup/tablesaw/issues/268)) |
| `colspan` | Supported | Supported | Supported | Supported |

## [Tests](http://filamentgroup.github.io/tablesaw/test/tablesaw.html)
## [Tests](http://filamentgroup.github.io/tablesaw/test-qunit/tablesaw.html)

## Browser Support

Expand Down
31 changes: 26 additions & 5 deletions package.json
Expand Up @@ -20,39 +20,60 @@
"node": ">= 4"
},
"scripts": {
"test": "./node_modules/.bin/grunt travis",
"test": "./node_modules/.bin/grunt test",
"precommit": "lint-staged",
"prepush": "grunt qunit"
"prepush": "grunt test"
},
"lint-staged": {
"src/*.js": [
"prettier --write --print-width 100 --use-tabs",
"git add"
]
},
"ava": {
"files": [
"test/**/*.test.js"
],
"require": [
"babel-register",
"./test/helpers/setup-browser-env.js"
],
"inherit": true,
"verbose": true
},
"babel": {
"presets": [
"@ava/stage-4"
]
},
"main": "dist/tablesaw.js",
"dependencies": {
"shoestring": "^2.0.0"
},
"devDependencies": {
"ava": "^0.23.0",
"babel-register": "^6.26.0",
"browser-env": "^3.2.2",
"console-advanced": "^1.0.7",
"grunt": "^1.0.1",
"grunt-bytesize": "~0.2.0",
"grunt-contrib-clean": "~1.1.0",
"grunt-contrib-compress": "~1.4.3",
"grunt-contrib-concat": "~1.0.1",
"grunt-contrib-copy": "~1.0.0",
"grunt-contrib-cssmin": "^2.2.0",
"grunt-contrib-qunit": "~2.0.0",
"grunt-contrib-qunit": "^2.0.0",
"grunt-contrib-uglify": "^3.0.1",
"grunt-contrib-watch": "~1.0.0",
"grunt-gh-pages": "~2.0.0",
"grunt-myth": "~1.1.0",
"grunt-run": "^0.8.0",
"husky": "^0.14.3",
"jquery": "^3.1.0",
"lint-staged": "^4.0.1",
"matchdep": "~1.0.1",
"prettier": "^1.5.2",
"qunitjs": "^2.0.0"
"prettier": "^1.8.2",
"qunitjs": "^2.4.1"
},
"optionalDependencies": {
"javascript-natural-sort": "^0.7.1"
Expand Down
6 changes: 5 additions & 1 deletion src/tables.btnmarkup.js
Expand Up @@ -22,7 +22,9 @@

if (sel) {
// TODO next major version: remove .btn-select
$(this).addClass("btn-select tablesaw-btn-select")[pluginName]("_select", sel);
$(this)
.addClass("btn-select tablesaw-btn-select")
[pluginName]("_select", sel);
}
return oEl;
},
Expand Down Expand Up @@ -90,4 +92,6 @@

// add methods
$.extend($.fn[pluginName].prototype, methods);

// TODO OOP this and add to Tablesaw object
})();
6 changes: 5 additions & 1 deletion src/tables.checkall.js
Expand Up @@ -31,7 +31,9 @@
CheckAll.prototype._filterCells = function($checkboxes) {
return $checkboxes
.filter(function() {
return !$(this).closest("tr").is("[data-tablesaw-subrow],[data-tablesaw-ignorerow]");
return !$(this)
.closest("tr")
.is("[data-tablesaw-subrow],[data-tablesaw-ignorerow]");
})
.find(this.checkboxSelector)
.not(this.checkAllSelector);
Expand Down Expand Up @@ -127,4 +129,6 @@
$(document).on(Tablesaw.events.create, function(e, tablesaw) {
new CheckAll(tablesaw);
});

Tablesaw.CheckAll = CheckAll;
})();
35 changes: 25 additions & 10 deletions src/tables.columntoggle.js
Expand Up @@ -136,15 +136,20 @@

if (self.set.length) {
var index;
$(self.$popup).find("input[type='checkbox']").each(function(j) {
if (this === e.target) {
index = j;
return false;
}
});
$(self.$popup)
.find("input[type='checkbox']")
.each(function(j) {
if (this === e.target) {
index = j;
return false;
}
});

$(self.set).each(function() {
var checkbox = $(this).data(data.key).$popup.find("input[type='checkbox']").get(index);
var checkbox = $(this)
.data(data.key)
.$popup.find("input[type='checkbox']")
.get(index);
if (checkbox) {
checkbox.checked = e.target.checked;
onToggleCheckboxChange(checkbox);
Expand Down Expand Up @@ -230,7 +235,11 @@
var invisibleColumns = 0;
this.$menu.find("input").each(function() {
var header = self.getHeaderFromCheckbox(this);
this.checked = self.tablesaw._$getCells(header).eq(0).css("display") === "table-cell";
this.checked =
self.tablesaw
._$getCells(header)
.eq(0)
.css("display") === "table-cell";
});

this.updateColspanCells();
Expand Down Expand Up @@ -260,13 +269,19 @@

$(document).on(Tablesaw.events.destroy, function(e, tablesaw) {
if (tablesaw.mode === "columntoggle") {
$(tablesaw.table).data(data.key).destroy();
$(tablesaw.table)
.data(data.key)
.destroy();
}
});

$(document).on(Tablesaw.events.refresh, function(e, tablesaw) {
if (tablesaw.mode === "columntoggle") {
$(tablesaw.table).data(data.key).refreshPriority();
$(tablesaw.table)
.data(data.key)
.refreshPriority();
}
});

Tablesaw.ColumnToggle = ColumnToggle;
})();
6 changes: 4 additions & 2 deletions src/tables.intro.jquery.js
Expand Up @@ -19,8 +19,10 @@
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
return {
$: jQuery,
Tablesaw: factory(jQuery)
};
};
} else {
// Browser globals
Expand Down
7 changes: 5 additions & 2 deletions src/tables.intro.shoestring.js
Expand Up @@ -19,8 +19,11 @@
shoestring = require('shoestring')(root);
}
}
factory(shoestring);
return shoestring;

return {
$: shoestring,
Tablesaw: factory(shoestring)
};
};
} else {
// Browser globals
Expand Down
59 changes: 39 additions & 20 deletions src/tables.js
Expand Up @@ -69,7 +69,10 @@ if (Tablesaw.mustard) {
this.$table = $(element);

// only one <thead> and <tfoot> are allowed, per the specification
this.$thead = this.$table.children().filter("thead").eq(0);
this.$thead = this.$table
.children()
.filter("thead")
.eq(0);

// multiple <tbody> are allowed, per the specification
this.$tbody = this.$table.children().filter("tbody");
Expand Down Expand Up @@ -120,9 +123,12 @@ if (Tablesaw.mustard) {
};

Table.prototype._getHeaderRows = function() {
return this.$thead.children().filter("tr").filter(function() {
return !$(this).is("[data-tablesaw-ignorerow]");
});
return this.$thead
.children()
.filter("tr")
.filter(function() {
return !$(this).is("[data-tablesaw-ignorerow]");
});
};

Table.prototype._getRowIndex = function($row) {
Expand All @@ -144,16 +150,18 @@ if (Tablesaw.mustard) {

Table.prototype._$getCells = function(th) {
var self = this;
return $(th).add(th.cells).filter(function() {
var $t = $(this);
var $row = $t.parent();
var hasColspan = $t.is("[colspan]");
// no subrows or ignored rows (keep cells in ignored rows that do not have a colspan)
return (
!$row.is("[" + self.attributes.subrow + "]") &&
(!$row.is("[" + self.attributes.ignorerow + "]") || !hasColspan)
);
});
return $(th)
.add(th.cells)
.filter(function() {
var $t = $(this);
var $row = $t.parent();
var hasColspan = $t.is("[colspan]");
// no subrows or ignored rows (keep cells in ignored rows that do not have a colspan)
return (
!$row.is("[" + self.attributes.subrow + "]") &&
(!$row.is("[" + self.attributes.ignorerow + "]") || !hasColspan)
);
});
};

Table.prototype._getVisibleColspan = function() {
Expand Down Expand Up @@ -188,9 +196,11 @@ if (Tablesaw.mustard) {
};

Table.prototype.isCellInColumn = function(header, cell) {
return $(header).add(header.cells).filter(function() {
return this === cell;
}).length;
return $(header)
.add(header.cells)
.filter(function() {
return this === cell;
}).length;
};

Table.prototype.updateColspanCells = function(cls, header, userAction) {
Expand Down Expand Up @@ -273,7 +283,9 @@ if (Tablesaw.mustard) {
Table.prototype.getRows = function() {
var self = this;
return this.$table.find("tr").filter(function() {
return $(this).closest("table").is(self.$table);
return $(this)
.closest("table")
.is(self.$table);
});
};

Expand Down Expand Up @@ -397,7 +409,9 @@ if (Tablesaw.mustard) {
var $anchor = this._getToolbarAnchor();
var $toolbar = this._getToolbar($anchor);
if (!$toolbar.length) {
$toolbar = $("<div>").addClass(classes.toolbar).insertBefore($anchor);
$toolbar = $("<div>")
.addClass(classes.toolbar)
.insertBefore($anchor);
}
this.$toolbar = $toolbar;

Expand Down Expand Up @@ -440,7 +454,10 @@ if (Tablesaw.mustard) {
$doc.on("enhance.tablesaw", function(e) {
// Cut the mustard
if (Tablesaw.mustard) {
$(e.target).find(initSelector).filter(initFilterSelector)[pluginName]();
$(e.target)
.find(initSelector)
.filter(initFilterSelector)
[pluginName]();
}
});

Expand Down Expand Up @@ -468,4 +485,6 @@ if (Tablesaw.mustard) {
}, 150); // must be less than the scrolling timeout above.
}
});

Tablesaw.Table = Table;
})();

0 comments on commit f84d4f6

Please sign in to comment.