Fixed a problem with incorrect height/width being reported both in quirks mode (in...
[jquery.git] / jquery / jquery.js
index 66a3af8..b100a05 100644 (file)
@@ -13,7 +13,7 @@
 window.undefined = window.undefined;
 
 // Map over the $ in case of overwrite
-if ( $ ) var ._$ = $;
+if ( $ ) var _$ = $;
 
 /**
  * Create a new jQuery Object
@@ -110,11 +110,12 @@ jQuery.fn = jQuery.prototype = {
        text: function(e) {
                e = e || this.get();
                var t = "";
-               for ( var j = 0; j < e.length; j++ )
-                       for ( var i = 0; i < e[j].childNodes.length; i++ )
-                               t += e[j].childNodes[i].nodeType != 1 ?
-                                       e[j].childNodes[i].nodeValue :
-                                       jQuery.fn.text(e[j].childNodes[i].childNodes);
+               for ( var j = 0; j < e.length; j++ ) {
+                       var r = e[j].childNodes;
+                       for ( var i = 0; i < r.length; i++ )
+                               t += r[i].nodeType != 1 ?
+                                       r[i].nodeValue : jQuery.fn.text([ r[i] ]);
+               }
                return t;
        },
        
@@ -172,8 +173,9 @@ jQuery.fn = jQuery.prototype = {
                });
        },
        remove: function() {
-               this.each(function(){this.parentNode.removeChild( this );});
-               return this.pushStack( [] );
+               return this.each(function(){
+                       this.parentNode.removeChild( this );
+               });
        },
        
        wrap: function() {
@@ -270,7 +272,7 @@ jQuery.fn = jQuery.prototype = {
        },
        
        parent: function(a) {
-               var ret = jQuery.map(this.cur,"d.parentNode");
+               var ret = jQuery.map(this.cur,"a.parentNode");
                if ( a ) ret = jQuery.filter(a,ret).r;
                return this.pushStack(ret);
        },
@@ -370,42 +372,39 @@ jQuery.className = {
        jQuery.boxModel = ( jQuery.browser != "msie" || document.compatMode == "CSS1Compat" );
 })();
 
+$.swap = function(e,o,f) {
+       for ( var i in o ) {
+               e.style["old"+i] = e.style[i];
+               e.style[i] = o[i];
+       }
+       f.apply( e, [] );
+       for ( var i in o )
+               e.style[i] = e.style["old"+i];
+};
+
 jQuery.css = function(e,p) {
        // Adapted from Prototype 1.4.0
        if ( p == "height" || p == "width" ) {
+               var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
 
-               // Handle extra width/height provided by the W3C box model
-               var ph = (!jQuery.boxModel ? 0 :
-                       jQuery.css(e,"paddingTop") + jQuery.css(e,"paddingBottom") +
-                       jQuery.css(e,"borderTopWidth") + jQuery.css(e,"borderBottomWidth")) || 0;
-
-               var pw = (!jQuery.boxModel ? 0 :
-                       jQuery.css(e,"paddingLeft") + jQuery.css(e,"paddingRight") +
-                       jQuery.css(e,"borderLeftWidth") + jQuery.css(e,"borderRightWidth")) || 0;
-
-               var oHeight, oWidth;
-
-               if (jQuery.css(e,"display") != 'none') {
-                       oHeight = e.offsetHeight || parseInt(e.style.height) || 0;
-                       oWidth = e.offsetWidth || parseInt(e.style.width) || 0;
-               } else {
-                       var els = e.style;
-                       var ov = els.visibility;
-                       var op = els.position;
-                       var od = els.display;
-                       els.visibility = "hidden";
-                       els.position = "absolute";
-                       els.display = "";
-                       oHeight = e.clientHeight || parseInt(e.style.height);
-                       oWidth = e.clientWidth || parseInt(e.style.width);
-                       els.display = od;
-                       els.position = op;
-                       els.visibility = ov;
+               for ( var i in d ) {
+                       old["padding" + d[i]] = 0;
+                       old["border" + d[i] + "Width"] = 0;
                }
 
-               return p == "height" ?
-                       (oHeight - ph < 0 ? 0 : oHeight - ph) :
-                       (oWidth - pw < 0 ? 0 : oWidth - pw);
+               $.swap( e, old, function() {
+                       if (jQuery.css(e,"display") != 'none') {
+                               oHeight = e.offsetHeight;
+                               oWidth = e.offsetWidth;
+                       } else
+                               $.swap( e, { visibility: 'hidden', position: 'absolute', display: '' },
+                                       function(){
+                                               oHeight = e.clientHeight;
+                                               oWidth = e.clientWidth;
+                                       });
+               });
+
+               return p == "height" ? oHeight : oWidth;
        }
        
        var r;
@@ -420,7 +419,7 @@ jQuery.css = function(e,p) {
                r = s ? s.getPropertyValue(p) : null;
        }
        
-       return /top|right|left|bottom/i.test(p) ? parseFloat( r ) : r;
+       return r;
 };
 
 jQuery.clean = function(a) {
@@ -751,7 +750,7 @@ jQuery.map = function(a,f) {
        var r = [];
        for ( var i = 0; i < a.length; i++ ) {
                var t = f(a[i],i);
-               if ( t !== null ) {
+               if ( t !== null && t != undefined ) {
                        if ( t.constructor != Array ) t = [t];
                        r = jQuery.merge( t, r );
                }
@@ -804,15 +803,20 @@ jQuery.event = {
        },
        
        handle: function(event) {
-               if ( !event && !window.event ) return;
+               // Handle adding events to items in IFrames, in IE
+               event = event ||
+                       jQuery.event.fix( ((this.ownerDocument || this.document || 
+                               this).parentWindow || window).event );
+
+               // If no correct event was found, fail
+               if ( !event ) return;
        
                var returnValue = true, handlers = [];
-               event = event || jQuery.event.fix(window.event);
        
                for ( var j in this.events[event.type] )
                        handlers[handlers.length] = this.events[event.type][j];
        
-               for ( var i = 0; i < handlers.length; i++ ) {
+               for ( var i = 0; i < handlers.length; i++ )
                        if ( handlers[i].constructor == Function ) {
                                this.handleEvent = handlers[i];
                                if (this.handleEvent(event) === false) {
@@ -821,18 +825,19 @@ jQuery.event = {
                                        returnValue = false;
                                }
                        }
-               }
                return returnValue;
        },
        
        fix: function(event) {
-               event.preventDefault = function() {
-                       this.returnValue = false;
-               };
+               if ( event ) {
+                       event.preventDefault = function() {
+                               this.returnValue = false;
+                       };
                
-               event.stopPropagation = function() {
-                       this.cancelBubble = true;
-               };
+                       event.stopPropagation = function() {
+                               this.cancelBubble = true;
+                       };
+               }
                
                return event;
        }