Core: add multiple widgets from table class. Fixes #1109

This commit is contained in:
Rob Garrison 2015-12-22 10:19:10 -06:00
parent e76e540982
commit 13068454c5
2 changed files with 36 additions and 8 deletions

View File

@ -1880,15 +1880,19 @@
var len, indx,
c = table.config,
// look for widgets to apply from table class
// stop using \b otherwise this matches 'ui-widget-content' & adds 'content' widget
regex = '\\s' + c.widgetClass.replace( ts.regex.templateName, '([\\w-]+)' ) + '\\s',
// don't match from 'ui-widget-content'; use \S instead of \w to include widgets
// with dashes in the name, e.g. "widget-test-2" extracts out "test-2"
regex = '^' + c.widgetClass.replace( ts.regex.templateName, '(\\S+)+' ) + '$',
widgetClass = new RegExp( regex, 'g' ),
// extract out the widget id from the table class (widget id's can include dashes)
widget = ( ' ' + c.table.className + ' ' ).match( widgetClass );
if ( widget ) {
len = widget.length;
// split up table class (widget id's can include dashes) - stop using match
// otherwise one one widgetClass gets extracted, see #1109
widgets = ( table.className || '' ).split( ts.regex.spaces );
if ( widgets.length ) {
len = widgets.length;
for ( indx = 0; indx < len; indx++ ) {
c.widgets.push( widget[ indx ].replace( widgetClass, '$1' ) );
if ( widgets[ indx ].match( widgetClass ) ) {
c.widgets.push( widgets[ indx ].replace( widgetClass, '$1' ) );
}
}
}
},

View File

@ -613,7 +613,6 @@ jQuery(function($){
});
QUnit.test( 'colspan parsing', function(assert) {
assert.expect(2);
@ -924,6 +923,31 @@ jQuery(function($){
$table2.tablesorter();
});
/************************************************
extract widgets from table class
************************************************/
QUnit.test('extract widget names from table class', function(assert) {
assert.expect(2);
var widgets,
t = {
className: 'widget-filter widget-stickyHeaders ui-widget-content widget-test-2',
config: {
widgetClass: 'widget-{name}',
widgets: []
}
};
ts.addWidgetFromClass( t );
assert.deepEqual( t.config.widgets, [ 'filter', 'stickyHeaders', 'test-2' ], 'Ignored "ui-widget-content"' );
t.className = 'stickyHeaders-widgey ui-widgey-content filter-widgey test-2-widgey';
t.config.widgetClass = '{name}-widgey';
t.config.widgets = [];
ts.addWidgetFromClass( t );
assert.deepEqual( t.config.widgets, [ 'stickyHeaders', 'filter', 'test-2' ], 'Modified widgetClass option' );
});
/************************************************
ipv6 parser testing
************************************************/