mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Core: add multiple widgets from table class. Fixes #1109
This commit is contained in:
parent
e76e540982
commit
13068454c5
@ -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' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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
|
||||
************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user