mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-17 16:10:04 +01:00
Merged master in
This commit is contained in:
commit
f45fae30ee
11 changed files with 79 additions and 35 deletions
|
|
@ -3,7 +3,8 @@ import Event from '../event';
|
|||
const global = window;
|
||||
const JSON = global.JSON;
|
||||
const location = global.location;
|
||||
const hasHashChange = () => {
|
||||
|
||||
export const hasHashChange = () => {
|
||||
var docMode = global.documentMode;
|
||||
return ('onhashchange' in global) && (docMode === undefined || docMode > 7);
|
||||
};
|
||||
|
|
@ -12,7 +13,7 @@ export class Hash {
|
|||
|
||||
constructor(state){
|
||||
this.state = state;
|
||||
this.lastHash = location.hash;
|
||||
this.lastHash = null;
|
||||
this.emitter = state.emitter;
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +21,9 @@ export class Hash {
|
|||
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());
|
||||
|
|
@ -45,17 +49,24 @@ export class Hash {
|
|||
}
|
||||
|
||||
sync(){
|
||||
let hash = this.parse(location.hash);
|
||||
if(!hash){
|
||||
let state = this.parse(location.hash);
|
||||
if(!state){
|
||||
return;
|
||||
}
|
||||
this.state.state = hash;
|
||||
|
||||
this.state.disable();
|
||||
this.state.override(state);
|
||||
this.state.sync();
|
||||
this.state.enable();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.state = null;
|
||||
this.lastHash = null;
|
||||
this.emitter = null;
|
||||
|
||||
this.emitter.off(['state-changed'], (tf, state) => this.update(state));
|
||||
this.emitter.off(['initialized'], () => this.sync());
|
||||
Event.aremove(global, 'hashchange', () => this.sync());
|
||||
Event.remove(global, 'hashchange', () => this.sync());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export class State extends Feature {
|
|||
|
||||
let cfg = this.config.state;
|
||||
|
||||
this.enableHash = cfg.type.indexOf('hash') !== -1;
|
||||
this.enableHash = cfg.type && cfg.type.indexOf('hash') !== -1;
|
||||
this.persistFilters = cfg.filters === false ? false : true;
|
||||
this.persistPageNumber = Boolean(cfg.page_number);
|
||||
this.persistPageLength = Boolean(cfg.page_length);
|
||||
|
|
@ -27,7 +27,7 @@ export class State extends Feature {
|
|||
this.state = {};
|
||||
this.prfxCol = 'col_';
|
||||
this.pageNbKey = 'page';
|
||||
this.pageLengthKey = 'results';
|
||||
this.pageLengthKey = 'page_length';
|
||||
}
|
||||
|
||||
init() {
|
||||
|
|
@ -49,6 +49,9 @@ export class State extends Feature {
|
|||
}
|
||||
|
||||
update() {
|
||||
if(!this.isEnabled()){
|
||||
return;
|
||||
}
|
||||
let tf = this.tf;
|
||||
|
||||
if (this.persistFilters) {
|
||||
|
|
@ -84,6 +87,7 @@ export class State extends Feature {
|
|||
this.state[this.pageLengthKey] = this.pageLength;
|
||||
}
|
||||
}
|
||||
|
||||
this.emitter.emit('state-changed', tf, this.state);
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +101,10 @@ export class State extends Feature {
|
|||
this.update();
|
||||
}
|
||||
|
||||
override(state){
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
sync() {
|
||||
let state = this.state;
|
||||
console.log('sync', state);
|
||||
|
|
@ -116,6 +124,7 @@ export class State extends Feature {
|
|||
|
||||
if (this.persistPageNumber) {
|
||||
let pageNumber = state[this.pageNbKey];
|
||||
console.log('pageNumber',pageNumber);
|
||||
this.emitter.emit('change-page', this.tf, pageNumber);
|
||||
}
|
||||
|
||||
|
|
@ -123,6 +132,8 @@ export class State extends Feature {
|
|||
let pageLength = state[this.pageLengthKey];
|
||||
this.emitter.emit('change-page-results', this.tf, pageLength);
|
||||
}
|
||||
|
||||
this.emitter.emit('state-synced', tf, this.state);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue