mirror of
https://github.com/koalyptus/TableFilter.git
synced 2026-03-18 08:29:50 +01:00
Removed Cookie dependency in TableFilter class
This commit is contained in:
parent
885b957d31
commit
e5a67eeee9
12 changed files with 9905 additions and 41 deletions
|
|
@ -9,6 +9,24 @@ function removeCookie(name){
|
|||
document.cookie = name + '=' + expire;
|
||||
}
|
||||
|
||||
function readCookie(name){
|
||||
var cookieValue = '',
|
||||
search = name + '=';
|
||||
if(document.cookie.length > 0){
|
||||
var cookie = document.cookie,
|
||||
offset = cookie.indexOf(search);
|
||||
if(offset !== -1){
|
||||
offset += search.length;
|
||||
var end = cookie.indexOf(';', offset);
|
||||
if(end === -1){
|
||||
end = cookie.length;
|
||||
}
|
||||
cookieValue = unescape(cookie.substring(offset, end));
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
var tf = new TableFilter('demo', {
|
||||
base_path: '../dist/tablefilter/',
|
||||
paging: true,
|
||||
|
|
@ -42,7 +60,6 @@ test('Page number value', function() {
|
|||
var cookieName = tf.pgNbCookie;
|
||||
deepEqual(tf.feature('store').getPageNb(cookieName), '2', 'Page number value');
|
||||
tf.clearFilters();
|
||||
tf.filter();
|
||||
});
|
||||
|
||||
module('Check page length persistence');
|
||||
|
|
@ -53,7 +70,6 @@ test('Page length value', function() {
|
|||
var cookieName = tf.pgLenCookie;
|
||||
deepEqual(tf.feature('store').getPageLength(cookieName), '2', 'Page length value');
|
||||
tf.clearFilters();
|
||||
tf.filter();
|
||||
});
|
||||
|
||||
module('Check filters persistence');
|
||||
|
|
@ -77,6 +93,15 @@ test('Apply cookie filters value', function() {
|
|||
deepEqual(tf.getFilterValue(3), '>=2', 'Applied filter value');
|
||||
});
|
||||
|
||||
test('Can remove cookies on clearFilters', function() {
|
||||
tf.clearFilters();
|
||||
|
||||
deepEqual(readCookie(tf.fltsValuesCookie), '',
|
||||
'fltsValuesCookie cookie removed');
|
||||
deepEqual(readCookie(tf.pgLenCookie), '', 'pgLenCookie cookie removed');
|
||||
deepEqual(readCookie(tf.pgNbCookie), '', 'pgNbCookie cookie removed');
|
||||
});
|
||||
|
||||
module('Tear-down');
|
||||
test('TableFilter removed', function() {
|
||||
tf.destroy();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue