diff options
author | John Resig <jeresig@gmail.com> | 2009-10-26 18:07:57 -0400 |
---|---|---|
committer | John Resig <jeresig@gmail.com> | 2009-10-26 18:07:57 -0400 |
commit | bbffc99f7c60d42d4286786dfd6a43aa31d62ae2 (patch) | |
tree | 58bd5ac0bebdd51a7b04275edf4f71d0db3f688a | |
parent | b7ccc58afec145120e8e675cf8fd30e9ea97f2a3 (diff) | |
download | jquery-bbffc99f7c60d42d4286786dfd6a43aa31d62ae2.tar.gz jquery-bbffc99f7c60d42d4286786dfd6a43aa31d62ae2.zip |
Moved a bunch of methods out of the jQuery-specific Sizzle code into more-appropriate files, in jQuery itself.
-rw-r--r-- | src/core.js | 2 | ||||
-rw-r--r-- | src/css.js | 16 | ||||
-rw-r--r-- | src/fx.js | 8 | ||||
-rw-r--r-- | src/manipulation.js | 2 | ||||
-rw-r--r-- | src/selector.js | 61 | ||||
-rw-r--r-- | src/traversing.js | 52 |
6 files changed, 75 insertions, 66 deletions
diff --git a/src/core.js b/src/core.js index ed1f7d5b1..f605e1d01 100644 --- a/src/core.js +++ b/src/core.js @@ -222,7 +222,7 @@ jQuery.fn = jQuery.prototype = { }, is: function( selector ) { - return !!selector && jQuery.multiFilter( selector, this ).length > 0; + return !!selector && jQuery.filter( selector, this ).length > 0; }, // For internal use only. diff --git a/src/css.js b/src/css.js index f47bc8e2b..6abcc956a 100644 --- a/src/css.js +++ b/src/css.js @@ -197,3 +197,19 @@ jQuery.extend({ } } }); + +if ( jQuery.expr && jQuery.expr.filters ) { + jQuery.expr.filters.hidden = function(elem){ + var width = elem.offsetWidth, height = elem.offsetHeight, + force = /^tr$/i.test( elem.nodeName ); // ticket #4512 + return ( width === 0 && height === 0 && !force ) ? + true : + ( width !== 0 && height !== 0 && !force ) ? + false : + !!( jQuery.curCSS(elem, "display") === "none" ); + }; + + jQuery.expr.filters.visible = function(elem){ + return !jQuery.expr.filters.hidden(elem); + }; +}
\ No newline at end of file @@ -420,3 +420,11 @@ jQuery.extend( jQuery.fx, { } } }); + +if ( jQuery.expr && jQuery.expr.filters ) { + jQuery.expr.filters.animated = function(elem){ + return jQuery.grep(jQuery.timers, function(fn){ + return elem === fn.elem; + }).length; + }; +}
\ No newline at end of file diff --git a/src/manipulation.js b/src/manipulation.js index 789bf54e7..eea377b7e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -333,7 +333,7 @@ jQuery.each({ jQuery.each({ // keepData is for internal use only--do not document remove: function( selector, keepData ) { - if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) { + if ( !selector || jQuery.filter( selector, [ this ] ).length ) { if ( !keepData && this.nodeType === 1 ) { cleanData( this.getElementsByTagName("*") ); cleanData( [ this ] ); diff --git a/src/selector.js b/src/selector.js index de8830aa1..6291d8621 100644 --- a/src/selector.js +++ b/src/selector.js @@ -998,67 +998,6 @@ var posProcess = function(selector, context){ jQuery.find = Sizzle; jQuery.expr = Sizzle.selectors; jQuery.expr[":"] = jQuery.expr.filters; - -Sizzle.selectors.filters.hidden = function(elem){ - var width = elem.offsetWidth, height = elem.offsetHeight, - force = /^tr$/i.test( elem.nodeName ); // ticket #4512 - return ( width === 0 && height === 0 && !force ) ? - true : - ( width !== 0 && height !== 0 && !force ) ? - false : - !!( jQuery.curCSS(elem, "display") === "none" ); -}; - -Sizzle.selectors.filters.visible = function(elem){ - return !Sizzle.selectors.filters.hidden(elem); -}; - -Sizzle.selectors.filters.animated = function(elem){ - return jQuery.grep(jQuery.timers, function(fn){ - return elem === fn.elem; - }).length; -}; - -jQuery.filter = jQuery.multiFilter = function( expr, elems, not ) { - if ( not ) { - expr = ":not(" + expr + ")"; - } - - return Sizzle.matches(expr, elems); -}; - -jQuery.dir = function( elem, dir ){ - var matched = [], cur = elem[dir]; - while ( cur && cur != document ) { - if ( cur.nodeType == 1 ) - matched.push( cur ); - cur = cur[dir]; - } - return matched; -}; - -jQuery.nth = function(cur, result, dir, elem){ - result = result || 1; - var num = 0; - - for ( ; cur; cur = cur[dir] ) - if ( cur.nodeType == 1 && ++num == result ) - break; - - return cur; -}; - -jQuery.sibling = function(n, elem){ - var r = []; - - for ( ; n; n = n.nextSibling ) { - if ( n.nodeType == 1 && n != elem ) - r.push( n ); - } - - return r; -}; - jQuery.unique = Sizzle.uniqueSort; return; diff --git a/src/traversing.js b/src/traversing.js index 8f1e5eb50..583a303d6 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -10,8 +10,8 @@ var winnow = function( elements, qualifier, keep ) { } else if( typeof qualifier === "string" ) { var filtered = jQuery.grep(elements, function(elem) { return elem.nodeType === 1 }); - if(isSimple.test( qualifier )) return jQuery.multiFilter(qualifier, filtered, !keep); - else qualifier = jQuery.multiFilter( qualifier, elements ); + if(isSimple.test( qualifier )) return jQuery.filter(qualifier, filtered, !keep); + else qualifier = jQuery.filter( qualifier, elements ); } return jQuery.grep(elements, function(elem, i) { @@ -128,7 +128,7 @@ jQuery.each({ var ret = jQuery.map( this, fn ); if ( selector && typeof selector === "string" ) { - ret = jQuery.multiFilter( selector, ret ); + ret = jQuery.filter( selector, ret ); } ret = this.length > 1 ? jQuery.unique( ret ) : ret; @@ -140,3 +140,49 @@ jQuery.each({ return this.pushStack( ret, name, selector ); }; }); + +jQuery.extend({ + filter: function( expr, elems, not ) { + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return jQuery.find.matches(expr, elems); + }, + + dir: function( elem, dir ) { + var matched = [], cur = elem[dir]; + while ( cur && cur.nodeType !== 9 ) { + if ( cur.nodeType === 1 ) { + matched.push( cur ); + } + cur = cur[dir]; + } + return matched; + }, + + nth: function( cur, result, dir, elem ) { + result = result || 1; + var num = 0; + + for ( ; cur; cur = cur[dir] ) { + if ( cur.nodeType === 1 && ++num === result ) { + break; + } + } + + return cur; + }, + + sibling: function( n, elem ) { + var r = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType === 1 && n !== elem ) { + r.push( n ); + } + } + + return r; + } +});
\ No newline at end of file |