1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2026-03-15 15:15:45 +01:00

Assigned empty function to callbacks

This commit is contained in:
Max Guglielmi 2016-12-22 22:01:59 +11:00
commit c75fbe169c
21 changed files with 136 additions and 172 deletions

View file

@ -1,6 +1,6 @@
import {Feature} from '../feature';
import {createElm, createText, elm, removeElm} from '../dom';
import {isFn} from '../types';
import {isFn, EMPTY_FN} from '../types';
import {root} from '../root';
import {NONE} from '../const';
@ -75,13 +75,14 @@ export class Loader extends Feature {
* Callback fired when loader is displayed
* @type {Function}
*/
this.onShow = isFn(f.on_show_loader) ? f.on_show_loader : null;
this.onShow = isFn(f.on_show_loader) ?
f.on_show_loader : EMPTY_FN;
/**
* Callback fired when loader is closed
* @type {Function}
*/
this.onHide = isFn(f.on_hide_loader) ? f.on_hide_loader : null;
this.onHide = isFn(f.on_hide_loader) ? f.on_hide_loader : EMPTY_FN;
}
/**
@ -137,12 +138,12 @@ export class Loader extends Feature {
if (!this.cont) {
return;
}
if (this.onShow && p !== NONE) {
this.onShow.call(null, this);
if (p !== NONE) {
this.onShow(this);
}
this.cont.style.display = p;
if (this.onHide && p === NONE) {
this.onHide.call(null, this);
if (p === NONE) {
this.onHide(this);
}
};

View file

@ -1,6 +1,6 @@
import {Feature} from '../feature';
import {createElm, elm, removeElm} from '../dom';
import {isEmpty, isFn} from '../types';
import {isEmpty, isFn, EMPTY_FN} from '../types';
import {NONE} from '../const';
/**
@ -64,28 +64,28 @@ export class NoResults extends Feature {
* @type {Function}
*/
this.onBeforeShow = isFn(f.on_before_show_msg) ?
f.on_before_show_msg : null;
f.on_before_show_msg : EMPTY_FN;
/**
* Callback fired after the message is displayed
* @type {Function}
*/
this.onAfterShow = isFn(f.on_after_show_msg) ?
f.on_after_show_msg : null;
f.on_after_show_msg : EMPTY_FN;
/**
* Callback fired before the message is hidden
* @type {Function}
*/
this.onBeforeHide = isFn(f.on_before_hide_msg) ?
f.on_before_hide_msg : null;
f.on_before_hide_msg : EMPTY_FN;
/**
* Callback fired after the message is hidden
* @type {Function}
*/
this.onAfterHide = isFn(f.on_after_hide_msg) ?
f.on_after_hide_msg : null;
f.on_after_hide_msg : EMPTY_FN;
}
/**
@ -141,17 +141,12 @@ export class NoResults extends Feature {
if (!this.initialized || !this.isEnabled()) {
return;
}
if (this.onBeforeShow) {
this.onBeforeShow.call(null, this.tf, this);
}
this.onBeforeShow(this.tf, this);
this.setWidth();
this.cont.style.display = 'block';
if (this.onAfterShow) {
this.onAfterShow.call(null, this.tf, this);
}
this.onAfterShow(this.tf, this);
}
/**
@ -161,16 +156,11 @@ export class NoResults extends Feature {
if (!this.initialized || !this.isEnabled()) {
return;
}
if (this.onBeforeHide) {
this.onBeforeHide.call(null, this.tf, this);
}
this.onBeforeHide(this.tf, this);
this.cont.style.display = NONE;
if (this.onAfterHide) {
this.onAfterHide.call(null, this.tf, this);
}
this.onAfterHide(this.tf, this);
}
/**

View file

@ -1,6 +1,6 @@
import {Feature} from '../feature';
import {createElm, createOpt, createText, elm, removeElm} from '../dom';
import {isArray, isFn, isNull} from '../types';
import {isArray, isFn, isNull, EMPTY_FN} from '../types';
import {addEvt, keyCode, removeEvt} from '../event';
import {INPUT, SELECT, NONE, ENTER_KEY} from '../const';
@ -211,14 +211,14 @@ export class Paging extends Feature {
* @type {Function}
*/
this.onBeforeChangePage = isFn(f.on_before_change_page) ?
f.on_before_change_page : null;
f.on_before_change_page : EMPTY_FN;
/**
* Callback fired after the page is changed
* @type {Function}
*/
this.onAfterChangePage = isFn(f.on_after_change_page) ?
f.on_after_change_page : null;
f.on_after_change_page : EMPTY_FN;
/**
* Label preciding results per page select
@ -717,9 +717,8 @@ export class Paging extends Feature {
this.pagingSlc.options.selectedIndex : this.pagingSlc.value - 1;
}
if (index >= 0 && index <= (this.nbPages - 1)) {
if (this.onBeforeChangePage) {
this.onBeforeChangePage.call(null, this, (index + 1));
}
this.onBeforeChangePage(this, (index + 1));
this.currentPageNb = parseInt(index, 10) + 1;
if (this.pageSelectorType === SELECT) {
this.pagingSlc.options[index].selected = true;
@ -732,9 +731,7 @@ export class Paging extends Feature {
this.groupByPage();
if (this.onAfterChangePage) {
this.onAfterChangePage.call(null, this, (index + 1));
}
this.onAfterChangePage(this, (index + 1));
}
this.emitter.emit('after-page-change', tf, (index + 1));

View file

@ -1,5 +1,5 @@
import {Feature} from '../feature';
import {isFn, isUndef} from '../types';
import {isFn, isUndef, EMPTY_FN} from '../types';
import {createElm, removeElm} from '../dom';
import {addEvt, cancelEvt, stopEvt, targetEvt, removeEvt} from '../event';
import {INPUT, NONE, CHECKLIST, MULTIPLE} from '../const';
@ -74,28 +74,28 @@ export class PopupFilter extends Feature {
* @type {Function}
*/
this.onBeforeOpen = isFn(f.on_before_popup_filter_open) ?
f.on_before_popup_filter_open : null;
f.on_before_popup_filter_open : EMPTY_FN;
/**
* Callback fired after a popup filter is opened
* @type {Function}
*/
this.onAfterOpen = isFn(f.on_after_popup_filter_open) ?
f.on_after_popup_filter_open : null;
f.on_after_popup_filter_open : EMPTY_FN;
/**
* Callback fired before a popup filter is closed
* @type {Function}
*/
this.onBeforeClose = isFn(f.on_before_popup_filter_close) ?
f.on_before_popup_filter_close : null;
f.on_before_popup_filter_close : EMPTY_FN;
/**
* Callback fired after a popup filter is closed
* @type {Function}
*/
this.onAfterClose = isFn(f.on_after_popup_filter_close) ?
f.on_after_popup_filter_close : null;
f.on_after_popup_filter_close : EMPTY_FN;
/**
* Collection of filters spans
@ -307,9 +307,8 @@ export class PopupFilter extends Feature {
let tf = this.tf,
container = this.fltElms[colIndex];
if (this.onBeforeOpen) {
this.onBeforeOpen.call(null, this, container, colIndex);
}
this.onBeforeOpen(this, container, colIndex);
container.style.display = 'block';
this.activeFilterIdx = colIndex;
addEvt(root, 'mouseup', (evt) => this.onMouseup(evt));
@ -320,9 +319,8 @@ export class PopupFilter extends Feature {
flt.focus();
}
}
if (this.onAfterOpen) {
this.onAfterOpen.call(null, this, container, colIndex);
}
this.onAfterOpen(this, container, colIndex);
}
/**
@ -331,17 +329,16 @@ export class PopupFilter extends Feature {
*/
close(colIndex) {
let container = this.fltElms[colIndex];
if (this.onBeforeClose) {
this.onBeforeClose.call(null, this, container, colIndex);
}
this.onBeforeClose(this, container, colIndex);
container.style.display = NONE;
if (this.activeFilterIdx === colIndex) {
this.activeFilterIdx = -1;
}
removeEvt(root, 'mouseup', (evt) => this.onMouseup(evt));
if (this.onAfterClose) {
this.onAfterClose.call(null, this, container, colIndex);
}
this.onAfterClose(this, container, colIndex);
}
/**

View file

@ -1,6 +1,6 @@
import {Feature} from '../feature';
import {createElm, createText, elm, removeElm} from '../dom';
import {isFn} from '../types';
import {isFn, EMPTY_FN} from '../types';
/**
* Rows counter UI component
@ -72,14 +72,14 @@ export class RowsCounter extends Feature {
* @type {Function}
*/
this.onBeforeRefreshCounter = isFn(f.on_before_refresh_counter) ?
f.on_before_refresh_counter : null;
f.on_before_refresh_counter : EMPTY_FN;
/**
* Callback fired after the counter is refreshed
* @type {Function}
*/
this.onAfterRefreshCounter = isFn(f.on_after_refresh_counter) ?
f.on_after_refresh_counter : null;
f.on_after_refresh_counter : EMPTY_FN;
}
/**
@ -142,9 +142,7 @@ export class RowsCounter extends Feature {
let tf = this.tf;
if (this.onBeforeRefreshCounter) {
this.onBeforeRefreshCounter.call(null, tf, this.label);
}
this.onBeforeRefreshCounter(tf, this.label);
let totTxt;
if (!tf.paging) {
@ -170,9 +168,7 @@ export class RowsCounter extends Feature {
}
this.label.innerHTML = totTxt;
if (this.onAfterRefreshCounter) {
this.onAfterRefreshCounter.call(null, tf, this.label, totTxt);
}
this.onAfterRefreshCounter(tf, this.label, totTxt);
}
/**

View file

@ -1,7 +1,7 @@
import {Feature} from '../feature';
import {root} from '../root';
import {createElm, createText, elm, removeElm} from '../dom';
import {isFn} from '../types';
import {isFn, EMPTY_FN} from '../types';
const EVENTS = [
'after-filtering',
@ -84,14 +84,14 @@ export class StatusBar extends Feature {
* @type {Function}
*/
this.onBeforeShowMsg = isFn(f.on_before_show_msg) ?
f.on_before_show_msg : null;
f.on_before_show_msg : EMPTY_FN;
/**
* Callback fired after the message is displayed
* @type {Function}
*/
this.onAfterShowMsg = isFn(f.on_after_show_msg) ?
f.on_after_show_msg : null;
f.on_after_show_msg : EMPTY_FN;
/**
* Message appearing upon filtering
@ -242,9 +242,7 @@ export class StatusBar extends Feature {
return;
}
if (this.onBeforeShowMsg) {
this.onBeforeShowMsg.call(null, this.tf, t);
}
this.onBeforeShowMsg(this.tf, t);
let d = t === '' ? this.delay : 1;
root.setTimeout(() => {
@ -252,9 +250,8 @@ export class StatusBar extends Feature {
return;
}
this.msgContainer.innerHTML = t;
if (this.onAfterShowMsg) {
this.onAfterShowMsg.call(null, this.tf, t);
}
this.onAfterShowMsg(this.tf, t);
}, d);
}