]> source.dussan.org Git - jquery.git/commitdiff
Remove attribute match from quickIs
authorDave Methvin <dave.methvin@gmail.com>
Mon, 24 Oct 2011 22:05:53 +0000 (18:05 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 24 Oct 2011 22:05:53 +0000 (18:05 -0400)
As @timmywil points out, attributes and properties are confused by IE6/7. This commit also reworks the unit test case to do a better job of checking className matches.

src/event.js
test/unit/event.js

index 23e9ca0e00a558d1da3dff4886442e28181b649f..382ff36140024d98e9ca94a97b35a2599a0f41de 100644 (file)
@@ -9,14 +9,14 @@ var rnamespaces = /\.(.*)$/,
        rhoverHack = /\bhover(\.\S+)?/,
        rkeyEvent = /^key/,
        rmouseEvent = /^(?:mouse|contextmenu)|click/,
-       rquickIs = /^([\w\-]+)?(?:#([\w\-]+))?(?:\.([\w\-]+))?(?:\[([\w+\-]+)=["']?([\w\-]*)["']?\])?$/,
+       rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,
        quickParse = function( selector ) {
                var quick = rquickIs.exec( selector );
                if ( quick ) {
-                       //   0  1    2   3      4         5
-                       // [ _, tag, id, class, attrName, attrValue ]
+                       //   0  1    2   3
+                       // [ _, tag, id, class ]
                        quick[1] = ( quick[1] || "" ).toLowerCase();
-                       quick[3] = quick[3] && new RegExp( "(?:^|\\w)" + quick[3] + "(?:\\w|$)" );
+                       quick[3] = quick[3] && new RegExp( "(?:^|\\s)" + quick[3] + "(?:\\s|$)" );
                }
                return quick;
        },
@@ -24,8 +24,7 @@ var rnamespaces = /\.(.*)$/,
                return (
                        (!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
                        (!m[2] || elem.id === m[2]) &&
-                       (!m[3] || m[3].test( elem.className )) &&
-                       (!m[4] || elem.getAttribute( m[4] ) == m[5])
+                       (!m[3] || m[3].test( elem.className ))
                );
        };
 
index de9c225c1a2517a07e61693d2fcc3266ef26c24a..35664b02246c0819f64a74332a983012902211ba 100644 (file)
@@ -2409,11 +2409,11 @@ test(".on and .off", function() {
 });
 
 test("delegated events quickIs", function() {
-       expect(17);
+       expect(14);
        var markup = jQuery(
                        '<div>'+
                                '<p class="D">'+
-                                       'dead<b devo="cool">beat</b>club'+
+                                       'dead<b class="devo-like">beat</b>club'+
                                '</p>'+
                                '<q id="famous">'+
                                        'worked<em>or</em>borked?<em></em>'+
@@ -2437,29 +2437,18 @@ test("delegated events quickIs", function() {
                .appendTo( "body" )
                .on( "blink", "em", func )
                .on( "blink", ".D", func )
+               .on( "blink", ".devo-like", func )
+               .on( "blink", ".devo", func )
                .on( "blink", ".d", func )
                .on( "blink", "p.d", func )
-               .on( "blink", "[devo=cool]", func )
-               .on( "blink", "[devo='NO']", func )
                .on( "blink", "#famous", func );
 
-       check( "[devo=cool]", "b|[devo=cool] p|.D" );
-       check( "[devo='']", "" );
+       check( ".devo-like", "b|.devo-like p|.D" );
+       check( ".devo", "" );
        check( "p", "p|.D" );
-       check( "b", "b|[devo=cool] p|.D" );
+       check( "b", "b|.devo-like p|.D" );
        check( "em", "em|em q|#famous em|em q|#famous" );
 
-       markup.find( "b" ).attr( "devo", "NO" );
-       check( "b", "b|[devo='NO'] p|.D" );
-
-       markup
-               .on( "blink", ".tricky", function() {
-                       ok( false, "triggered on wrong class name match" );
-               })
-               .find( "p" )
-                       .attr( "class", "tricky-match" )
-                       .trigger( "blink" );
-
        markup.remove();
 });