1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-20 06:35:24 +02:00

Trying again

This commit is contained in:
Max Guglielmi 2016-03-24 17:30:53 +11:00
commit 22ecda6411
32 changed files with 860 additions and 157 deletions

15
.editorconfig Normal file
View file

@ -0,0 +1,15 @@
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
# Trailing whitespace is significant in markdown files.
[*.md]
trim_trailing_whitespace = false

View file

@ -3,8 +3,8 @@
"rules": {
"max-len": [2, 80, 2, {"ignoreUrls": true}],
"max-depth": [2, 7],
"max-statements": [2, 169],
"complexity": [2, 87],
"max-statements": [2, 170],
"complexity": [2, 88],
"no-unused-vars": 2,
"no-eval": 2,
"no-underscore-dangle": 0,
@ -17,7 +17,8 @@
"no-trailing-spaces": 2,
"no-multi-spaces": 2,
"array-bracket-spacing": 2,
"new-cap": 2
"new-cap": 2,
"radix": [2, "always"]
},
"ecmaFeatures": {
"modules": true
@ -27,4 +28,4 @@
"browser": true,
"node": false
}
}
}

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ npm-debug.log
*.js.map
.codio
.settings
.vscode

View file

@ -1,6 +1,6 @@
language: node_js
node_js:
- '0.10'
- '0.12'
before_script:
- npm install grunt-cli -g
script:

4
dist/starter.html vendored
View file

@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>tablefilter v0.1.19 - Starter</title>
<title>tablefilter v0.2.4 - Starter</title>
</head>
<body>
<h1>tablefilter v0.1.19</h1>
<h1>tablefilter v0.2.4</h1>

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.19 by Max Guglielmi
* build date: 2016-03-13T06:10:32.971Z
* tablefilter v0.2.4 by Max Guglielmi
* build date: 2016-03-24T01:04:40.614Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.19 by Max Guglielmi
* build date: 2016-03-13T06:10:32.971Z
* tablefilter v0.2.4 by Max Guglielmi
* build date: 2016-03-24T01:04:40.614Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.19 by Max Guglielmi
* build date: 2016-03-13T06:10:32.971Z
* tablefilter v0.2.4 by Max Guglielmi
* build date: 2016-03-24T01:04:40.614Z
* MIT License
*/
.activeHeader{background-color:#66afe9 !important;color:#fff !important}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.19 by Max Guglielmi
* build date: 2016-03-13T06:10:32.971Z
* tablefilter v0.2.4 by Max Guglielmi
* build date: 2016-03-24T01:04:40.614Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.19 by Max Guglielmi
* build date: 2016-03-13T06:10:32.971Z
* tablefilter v0.2.4 by Max Guglielmi
* build date: 2016-03-24T01:04:40.614Z
* 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}

View file

@ -1,6 +1,6 @@
/**
* tablefilter v0.1.19 by Max Guglielmi
* build date: 2016-03-13T06:10:32.971Z
* tablefilter v0.2.4 by Max Guglielmi
* build date: 2016-03-24T01:04:40.614Z
* 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}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.1.19",
"version": "0.2.4",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {
@ -28,15 +28,16 @@
"tag": "next"
},
"devDependencies": {
"babel-core": "^6.7.2",
"babel-eslint": "6.0.0-beta.5",
"babel-core": "^6.7.4",
"babel-eslint": "5.0.0",
"babel-loader": "^6.0.1",
"babel-preset-es2015": "^6.5.0",
"babel-plugin-transform-es2015-classes": "^6.6.5",
"clean-webpack-plugin": "^0.1.3",
"grunt": "^0.4.5",
"grunt-babel": "^6.0.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-connect": "^1.0.0",
"grunt-contrib-connect": "^1.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-qunit": "^1.1.0",
"grunt-contrib-stylus": "^1.2.0",

108
src/modules/hash.js Normal file
View file

@ -0,0 +1,108 @@
import Event from '../event';
const global = window;
const JSON = global.JSON;
const location = global.location;
const decodeURIComponent = global.decodeURIComponent;
export const hasHashChange = () => {
var docMode = global.documentMode;
return ('onhashchange' in global) && (docMode === undefined || docMode > 7);
};
/**
* Manages the URL hash reflecting the features state to be persisted
*
* @export
* @class Hash
*/
export class Hash {
/**
* Creates an instance of Hash
*
* @param {State} state Instance of State
*/
constructor(state) {
this.state = state;
this.lastHash = null;
this.emitter = state.emitter;
}
/**
* Initializes the Hash object
*/
init() {
if (!hasHashChange()) {
return;
}
this.lastHash = location.hash;
this.emitter.on(['state-changed'], (tf, state) => this.update(state));
this.emitter.on(['initialized'], () => this.sync());
Event.add(global, 'hashchange', () => this.sync());
}
/**
* Updates the URL hash based on a state change
*
* @param {State} state Instance of State
*/
update(state) {
let hash = `#${JSON.stringify(state)}`;
if (this.lastHash === hash) {
return;
}
location.hash = hash;
this.lastHash = hash;
}
/**
* Converts a URL hash into a state JSON object
*
* @param {String} hash URL hash fragment
* @returns {Object} JSON object
*/
parse(hash) {
if (hash.indexOf('#') === -1) {
return null;
}
hash = hash.substr(1);
return JSON.parse(decodeURIComponent(hash));
}
/**
* Applies current hash state to features
*/
sync() {
let state = this.parse(location.hash);
if (!state) {
return;
}
// To prevent state to react to features changes, state is temporarily
// disabled
this.state.disable();
// State is overriden with hash state object
this.state.override(state);
// New hash state is applied to features
this.state.sync();
// State is re-enabled
this.state.enable();
}
/**
* Destroy Hash instance
*/
destroy() {
this.emitter.off(['state-changed'], (tf, state) => this.update(state));
this.emitter.off(['initialized'], () => this.sync());
Event.remove(global, 'hashchange', () => this.sync());
this.state = null;
this.lastHash = null;
this.emitter = null;
}
}

