Core: Fix widget option changes across multiple tables

Seen in the second table of the math page demo with the
`math_ignore` option
This commit is contained in:
Rob Garrison 2017-05-03 16:35:52 -05:00
parent 74bfdb096b
commit 5e6c926d6b
2 changed files with 33 additions and 3 deletions

View File

@ -1931,7 +1931,7 @@
for ( indx = 0; indx < len; indx++ ) {
widget = ts.getWidgetById( c.widgets[ indx ] );
if ( widget && widget.options ) {
wo = $.extend( {}, widget.options );
wo = $.extend( true, {}, widget.options );
c.widgetOptions = $.extend( true, wo, c.widgetOptions );
// add widgetOptions to defaults for option validator
$.extend( true, ts.defaults.widgetOptions, widget.options );

View File

@ -161,17 +161,37 @@ jQuery(function($){
},
undef, c1, c2, c3, c4, e, i, t;
/* test widget */
ts.addWidget({
id : 'test',
options: {
'test': []
},
format: function() {}
});
$table1
.on('tablesorter-initialized', function(){
init = true;
})
.tablesorter();
.tablesorter({
widgets: ['test'],
widgetOptions: {
// check widget option defaults across tables
test: [0,1]
}
});
$table2.tablesorter({
headers: {
0: { sorter: 'text' },
1: { sorter: 'text' },
2: { sorter: false }
},
widgets: ['test'],
widgetOptions: {
// check widget option defaults across tables
test: [0]
}
});
@ -182,7 +202,9 @@ jQuery(function($){
0: { empty : 'top' }, // sort empty cells to the top
2: { string: 'min' }, // non-numeric content is treated as a MIN value
3: { sorter: 'digit', empty : 'zero', string : 'top' }
}
},
// check widget option defaults across tables
widgets: ['test']
});
$table4.tablesorter({
@ -907,6 +929,14 @@ jQuery(function($){
return t;
};
QUnit.test( 'check widgetOption defaults across tables', function(assert) {
assert.expect(4);
assert.deepEqual(c1.widgetOptions.test, [0,1], 'widget option properly set');
assert.deepEqual(c2.widgetOptions.test, [0], 'widget option properly set');
assert.deepEqual(c3.widgetOptions.test, [], 'default widget option set on table');
assert.deepEqual(ts.defaults.widgetOptions.test, [], 'default widget option set in core');
});
QUnit.test( 'apply zebra widget', function(assert) {
assert.expect(3);
assert.equal( zebra(), false, 'zebra not applied' );