From: John Resig Date: Mon, 25 Oct 2010 19:36:40 +0000 (-0700) Subject: Merge branch 'unusedTrue' of http://github.com/lrbabe/jquery into lrbabe-unusedTrue X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=36143ce63359cc64ebac696f27e4e7968caee902;hp=1a2400de08a762c854e02865603d4f14f9f1c6cc;p=jquery.git Merge branch 'unusedTrue' of github.com/lrbabe/jquery into lrbabe-unusedTrue --- diff --git a/Makefile b/Makefile index 6b46c7d..0dae732 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ SIZZLE_DIR = ${SRC_DIR}/sizzle QUNIT_DIR = ${TEST_DIR}/qunit JQ_VER = $(shell cat version.txt) -VER = sed s/@VERSION/${JQ_VER}/ +VER = sed "s/@VERSION/${JQ_VER}/" DATE=$(shell git log -1 --pretty=format:%ad) diff --git a/src/core.js b/src/core.js index 99521d9..3a37c4a 100644 --- a/src/core.js +++ b/src/core.js @@ -424,8 +424,8 @@ jQuery.extend({ } // Trigger any bound ready events - if ( jQuery.fn.triggerHandler ) { - jQuery( document ).triggerHandler( "ready" ); + if ( jQuery.fn.trigger ) { + jQuery( document ).trigger( "ready" ).unbind( "ready" ); } } }, diff --git a/src/css.js b/src/css.js index 933d2b4..30cecf3 100644 --- a/src/css.js +++ b/src/css.js @@ -169,7 +169,19 @@ jQuery.each(["height", "width"], function( i, name ) { }); } - return val + "px"; + if ( val <= 0 ) { + val = curCSS( elem, name, name ); + + if ( val != null ) { + return val === "auto" ? "" : val; + } + } + + if ( val < 0 || val == null ) { + return elem.style[ name ]; + } + + return typeof val === "string" ? val : val + "px"; } }, diff --git a/src/data.js b/src/data.js index 31cdc12..0407f73 100644 --- a/src/data.js +++ b/src/data.js @@ -134,9 +134,9 @@ jQuery.extend({ jQuery.fn.extend({ data: function( key, value ) { - if ( typeof key === "undefined" ) { - var data = null; + var data = null; + if ( typeof key === "undefined" ) { if ( this.length ) { var attr = this[0].attributes, name; data = jQuery.data( this[0] ); @@ -163,7 +163,7 @@ jQuery.fn.extend({ parts[1] = parts[1] ? "." + parts[1] : ""; if ( value === undefined ) { - var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); + data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); // Try to fetch any internally stored data first if ( data === undefined && this.length ) { diff --git a/src/dimensions.js b/src/dimensions.js index 5aafbf4..f5212e1 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -33,27 +33,29 @@ jQuery.each([ "Height", "Width" ], function( i, name ) { }); } - return jQuery.isWindow( elem ) ? + if ( jQuery.isWindow( elem ) ) { // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode - elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] || - elem.document.body[ "client" + name ] : - - // Get document width or height - (elem.nodeType === 9) ? // is it a document - // Either scroll[Width/Height] or offset[Width/Height], whichever is greater - Math.max( - elem.documentElement["client" + name], - elem.body["scroll" + name], elem.documentElement["scroll" + name], - elem.body["offset" + name], elem.documentElement["offset" + name] - ) : - - // Get or set width or height on the element - size === undefined ? - // Get width or height on the element - parseFloat( jQuery.css( elem, type ) ) : - - // Set the width or height on the element (default to pixels if value is unitless) - this.css( type, typeof size === "string" ? size : size + "px" ); + return elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] || + elem.document.body[ "client" + name ]; + + // Get document width or height + } else if ( elem.nodeType === 9 ) { + // Either scroll[Width/Height] or offset[Width/Height], whichever is greater + return Math.max( + elem.documentElement["client" + name], + elem.body["scroll" + name], elem.documentElement["scroll" + name], + elem.body["offset" + name], elem.documentElement["offset" + name] + ); + + // Get or set width or height on the element + } else if ( size === undefined ) { + var orig = jQuery.css( elem, type ), ret = parseFloat( orig ); + return jQuery.isNaN( ret ) ? orig : ret; + + // Set the width or height on the element (default to pixels if value is unitless) + } else { + return this.css( type, typeof size === "string" ? size : size + "px" ); + } }; }); diff --git a/test/unit/css.js b/test/unit/css.js index 40959b1..9c262af 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css"); test("css(String|Hash)", function() { - expect(34); + expect(41); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -11,6 +11,24 @@ test("css(String|Hash)", function() { jQuery('#nothiddendiv').css({display: 'block'}); ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible'); + var div = jQuery( "
" ); + + equals( div.css("width"), "", "Width on disconnected node." ); + equals( div.css("height"), "", "Height on disconnected node." ); + + div.css({ width: 4, height: 4 }); + + equals( div.css("width"), "4px", "Width on disconnected node." ); + equals( div.css("height"), "4px", "Height on disconnected node." ); + + var div2 = jQuery( "