Widget: Support events with dashes and colons

Fixes #9708
Closes gh-1159
This commit is contained in:
Ruslan Yakhyaev 2014-01-03 18:19:32 +01:00 committed by Scott González
parent 28310ff55f
commit be2a339b2b
2 changed files with 18 additions and 3 deletions

View File

@ -865,21 +865,36 @@ test( "_on() with delegate to descendent", function() {
}); });
test( "_on() to common element", function() { test( "_on() to common element", function() {
expect( 1 ); expect( 4 );
$.widget( "ui.testWidget", { $.widget( "ui.testWidget", {
_create: function() { _create: function() {
this._on( this.document, { this._on( this.document, {
"customevent": "_handler" "customevent": "_handler",
"with:colons": "_colonHandler",
"with-dashes": "_dashHandler",
"with-dashes:and-colons": "_commbinedHandler"
}); });
}, },
_handler: function() { _handler: function() {
ok( true, "handler triggered" ); ok( true, "handler triggered" );
},
_colonHandler: function() {
ok( true, "colon handler triggered" );
},
_dashHandler: function() {
ok( true, "dash handler triggered" );
},
_commbinedHandler: function() {
ok( true, "combined handler triggered" );
} }
}); });
var widget = $( "#widget" ).testWidget().testWidget( "instance" ); var widget = $( "#widget" ).testWidget().testWidget( "instance" );
$( "#widget-wrapper" ).testWidget(); $( "#widget-wrapper" ).testWidget();
widget.destroy(); widget.destroy();
$( document ).trigger( "customevent" ); $( document ).trigger( "customevent" );
$( document ).trigger( "with:colons" );
$( document ).trigger( "with-dashes" );
$( document ).trigger( "with-dashes:and-colons" );
}); });
test( "_off() - single event", function() { test( "_off() - single event", function() {

View File

@ -414,7 +414,7 @@ $.Widget.prototype = {
handler.guid || handlerProxy.guid || $.guid++; handler.guid || handlerProxy.guid || $.guid++;
} }
var match = event.match( /^(\w+)\s*(.*)$/ ), var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
eventName = match[1] + instance.eventNamespace, eventName = match[1] + instance.eventNamespace,
selector = match[2]; selector = match[2];
if ( selector ) { if ( selector ) {