diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/core.js | 4 | ||||
-rw-r--r-- | src/css.js | 14 | ||||
-rw-r--r-- | src/data.js | 6 | ||||
-rw-r--r-- | src/dimensions.js | 42 | ||||
-rw-r--r-- | test/unit/css.js | 20 | ||||
-rw-r--r-- | test/unit/selector.js | 21 |
7 files changed, 77 insertions, 32 deletions
@@ -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 99521d91c..3a37c4a89 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 933d2b45e..30cecf39d 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 31cdc121e..0407f73ff 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 5aafbf41e..f5212e1b6 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 40959b146..9c262af97 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( "<div>" ); + + 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( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body"); + + equals( div2.find("input").css("height"), "20px", "Height on hidden input." ); + equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." ); + equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." ); + + div2.remove(); + // handle negative numbers by ignoring #1599, #4216 jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 }); diff --git a/test/unit/selector.js b/test/unit/selector.js index 622e37e5b..856257f38 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -36,7 +36,7 @@ test("element", function() { if ( location.protocol != "file:" ) { test("XML Document Selectors", function() { - expect(7); + expect(8); stop(); jQuery.get("data/with_fries.xml", function(xml) { equals( jQuery("foo_bar", xml).length, 1, "Element Selector with underscore" ); @@ -46,6 +46,7 @@ if ( location.protocol != "file:" ) { equals( jQuery("[name=prop2]", xml).length, 1, "Attribute selector with name" ); equals( jQuery("#seite1", xml).length, 1, "Attribute selector with ID" ); equals( jQuery("component#seite1", xml).length, 1, "Attribute selector with ID" ); + equals( jQuery("component", xml).filter("#seite1").length, 1, "Attribute selector filter with ID" ); start(); }); }); @@ -153,7 +154,7 @@ test("class", function() { }); test("name", function() { - expect(14); + expect(15); t( "Name selector", "input[name=action]", ["text1"] ); t( "Name selector with single quotes", "input[name='action']", ["text1"] ); @@ -168,6 +169,12 @@ test("name", function() { same( jQuery("#form").find("input[name=action]").get(), q("text1"), "Name selector within the context of another element" ); same( jQuery("#form").find("input[name='foo[bar]']").get(), q("hidden2"), "Name selector for grouped form element within the context of another element" ); + var form = jQuery("<form><input name='id'/></form>").appendTo("body"); + + equals( form.find("input").length, 1, "Make sure that rooted queries on forms (with possible expandos) work." ); + + form.remove(); + var a = jQuery('<div><a id="tName1ID" name="tName1">tName1 A</a><a id="tName2ID" name="tName2">tName2 A</a><div id="tName1">tName1 Div</div></div>').appendTo('#main').children(); equals( a.length, 3, "Make sure the right number of elements were inserted." ); @@ -225,7 +232,7 @@ test("child and adjacent", function() { }); test("attributes", function() { - expect(34); + expect(35); t( "Attribute Exists", "a[title]", ["google"] ); t( "Attribute Exists", "*[title]", ["google"] ); t( "Attribute Exists", "[title]", ["google"] ); @@ -263,6 +270,9 @@ test("attributes", function() { t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] ); t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] ); + var opt = document.getElementById("option1a"); + ok( (window.Sizzle || window.jQuery.find).matchesSelector( opt, "[id*=option1][type!=checkbox]" ), "Attribute Is Not Equal Matches" ); + t("Empty values", "#select1 option[value='']", ["option1a"]); t("Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"]); @@ -320,10 +330,13 @@ test("pseudo - child", function() { }); test("pseudo - misc", function() { - expect(6); + expect(7); t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] ); t( "Has Children - :has()", "p:has(a)", ["firstp","ap","en","sap"] ); + + var select = document.getElementById("select1"); + ok( (window.Sizzle || window.jQuery.find).matchesSelector( select, ":has(option)" ), "Has Option Matches" ); t( "Text Contains", "a:contains(Google)", ["google","groups"] ); t( "Text Contains", "a:contains(Google Groups)", ["groups"] ); |