diff --git a/dist/starter.html b/dist/starter.html
index ef2547b2..7b3e0abf 100644
--- a/dist/starter.html
+++ b/dist/starter.html
@@ -1,10 +1,10 @@
- tablefilter v0.2.0 - Starter
+ tablefilter v0.2.1 - Starter
-tablefilter v0.2.0
+tablefilter v0.2.1
diff --git a/dist/tablefilter/style/colsVisibility.css b/dist/tablefilter/style/colsVisibility.css
index b62917cc..552bdca1 100644
--- a/dist/tablefilter/style/colsVisibility.css
+++ b/dist/tablefilter/style/colsVisibility.css
@@ -1,6 +1,6 @@
/**
* tablefilter v0.2.0 by Max Guglielmi
- * build date: 2016-03-18T05:56:15.430Z
+ * build date: 2016-03-19T11:33:23.153Z
* MIT License
*/
span.colVisSpan{text-align:left;}span.colVisSpan a.colVis{display:inline-block;padding:7px 5px 0;font-size:inherit;font-weight:inherit;vertical-align:top}div.colVisCont{position:relative;background:#fff;-webkit-box-shadow:3px 3px 2px #888;-moz-box-shadow:3px 3px 2px #888;box-shadow:3px 3px 2px #888;position:absolute;display:none;border:1px solid #ccc;height:auto;width:250px;background-color:#fff;margin:35px 0 0 -100px;z-index:10000;padding:10px 10px 10px 10px;text-align:left;font-size:12px;}div.colVisCont:after,div.colVisCont:before{bottom:100%;left:50%;border:solid transparent;content:" ";height:0;width:0;position:absolute;pointer-events:none}div.colVisCont:after{border-color:rgba(255,255,255,0);border-bottom-color:#fff;border-width:10px;margin-left:-10px}div.colVisCont:before{border-color:rgba(255,255,255,0);border-bottom-color:#ccc;border-width:12px;margin-left:-12px}div.colVisCont p{margin:6px auto 6px auto}div.colVisCont a.colVis{display:initial;font-weight:inherit}ul.cols_checklist{padding:0;margin:0;list-style:none;}ul.cols_checklist label{display:block}ul.cols_checklist input{vertical-align:middle;margin:2px 5px 2px 1px}li.cols_checklist_item{padding:4px;margin:0;}li.cols_checklist_item:hover{background-color:#335ea8;color:#fff}.cols_checklist_slc_item{background-color:#335ea8;color:#fff}
\ No newline at end of file
diff --git a/dist/tablefilter/style/filtersVisibility.css b/dist/tablefilter/style/filtersVisibility.css
index 8353ecad..02e24ba6 100644
--- a/dist/tablefilter/style/filtersVisibility.css
+++ b/dist/tablefilter/style/filtersVisibility.css
@@ -1,6 +1,6 @@
/**
* tablefilter v0.2.0 by Max Guglielmi
- * build date: 2016-03-18T05:56:15.430Z
+ * build date: 2016-03-19T11:33:23.153Z
* MIT License
*/
span.expClpFlt a.btnExpClpFlt{width:35px;height:35px;display:inline-block;}span.expClpFlt a.btnExpClpFlt:hover{background-color:#f4f4f4}span.expClpFlt img{padding:8px 11px 11px 11px}
\ No newline at end of file
diff --git a/dist/tablefilter/style/tablefilter.css b/dist/tablefilter/style/tablefilter.css
index 0db68fbd..08b621ee 100644
--- a/dist/tablefilter/style/tablefilter.css
+++ b/dist/tablefilter/style/tablefilter.css
@@ -1,6 +1,6 @@
/**
* tablefilter v0.2.0 by Max Guglielmi
- * build date: 2016-03-18T05:56:15.430Z
+ * build date: 2016-03-19T11:33:23.153Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}
diff --git a/dist/tablefilter/style/themes/default/default.css b/dist/tablefilter/style/themes/default/default.css
index b0a2e6b6..72fc0783 100644
--- a/dist/tablefilter/style/themes/default/default.css
+++ b/dist/tablefilter/style/themes/default/default.css
@@ -1,6 +1,6 @@
/**
* tablefilter v0.2.0 by Max Guglielmi
- * build date: 2016-03-18T05:56:15.430Z
+ * build date: 2016-03-19T11:33:23.153Z
* MIT License
*/
table.TF{border-left:1px solid #ccc;border-top:none;border-right:none;border-bottom:none;}table.TF th{background:#ebecee url("images/bg_th.jpg") left top repeat-x;border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;border-left:1px solid #fff;border-top:1px solid #fff;color:#333}table.TF td{border-bottom:1px dotted #999;padding:5px}.fltrow{background-color:#ebecee !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #666 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #999 !important}input.flt{width:99% !important}.inf{height:$min-height;background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important}input.reset{background:transparent url("images/btn_eraser.gif") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;}.nextPage:hover{background:transparent url("images/btn_over_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important;}.previousPage:hover{background:transparent url("images/btn_over_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;}.firstPage:hover{background:transparent url("images/btn_over_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;}.lastPage:hover{background:transparent url("images/btn_over_last_page.gif") center center no-repeat !important}div.grd_Cont{background-color:#ebecee !important;border:1px solid #ccc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#d5d5d5}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important;}div.grd_headTblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#ebecee url("images/bg_th.jpg") left top repeat-x !important;border-bottom:1px solid #d0d0d0 !important;border-right:1px solid #d0d0d0 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #999 !important}.grd_inf{background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important;border-top:1px solid #d0d0d0 !important}.loader{border:1px solid #999}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#fff}.odd{background-color:#d5d5d5}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#999 !important}
\ No newline at end of file
diff --git a/dist/tablefilter/style/themes/mytheme/mytheme.css b/dist/tablefilter/style/themes/mytheme/mytheme.css
index e9db41b7..7b2dd28f 100644
--- a/dist/tablefilter/style/themes/mytheme/mytheme.css
+++ b/dist/tablefilter/style/themes/mytheme/mytheme.css
@@ -1,6 +1,6 @@
/**
* tablefilter v0.2.0 by Max Guglielmi
- * build date: 2016-03-18T05:56:15.430Z
+ * build date: 2016-03-19T11:33:23.153Z
* MIT License
*/
table.TF{border-left:1px dotted #81963b;border-top:none;border-right:0;border-bottom:none;}table.TF th{background:#39424b url("images/bg_headers.jpg") left top repeat-x;border-bottom:0;border-right:1px dotted #d0d0d0;border-left:0;border-top:0;color:#fff}table.TF td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b;padding:5px}.fltrow{background-color:#81963b !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #687830 !important}input.flt{width:99% !important}.inf{background:#d8d8d8;height:$min-height}input.reset{width:53px;background:transparent url("images/btn_filter.png") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important}div.grd_Cont{background:#81963b url("images/bg_headers.jpg") left top repeat-x !important;border:1px solid #ccc !important;padding:0 1px 1px 1px !important;}div.grd_Cont .even{background-color:#bccd83}div.grd_Cont .odd{background-color:#fff}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important;}div.grd_tblCont table td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b}div.grd_tblCont table th,div.grd_headTblCont table th{background:transparent url("images/bg_headers.jpg") 0 0 repeat-x !important;border-bottom:0 !important;border-right:1px dotted #d0d0d0 !important;border-left:0 !important;border-top:0 !important;padding:0 4px 0 4px !important;color:#fff !important;height:35px !important}div.grd_headTblCont table td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;background-color:#81963b !important;padding:1px 3px 1px 3px !important}.grd_inf{background-color:#d8d8d8;border-top:1px solid #d0d0d0 !important}.loader{border:0 !important;background:#81963b !important}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#bccd83}.odd{background-color:#fff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#81963b !important}
\ No newline at end of file
diff --git a/dist/tablefilter/style/themes/skyblue/skyblue.css b/dist/tablefilter/style/themes/skyblue/skyblue.css
index 6efd8284..bfc55188 100644
--- a/dist/tablefilter/style/themes/skyblue/skyblue.css
+++ b/dist/tablefilter/style/themes/skyblue/skyblue.css
@@ -1,6 +1,6 @@
/**
* tablefilter v0.2.0 by Max Guglielmi
- * build date: 2016-03-18T05:56:15.430Z
+ * build date: 2016-03-19T11:33:23.153Z
* MIT License
*/
table.TF{padding:0;color:#000;border-right:1px solid #a4bed4;border-top:1px solid #a4bed4;border-left:1px solid #a4bed4;border-bottom:0;}table.TF th{margin:0;color:inherit;background:#d1e5fe url("images/bg_skyblue.gif") 0 0 repeat-x;border-color:#fdfdfd #a4bed4 #a4bed4 #fdfdfd;border-width:1px;border-style:solid}table.TF td{margin:0;padding:5px;color:inherit;border-bottom:1px solid #a4bed4;border-left:0;border-top:0;border-right:0}.fltrow{background-color:#d1e5fe !important;}.fltrow th,.fltrow td{padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #a4bed4 !important}input.flt{width:99% !important}.inf{background-color:#e3efff !important;border:1px solid #a4bed4;height:$min-height;color:#004a6f}div.tot,div.status{border-right:0 !important}.helpBtn:hover{background-color:transparent}input.reset{background:transparent url("images/icn_clear_filters.png") center center no-repeat !important}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.nextPage:hover{background:#ffe4ab url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.previousPage{background:transparent url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.previousPage:hover{background:#ffe4ab url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.firstPage:hover{background:#ffe4ab url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.lastPage:hover{background:#ffe4ab url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.activeHeader{background:#ffe4ab !important;border:1px solid #ffb552 !important;color:inherit !important}div.grd_Cont{background-color:#d9eaed !important;border:1px solid #9cc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#e3efff}div.grd_headTblCont{background-color:#d9eaed !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#d9eaed url("images/bg_skyblue.gif") left top repeat-x;border-bottom:1px solid #a4bed4;border-right:1px solid #a4bed4 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #a4bed4 !important;border-right:0 !important;border-left:0 !important;border-top:0 !important}.grd_inf{background-color:#cce2fe;color:#004a6f;border-top:1px solid #9cc !important;}.grd_inf a{text-decoration:none;font-weight:bold}.loader{background-color:#2d8eef;border:1px solid #cce2fe;border-radius:5px}.even{background-color:#fff}.odd{background-color:#e3efff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.ezActiveRow{background-color:#ffdc61 !important;color:inherit}.ezSelectedRow{background-color:#ffe4ab !important;color:inherit}.ezActiveCell{background-color:#fff !important;color:#000 !important;font-weight:bold}.ezETSelectedCell{background-color:#fff !important;font-weight:bold;color:#000 !important}
\ No newline at end of file
diff --git a/dist/tablefilter/tablefilter.js b/dist/tablefilter/tablefilter.js
index 4e0faf77..6d94825a 100644
--- a/dist/tablefilter/tablefilter.js
+++ b/dist/tablefilter/tablefilter.js
@@ -173,7 +173,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _noResults = __webpack_require__(25);
- var _stateful = __webpack_require__(26);
+ var _state = __webpack_require__(26);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -487,7 +487,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.noResults = _types2.default.isObj(f.no_results_message) || Boolean(f.no_results_message);
// stateful
- this.isStateful = _types2.default.isObj(f.stateful) || Boolean(f.stateful);
+ this.hasState = _types2.default.isObj(f.state) || Boolean(f.state);
/*** data types ***/
//defines default date type (european DMY)
@@ -667,11 +667,11 @@ return /******/ (function(modules) { // webpackBootstrap
Mod.help.init();
}
- if (this.isStateful) {
- if (!Mod.stateful) {
- Mod.stateful = new _stateful.Stateful(tf);
+ if (this.hasState) {
+ if (!Mod.state) {
+ Mod.state = new _state.State(this);
}
- Mod.stateful.init();
+ Mod.state.init();
}
if (this.hasPersistence) {
@@ -1013,7 +1013,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
// Require pattern for Webpack
- __webpack_require__.e/* require */(1, function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [__webpack_require__(27)("./" + modulePath)]; (function (mod) {
+ __webpack_require__.e/* require */(1, function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [__webpack_require__(28)("./" + modulePath)]; (function (mod) {
/* eslint-disable */
var inst = new mod.default(_this4, ext);
/* eslint-enable */
@@ -7716,20 +7716,18 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(exports, "__esModule", {
value: true
});
- exports.Stateful = undefined;
+ exports.State = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _feature = __webpack_require__(11);
+ var _hash = __webpack_require__(27);
+
var _string = __webpack_require__(3);
var _string2 = _interopRequireDefault(_string);
- var _event = __webpack_require__(1);
-
- var _event2 = _interopRequireDefault(_event);
-
var _types = __webpack_require__(4);
var _types2 = _interopRequireDefault(_types);
@@ -7742,37 +7740,30 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- var global = window;
- var JSON = global.JSON;
- var location = global.location;
- var hasHashChange = function hasHashChange() {
- var docMode = global.documentMode;
- return 'onhashchange' in global && (docMode === undefined || docMode > 7);
- };
-
- var Stateful = exports.Stateful = function (_Feature) {
- _inherits(Stateful, _Feature);
+ var State = exports.State = function (_Feature) {
+ _inherits(State, _Feature);
/**
- * Creates an instance of Stateful.
+ * Creates an instance of State
*
* @param tf TableFilter instance
*/
- function Stateful(tf) {
- _classCallCheck(this, Stateful);
+ function State(tf) {
+ _classCallCheck(this, State);
- var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Stateful).call(this, tf, 'stateful'));
+ var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(State).call(this, tf, 'state'));
- var cfg = _this.config.stateful;
+ var cfg = _this.config.state;
+ _this.enableHash = cfg.type.indexOf('hash') !== -1;
_this.persistFilters = cfg.filters === false ? false : true;
_this.persistPageNumber = Boolean(cfg.page_number);
_this.persistPageLength = Boolean(cfg.page_length);
+ _this.hash = null;
_this.pageNb = null;
_this.pageLength = null;
- _this.lastHash = null;
_this.state = {};
_this.prfxCol = 'col_';
@@ -7781,18 +7772,15 @@ return /******/ (function(modules) { // webpackBootstrap
return _this;
}
- _createClass(Stateful, [{
+ _createClass(State, [{
key: 'init',
value: function init() {
var _this2 = this;
- if (this.initialized || !hasHashChange()) {
+ if (this.initialized) {
return;
}
- this.emitter.on(['initialized'], function () {
- return _this2.sync();
- });
this.emitter.on(['after-filtering'], function () {
return _this2.update();
});
@@ -7803,16 +7791,15 @@ return /******/ (function(modules) { // webpackBootstrap
return _this2.updatePageLength(index);
});
- _event2.default.add(global, 'hashchange', function () {
- return _this2.sync();
- });
-
- this.lastHash = location.hash;
+ if (this.enableHash) {
+ this.hash = new _hash.Hash(this);
+ this.hash.init();
+ }
this.initialized = true;
}
}, {
- key: 'format',
- value: function format() {
+ key: 'update',
+ value: function update() {
var _this3 = this;
var tf = this.tf;
@@ -7849,30 +7836,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.state[this.pageLengthKey] = this.pageLength;
}
}
-
- return '#' + JSON.stringify(this.state);
- }
- }, {
- key: 'parse',
- value: function parse(hash) {
- if (hash.indexOf('#') === 0) {
- hash = hash.substr(1);
- } else {
- hash = '{}';
- }
- return JSON.parse(hash);
- }
- }, {
- key: 'update',
- value: function update() {
- var hash = this.format();
- console.log(hash, this.lastHash, this.lastHash === hash);
- if (this.lastHash === hash) {
- return;
- }
-
- location.hash = hash;
- this.lastHash = hash;
+ this.emitter.emit('state-changed', tf, this.state);
}
}, {
key: 'updatePage',
@@ -7891,7 +7855,7 @@ return /******/ (function(modules) { // webpackBootstrap
value: function sync() {
var _this4 = this;
- var state = this.parse(location.hash);
+ var state = this.state;
console.log('sync', state);
var tf = this.tf;
@@ -7926,9 +7890,6 @@ return /******/ (function(modules) { // webpackBootstrap
return;
}
- this.emitter.off(['initialized'], function () {
- return _this5.sync();
- });
this.emitter.off(['after-filtering'], function () {
return _this5.update();
});
@@ -7939,16 +7900,128 @@ return /******/ (function(modules) { // webpackBootstrap
return _this5.updatePageLength(index);
});
- _event2.default.remove(global, 'hashchange', function () {
- return _this5.sync();
- });
+ if (this.enableHash) {
+ this.hash.destroy();
+ this.hash = null;
+ }
+
this.initialized = false;
}
}]);
- return Stateful;
+ return State;
}(_feature.Feature);
+/***/ },
+/* 27 */
+/***/ function(module, exports, __webpack_require__) {
+
+ 'use strict';
+
+ Object.defineProperty(exports, "__esModule", {
+ value: true
+ });
+ exports.Hash = undefined;
+
+ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // import Str from '../string';
+
+
+ var _event = __webpack_require__(1);
+
+ var _event2 = _interopRequireDefault(_event);
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+ // import Types from '../types';
+
+ var global = window;
+ var JSON = global.JSON;
+ var location = global.location;
+ var hasHashChange = function hasHashChange() {
+ var docMode = global.documentMode;
+ return 'onhashchange' in global && (docMode === undefined || docMode > 7);
+ };
+
+ var Hash = exports.Hash = function () {
+ function Hash(state) {
+ _classCallCheck(this, Hash);
+
+ this.state = state;
+ this.lastHash = location.hash;
+ this.emitter = state.emitter;
+ }
+
+ _createClass(Hash, [{
+ key: 'init',
+ value: function init() {
+ var _this = this;
+
+ if (!hasHashChange()) {
+ return;
+ }
+ this.emitter.on(['state-changed'], function (tf, state) {
+ return _this.update(state);
+ });
+ this.emitter.on(['initialized'], function () {
+ return _this.sync();
+ });
+ _event2.default.add(global, 'hashchange', function () {
+ return _this.sync();
+ });
+ }
+ }, {
+ key: 'update',
+ value: function update(state) {
+ var hash = '#' + JSON.stringify(state);
+ console.log(hash, this.lastHash, this.lastHash === hash);
+ if (this.lastHash === hash) {
+ return;
+ }
+
+ location.hash = hash;
+ this.lastHash = hash;
+ }
+ }, {
+ key: 'parse',
+ value: function parse(hash) {
+ if (hash.indexOf('#') === -1) {
+ return null;
+ }
+ hash = hash.substr(1);
+ return JSON.parse(hash);
+ }
+ }, {
+ key: 'sync',
+ value: function sync() {
+ var hash = this.parse(location.hash);
+ if (!hash) {
+ return;
+ }
+ this.state.state = hash;
+ this.state.sync();
+ }
+ }, {
+ key: 'destroy',
+ value: function destroy() {
+ var _this2 = this;
+
+ this.emitter.off(['state-changed'], function (tf, state) {
+ return _this2.update(state);
+ });
+ this.emitter.off(['initialized'], function () {
+ return _this2.sync();
+ });
+ _event2.default.aremove(global, 'hashchange', function () {
+ return _this2.sync();
+ });
+ }
+ }]);
+
+ return Hash;
+ }();
+
/***/ }
/******/ ])
});
diff --git a/dist/tablefilter/tf-1.js b/dist/tablefilter/tf-1.js
index 6d551761..be5397d8 100644
--- a/dist/tablefilter/tf-1.js
+++ b/dist/tablefilter/tf-1.js
@@ -1,6 +1,6 @@
webpackJsonp([1],{
-/***/ 27:
+/***/ 28:
/***/ function(module, exports, __webpack_require__) {
var map = {
@@ -16,20 +16,20 @@ webpackJsonp([1],{
"./emitter.js": 7,
"./event": 1,
"./event.js": 1,
- "./extensions/advancedGrid/adapterEzEditTable": 28,
- "./extensions/advancedGrid/adapterEzEditTable.js": 28,
- "./extensions/advancedGrid/advancedGrid": 29,
- "./extensions/advancedGrid/advancedGrid.js": 29,
- "./extensions/colOps/colOps": 30,
- "./extensions/colOps/colOps.js": 30,
- "./extensions/colsVisibility/colsVisibility": 31,
- "./extensions/colsVisibility/colsVisibility.js": 31,
- "./extensions/filtersVisibility/filtersVisibility": 32,
- "./extensions/filtersVisibility/filtersVisibility.js": 32,
- "./extensions/sort/adapterSortabletable": 33,
- "./extensions/sort/adapterSortabletable.js": 33,
- "./extensions/sort/sort": 34,
- "./extensions/sort/sort.js": 34,
+ "./extensions/advancedGrid/adapterEzEditTable": 29,
+ "./extensions/advancedGrid/adapterEzEditTable.js": 29,
+ "./extensions/advancedGrid/advancedGrid": 30,
+ "./extensions/advancedGrid/advancedGrid.js": 30,
+ "./extensions/colOps/colOps": 31,
+ "./extensions/colOps/colOps.js": 31,
+ "./extensions/colsVisibility/colsVisibility": 32,
+ "./extensions/colsVisibility/colsVisibility.js": 32,
+ "./extensions/filtersVisibility/filtersVisibility": 33,
+ "./extensions/filtersVisibility/filtersVisibility.js": 33,
+ "./extensions/sort/adapterSortabletable": 34,
+ "./extensions/sort/adapterSortabletable.js": 34,
+ "./extensions/sort/sort": 35,
+ "./extensions/sort/sort.js": 35,
"./helpers": 6,
"./helpers.js": 6,
"./modules/alternateRows": 24,
@@ -44,6 +44,8 @@ webpackJsonp([1],{
"./modules/feature.js": 11,
"./modules/gridLayout": 10,
"./modules/gridLayout.js": 10,
+ "./modules/hash": 27,
+ "./modules/hash.js": 27,
"./modules/help": 23,
"./modules/help.js": 23,
"./modules/highlightKeywords": 13,
@@ -58,8 +60,8 @@ webpackJsonp([1],{
"./modules/popupFilter.js": 14,
"./modules/rowsCounter": 19,
"./modules/rowsCounter.js": 19,
- "./modules/stateful": 26,
- "./modules/stateful.js": 26,
+ "./modules/state": 26,
+ "./modules/state.js": 26,
"./modules/statusBar": 20,
"./modules/statusBar.js": 20,
"./modules/store": 8,
@@ -82,12 +84,12 @@ webpackJsonp([1],{
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
- webpackContext.id = 27;
+ webpackContext.id = 28;
/***/ },
-/***/ 28:
+/***/ 29:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -573,7 +575,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 29:
+/***/ 30:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -582,7 +584,7 @@ webpackJsonp([1],{
value: true
});
- var _adapterEzEditTable = __webpack_require__(28);
+ var _adapterEzEditTable = __webpack_require__(29);
var _adapterEzEditTable2 = _interopRequireDefault(_adapterEzEditTable);
@@ -592,7 +594,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 30:
+/***/ 31:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -945,7 +947,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 31:
+/***/ 32:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -1533,7 +1535,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 32:
+/***/ 33:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -1755,7 +1757,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 33:
+/***/ 34:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -2215,7 +2217,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 34:
+/***/ 35:
/***/ function(module, exports, __webpack_require__) {
'use strict';
@@ -2224,14 +2226,14 @@ webpackJsonp([1],{
value: true
});
- var _adapterSortabletable = __webpack_require__(33);
+ var _adapterSortabletable = __webpack_require__(34);
var _adapterSortabletable2 = _interopRequireDefault(_adapterSortabletable);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (!window.SortableTable) {
- __webpack_require__(35);
+ __webpack_require__(36);
} // import 'script!sortabletable';
@@ -2239,14 +2241,14 @@ webpackJsonp([1],{
/***/ },
-/***/ 35:
+/***/ 36:
/***/ function(module, exports, __webpack_require__) {
- __webpack_require__(36)(__webpack_require__(37)+"\n\n// SCRIPT-LOADER FOOTER\n//# sourceURL=script:///C:/Users/max.guglielmi/Documents/dev/perso/javascript/GitHub/TableFilter/libs/sortabletable.js")
+ __webpack_require__(37)(__webpack_require__(38)+"\n\n// SCRIPT-LOADER FOOTER\n//# sourceURL=script:///C:/Users/max.guglielmi/Documents/dev/perso/javascript/GitHub/TableFilter/libs/sortabletable.js")
/***/ },
-/***/ 36:
+/***/ 37:
/***/ function(module, exports) {
/*
@@ -2262,7 +2264,7 @@ webpackJsonp([1],{
/***/ },
-/***/ 37:
+/***/ 38:
/***/ function(module, exports) {
module.exports = "/*----------------------------------------------------------------------------\\\r\n| Sortable Table 1.12 |\r\n|-----------------------------------------------------------------------------|\r\n| Created by Erik Arvidsson |\r\n| (http://webfx.eae.net/contact.html#erik) |\r\n| For WebFX (http://webfx.eae.net/) |\r\n|-----------------------------------------------------------------------------|\r\n| A DOM 1 based script that allows an ordinary HTML table to be sortable. |\r\n|-----------------------------------------------------------------------------|\r\n| Copyright (c) 1998 - 2006 Erik Arvidsson |\r\n|-----------------------------------------------------------------------------|\r\n| Licensed under the Apache License, Version 2.0 (the \"License\"); you may not |\r\n| use this file except in compliance with the License. You may obtain a copy |\r\n| of the License at http://www.apache.org/licenses/LICENSE-2.0 |\r\n| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |\r\n| Unless required by applicable law or agreed to in writing, software |\r\n| distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT |\r\n| WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |\r\n| License for the specific language governing permissions and limitations |\r\n| under the License. |\r\n|-----------------------------------------------------------------------------|\r\n| 2003-01-10 | First version |\r\n| 2003-01-19 | Minor changes to the date parsing |\r\n| 2003-01-28 | JScript 5.0 fixes (no support for 'in' operator) |\r\n| 2003-02-01 | Sloppy typo like error fixed in getInnerText |\r\n| 2003-07-04 | Added workaround for IE cellIndex bug. |\r\n| 2003-11-09 | The bDescending argument to sort was not correctly working |\r\n| | Using onclick DOM0 event if no support for addEventListener |\r\n| | or attachEvent |\r\n| 2004-01-13 | Adding addSortType and removeSortType which makes it a lot |\r\n| | easier to add new, custom sort types. |\r\n| 2004-01-27 | Switch to use descending = false as the default sort order. |\r\n| | Change defaultDescending to suit your needs. |\r\n| 2004-03-14 | Improved sort type None look and feel a bit |\r\n| 2004-08-26 | Made the handling of tBody and tHead more flexible. Now you |\r\n| | can use another tHead or no tHead, and you can chose some |\r\n| | other tBody. |\r\n| 2006-04-25 | Changed license to Apache Software License 2.0 |\r\n|-----------------------------------------------------------------------------|\r\n| Created 2003-01-10 | All changes are in the log above. | Updated 2006-04-25 |\r\n\\----------------------------------------------------------------------------*/\r\n\r\n\r\nfunction SortableTable(oTable, oSortTypes) {\r\n\r\n\tthis.sortTypes = oSortTypes || [];\r\n\r\n\tthis.sortColumn = null;\r\n\tthis.descending = null;\r\n\r\n\tvar oThis = this;\r\n\tthis._headerOnclick = function (e) {\r\n\t\toThis.headerOnclick(e);\r\n\t};\r\n\r\n\tif (oTable) {\r\n\t\tthis.setTable( oTable );\r\n\t\tthis.document = oTable.ownerDocument || oTable.document;\r\n\t}\r\n\telse {\r\n\t\tthis.document = document;\r\n\t}\r\n\r\n\r\n\t// only IE needs this\r\n\tvar win = this.document.defaultView || this.document.parentWindow;\r\n\tthis._onunload = function () {\r\n\t\toThis.destroy();\r\n\t};\r\n\tif (win && typeof win.attachEvent != \"undefined\") {\r\n\t\twin.attachEvent(\"onunload\", this._onunload);\r\n\t}\r\n}\r\n\r\nSortableTable.gecko = navigator.product == \"Gecko\";\r\nSortableTable.msie = /msie/i.test(navigator.userAgent);\r\n// Mozilla is faster when doing the DOM manipulations on\r\n// an orphaned element. MSIE is not\r\nSortableTable.removeBeforeSort = SortableTable.gecko;\r\n\r\nSortableTable.prototype.onsort = function () {};\r\n\r\n// default sort order. true -> descending, false -> ascending\r\nSortableTable.prototype.defaultDescending = false;\r\n\r\n// shared between all instances. This is intentional to allow external files\r\n// to modify the prototype\r\nSortableTable.prototype._sortTypeInfo = {};\r\n\r\nSortableTable.prototype.setTable = function (oTable) {\r\n\tif ( this.tHead )\r\n\t\tthis.uninitHeader();\r\n\tthis.element = oTable;\r\n\tthis.setTHead( oTable.tHead );\r\n\tthis.setTBody( oTable.tBodies[0] );\r\n};\r\n\r\nSortableTable.prototype.setTHead = function (oTHead) {\r\n\tif (this.tHead && this.tHead != oTHead )\r\n\t\tthis.uninitHeader();\r\n\tthis.tHead = oTHead;\r\n\tthis.initHeader( this.sortTypes );\r\n};\r\n\r\nSortableTable.prototype.setTBody = function (oTBody) {\r\n\tthis.tBody = oTBody;\r\n};\r\n\r\nSortableTable.prototype.setSortTypes = function ( oSortTypes ) {\r\n\tif ( this.tHead )\r\n\t\tthis.uninitHeader();\r\n\tthis.sortTypes = oSortTypes || [];\r\n\tif ( this.tHead )\r\n\t\tthis.initHeader( this.sortTypes );\r\n};\r\n\r\n// adds arrow containers and events\r\n// also binds sort type to the header cells so that reordering columns does\r\n// not break the sort types\r\nSortableTable.prototype.initHeader = function (oSortTypes) {\r\n\tif (!this.tHead) return;\r\n\tvar cells = this.tHead.rows[0].cells;\r\n\tvar doc = this.tHead.ownerDocument || this.tHead.document;\r\n\tthis.sortTypes = oSortTypes || [];\r\n\tvar l = cells.length;\r\n\tvar img, c;\r\n\tfor (var i = 0; i < l; i++) {\r\n\t\tc = cells[i];\r\n\t\tif (this.sortTypes[i] != null && this.sortTypes[i] != \"None\") {\r\n\t\t\timg = doc.createElement(\"IMG\");\r\n\t\t\timg.src = \"images/blank.png\";\r\n\t\t\tc.appendChild(img);\r\n\t\t\tif (this.sortTypes[i] != null)\r\n\t\t\t\tc._sortType = this.sortTypes[i];\r\n\t\t\tif (typeof c.addEventListener != \"undefined\")\r\n\t\t\t\tc.addEventListener(\"click\", this._headerOnclick, false);\r\n\t\t\telse if (typeof c.attachEvent != \"undefined\")\r\n\t\t\t\tc.attachEvent(\"onclick\", this._headerOnclick);\r\n\t\t\telse\r\n\t\t\t\tc.onclick = this._headerOnclick;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tc.setAttribute( \"_sortType\", oSortTypes[i] );\r\n\t\t\tc._sortType = \"None\";\r\n\t\t}\r\n\t}\r\n\tthis.updateHeaderArrows();\r\n};\r\n\r\n// remove arrows and events\r\nSortableTable.prototype.uninitHeader = function () {\r\n\tif (!this.tHead) return;\r\n\tvar cells = this.tHead.rows[0].cells;\r\n\tvar l = cells.length;\r\n\tvar c;\r\n\tfor (var i = 0; i < l; i++) {\r\n\t\tc = cells[i];\r\n\t\tif (c._sortType != null && c._sortType != \"None\") {\r\n\t\t\tc.removeChild(c.lastChild);\r\n\t\t\tif (typeof c.removeEventListener != \"undefined\")\r\n\t\t\t\tc.removeEventListener(\"click\", this._headerOnclick, false);\r\n\t\t\telse if (typeof c.detachEvent != \"undefined\")\r\n\t\t\t\tc.detachEvent(\"onclick\", this._headerOnclick);\r\n\t\t\tc._sortType = null;\r\n\t\t\tc.removeAttribute( \"_sortType\" );\r\n\t\t}\r\n\t}\r\n};\r\n\r\nSortableTable.prototype.updateHeaderArrows = function () {\r\n\tif (!this.tHead) return;\r\n\tvar cells = this.tHead.rows[0].cells;\r\n\tvar l = cells.length;\r\n\tvar img;\r\n\tfor (var i = 0; i < l; i++) {\r\n\t\tif (cells[i]._sortType != null && cells[i]._sortType != \"None\") {\r\n\t\t\timg = cells[i].lastChild;\r\n\t\t\tif (i == this.sortColumn)\r\n\t\t\t\timg.className = \"sort-arrow \" + (this.descending ? \"descending\" : \"ascending\");\r\n\t\t\telse\r\n\t\t\t\timg.className = \"sort-arrow\";\r\n\t\t}\r\n\t}\r\n};\r\n\r\nSortableTable.prototype.headerOnclick = function (e) {\r\n\t// find TD element\r\n\tvar el = e.target || e.srcElement;\r\n\twhile (el.tagName != \"TD\")\r\n\t\tel = el.parentNode;\r\n\r\n\tthis.sort(SortableTable.msie ? SortableTable.getCellIndex(el) : el.cellIndex);\r\n};\r\n\r\n// IE returns wrong cellIndex when columns are hidden\r\nSortableTable.getCellIndex = function (oTd) {\r\n\tvar cells = oTd.parentNode.childNodes\r\n\tvar l = cells.length;\r\n\tvar i;\r\n\tfor (i = 0; cells[i] != oTd && i < l; i++)\r\n\t\t;\r\n\treturn i;\r\n};\r\n\r\nSortableTable.prototype.getSortType = function (nColumn) {\r\n\treturn this.sortTypes[nColumn] || \"String\";\r\n};\r\n\r\n// only nColumn is required\r\n// if bDescending is left out the old value is taken into account\r\n// if sSortType is left out the sort type is found from the sortTypes array\r\n\r\nSortableTable.prototype.sort = function (nColumn, bDescending, sSortType) {\r\n\tif (!this.tBody) return;\r\n\tif (sSortType == null)\r\n\t\tsSortType = this.getSortType(nColumn);\r\n\r\n\t// exit if None\r\n\tif (sSortType == \"None\")\r\n\t\treturn;\r\n\r\n\tif (bDescending == null) {\r\n\t\tif (this.sortColumn != nColumn)\r\n\t\t\tthis.descending = this.defaultDescending;\r\n\t\telse\r\n\t\t\tthis.descending = !this.descending;\r\n\t}\r\n\telse\r\n\t\tthis.descending = bDescending;\r\n\r\n\tthis.sortColumn = nColumn;\r\n\r\n\tif (typeof this.onbeforesort == \"function\")\r\n\t\tthis.onbeforesort();\r\n\r\n\tvar f = this.getSortFunction(sSortType, nColumn);\r\n\tvar a = this.getCache(sSortType, nColumn);\r\n\tvar tBody = this.tBody;\r\n\r\n\ta.sort(f);\r\n\r\n\tif (this.descending)\r\n\t\ta.reverse();\r\n\r\n\tif (SortableTable.removeBeforeSort) {\r\n\t\t// remove from doc\r\n\t\tvar nextSibling = tBody.nextSibling;\r\n\t\tvar p = tBody.parentNode;\r\n\t\tp.removeChild(tBody);\r\n\t}\r\n\r\n\t// insert in the new order\r\n\tvar l = a.length;\r\n\tfor (var i = 0; i < l; i++)\r\n\t\ttBody.appendChild(a[i].element);\r\n\r\n\tif (SortableTable.removeBeforeSort) {\r\n\t\t// insert into doc\r\n\t\tp.insertBefore(tBody, nextSibling);\r\n\t}\r\n\r\n\tthis.updateHeaderArrows();\r\n\r\n\tthis.destroyCache(a);\r\n\r\n\tif (typeof this.onsort == \"function\")\r\n\t\tthis.onsort();\r\n};\r\n\r\nSortableTable.prototype.asyncSort = function (nColumn, bDescending, sSortType) {\r\n\tvar oThis = this;\r\n\tthis._asyncsort = function () {\r\n\t\toThis.sort(nColumn, bDescending, sSortType);\r\n\t};\r\n\twindow.setTimeout(this._asyncsort, 1);\r\n};\r\n\r\nSortableTable.prototype.getCache = function (sType, nColumn) {\r\n\tif (!this.tBody) return [];\r\n\tvar rows = this.tBody.rows;\r\n\tvar l = rows.length;\r\n\tvar a = new Array(l);\r\n\tvar r;\r\n\tfor (var i = 0; i < l; i++) {\r\n\t\tr = rows[i];\r\n\t\ta[i] = {\r\n\t\t\tvalue:\t\tthis.getRowValue(r, sType, nColumn),\r\n\t\t\telement:\tr\r\n\t\t};\r\n\t};\r\n\treturn a;\r\n};\r\n\r\nSortableTable.prototype.destroyCache = function (oArray) {\r\n\tvar l = oArray.length;\r\n\tfor (var i = 0; i < l; i++) {\r\n\t\toArray[i].value = null;\r\n\t\toArray[i].element = null;\r\n\t\toArray[i] = null;\r\n\t}\r\n};\r\n\r\nSortableTable.prototype.getRowValue = function (oRow, sType, nColumn) {\r\n\t// if we have defined a custom getRowValue use that\r\n\tif (this._sortTypeInfo[sType] && this._sortTypeInfo[sType].getRowValue)\r\n\t\treturn this._sortTypeInfo[sType].getRowValue(oRow, nColumn);\r\n\r\n\tvar s;\r\n\tvar c = oRow.cells[nColumn];\r\n\tif (typeof c.innerText != \"undefined\")\r\n\t\ts = c.innerText;\r\n\telse\r\n\t\ts = SortableTable.getInnerText(c);\r\n\treturn this.getValueFromString(s, sType);\r\n};\r\n\r\nSortableTable.getInnerText = function (oNode) {\r\n\tvar s = \"\";\r\n\tvar cs = oNode.childNodes;\r\n\tvar l = cs.length;\r\n\tfor (var i = 0; i < l; i++) {\r\n\t\tswitch (cs[i].nodeType) {\r\n\t\t\tcase 1: //ELEMENT_NODE\r\n\t\t\t\ts += SortableTable.getInnerText(cs[i]);\r\n\t\t\t\tbreak;\r\n\t\t\tcase 3:\t//TEXT_NODE\r\n\t\t\t\ts += cs[i].nodeValue;\r\n\t\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\treturn s;\r\n};\r\n\r\nSortableTable.prototype.getValueFromString = function (sText, sType) {\r\n\tif (this._sortTypeInfo[sType])\r\n\t\treturn this._sortTypeInfo[sType].getValueFromString( sText );\r\n\treturn sText;\r\n\t/*\r\n\tswitch (sType) {\r\n\t\tcase \"Number\":\r\n\t\t\treturn Number(sText);\r\n\t\tcase \"CaseInsensitiveString\":\r\n\t\t\treturn sText.toUpperCase();\r\n\t\tcase \"Date\":\r\n\t\t\tvar parts = sText.split(\"-\");\r\n\t\t\tvar d = new Date(0);\r\n\t\t\td.setFullYear(parts[0]);\r\n\t\t\td.setDate(parts[2]);\r\n\t\t\td.setMonth(parts[1] - 1);\r\n\t\t\treturn d.valueOf();\r\n\t}\r\n\treturn sText;\r\n\t*/\r\n\t};\r\n\r\nSortableTable.prototype.getSortFunction = function (sType, nColumn) {\r\n\tif (this._sortTypeInfo[sType])\r\n\t\treturn this._sortTypeInfo[sType].compare;\r\n\treturn SortableTable.basicCompare;\r\n};\r\n\r\nSortableTable.prototype.destroy = function () {\r\n\tthis.uninitHeader();\r\n\tvar win = this.document.parentWindow;\r\n\tif (win && typeof win.detachEvent != \"undefined\") {\t// only IE needs this\r\n\t\twin.detachEvent(\"onunload\", this._onunload);\r\n\t}\r\n\tthis._onunload = null;\r\n\tthis.element = null;\r\n\tthis.tHead = null;\r\n\tthis.tBody = null;\r\n\tthis.document = null;\r\n\tthis._headerOnclick = null;\r\n\tthis.sortTypes = null;\r\n\tthis._asyncsort = null;\r\n\tthis.onsort = null;\r\n};\r\n\r\n// Adds a sort type to all instance of SortableTable\r\n// sType : String - the identifier of the sort type\r\n// fGetValueFromString : function ( s : string ) : T - A function that takes a\r\n// string and casts it to a desired format. If left out the string is just\r\n// returned\r\n// fCompareFunction : function ( n1 : T, n2 : T ) : Number - A normal JS sort\r\n// compare function. Takes two values and compares them. If left out less than,\r\n// <, compare is used\r\n// fGetRowValue : function( oRow : HTMLTRElement, nColumn : int ) : T - A function\r\n// that takes the row and the column index and returns the value used to compare.\r\n// If left out then the innerText is first taken for the cell and then the\r\n// fGetValueFromString is used to convert that string the desired value and type\r\n\r\nSortableTable.prototype.addSortType = function (sType, fGetValueFromString, fCompareFunction, fGetRowValue) {\r\n\tthis._sortTypeInfo[sType] = {\r\n\t\ttype:\t\t\t\tsType,\r\n\t\tgetValueFromString:\tfGetValueFromString || SortableTable.idFunction,\r\n\t\tcompare:\t\t\tfCompareFunction || SortableTable.basicCompare,\r\n\t\tgetRowValue:\t\tfGetRowValue\r\n\t};\r\n};\r\n\r\n// this removes the sort type from all instances of SortableTable\r\nSortableTable.prototype.removeSortType = function (sType) {\r\n\tdelete this._sortTypeInfo[sType];\r\n};\r\n\r\nSortableTable.basicCompare = function compare(n1, n2) {\r\n\tif (n1.value < n2.value)\r\n\t\treturn -1;\r\n\tif (n2.value < n1.value)\r\n\t\treturn 1;\r\n\treturn 0;\r\n};\r\n\r\nSortableTable.idFunction = function (x) {\r\n\treturn x;\r\n};\r\n\r\nSortableTable.toUpperCase = function (s) {\r\n\treturn s.toUpperCase();\r\n};\r\n\r\nSortableTable.toDate = function (s) {\r\n\tvar parts = s.split(\"-\");\r\n\tvar d = new Date(0);\r\n\td.setFullYear(parts[0]);\r\n\td.setDate(parts[2]);\r\n\td.setMonth(parts[1] - 1);\r\n\treturn d.valueOf();\r\n};\r\n\r\n\r\n// add sort types\r\nSortableTable.prototype.addSortType(\"Number\", Number);\r\nSortableTable.prototype.addSortType(\"CaseInsensitiveString\", SortableTable.toUpperCase);\r\nSortableTable.prototype.addSortType(\"Date\", SortableTable.toDate);\r\nSortableTable.prototype.addSortType(\"String\");\r\n// None is a special case\r\n"
diff --git a/package.json b/package.json
index d8a7d1ec..fe811b3f 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "tablefilter",
- "version": "0.2.0",
+ "version": "0.2.1",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {
diff --git a/src/modules/hash.js b/src/modules/hash.js
new file mode 100644
index 00000000..92f6b8d7
--- /dev/null
+++ b/src/modules/hash.js
@@ -0,0 +1,63 @@
+// import Str from '../string';
+import Event from '../event';
+// import Types from '../types';
+
+const global = window;
+const JSON = global.JSON;
+const location = global.location;
+const hasHashChange = () => {
+ var docMode = global.documentMode;
+ return ('onhashchange' in global) && (docMode === undefined || docMode > 7);
+};
+
+export class Hash {
+
+ constructor(state){
+ this.state = state;
+ this.lastHash = location.hash;
+ this.emitter = state.emitter;
+ }
+
+ init() {
+ if(!hasHashChange()){
+ return;
+ }
+ this.emitter.on(['state-changed'], (tf, state) => this.update(state));
+ this.emitter.on(['initialized'], () => this.sync());
+ Event.add(global, 'hashchange', () => this.sync());
+ }
+
+ update(state) {
+ let hash = `#${JSON.stringify(state)}`;
+ console.log(hash, this.lastHash, this.lastHash === hash);
+ if (this.lastHash === hash) {
+ return;
+ }
+
+ location.hash = hash;
+ this.lastHash = hash;
+ }
+
+ parse(hash) {
+ if (hash.indexOf('#') === -1) {
+ return null;
+ }
+ hash = hash.substr(1);
+ return JSON.parse(hash);
+ }
+
+ sync(){
+ let hash = this.parse(location.hash);
+ if(!hash){
+ return;
+ }
+ this.state.state = hash;
+ this.state.sync();
+ }
+
+ destroy() {
+ this.emitter.off(['state-changed'], (tf, state) => this.update(state));
+ this.emitter.off(['initialized'], () => this.sync());
+ Event.aremove(global, 'hashchange', () => this.sync());
+ }
+}
diff --git a/src/modules/stateful.js b/src/modules/state.js
similarity index 71%
rename from src/modules/stateful.js
rename to src/modules/state.js
index 8a6baadd..ef74d812 100644
--- a/src/modules/stateful.js
+++ b/src/modules/state.js
@@ -1,35 +1,28 @@
import {Feature} from './feature';
+import {Hash} from './hash';
import Str from '../string';
-import Event from '../event';
import Types from '../types';
-const global = window;
-const JSON = global.JSON;
-const location = global.location;
-const hasHashChange = () => {
- var docMode = global.documentMode;
- return ('onhashchange' in global) && (docMode === undefined || docMode > 7);
-};
-
-export class Stateful extends Feature {
+export class State extends Feature {
/**
- * Creates an instance of Stateful.
+ * Creates an instance of State
*
* @param tf TableFilter instance
*/
constructor(tf) {
- super(tf, 'stateful');
+ super(tf, 'state');
- let cfg = this.config.stateful;
+ let cfg = this.config.state;
+ this.enableHash = cfg.type.indexOf('hash') !== -1;
this.persistFilters = cfg.filters === false ? false : true;
this.persistPageNumber = Boolean(cfg.page_number);
this.persistPageLength = Boolean(cfg.page_length);
+ this.hash = null;
this.pageNb = null;
this.pageLength = null;
- this.lastHash = null;
this.state = {};
this.prfxCol = 'col_';
@@ -38,24 +31,24 @@ export class Stateful extends Feature {
}
init() {
- if (this.initialized || !hasHashChange()) {
+ if (this.initialized) {
return;
}
- this.emitter.on(['initialized'], () => this.sync());
this.emitter.on(['after-filtering'], () => this.update());
this.emitter.on(['after-page-change'],
(tf, pageNb) => this.updatePage(pageNb));
this.emitter.on(['after-page-length-change'],
(tf, index) => this.updatePageLength(index));
- Event.add(global, 'hashchange', () => this.sync());
-
- this.lastHash = location.hash;
+ if(this.enableHash){
+ this.hash = new Hash(this);
+ this.hash.init();
+ }
this.initialized = true;
}
- format() {
+ update() {
let tf = this.tf;
if (this.persistFilters) {
@@ -91,28 +84,7 @@ export class Stateful extends Feature {
this.state[this.pageLengthKey] = this.pageLength;
}
}
-
- return `#${JSON.stringify(this.state)}`;
- }
-
- parse(hash) {
- if (hash.indexOf('#') === 0) {
- hash = hash.substr(1);
- } else {
- hash = '{}';
- }
- return JSON.parse(hash);
- }
-
- update() {
- let hash = this.format();
- console.log(hash, this.lastHash, this.lastHash === hash);
- if (this.lastHash === hash) {
- return;
- }
-
- location.hash = hash;
- this.lastHash = hash;
+ this.emitter.emit('state-changed', tf, this.state);
}
updatePage(pageNb){
@@ -126,8 +98,8 @@ export class Stateful extends Feature {
}
sync() {
- let state = this.parse(location.hash);
- console.log('sync',state);
+ let state = this.state;
+ console.log('sync', state);
let tf = this.tf;
if (this.persistFilters) {
@@ -158,14 +130,17 @@ export class Stateful extends Feature {
return;
}
- this.emitter.off(['initialized'], () => this.sync());
this.emitter.off(['after-filtering'], () => this.update());
this.emitter.off(['after-page-change'],
(tf, pageNb) => this.updatePage(pageNb));
this.emitter.off(['after-page-length-change'],
(tf, index) => this.updatePageLength(index));
- Event.remove(global, 'hashchange', () => this.sync());
+ if(this.enableHash){
+ this.hash.destroy();
+ this.hash = null;
+ }
+
this.initialized = false;
}
}
diff --git a/src/tablefilter.js b/src/tablefilter.js
index cf594687..aed506ad 100644
--- a/src/tablefilter.js
+++ b/src/tablefilter.js
@@ -21,7 +21,7 @@ import {ClearButton} from './modules/clearButton';
import {Help} from './modules/help';
import {AlternateRows} from './modules/alternateRows';
import {NoResults} from './modules/noResults';
-import {Stateful} from './modules/stateful';
+import {State} from './modules/state';
let global = window,
doc = global.document;
@@ -337,7 +337,7 @@ export class TableFilter {
Boolean(f.no_results_message);
// stateful
- this.isStateful = Types.isObj(f.stateful) || Boolean(f.stateful);
+ this.hasState = Types.isObj(f.state) || Boolean(f.state);
/*** data types ***/
//defines default date type (european DMY)
@@ -502,11 +502,11 @@ export class TableFilter {
Mod.help.init();
}
- if(this.isStateful){
- if(!Mod.stateful){
- Mod.stateful = new Stateful(tf);
+ if(this.hasState){
+ if(!Mod.state){
+ Mod.state = new State(this);
}
- Mod.stateful.init();
+ Mod.state.init();
}
if(this.hasPersistence){
diff --git a/static/templates/pagination.html b/static/templates/pagination.html
index 69a85858..f0fb1737 100644
--- a/static/templates/pagination.html
+++ b/static/templates/pagination.html
@@ -30,7 +30,12 @@