View file

@ -2,30 +2,29 @@ import Dom from '../dom';
import Str from '../string';
import Types from '../types';
export class HighlightKeyword{
export class HighlightKeyword {
/**
* HighlightKeyword, highlight matched keyword
* @param {Object} tf TableFilter instance
*/
constructor(tf) {
var f = tf.config();
let f = tf.config();
//defines css class for highlighting
this.highlightCssClass = f.highlight_css_class || 'keyword';
this.highlightedNodes = [];
this.tf = tf;
this.emitter = tf.emitter;
}
init(){
init() {
this.emitter.on(
['before-filtering', 'destroy'],
()=> this.unhighlightAll()
() => this.unhighlightAll()
);
this.emitter.on(
['highlight-keyword'],
(tf, cell, word)=>
(tf, cell, word) =>
this.highlight(cell, word, this.highlightCssClass)
);
}
@ -35,38 +34,39 @@ export class HighlightKeyword{
* @param {Node} node
* @param {String} word Searched term
* @param {String} cssClass Css class name
*
* TODO: refactor this method
*/
highlight(node, word, cssClass){
highlight(node, word, cssClass) {
// Iterate into this nodes childNodes
if(node.hasChildNodes){
var children = node.childNodes;
for(var i=0; i<children.length; i++){
if (node.hasChildNodes) {
let children = node.childNodes;
for (let i = 0; i < children.length; i++) {
this.highlight(children[i], word, cssClass);
}
}
if(node.nodeType === 3){
var tempNodeVal = Str.lower(node.nodeValue);
var tempWordVal = Str.lower(word);
if(tempNodeVal.indexOf(tempWordVal) != -1){
var pn = node.parentNode;
if(pn && pn.className != cssClass){
if (node.nodeType === 3) {
let tempNodeVal = Str.lower(node.nodeValue);
let tempWordVal = Str.lower(word);
if (tempNodeVal.indexOf(tempWordVal) !== -1) {
let pn = node.parentNode;
if (pn && pn.className !== cssClass) {
// word not highlighted yet
var nv = node.nodeValue,
let nv = node.nodeValue,
ni = tempNodeVal.indexOf(tempWordVal),
// Create a load of replacement nodes
before = Dom.text(nv.substr(0, ni)),
docWordVal = nv.substr(ni,word.length),
after = Dom.text(nv.substr(ni+word.length)),
docWordVal = nv.substr(ni, word.length),
after = Dom.text(nv.substr(ni + word.length)),
hiwordtext = Dom.text(docWordVal),
hiword = Dom.create('span');
hiword.className = cssClass;
hiword.appendChild(hiwordtext);
pn.insertBefore(before,node);
pn.insertBefore(hiword,node);
pn.insertBefore(after,node);
pn.insertBefore(before, node);
pn.insertBefore(hiword, node);
pn.insertBefore(after, node);
pn.removeChild(node);
this.highlightedNodes.push(hiword.firstChild);
}
}
}
@ -77,63 +77,47 @@ export class HighlightKeyword{
* @param {String} word
* @param {String} cssClass Css class to remove
*/
unhighlight(word, cssClass){
var arrRemove = [];
var highlightedNodes = this.highlightedNodes;
for(var i=0; i<highlightedNodes.length; i++){
var n = highlightedNodes[i];
if(!n){
continue;
}
var tempNodeVal = Str.lower(n.nodeValue),
unhighlight(word, cssClass) {
let highlightedNodes = this.tf.tbl.querySelectorAll(`.${cssClass}`);
for (let i = 0; i < highlightedNodes.length; i++) {
let n = highlightedNodes[i];
let nodeVal = Dom.getText(n),
tempNodeVal = Str.lower(nodeVal),
tempWordVal = Str.lower(word);
if(tempNodeVal.indexOf(tempWordVal) !== -1){
var pn = n.parentNode;
if(pn && pn.className === cssClass){
var prevSib = pn.previousSibling,
nextSib = pn.nextSibling;
if(!prevSib || !nextSib){ continue; }
nextSib.nodeValue = prevSib.nodeValue + n.nodeValue +
nextSib.nodeValue;
prevSib.nodeValue = '';
n.nodeValue = '';
arrRemove.push(i);
}
if (tempNodeVal.indexOf(tempWordVal) !== -1) {
n.parentNode.replaceChild(Dom.text(nodeVal), n);
}
}
for(var k=0; k<arrRemove.length; k++){
highlightedNodes.splice(arrRemove[k], 1);
}
}
/**
* Clear all occurrences of highlighted nodes
*/
unhighlightAll(){
if(!this.tf.highlightKeywords){
unhighlightAll() {
if (!this.tf.highlightKeywords) {
return;
}
// iterate filters values to unhighlight all values
this.tf.getFiltersValue().forEach((val)=> {
if(Types.isArray(val)){
val.forEach((item)=>
this.tf.getFiltersValue().forEach((val) => {
if (Types.isArray(val)) {
val.forEach((item) =>
this.unhighlight(item, this.highlightCssClass));
} else {
this.unhighlight(val, this.highlightCssClass);
}
});
this.highlightedNodes = [];
}
destroy(){
destroy() {
this.emitter.off(
['before-filtering', 'destroy'],
()=> this.unhighlightAll()
() => this.unhighlightAll()
);
this.emitter.off(
['highlight-keyword'],
(tf, cell, word)=>
(tf, cell, word) =>
this.highlight(cell, word, this.highlightCssClass)
);
}
}
}

View file

@ -69,9 +69,9 @@ export class Loader extends Feature{
emitter.on([
'before-filtering',
'before-populating-filter',
'before-changing-page',
'before-page-change',
'before-clearing-filters',
'before-changing-results-per-page',
'before-page-length-change',
'before-reset-page',
'before-reset-page-length',
'before-loading-extensions',
@ -81,9 +81,9 @@ export class Loader extends Feature{
emitter.on([
'after-filtering',
'after-populating-filter',
'after-changing-page',
'after-page-change',
'after-clearing-filters',
'after-changing-results-per-page',
'after-page-length-change',
'after-reset-page',
'after-reset-page-length',
'after-loading-extensions',
@ -130,9 +130,9 @@ export class Loader extends Feature{
emitter.off([
'before-filtering',
'before-populating-filter',
'before-changing-page',
'before-page-change',
'before-clearing-filters',
'before-changing-results-per-page',
'before-page-length-change',
'before-reset-page',
'before-reset-page-length',
'before-loading-extensions',
@ -142,9 +142,9 @@ export class Loader extends Feature{
emitter.off([
'after-filtering',
'after-populating-filter',
'after-changing-page',
'after-page-change',
'after-clearing-filters',
'after-changing-results-per-page',
'after-page-length-change',
'after-reset-page',
'after-reset-page-length',
'after-loading-extensions',

View file

@ -336,6 +336,10 @@ export class Paging extends Feature{
this.emitter.on(['after-filtering'], ()=> this.resetPagingInfo());
this.emitter.on(['initialized'], ()=> this.resetValues());
this.emitter.on(['change-page'],
(tf, pageNumber) => this.setPage(pageNumber));
this.emitter.on(['change-page-results'],
(tf, pageLength) => this.changeResultsPerPage(pageLength));
this.initialized = true;
}
@ -502,7 +506,7 @@ export class Paging extends Feature{
}
evt.slcResultsChange = (ev) => {
this.changeResultsPerPage();
this.onChangeResultsPerPage();
ev.target.blur();
};
@ -570,7 +574,7 @@ export class Paging extends Feature{
return;
}
this.emitter.emit('before-changing-page', tf, index);
this.emitter.emit('before-page-change', tf, (index + 1));
if(index === null){
index = this.pageSelectorType === tf.fltTypeSlc ?
@ -578,7 +582,7 @@ export class Paging extends Feature{
}
if( index>=0 && index<=(this.nbPages-1) ){
if(this.onBeforeChangePage){
this.onBeforeChangePage.call(null, this, index);
this.onBeforeChangePage.call(null, this, (index + 1));
}
this.currentPageNb = parseInt(index, 10)+1;
if(this.pageSelectorType===tf.fltTypeSlc){
@ -593,25 +597,33 @@ export class Paging extends Feature{
this.groupByPage();
if(this.onAfterChangePage){
this.onAfterChangePage.call(null, this, index);
this.onAfterChangePage.call(null, this, (index + 1));
}
}
this.emitter.emit('after-changing-page', tf, index);
this.emitter.emit('after-page-change', tf, (index + 1));
}
changeResultsPerPage(val){
if(!this.isEnabled() || isNaN(val)){
return;
}
this.resultsPerPageSlc.value = val;
this.onChangeResultsPerPage();
}
/**
* Change rows according to page results drop-down
* TODO: accept a parameter setting the results per page length
*/
changeResultsPerPage(){
onChangeResultsPerPage(){
var tf = this.tf;
if(!this.isEnabled()){
return;
}
this.emitter.emit('before-changing-results-per-page', tf);
this.emitter.emit('before-page-length-change', tf);
var slcR = this.resultsPerPageSlc;
var slcIndex = slcR.selectedIndex;
@ -635,7 +647,7 @@ export class Paging extends Feature{
}
}
this.emitter.emit('after-changing-results-per-page', tf, slcIndex);
this.emitter.emit('after-page-length-change', tf, this.pagingLength);
}
/**
@ -756,6 +768,10 @@ export class Paging extends Feature{
this.emitter.off(['after-filtering'], ()=> this.resetPagingInfo());
this.emitter.off(['initialized'], ()=> this.resetValues());
this.emitter.off(['change-page'],
(tf, pageNumber) => this.setPage(pageNumber));
this.emitter.off(['change-page-results'],
(tf, pageLength) => this.changeResultsPerPage(pageLength));
this.pagingSlc = null;
this.nbPages = 0;

193
src/modules/state.js Normal file
View file

@ -0,0 +1,193 @@
import {Feature} from './feature';
import {Hash} from './hash';
import Str from '../string';
import Types from '../types';
/**
* Reflects the state of features to be persisted via hash, localStorage or
* cookie
*
* @export
* @class State
* @extends {Feature}
*/
export class State extends Feature {
/**
* Creates an instance of State
*
* @param {TableFilter} tf TableFilter instance
*/
constructor(tf) {
super(tf, 'state');
let cfg = this.config.state;
// hash enabled by default if state setting is simply set true
this.enableHash = (cfg.types && cfg.types.indexOf('hash') !== -1) ||
tf.state === true;
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.state = {};
this.prfxCol = 'col_';
this.pageNbKey = 'page';
this.pageLengthKey = 'page_length';
}
/**
* Initializes the State object
*/
init() {
if (this.initialized) {
return;
}
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));
if (this.enableHash) {
this.hash = new Hash(this);
this.hash.init();
}
this.initialized = true;
}
/**
* Update state field based on current features state
*/
update() {
if (!this.isEnabled()) {
return;
}
let tf = this.tf;
if (this.persistFilters) {
let filterValues = tf.getFiltersValue();
filterValues.forEach((val, idx) => {
let key = `${this.prfxCol}${idx}`;
if (Types.isString(val) && Str.isEmpty(val)) {
if (this.state.hasOwnProperty(key)) {
this.state[key] = undefined;
}
} else {
this.state[key] = this.state[key] || {};
this.state[key].flt = val;
}
});
}
if (this.persistPageNumber) {
if (Types.isNull(this.pageNb)) {
this.state[this.pageNbKey] = undefined;
} else {
this.state[this.pageNbKey] = this.pageNb;
}
}
if (this.persistPageLength) {
if (Types.isNull(this.pageLength)) {
this.state[this.pageLengthKey] = undefined;
} else {
this.state[this.pageLengthKey] = this.pageLength;
}
}
this.emitter.emit('state-changed', tf, this.state);
}
/**
* Refresh page number field on page number change
*
* @param pageNb Current page number
*/
updatePage(pageNb) {
this.pageNb = pageNb;
this.update();
}
/**
* Refresh page length field on page length change
*
* @param pageLength Current page length value
*/
updatePageLength(pageLength) {
this.pageLength = pageLength;
this.update();
}
/**
* Override state field
*
* @param state State object
*/
override(state) {
this.state = state;
}
/**
* Apply current features state
*/
sync() {
let state = this.state;
let tf = this.tf;
if (this.persistFilters) {
Object.keys(state).forEach((key) => {
if (key.indexOf(this.prfxCol) !== -1) {
let colIdx = parseInt(key.replace(this.prfxCol, ''), 10);
let val = state[key].flt;
tf.setFilterValue(colIdx, val);
}
});
tf.filter();
}
if (this.persistPageNumber) {
let pageNumber = state[this.pageNbKey];
this.emitter.emit('change-page', this.tf, pageNumber);
}
if (this.persistPageLength) {
let pageLength = state[this.pageLengthKey];
this.emitter.emit('change-page-results', this.tf, pageLength);
}
}
/**
* Destroy State instance
*/
destroy() {
if (!this.initialized) {
return;
}
this.state = {};
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));
if (this.enableHash) {
this.hash.destroy();
this.hash = null;
}
this.initialized = false;
}
}

View file

@ -118,11 +118,11 @@ export class StatusBar extends Feature{
emitter.on(['before-filtering'], ()=> this.message(this.msgFilter));
emitter.on(['before-populating-filter'],
()=> this.message(this.msgPopulate));
emitter.on(['before-changing-page'],
emitter.on(['before-page-change'],
()=> this.message(this.msgChangePage));
emitter.on(['before-clearing-filters'], ()=>
this.message(this.msgClear));
emitter.on(['before-changing-results-per-page'],
emitter.on(['before-page-length-change'],
()=> this.message(this.msgChangeResults));
emitter.on(['before-reset-page'], ()=> this.message(this.msgResetPage));
emitter.on(['before-reset-page-length'],
@ -135,9 +135,9 @@ export class StatusBar extends Feature{
emitter.on([
'after-filtering',
'after-populating-filter',
'after-changing-page',
'after-page-change',
'after-clearing-filters',
'after-changing-results-per-page',
'after-page-length-change',
'after-reset-page',
'after-reset-page-length',
'after-loading-extensions',
@ -188,11 +188,11 @@ export class StatusBar extends Feature{
emitter.off(['before-filtering'], ()=> this.message(this.msgFilter));
emitter.off(['before-populating-filter'],
()=> this.message(this.msgPopulate));
emitter.off(['before-changing-page'],
emitter.off(['before-page-change'],
()=> this.message(this.msgChangePage));
emitter.off(['before-clearing-filters'],
()=> this.message(this.msgClear));
emitter.off(['before-changing-results-per-page'],
emitter.off(['before-page-length-change'],
()=> this.message(this.msgChangeResults));
emitter.off(['before-reset-page'], ()=>
this.message(this.msgResetPage));
@ -206,9 +206,9 @@ export class StatusBar extends Feature{
emitter.off([
'after-filtering',
'after-populating-filter',
'after-changing-page',
'after-page-change',
'after-clearing-filters',
'after-changing-results-per-page',
'after-page-length-change',
'after-reset-page',
'after-reset-page-length',
'after-loading-extensions',

View file

@ -29,9 +29,9 @@ export class Store{
init(){
this.emitter.on(['after-filtering'], ()=> this.saveFilterValues());
this.emitter.on(['after-clearing-filters'], ()=> this.clearCookies());
this.emitter.on(['after-changing-page'],
this.emitter.on(['after-page-change'],
(tf, index)=> this.savePageNb(index));
this.emitter.on(['after-changing-results-per-page'],
this.emitter.on(['after-page-length-change'],
(tf, index)=> this.savePageLength(index));
}
@ -82,15 +82,15 @@ export class Store{
/**
* Store page number in cookie
* @param {Number} index page index to persist
* @param {Number} pageIndex page index to persist
*/
savePageNb(index){
savePageNb(pageIndex){
if(!this.tf.rememberPageNb){
return;
}
Cookie.write(
this.pgNbCookie,
(index+1),
pageIndex,
this.duration
);
}
@ -138,9 +138,9 @@ export class Store{
destroy(){
this.emitter.off(['after-filtering'], ()=> this.saveFilterValues());
this.emitter.off(['after-clearing-filters'], ()=> this.clearCookies());
this.emitter.off(['after-changing-page'],
this.emitter.off(['after-page-change'],
(tf, index)=> this.savePageNb(index));
this.emitter.off(['after-changing-results-per-page'],
this.emitter.off(['after-page-length-change'],
(tf, index)=> this.savePageLength(index));
}
}

View file

@ -21,6 +21,7 @@ import {ClearButton} from './modules/clearButton';
import {Help} from './modules/help';
import {AlternateRows} from './modules/alternateRows';
import {NoResults} from './modules/noResults';
import {State} from './modules/state';
let global = window,
doc = global.document;
@ -335,6 +336,9 @@ export class TableFilter {
this.noResults = Types.isObj(f.no_results_message) ||
Boolean(f.no_results_message);
// stateful
this.state = Types.isObj(f.state) || Boolean(f.state);
/*** data types ***/
//defines default date type (european DMY)
this.defaultDateType = f.default_date_type || 'DMY';
@ -488,7 +492,9 @@ export class TableFilter {
this.import(this.stylesheetId, this.stylesheet, null, 'link');
//loads theme
if(this.hasThemes){ this.loadThemes(); }
if(this.hasThemes){
this.loadThemes();
}
// Instantiate help feature and initialise only if set true
if(!Mod.help){
@ -498,6 +504,13 @@ export class TableFilter {
Mod.help.init();
}
if(this.state){
if(!Mod.state){
Mod.state = new State(this);
}
Mod.state.init();
}
if(this.hasPersistence){
if(!Mod.store){
Mod.store = new Store(this);
@ -1035,6 +1048,9 @@ export class TableFilter {
// emit help initialisation only if undefined
if(Types.isUndef(this.help)){
// explicitily set enabled field to true to initialise help by
// default, only if setting is undefined
this.Mod.help.enabled = true;
this.emitter.emit('init-help', this);
}
}
@ -1484,7 +1500,7 @@ export class TableFilter {
this.onAfterFilter.call(null, this);
}
this.emitter.emit('after-filtering', this);
this.emitter.emit('after-filtering', this, searchArgs);
}
/**

View file

@ -42,6 +42,15 @@ export default {
return (obj && obj.constructor == Array);
},
/**
* Check argument is a string
* @param {String} val Value
* @returns {Boolean}
*/
isString(val){
return Object.prototype.toString.call(val) === '[object String]';
},
/**
* Determine if argument is undefined
* @param {Any} o

78
test/test-hash.html Normal file
View file

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TableFilter hash persistence</title>
<link rel="stylesheet" href="libs/qunit/qunit.css">
<script src="libs/qunit/qunit.js"></script>
<script src="libs/polyfill.js"></script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>From</th>
<th>Destination</th>
<th>Road Distance (km)</th>
<th>By Air (hrs)</th>
<th>By Rail (hrs)</th>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Adelaide</td>
<td>1412</td>
<td>1.4</td>
<td>25.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Brisbane</td>
<td>982</td>
<td>1.5</td>
<td>16</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Canberra</td>
<td>286</td>
<td>.6</td>
<td>4.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Melbourne</td>
<td>872</td>
<td>1.1</td>
<td>10.5</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Perth</td>
<td>2781</td>
<td>3.1</td>
<td>38</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Alice Springs</td>
<td>1533</td>
<td>2</td>
<td>20.25</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Brisbane</td>
<td>2045</td>
<td>2.15</td>
<td>40</td>
</tr>
</tbody>
</table>
<script src="../dist/tablefilter/tablefilter.js"></script>
<script src="test-hash.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

84
test/test-hash.js Normal file
View file

@ -0,0 +1,84 @@
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
state: {
type: ['hash'],
filters: true,
page_number: true,
page_length: true
},
paging: true,
results_per_page: ['Records: ', [2, 4, 6]],
});
tf.init();
var state = tf.feature('state');
var hash = state.hash;
module('Sanity checks');
test('State instance', function() {
deepEqual(typeof hash, 'object', 'Hash is instantiated');
deepEqual(hash.lastHash, '', 'Last store hash');
deepEqual(hash.state, state, 'State instance');
deepEqual(hash.emitter, state.emitter, 'Emitter instance');
});
module('Behaviour');
test('Can update URL hash', function() {
// setup
var stateObj = {
'page': 2,
'page_length': 4,
'col_2': {'flt': '>500'}
};
// act
state.emitter.emit('state-changed', tf, stateObj);
// assert
deepEqual(location.hash,
'#{"page":2,"page_length":4,"col_2":{"flt":">500"}}',
'URL hash updated');
});
test('Can parse a URL hash', function() {
// setup
var hashStr = '#{"page":2,"page_length":4,"col_2":{"flt":">500"}}';
// act
var result = hash.parse(hashStr);
// assert
deepEqual(result,
{
'page': 2,
'page_length': 4,
'col_2': {'flt': '>500'}
},
'Parsed hash'
);
});
test('Can sync state', function() {
// setup
location.hash = '#{"page":2,"page_length":4,"col_2":{"flt":">500"}}';
// act
hash.sync();
// assert
deepEqual(tf.getValidRows(), [2,3,5,6,7,8], 'Table filters are synced');
});
module('Tear-down');
test('Can destroy', function() {
// setup
location.hash = '';
// act
hash.destroy();
// assert
deepEqual(hash.state, null, 'State instance is null');
deepEqual(hash.lastHash, null, 'Last hash reference is null');
deepEqual(hash.emitter, null, 'Emitter instance is null');
});

View file

@ -90,16 +90,38 @@ test('Re-set UI', function() {
module('Destroy and re-init with help property undefined');
test('Can init help when property is undefined and toolbar is set', function(){
tf.destroy();
tf.help = undefined;
tf.rowsCounter = true;
var help = tf.feature('help');
help.btnText = '?';
tf.init();
test('Can init help when property is undefined and toolbar is set',
function() {
tf.destroy();
tf.help = undefined;
tf.rowsCounter = true;
var help = tf.feature('help');
help.btnText = '?';
tf.init();
notEqual(help.btn, null, 'btn property');
});
notEqual(help.btn, null, 'btn property');
}
);
test('Can toggle help when property is undefined and toolbar is set',
function() {
tf.destroy();
tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
// creates toolbar
rows_counter: true
});
tf.init();
var help = tf.feature('help');
// Pull 157, help button regression when setting is undefined
help.toggle();
notEqual(help, null, 'help instantiated');
deepEqual(help.enabled, true, 'help enabled');
deepEqual(help.cont.style.display, 'inline', 'Container is open');
}
);
module('Tear-down');
test('can destroy TableFilter DOM elements', function() {

View file

@ -9,25 +9,20 @@ var highlightKeyword = tf.feature('highlightKeyword');
module('Sanity checks');
test('HighlightKeyword component', function() {
deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
deepEqual(highlightKeyword.highlightedNodes instanceof Array,
true, 'Property check');
deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
});
test('Highlighted keywords', function() {
tf.setFilterValue(1, 'Perth');
tf.setFilterValue(3, '3.1');
tf.filter();
deepEqual(highlightKeyword.highlightedNodes.length,
2, 'Number of highlighted words');
deepEqual(tf.tbl.querySelectorAll('.keyword').length, 2,
'Number of applied CSS classes');
tf.clearFilters();
deepEqual(highlightKeyword.highlightedNodes.length,
0, 'Number of highlighted words');
// TODO: uncomment when fixed
// deepEqual(tf.tbl.querySelectorAll('.keyword').length, 0,
// 'Number of applied CSS classes');
// issue 155
deepEqual(tf.tbl.querySelectorAll('.keyword').length, 0,
'Number of applied CSS classes');
});
module('Reset feature');
@ -35,8 +30,7 @@ test('can destroy and init TableFilter', function() {
tf.destroy();
tf.init();
deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
deepEqual(highlightKeyword.highlightedNodes instanceof Array,
true, 'Property check');
deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
});
module('Tear-down');
@ -46,7 +40,7 @@ test('can destroy TableFilter DOM elements and clean highlighted words',
tf.filter();
tf.destroy();
deepEqual(tf.hasGrid(), false, 'Filters removed');
deepEqual(highlightKeyword.highlightedNodes.length,
0, 'Number of highlighted words');
deepEqual(tf.tbl.querySelectorAll('.keyword').length, 0,
'Number of applied CSS classes');
}
);

View file

@ -130,12 +130,10 @@ test('Filter with dummy value', function() {
test('Set results per page', function() {
tf.clearFilters();
paging.resultsPerPageSlc.options[1].selected = true;
paging.changeResultsPerPage();
paging.changeResultsPerPage('4');
deepEqual(paging.pagingLength, 4, 'Expected page length');
deepEqual(paging.nbPages, 2, 'Expected number of pages');
paging.resultsPerPageSlc.options[2].selected = true;
paging.changeResultsPerPage();
paging.changeResultsPerPage('6');
deepEqual(paging.pagingLength, 6, 'Expected page length');
deepEqual(paging.nbPages, 2, 'Expected number of pages');
});
@ -200,12 +198,10 @@ test('Filter with dummy value', function() {
test('Set results per page', function() {
tf.clearFilters();
paging.resultsPerPageSlc.options[1].selected = true;
paging.changeResultsPerPage();
paging.changeResultsPerPage('4');
deepEqual(paging.pagingLength, 4, 'Expected page length');
deepEqual(paging.nbPages, 2, 'Expected number of pages');
paging.resultsPerPageSlc.options[2].selected = true;
paging.changeResultsPerPage();
paging.changeResultsPerPage('6');
deepEqual(paging.pagingLength, 6, 'Expected page length');
deepEqual(paging.nbPages, 2, 'Expected number of pages');
});

78
test/test-state.html Normal file
View file

@ -0,0 +1,78 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TableFilter state object</title>
<link rel="stylesheet" href="libs/qunit/qunit.css">
<script src="libs/qunit/qunit.js"></script>
<script src="libs/polyfill.js"></script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>From</th>
<th>Destination</th>
<th>Road Distance (km)</th>
<th>By Air (hrs)</th>
<th>By Rail (hrs)</th>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Adelaide</td>
<td>1412</td>
<td>1.4</td>
<td>25.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Brisbane</td>
<td>982</td>
<td>1.5</td>
<td>16</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Canberra</td>
<td>286</td>
<td>.6</td>
<td>4.3</td>
</tr>
<tr>
<td><strong>Sydney</strong></td>
<td>Melbourne</td>
<td>872</td>
<td>1.1</td>
<td>10.5</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Perth</td>
<td>2781</td>
<td>3.1</td>
<td>38</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Alice Springs</td>
<td>1533</td>
<td>2</td>
<td>20.25</td>
</tr>
<tr>
<td><strong>Adelaide</strong></td>
<td>Brisbane</td>
<td>2045</td>
<td>2.15</td>
<td>40</td>
</tr>
</tbody>
</table>
<script src="../dist/tablefilter/tablefilter.js"></script>
<script src="test-state.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

107
test/test-state.js Normal file
View file

@ -0,0 +1,107 @@
var tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
state: true
});
tf.init();
var state = tf.feature('state');
module('Sanity checks');
test('State instance', function() {
deepEqual(tf.state, true, 'State is enabled');
deepEqual(typeof state, 'object', 'State is instantiated');
deepEqual(state.initialized, true, 'State is initialized');
deepEqual(state.enableHash, true, 'Hash is enabled by default');
deepEqual(state.persistFilters, true, 'Filters are persisted by default');
deepEqual(state.persistPageNumber, false, 'Page number not persisted');
deepEqual(state.persistPageLength, false, 'Page length not persisted');
deepEqual(typeof state.state, 'object', 'State field is an object');
});
module('Behaviour');
test('Can update', function() {
// setup
state.state = {};
// act
tf.setFilterValue(1, 'Adelaide');
tf.filter();
// assert
deepEqual(state.state.col_1, { 'flt': 'Adelaide' },
'State object updated');
});
test('Can update on clear filters', function() {
// setup
state.state = {};
// act
tf.clearFilters();
// assert
deepEqual(state.state.col_1, undefined, 'State object updated');
});
test('Can sync state', function() {
// setup
state.state = {};
state.state.col_2 = { 'flt': '>1500' };
// act
state.sync();
// assert
deepEqual(tf.getValidRows(), [6, 7, 8], 'Table filters are synced');
});
test('Can override state', function() {
// setup
state.state = {};
// act
state.override({ 'col_1': { 'flt': 'Ade' } });
// assert
deepEqual(state.state, { 'col_1': { 'flt': 'Ade' } },
'State field overriden');
});
test('Can update page number', function() {
// setup
state.persistPageNumber = true;
state.state = {};
// act
state.updatePage('2');
// assert
deepEqual(state.state.page, '2', 'Page number updated');
state.persistPageNumber = false;
});
test('Can update page length', function() {
// setup
state.persistPageLength = true;
state.state = {};
// act
state.updatePageLength('10');
// assert
deepEqual(state.state.page_length, '10', 'Page length updated');
state.persistPageLength = false;
});
module('Tear-down');
test('Can destroy TF', function() {
// setup
location.hash = null;
// act
tf.destroy();
// assert
deepEqual(state.initialized, false, 'State not initialized');
});

View file

@ -66,8 +66,7 @@ test('Page number value', function() {
module('Check page length persistence');
test('Page length value', function() {
var paging = tf.feature('paging');
paging.resultsPerPageSlc.options[2].selected = true;
paging.changeResultsPerPage();
paging.changeResultsPerPage('2');
deepEqual(tf.feature('store').getPageLength(), '2', 'Page length value');
tf.clearFilters();

View file

@ -30,7 +30,8 @@ module.exports = {
exclude: /tablefilter\/node_modules/,
query: {
compact: false,
presets: ['es2015']
presets: ['es2015'],
plugins: [['transform-es2015-classes', {loose: true}]]
},
loader: 'babel-loader'
},