Fixed issue with .remove() not working correctly.
[jquery.git] / src / jquery / jquery.js
index 33d7c05..e26ae9e 100644 (file)
@@ -29,9 +29,6 @@ window.undefined = window.undefined;
  */
 function jQuery(a,c) {
 
-       // Initalize the extra macro functions
-       if ( !jQuery.initDone ) jQuery.init();
-
        // Shortcut for document ready (because $(document).each() is silly)
        if ( a && a.constructor == Function && jQuery.fn.ready )
                return jQuery(document).ready(a);
@@ -39,25 +36,6 @@ function jQuery(a,c) {
        // Make sure that a selection was provided
        a = a || jQuery.context || document;
 
-       /*
-        * Handle support for overriding other $() functions. Way too many libraries
-        * provide this function to simply ignore it and overwrite it.
-        */
-       /*
-       // Check to see if this is a possible collision case
-       if ( jQuery._$ && !c && a.constructor == String && 
-      
-               // Make sure that the expression is a colliding one
-               !/[^a-zA-Z0-9_-]/.test(a) &&
-        
-               // and that there are no elements that match it
-               // (this is the one truly ambiguous case)
-               !document.getElementsByTagName(a).length )
-
-                       // Use the default method, in case it works some voodoo
-                       return jQuery._$( a );
-       */
-
        // Watch for when a jQuery object is passed as the selector
        if ( a.jquery )
                return $( jQuery.merge( a, [] ) );
@@ -82,13 +60,16 @@ function jQuery(a,c) {
                // Find the matching elements and save them for later
                jQuery.find( a, c ) );
 
+  // See if an extra function was provided
        var fn = arguments[ arguments.length - 1 ];
+       
+       // If so, execute it in context
        if ( fn && fn.constructor == Function )
                this.each(fn);
 }
 
 // Map over the $ in case of overwrite
-if ( $ )
+if ( typeof $ != "undefined" )
        jQuery._$ = $;
 
 // Map the jQuery namespace to the '$' one
@@ -212,7 +193,15 @@ jQuery.fn = jQuery.prototype = {
         * argument representing the position of the element in the matched
         * set.
         *
-        * @example $("img").each(function(){ this.src = "test.jpg"; });
+        * @example $("img").each(function(){
+        *   this.src = "test.jpg";
+        * });
+        * @before <img/> <img/>
+        * @result <img src="test.jpg"/> <img src="test.jpg"/>
+        *
+        * @example $("img").each(function(i){
+        *   alert( "Image #" + i + " is " + this );
+        * });
         * @before <img/> <img/>
         * @result <img src="test.jpg"/> <img src="test.jpg"/>
         *
@@ -648,6 +637,7 @@ jQuery.fn = jQuery.prototype = {
         * @example $("p").not("#selected")
         * @before <p>Hello</p><p id="selected">Hello Again</p>
         * @result [ <p>Hello</p> ]
+        * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not")
         *
         * @name not
         * @type jQuery
@@ -685,7 +675,7 @@ jQuery.fn = jQuery.prototype = {
         * @name add
         * @type jQuery
         * @param Array<Element> els An array of Elements to add
-        * @cat jQuery
+        * @cat DOM/Traversing
         */
 
        /**
@@ -699,7 +689,7 @@ jQuery.fn = jQuery.prototype = {
         * @name add
         * @type jQuery
         * @param Element el An Element to add
-        * @cat jQuery
+        * @cat DOM/Traversing
         */
        add: function(t) {
                return this.pushStack( jQuery.merge( this, t.constructor == String ?
@@ -714,7 +704,7 @@ jQuery.fn = jQuery.prototype = {
         * @member jQuery
         * @param {String} expr The expression with which to filter
         * @type Boolean
-        * @cat jQuery
+        * @cat DOM/Traversing
         */
        is: function(expr) {
                return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
@@ -811,8 +801,6 @@ jQuery.extend = jQuery.fn.extend = function(obj,prop) {
 
 jQuery.extend({
        /**
-        * 
-        *
         * @private
         * @name init
         * @type undefined
@@ -934,17 +922,21 @@ jQuery.extend({
                                if (jQuery.css(e,"display") != "none") {
                                        oHeight = e.offsetHeight;
                                        oWidth = e.offsetWidth;
-                               } else
-                                       jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "block" },
-                                               function(){
-                                                       oHeight = e.clientHeight;
-                                                       oWidth = e.clientWidth;
-                                               });
+                               } else {
+                                       e = $(e.cloneNode(true)).css({
+                                               visibility: "hidden", position: "absolute", display: "block"
+                                       }).prependTo("body")[0];
+
+                                       oHeight = e.clientHeight;
+                                       oWidth = e.clientWidth;
+                                       
+                                       e.parentNode.removeChild(e);
+                               }
                        });
        
                        return p == "height" ? oHeight : oWidth;
                } else if ( p == "opacity" && jQuery.browser.msie )
-                       return parseFloat(  jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
+                       return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
 
                return jQuery.curCSS( e, p );
        },
@@ -959,7 +951,7 @@ jQuery.extend({
                } else if (elem.currentStyle) {
 
                        var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); 
-                       ret = elem.currentStyle[prop] || elem.currentStyle[np];
+                       ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
 
                } else if (document.defaultView && document.defaultView.getComputedStyle) {
 
@@ -2218,7 +2210,7 @@ jQuery.macros = {
 
                /**
                 * Get a set of elements containing the unique ancestors of the matched
-                * set of elements.
+                * set of elements (except for the root element).
                 *
                 * @example $("span").ancestors()
                 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
@@ -2246,7 +2238,7 @@ jQuery.macros = {
                
                /**
                 * Get a set of elements containing the unique ancestors of the matched
-                * set of elements.
+                * set of elements (except for the root element).
                 *
                 * @example $("span").ancestors()
                 * @before <html><body><div><p><span>Hello</span></p><span>Hello Again</span></div></body></html>
@@ -2391,7 +2383,7 @@ jQuery.macros = {
                 * @param String expr An expression to filter the child Elements with
                 * @cat DOM/Traversing
                 */
-               children: "a.childNodes"
+               children: "jQuery.sibling(a.firstChild)"
        },
 
        each: {
@@ -2417,7 +2409,7 @@ jQuery.macros = {
                 * @type jQuery
                 * @cat Effects
                 */
-               _show: function(){
+               show: function(){
                        this.style.display = this.oldblock ? this.oldblock : "";
                        if ( jQuery.css(this,"display") == "none" )
                                this.style.display = "block";
@@ -2440,7 +2432,7 @@ jQuery.macros = {
                 * @type jQuery
                 * @cat Effects
                 */
-               _hide: function(){
+               hide: function(){
                        this.oldblock = this.oldblock || jQuery.css(this,"display");
                        if ( this.oldblock == "none" )
                                this.oldblock = "block";
@@ -2460,9 +2452,8 @@ jQuery.macros = {
                 * @type jQuery
                 * @cat Effects
                 */
-               _toggle: function(){
-                       var d = jQuery.css(this,"display");
-                       $(this)[ !d || d == "none" ? "show" : "hide" ]();
+               toggle: function(){
+                       $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
                },
                
                /**
@@ -2558,7 +2549,7 @@ jQuery.macros = {
                 * @cat DOM/Manipulation
                 */
                remove: function(a){
-                       if ( !a || jQuery.filter( [this], a ).r )
+                       if ( !a || jQuery.filter( a, [this] ).r )
                                this.parentNode.removeChild( this );
                },
        
@@ -2672,3 +2663,5 @@ jQuery.macros = {
                }
        }
 };
+
+jQuery.init();