]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Support events with dashes and colons
authorRuslan Yakhyaev <ruslan@ruslan.io>
Fri, 3 Jan 2014 17:19:32 +0000 (18:19 +0100)
committerScott González <scott.gonzalez@gmail.com>
Thu, 16 Jan 2014 17:12:04 +0000 (12:12 -0500)
Fixes #9708
Closes gh-1159

tests/unit/widget/widget_core.js
ui/jquery.ui.widget.js

index 3cda48df9fa97e103cb7fcf932cc1f314ca60c72..2fdb9bc76e00f63001c242bead0170dd880e47ac 100644 (file)
@@ -865,21 +865,36 @@ test( "_on() with delegate to descendent", function() {
 });
 
 test( "_on() to common element", function() {
-       expect( 1 );
+       expect( 4 );
        $.widget( "ui.testWidget", {
                _create: function() {
                        this._on( this.document, {
-                               "customevent": "_handler"
+                               "customevent": "_handler",
+                               "with:colons": "_colonHandler",
+                               "with-dashes": "_dashHandler",
+                               "with-dashes:and-colons": "_commbinedHandler"
                        });
                },
                _handler: function() {
                        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" );
        $( "#widget-wrapper" ).testWidget();
        widget.destroy();
        $( document ).trigger( "customevent" );
+       $( document ).trigger( "with:colons" );
+       $( document ).trigger( "with-dashes" );
+       $( document ).trigger( "with-dashes:and-colons" );
 });
 
 test( "_off() - single event", function() {
index 97f5fd7e02c9ebdec354274a81fbe2b193e0d11b..b62b877f7b3e69c07c86704dd7c7795ecea1fe98 100644 (file)
@@ -414,7 +414,7 @@ $.Widget.prototype = {
                                        handler.guid || handlerProxy.guid || $.guid++;
                        }
 
-                       var match = event.match( /^(\w+)\s*(.*)$/ ),
+                       var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
                                eventName = match[1] + instance.eventNamespace,
                                selector = match[2];
                        if ( selector ) {