Core: Add option validator. Fixes #1319

This commit is contained in:
Rob Garrison 2016-11-26 10:39:31 -06:00
parent 4053331c13
commit 4ae7ce24d8
5 changed files with 57 additions and 1 deletions

View File

@ -116,7 +116,11 @@
headerList: [],
empties: {},
strings: {},
parsers: []
parsers: [],
// *** parser options for validator; values must be falsy!
globalize: 0,
imgAttr: 0
// removed: widgetZebra: { css: ['even', 'odd'] }
@ -290,6 +294,7 @@
ts.setupParsers( c );
// start total row count at zero
c.totalRows = 0;
ts.validateOptions( c );
// build the cache for the tbody cells
// delayInit will delay building the cache until the user starts a sort
if ( !c.delayInit ) { ts.buildCache( c ); }
@ -1911,6 +1916,8 @@
widget = ts.getWidgetById( c.widgets[ indx ] );
if ( widget && widget.options ) {
c.widgetOptions = $.extend( true, {}, widget.options, c.widgetOptions );
// add widgetOptions to defaults for option validator
$.extend( true, ts.defaults.widgetOptions, widget.options );
}
}
}
@ -2396,6 +2403,34 @@
return str;
},
validateOptions : function( c ) {
var setting, setting2, typ, timer,
// ignore options containing an array
ignore = 'sortForce sortList sortAppend widgets'.split( ' ' ),
orig = c.originalSettings;
if ( orig ) {
if ( c.debug ) {
timer = new Date();
}
for ( setting in orig ) {
typ = typeof ts.defaults[setting];
if ( typ === 'undefined' ) {
console.warn( 'Tablesorter Warning! "table.config.' + setting + '" option not recognized' );
} else if ( typ === 'object' ) {
for ( setting2 in orig[setting] ) {
typ = typeof ts.defaults[setting][setting2];
if ( $.inArray( setting, ignore ) < 0 && typ === 'undefined' ) {
console.warn( 'Tablesorter Warning! "table.config.' + setting + '.' + setting2 + '" option not recognized' );
}
}
}
}
if ( c.debug ) {
console.log( 'validate options time:' + ts.benchmark( timer ) );
}
}
},
// restore headers
restoreHeaders : function( table ) {
var index, $cell,

View File

@ -13,6 +13,9 @@
ts = $.tablesorter,
now = new Date().getFullYear();
// add dateRange to defaults for validator; value must be falsy
ts.defaults.dataRange = '';
if ( !ts.dates ) { ts.dates = {}; }
ts.dates.regxxxxyy = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/;
ts.dates.regyyxxxx = /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/;

View File

@ -110,6 +110,10 @@
type : 'text'
});
// update defaults for validator; values must be falsy
ts.defaults.checkboxClass = '';
ts.defaults.checkboxVisible = '';
// update select and all input types in the tablesorter cache when the change event fires.
// This method only works with jQuery 1.7+
// you can change it to use delegate (v1.4.3+) or live (v1.3+) as desired

View File

@ -79,6 +79,9 @@
}
};
// add data to defaults for validator; value must be falsy!
ts.defaults.data = '';
bt.defaults = {
// *** build widget core ***
build_type : '', // array, csv, object, json, html

View File

@ -43,6 +43,17 @@
url = options && options.url ||
$table.attr(options && options.page || wo && wo.storage_page || 'data-table-page') ||
wo && wo.storage_fixedUrl || c && c.fixedUrl || window.location.pathname;
// update defaults for validator; these values must be falsy!
$.extend(true, ts.defaults, {
fixedUrl: '',
widgetOptions: {
storage_fixedUrl: '',
storage_group: '',
storage_page: '',
storage_tableId: '',
storage_useSessionStorage: ''
}
});
// https://gist.github.com/paulirish/5558557
if (storageType in window) {
try {