1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-04-26 12:10:45 +02:00

fix events loader subscribes to

This commit is contained in:
koalyptus 2018-10-27 21:46:27 +11:00
parent 335f97a9de
commit 50fda2a900
8 changed files with 103 additions and 16 deletions

4
dist/starter.html vendored
View file

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

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.6.64",
"version": "0.6.65",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {

View file

@ -5,7 +5,7 @@ import {root} from '../root';
import {NONE} from '../const';
import {defaultsStr, defaultsFn} from '../settings';
const EVENTS = [
const BEFORE_ACTION_EVENTS = [
'before-filtering',
'before-populating-filter',
'before-page-change',
@ -17,6 +17,18 @@ const EVENTS = [
'before-loading-themes'
];
const AFTER_ACTION_EVENTS = [
'after-filtering',
'after-populating-filter',
'after-page-change',
'after-clearing-filters',
'after-page-length-change',
'after-reset-page',
'after-reset-page-length',
'after-loading-extensions',
'after-loading-themes'
];
/**
* Activity indicator
*
@ -116,8 +128,8 @@ export class Loader extends Feature {
this.show(NONE);
// Subscribe to events
emitter.on(EVENTS, () => this.show(''));
emitter.on(EVENTS, () => this.show(NONE));
emitter.on(BEFORE_ACTION_EVENTS, () => this.show(''));
emitter.on(AFTER_ACTION_EVENTS, () => this.show(NONE));
/** @inherited */
this.initialized = true;
@ -132,7 +144,7 @@ export class Loader extends Feature {
return;
}
let displayLoader = () => {
function displayLoader() {
if (!this.cont) {
return;
}
@ -146,7 +158,7 @@ export class Loader extends Feature {
};
let t = p === NONE ? this.closeDelay : 1;
root.setTimeout(displayLoader, t);
root.setTimeout(displayLoader.bind(this), t);
}
/**
@ -163,8 +175,8 @@ export class Loader extends Feature {
this.cont = null;
// Unsubscribe to events
emitter.off(EVENTS, () => this.show(''));
emitter.off(EVENTS, () => this.show(NONE));
emitter.off(BEFORE_ACTION_EVENTS, () => this.show(''));
emitter.off(AFTER_ACTION_EVENTS, () => this.show(NONE));
this.initialized = false;
}

View file

@ -95,8 +95,6 @@
tf.clearFilters();
tf.setFilterValue(4, '[nonempty]');
tf.filter();
var filteredData = tf.getFilteredData();
console.log(filteredData);
deepEqual(tf.getValidRows().length, 7, 'Expected number of matches');
});

View file

@ -2,12 +2,13 @@
<html>
<head>
<meta charset="utf-8">
<title>TableFilter basic test</title>
<title>TableFilter loader ui component tests</title>
<link rel="stylesheet" href="libs/qunit/qunit.css">
<script src="libs/qunit/qunit.js"></script>
<script src="libs/polyfill.js"></script>
</head>
<body>
<div id="my-loader"></div>
<table id="demo" cellpadding="0" cellspacing="0">
<tbody>
<tr>
@ -75,4 +76,4 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
</html>

View file

@ -75,6 +75,82 @@ test('Can show loader', function() {
loader.show('');
deepEqual(loader.cont.style.display, '', 'Loader is displayed');
});
test('Does not show loader if feature not enabled', function() {
// setup
var isEnabled = loader.isEnabled;
var hit = 0;
loader.isEnabled = function() {
hit++;
};
// act
loader.show('');
// assert
deepEqual(hit, 1, 'loader not shown');
loader.isEnabled = isEnabled;
});
test('Can generate loader in target element', function() {
// setup
loader.destroy();
loader.targetId = 'my-loader';
var targetEl = document.getElementById('my-loader');
// act
loader.init();
// assert
deepEqual(targetEl.innerHTML, '<div class="loader">Loading...</div>',
'Loader injected in target element');
});
test('Can generate loader with custom html', function() {
// setup
loader.destroy();
loader.html = '<h3>loading...</h3>';
// act
loader.init();
// assert
deepEqual(loader.cont.innerHTML, '<h3>loading...</h3>',
'Loader with custom html');
});
test('Can show loader when known event is emitted', function() {
// setup
var show = loader.show;
var hit = 0;
loader.show = function() {
hit++;
};
// act
tf.emitter.emit('before-clearing-filters', tf);
// assert
deepEqual(hit, 1, 'show method is called');
loader.show = show;
});
test('Can hide loader when known event is emitted', function() {
// setup
var show = loader.show;
var hit = 0;
var arg = null;
loader.show = function() {
hit++;
arg = arguments[0];
};
// act
tf.emitter.emit('after-clearing-filters', tf);
// assert
deepEqual(hit, 1, 'show method is called');
deepEqual(arg, 'none', 'with `none` argument');
loader.show = show;
});
module('Tear-down');
test('can destroy TableFilter DOM elements', function() {