Skip to content

Commit be2a339

Browse files
ryakhscottgonzalez
authored andcommitted
Widget: Support events with dashes and colons
Fixes #9708 Closes jquerygh-1159
1 parent 28310ff commit be2a339

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

tests/unit/widget/widget_core.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,21 +865,36 @@ test( "_on() with delegate to descendent", function() {
865865
});
866866

867867
test( "_on() to common element", function() {
868-
expect( 1 );
868+
expect( 4 );
869869
$.widget( "ui.testWidget", {
870870
_create: function() {
871871
this._on( this.document, {
872-
"customevent": "_handler"
872+
"customevent": "_handler",
873+
"with:colons": "_colonHandler",
874+
"with-dashes": "_dashHandler",
875+
"with-dashes:and-colons": "_commbinedHandler"
873876
});
874877
},
875878
_handler: function() {
876879
ok( true, "handler triggered" );
880+
},
881+
_colonHandler: function() {
882+
ok( true, "colon handler triggered" );
883+
},
884+
_dashHandler: function() {
885+
ok( true, "dash handler triggered" );
886+
},
887+
_commbinedHandler: function() {
888+
ok( true, "combined handler triggered" );
877889
}
878890
});
879891
var widget = $( "#widget" ).testWidget().testWidget( "instance" );
880892
$( "#widget-wrapper" ).testWidget();
881893
widget.destroy();
882894
$( document ).trigger( "customevent" );
895+
$( document ).trigger( "with:colons" );
896+
$( document ).trigger( "with-dashes" );
897+
$( document ).trigger( "with-dashes:and-colons" );
883898
});
884899

885900
test( "_off() - single event", function() {

ui/jquery.ui.widget.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ $.Widget.prototype = {
414414
handler.guid || handlerProxy.guid || $.guid++;
415415
}
416416

417-
var match = event.match( /^(\w+)\s*(.*)$/ ),
417+
var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
418418
eventName = match[1] + instance.eventNamespace,
419419
selector = match[2];
420420
if ( selector ) {

0 commit comments

Comments
 (0)