Added a new :animated selector - only selects elements that are currently being animated.
[jquery.git] / src / selector / selector.js
index f75bae3..33017aa 100644 (file)
@@ -2,7 +2,7 @@
 var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
                "(?:[\\w*_-]|\\\\.)" :
                "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
-       quickChild = new RegExp("^[/>]\\s*(" + chars + "+)"),
+       quickChild = new RegExp("^>\\s*(" + chars + "+)"),
        quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
        quickClass = new RegExp("^([#.]?)(" + chars + "*)");
 
@@ -59,20 +59,17 @@ jQuery.extend({
                        has: "jQuery.find(m[3],a).length",
 
                        // :header
-                       header: "/h\\d/i.test(a.nodeName)"
-               },
-               // DEPRECATED
-               "[": "jQuery.find(m[2],a).length"
+                       header: "/h\\d/i.test(a.nodeName)",
+
+                       // :animated
+                       animated: "jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length"
+               }
        },
        
        // The regular expressions that power the parsing engine
        parse: [
                // Match: [@value='test'], [@foo]
-               /^\[ *(@)([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
-
-               // DEPRECATED
-               // Match: [div], [div p]
-               /^(\[)\s*(.*?(\[.*?\])?[^[]*?)\s*\]/,
+               /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
 
                // Match: :contains('foo')
                /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
@@ -94,12 +91,6 @@ jQuery.extend({
                return cur;
        },
 
-       /**
-        * @name $.find
-        * @type Array<Element>
-        * @private
-        * @cat Core
-        */
        find: function( t, context ) {
                // Quickly handle non-string expressions
                if ( typeof t != "string" )
@@ -112,21 +103,6 @@ jQuery.extend({
                // Set the correct context (if none is provided)
                context = context || document;
 
-               // DEPRECATED
-               // Handle the common XPath // expression
-               if ( !t.indexOf("//") ) {
-                       //context = context.documentElement;
-                       t = t.substr(2,t.length);
-
-               // DEPRECATED
-               // And the / root expression
-               } else if ( !t.indexOf("/") && !context.ownerDocument ) {
-                       context = context.documentElement;
-                       t = t.substr(1,t.length);
-                       if ( t.indexOf("/") >= 1 )
-                               t = t.substr(t.indexOf("/"),t.length);
-               }
-
                // Initialize the search
                var ret = [context], done = [], last;
 
@@ -136,8 +112,7 @@ jQuery.extend({
                        var r = [];
                        last = t;
 
-                       // DEPRECATED
-                       t = jQuery.trim(t).replace( /^\/\//, "" );
+                       t = jQuery.trim(t);
 
                        var foundToken = false;
 
@@ -160,32 +135,28 @@ jQuery.extend({
                                if ( t.indexOf(" ") == 0 ) continue;
                                foundToken = true;
                        } else {
-                               // (.. and /) DEPRECATED
-                               re = /^((\/?\.\.)|([>\/+~]))\s*(\w*)/i;
+                               re = /^([>+~])\s*(\w*)/i;
 
                                if ( (m = re.exec(t)) != null ) {
                                        r = [];
 
-                                       var nodeName = m[4], mergeNum = jQuery.mergeNum++;
+                                       var nodeName = m[2], mergeNum = jQuery.mergeNum++;
                                        m = m[1];
 
-                                       for ( var j = 0, rl = ret.length; j < rl; j++ )
-                                               if ( m.indexOf("..") < 0 ) {
-                                                       var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
-                                                       for ( ; n; n = n.nextSibling )
-                                                               if ( n.nodeType == 1 ) {
-                                                                       if ( m == "~" && n.mergeNum == mergeNum ) break;
-                                                                       
-                                                                       if (!nodeName || n.nodeName.toUpperCase() == nodeName.toUpperCase() ) {
-                                                                               if ( m == "~" ) n.mergeNum = mergeNum;
-                                                                               r.push( n );
-                                                                       }
-                                                                       
-                                                                       if ( m == "+" ) break;
+                                       for ( var j = 0, rl = ret.length; j < rl; j++ ) {
+                                               var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
+                                               for ( ; n; n = n.nextSibling )
+                                                       if ( n.nodeType == 1 ) {
+                                                               if ( m == "~" && n.mergeNum == mergeNum ) break;
+                                                               
+                                                               if (!nodeName || n.nodeName.toUpperCase() == nodeName.toUpperCase() ) {
+                                                                       if ( m == "~" ) n.mergeNum = mergeNum;
+                                                                       r.push( n );
                                                                }
-                                               // DEPRECATED
-                                               } else
-                                                       r.push( ret[j].parentNode );
+                                                               
+                                                               if ( m == "+" ) break;
+                                                       }
+                                       }
 
                                        ret = r;
 
@@ -353,7 +324,7 @@ jQuery.extend({
                        else if ( m[1] == "." )
                                r = jQuery.classFilter(r, m[2], not);
 
-                       else if ( m[1] == "@" ) {
+                       else if ( m[1] == "[" ) {
                                var tmp = [], type = m[3];
                                
                                for ( var i = 0, rl = r.length; i < rl; i++ ) {
@@ -427,15 +398,6 @@ jQuery.extend({
                return { r: r, t: t };
        },
 
-       /**
-        * All ancestors of a given element.
-        *
-        * @private
-        * @name $.parents
-        * @type Array<Element>
-        * @param Element elem The element to find the ancestors of.
-        * @cat DOM/Traversing
-        */
        parents: function( elem ){
                var matched = [];
                var cur = elem.parentNode;
@@ -446,18 +408,6 @@ jQuery.extend({
                return matched;
        },
        
-       /**
-        * A handy, and fast, way to traverse in a particular direction and find
-        * a specific element.
-        *
-        * @private
-        * @name $.nth
-        * @type DOMElement
-        * @param DOMElement cur The element to search from.
-        * @param String|Number num The Nth result to match. Can be a number or a string (like 'even' or 'odd').
-        * @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
-        * @cat DOM/Traversing
-        */
        nth: function(cur,result,dir,elem){
                result = result || 1;
                var num = 0;
@@ -469,15 +419,6 @@ jQuery.extend({
                return cur;
        },
        
-       /**
-        * All elements on a specified axis.
-        *
-        * @private
-        * @name $.sibling
-        * @type Array
-        * @param Element elem The element to find all the siblings of (including itself).
-        * @cat DOM/Traversing
-        */
        sibling: function( n, elem ) {
                var r = [];