From: jeresig Date: Thu, 9 Dec 2010 17:33:26 +0000 (-0500) Subject: Merge branch 'support_6897' of https://github.com/rwldrn/jquery into rwldrn-support_6897 X-Git-Url: http://git.asbjorn.biz/?a=commitdiff_plain;h=b67154fd10c6226963dbbc4b3fe70d9f529b9d50;hp=e2d0671f4c260f2bd97fe76269188d5d6fc19dcd;p=jquery.git Merge branch 'support_6897' of https://github.com/rwldrn/jquery into rwldrn-support_6897 --- diff --git a/.gitattributes b/.gitattributes index bcb36db..d6dc470 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -* crlf=input +* eol=lf +*.jar binary diff --git a/src/ajax.js b/src/ajax.js index d10b931..90dc350 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -195,10 +195,24 @@ jQuery.extend({ }, ajax: function( origSettings ) { + // IE8 leaks a lot when we've set abort, and IE6-8 a little + // when we have set onreadystatechange. Bug #6242 + // XXX IE7 still leaks when abort is called, no matter what + // we do + function cleanup() { + // IE6 will throw an error setting xhr.abort + try { + xhr.abort = xhr.onreadystatechange = jQuery.noop; + } catch(e) {} + } + var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings), jsonp, status, data, type = s.type.toUpperCase(), noContent = rnoContent.test(type); - s.url = s.url.replace( rhash, "" ); + // toString fixes people passing a window.location or + // document.location to $.ajax, which worked in 1.4.2 and + // earlier (bug #7531). It should be removed in 1.5. + s.url = ("" + s.url).replace( rhash, "" ); // Use original (not extended) context object if it was provided s.context = origSettings && origSettings.context != null ? origSettings.context : s; @@ -261,7 +275,7 @@ jQuery.extend({ }; } - if ( s.dataType === "script" && s.cache === null ) { + if ( s.dataType === "script" && s.cache === undefined ) { s.cache = false; } @@ -403,13 +417,12 @@ jQuery.extend({ requestDone = true; if ( xhr ) { - xhr.onreadystatechange = jQuery.noop; + cleanup(); } // The transfer is complete and the data is available, or the request timed out } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) { requestDone = true; - xhr.onreadystatechange = jQuery.noop; status = isTimeout === "timeout" ? "timeout" : @@ -451,10 +464,7 @@ jQuery.extend({ xhr.abort(); } - // Stop memory leaks - if ( s.async ) { - xhr = null; - } + cleanup(); } }; diff --git a/src/attributes.js b/src/attributes.js index 4824c29..b0e3601 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -1,6 +1,6 @@ (function( jQuery ) { -var rclass = /[\n\t]/g, +var rclass = /[\n\t\r]/g, rspaces = /\s+/, rreturn = /\r/g, rspecialurl = /^(?:href|src|style)$/, @@ -205,7 +205,6 @@ jQuery.fn.extend({ if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) { return elem.getAttribute("value") === null ? "on" : elem.value; } - // Everything else, we just grab the value return (elem.value || "").replace(rreturn, ""); @@ -271,7 +270,7 @@ jQuery.extend({ height: true, offset: true }, - + attr: function( elem, name, value, pass ) { // don't set attributes on text and comment nodes if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { @@ -289,88 +288,96 @@ jQuery.extend({ // Try to normalize/fix the name name = notxml && jQuery.props[ name ] || name; - // These attributes require special treatment - var special = rspecialurl.test( name ); + // Only do all the following if this is a node (faster for style) + if ( elem.nodeType === 1 ) { + // These attributes require special treatment + var special = rspecialurl.test( name ); + + // Safari mis-reports the default selected property of an option + // Accessing the parent's selectedIndex property fixes it + if ( name === "selected" && !jQuery.support.optSelected ) { + var parent = elem.parentNode; + if ( parent ) { + parent.selectedIndex; + + // Make sure that it also works with optgroups, see #5701 + if ( parent.parentNode ) { + parent.parentNode.selectedIndex; + } + } + } - // Safari mis-reports the default selected property of an option - // Accessing the parent's selectedIndex property fixes it - if ( name === "selected" && !jQuery.support.optSelected ) { - var parent = elem.parentNode; - if ( parent ) { - parent.selectedIndex; + // If applicable, access the attribute via the DOM 0 way + // 'in' checks fail in Blackberry 4.7 #6931 + if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) { + if ( set ) { + // We can't allow the type property to be changed (since it causes problems in IE) + if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) { + jQuery.error( "type property can't be changed" ); + } + + if ( value === null ) { + if ( elem.nodeType === 1 ) { + elem.removeAttribute( name ); + } - // Make sure that it also works with optgroups, see #5701 - if ( parent.parentNode ) { - parent.parentNode.selectedIndex; + } else { + elem[ name ] = value; + } } - } - } - // If applicable, access the attribute via the DOM 0 way - // 'in' checks fail in Blackberry 4.7 #6931 - if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) { - if ( set ) { - // We can't allow the type property to be changed (since it causes problems in IE) - if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) { - jQuery.error( "type property can't be changed" ); + // browsers index elements by id/name on forms, give priority to attributes. + if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) { + return elem.getAttributeNode( name ).nodeValue; } - if ( value === null ) { - if ( elem.nodeType === 1 ) { - elem.removeAttribute( name ); - } + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set + // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ + if ( name === "tabIndex" ) { + var attributeNode = elem.getAttributeNode( "tabIndex" ); - } else { - elem[ name ] = value; + return attributeNode && attributeNode.specified ? + attributeNode.value : + rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? + 0 : + undefined; } - } - // browsers index elements by id/name on forms, give priority to attributes. - if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) { - return elem.getAttributeNode( name ).nodeValue; + return elem[ name ]; } - // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set - // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ - if ( name === "tabIndex" ) { - var attributeNode = elem.getAttributeNode( "tabIndex" ); + if ( !jQuery.support.style && notxml && name === "style" ) { + if ( set ) { + elem.style.cssText = "" + value; + } - return attributeNode && attributeNode.specified ? - attributeNode.value : - rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? - 0 : - undefined; + return elem.style.cssText; } - return elem[ name ]; - } - - if ( !jQuery.support.style && notxml && name === "style" ) { if ( set ) { - elem.style.cssText = "" + value; + // convert the value to a string (all browsers do this but IE) see #1070 + elem.setAttribute( name, "" + value ); } - return elem.style.cssText; - } + // Ensure that missing attributes return undefined + // Blackberry 4.7 returns "" from getAttribute #6938 + if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) { + return undefined; + } - if ( set ) { - // convert the value to a string (all browsers do this but IE) see #1070 - elem.setAttribute( name, "" + value ); - } + var attr = !jQuery.support.hrefNormalized && notxml && special ? + // Some attributes require a special call on IE + elem.getAttribute( name, 2 ) : + elem.getAttribute( name ); - // Ensure that missing attributes return undefined - // Blackberry 4.7 returns "" from getAttribute #6938 - if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) { - return undefined; + // Non-existent attributes return null, we normalize to undefined + return attr === null ? undefined : attr; } - - var attr = !jQuery.support.hrefNormalized && notxml && special ? - // Some attributes require a special call on IE - elem.getAttribute( name, 2 ) : - elem.getAttribute( name ); - - // Non-existent attributes return null, we normalize to undefined - return attr === null ? undefined : attr; + // Handle everything which isn't a DOM element node + if ( set ) { + elem[ name ] = value; + } + return elem[ name ]; } }); diff --git a/src/core.js b/src/core.js index 9e1bfc6..07d5caf 100644 --- a/src/core.js +++ b/src/core.js @@ -215,7 +215,7 @@ jQuery.fn = jQuery.prototype = { this.toArray() : // Return just the object - ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] ); + ( num < 0 ? this[ this.length + num ] : this[ num ] ); }, // Take an array of elements and push it onto the stack @@ -532,6 +532,12 @@ jQuery.extend({ }, isEmptyObject: function( obj ) { + + // Fixes #7413 Check to see if obj passes isPlainObject + if ( !jQuery.isPlainObject( obj ) ) { + return false; + } + for ( var name in obj ) { return false; } diff --git a/src/css.js b/src/css.js index 4665fa7..8a83c60 100644 --- a/src/css.js +++ b/src/css.js @@ -177,13 +177,18 @@ jQuery.each(["height", "width"], function( i, name ) { } if ( val != null ) { - return val === "" ? "auto" : val; + // Should return "auto" instead of 0, use 0 for + // temporary backwards-compat + return val === "" || val === "auto" ? "0px" : val; } } if ( val < 0 || val == null ) { val = elem.style[ name ]; - return val === "" ? "auto" : val; + + // Should return "auto" instead of 0, use 0 for + // temporary backwards-compat + return val === "" || val === "auto" ? "0px" : val; } return typeof val === "string" ? val : val + "px"; diff --git a/src/data.js b/src/data.js index f7f65ef..f1e031f 100644 --- a/src/data.js +++ b/src/data.js @@ -138,15 +138,17 @@ jQuery.fn.extend({ if ( typeof key === "undefined" ) { if ( this.length ) { - var attr = this[0].attributes, name; data = jQuery.data( this[0] ); - for ( var i = 0, l = attr.length; i < l; i++ ) { - name = attr[i].name; - - if ( name.indexOf( "data-" ) === 0 ) { - name = name.substr( 5 ); - dataAttr( this[0], name, data[ name ] ); + if ( this[0].nodeType === 1 ) { + var attr = this[0].attributes, name; + for ( var i = 0, l = attr.length; i < l; i++ ) { + name = attr[i].name; + + if ( name.indexOf( "data-" ) === 0 ) { + name = name.substr( 5 ); + dataAttr( this[0], name, data[ name ] ); + } } } } diff --git a/src/event.js b/src/event.js index 3cfc817..fd470e7 100644 --- a/src/event.js +++ b/src/event.js @@ -716,7 +716,7 @@ if ( !jQuery.support.submitBubbles ) { jQuery.event.special.submit = { setup: function( data, namespaces ) { - if ( this.nodeName.toLowerCase() !== "form" ) { + if ( this.nodeName && this.nodeName.toLowerCase() !== "form" ) { jQuery.event.add(this, "click.specialSubmit", function( e ) { var elem = e.target, type = elem.type; @@ -1075,8 +1075,8 @@ function liveHandler( event ) { events = events.events; } - // Make sure we avoid non-left-click bubbling in Firefox (#3861) - if ( event.liveFired === this || !events || !events.live || event.button && event.type === "click" ) { + // Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911) + if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) { return; } diff --git a/src/manipulation.js b/src/manipulation.js index d8fa020..e09dd7e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -10,6 +10,8 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, // checked="checked" or checked (html5) rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, raction = /\=([^="'>\s]+\/)>/g, + rbodystart = /^\s*\s*$/i, wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], @@ -198,11 +200,12 @@ jQuery.fn.extend({ // the name attribute on an input). var html = this.outerHTML, ownerDocument = this.ownerDocument; - if ( !html ) { var div = ownerDocument.createElement("div"); div.appendChild( this.cloneNode(true) ); html = div.innerHTML; + } else if ( rbodystart.test(html) && rbodyend.test(html) ) { + html = html.replace( rbodystart, "
" ).replace( rbodyend, "
" ); } return jQuery.clean([html.replace(rinlinejQuery, "") diff --git a/test/data/text.php b/test/data/text.php index c06ef4b..b9df4cf 100644 --- a/test/data/text.php +++ b/test/data/text.php @@ -1,12 +1,12 @@ -Lorem ipsum dolor sit amet -consectetuer adipiscing elit -Sed lorem leo -lorem leo consectetuer adipiscing elit -Sed lorem leo -rhoncus sit amet -elementum at -bibendum at, eros -Cras at mi et tortor egestas vestibulum -sed Cras at mi vestibulum -Phasellus sed felis sit amet -orci dapibus semper. +Lorem ipsum dolor sit amet +consectetuer adipiscing elit +Sed lorem leo +lorem leo consectetuer adipiscing elit +Sed lorem leo +rhoncus sit amet +elementum at +bibendum at, eros +Cras at mi et tortor egestas vestibulum +sed Cras at mi vestibulum +Phasellus sed felis sit amet +orci dapibus semper. diff --git a/test/delegatetest.html b/test/delegatetest.html index b2840c1..327085c 100644 --- a/test/delegatetest.html +++ b/test/delegatetest.html @@ -1,242 +1,242 @@ - - - - - - -

Change Tests

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Change each: - - - - - - - -
- - - - -
- -
- - - - -
- - - - - - - $(document).bind('change')
Live:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREADOCUMENT
Bind:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREA
Focusin:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREADOCUMENT
Focusout:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREADOCUMENT
Live Focus:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREA
Live Blur:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREA
-

Submit Tests

- - - - - - - - - - - - - - - -
- Submit each: - -
- -
-
-
- -
-
-
- -
-
$(document).bind('submit')
Results:TEXTPASSWORDBUTTONDOCUMENT
- - - - - - + + + + + + +

Change Tests

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Change each: + + + + + + + +
+ + + + +
+ +
+ + + + +
+ + + + + + + $(document).bind('change')
Live:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREADOCUMENT
Bind:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREA
Focusin:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREADOCUMENT
Focusout:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREADOCUMENT
Live Focus:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREA
Live Blur:SELECTMULTICHECKBOXRADIOFILETEXTTEXTAREA
+

Submit Tests

+ + + + + + + + + + + + + + + +
+ Submit each: + +
+ +
+
+
+ +
+
+
+ +
+
$(document).bind('submit')
Results:TEXTPASSWORDBUTTONDOCUMENT
+ + + + + + diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 4ce14c2..a0f3d49 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -710,10 +710,10 @@ test("jQuery.getScript(String, Function) - no callback", function() { }); test("jQuery.ajax() - JSONP, Local", function() { - expect(8); + expect(9); var count = 0; - function plus(){ if ( ++count == 8 ) start(); } + function plus(){ if ( ++count == 9 ) start(); } stop(); @@ -828,6 +828,17 @@ test("jQuery.ajax() - JSONP, Local", function() { plus(); } }); + + //#7578 + jQuery.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + beforeSend: function(){ + strictEqual( this.cache, false, "cache must be false on JSON request" ); + plus(); + return false; + } + }); }); test("JSONP - Custom JSONP Callback", function() { @@ -1350,6 +1361,16 @@ test("jQuery.ajax - active counter", function() { ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); }); +test( "jQuery.ajax - Location object as url (#7531)", 1, function () { + var success = false; + try { + var xhr = jQuery.ajax({ url: document.location }); + success = true; + xhr.abort(); + } catch (e) {} + + ok( success, "document.location did not generate exception" ); +}); } diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 3eb2474..f30779d 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -29,7 +29,7 @@ test("jQuery.props: itegrity test", function() { }); test("attr(String)", function() { - expect(31); + expect(37); // This one sometimes fails randomly ?! equals( jQuery('#text1').attr('value'), "Test", 'Check for value attribute' ); @@ -92,6 +92,14 @@ test("attr(String)", function() { ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." ); equals( jQuery(document).attr("nodeName"), "#document", "attr works correctly on document nodes (bug #7451)." ); + + var attributeNode = document.createAttribute("irrelevant"), + commentNode = document.createComment("some comment"), + textNode = document.createTextNode("some text"), + obj = {}; + jQuery.each( [document, attributeNode, commentNode, textNode, obj, "#firstp"], function( i, ele ) { + strictEqual( jQuery(ele).attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." ); + }); }); if ( !isLocal ) { @@ -125,7 +133,7 @@ test("attr(Hash)", function() { }); test("attr(String, Object)", function() { - expect(24); + expect(30); var div = jQuery("div").attr("foo", "bar"), fail = false; @@ -159,6 +167,25 @@ test("attr(String, Object)", function() { jQuery("#name").attr('maxLength', '10'); equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' ); + var attributeNode = document.createAttribute("irrelevant"), + commentNode = document.createComment("some comment"), + textNode = document.createTextNode("some text"), + obj = {}; + jQuery.each( [document, attributeNode, obj, "#firstp"], function( i, ele ) { + var $ele = jQuery( ele ); + $ele.attr( "nonexisting", "foo" ); + equal( $ele.attr("nonexisting"), "foo", "attr(name, value) works correctly for non existing attributes (bug #7500)." ); + }); + jQuery.each( [commentNode, textNode], function( i, ele ) { + var $ele = jQuery( ele ); + $ele.attr( "nonexisting", "foo" ); + strictEqual( $ele.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." ); + }); + //cleanup + jQuery.each( [document, "#firstp"], function( i, ele ) { + jQuery( ele ).removeAttr("nonexisting"); + }); + var table = jQuery('#table').append("cellcellcellcellcell"), td = table.find('td:first'); td.attr("rowspan", "2"); @@ -329,8 +356,26 @@ test("attr('tabindex', value)", function() { }); test("removeAttr(String)", function() { - expect(1); + expect(7); equals( jQuery('#mark').removeAttr( "class" )[0].className, "", "remove class" ); + + var attributeNode = document.createAttribute("irrelevant"), + commentNode = document.createComment("some comment"), + textNode = document.createTextNode("some text"), + obj = {}; + //removeAttr only really removes on DOM element nodes handle all other seperatyl + strictEqual( jQuery( "#firstp" ).attr( "nonexisting", "foo" ).removeAttr( "nonexisting" )[0].nonexisting, undefined, "removeAttr works correctly on DOM element nodes" ); + + jQuery.each( [document, attributeNode, obj], function( i, ele ) { + var $ele = jQuery( ele ); + $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" ); + strictEqual( ele.nonexisting, "", "removeAttr works correctly on non DOM element nodes (bug #7500)." ); + }); + jQuery.each( [commentNode, textNode], function( i, ele ) { + $ele = jQuery( ele ); + $ele.attr( "nonexisting", "foo" ).removeAttr( "nonexisting" ); + strictEqual( ele.nonexisting, undefined, "removeAttr works correctly on non DOM element nodes (bug #7500)." ); + }); }); test("val()", function() { @@ -744,7 +789,7 @@ test("toggleClass(Fucntion[, boolean]) with incoming value", function() { }); test("addClass, removeClass, hasClass", function() { - expect(14); + expect(17); var jq = jQuery("

Hi

"), x = jq[0]; @@ -764,12 +809,14 @@ test("addClass, removeClass, hasClass", function() { ok( jq.hasClass("hi"), "Check has1" ); ok( jq.hasClass("bar"), "Check has2" ); - var jq = jQuery("

"); - ok( jq.hasClass("class1"), "Check hasClass with carriage return" ); - ok( jq.is(".class1"), "Check is with carriage return" ); + var jq = jQuery("

"); + ok( jq.hasClass("class1"), "Check hasClass with line feed" ); + ok( jq.is(".class1"), "Check is with line feed" ); ok( jq.hasClass("class2"), "Check hasClass with tab" ); ok( jq.is(".class2"), "Check is with tab" ); ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" ); + ok( jq.hasClass("class4"), "Check hasClass with carriage return" ); + ok( jq.is(".class4"), "Check is with carriage return" ); jq.removeClass("class2"); ok( jq.hasClass("class2")==false, "Check the class has been properly removed" ); @@ -777,4 +824,6 @@ test("addClass, removeClass, hasClass", function() { ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" ); jq.removeClass("cla.ss3"); ok( jq.hasClass("cla.ss3")==false, "Check the dotted class has been removed" ); + jq.removeClass("class4"); + ok( jq.hasClass("class4")==false, "Check the class has been properly removed" ); }); diff --git a/test/unit/core.js b/test/unit/core.js index 7ef2ad7..3cbf3f6 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -547,15 +547,15 @@ test("toArray()", function() { }) test("get(Number)", function() { - expect(1); + expect(2); equals( jQuery("p").get(0), document.getElementById("firstp"), "Get A Single Element" ); + strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" ); }); test("get(-Number)",function() { - expect(1); - equals( jQuery("p").get(-1), - document.getElementById("first"), - "Get a single element with negative index" ) + expect(2); + equals( jQuery("p").get(-1), document.getElementById("first"), "Get a single element with negative index" ); + strictEqual( jQuery("#firstp").get(-2), undefined, "Try get with index negative index larger then elements count" ); }) test("each(Function)", function() { @@ -848,13 +848,20 @@ test("jQuery.makeArray", function(){ }); test("jQuery.isEmptyObject", function(){ - expect(2); + expect(11); equals(true, jQuery.isEmptyObject({}), "isEmptyObject on empty object literal" ); equals(false, jQuery.isEmptyObject({a:1}), "isEmptyObject on non-empty object literal" ); - - // What about this ? - // equals(true, jQuery.isEmptyObject(null), "isEmptyObject on null" ); + equals(false, jQuery.isEmptyObject(1), "isEmptyObject on number (wrong argument type)"); + equals(false, jQuery.isEmptyObject(0), "isEmptyObject on falsy number (wrong argument type)"); + equals(false, jQuery.isEmptyObject("test"), "isEmptyObject on string (wrong argument type)"); + equals(false, jQuery.isEmptyObject(""), "isEmptyObject on falsy string (wrong argument type)"); + equals(false, jQuery.isEmptyObject([1,2,3]), "isEmptyObject on array (wrong argument type)"); + equals(false, jQuery.isEmptyObject([]), "isEmptyObject on an empty array (wrong argument type)"); + equals(false, jQuery.isEmptyObject(undefined), "isEmptyObject on undefined (wrong argument type)"); + equals(false, jQuery.isEmptyObject(false), "isEmptyObject on undefined (wrong argument type)"); + equals(false, jQuery.isEmptyObject(null), "isEmptyObject on null (wrong argument type)" ); + }); test("jQuery.proxy", function(){ diff --git a/test/unit/css.js b/test/unit/css.js index 71f8835..cddd902 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -13,8 +13,10 @@ test("css(String|Hash)", function() { var div = jQuery( "
" ); - equals( div.css("width"), "auto", "Width on disconnected node." ); - equals( div.css("height"), "auto", "Height on disconnected node." ); + // These should be "auto" (or some better value) + // temporarily provide "0px" for backwards compat + equals( div.css("width"), "0px", "Width on disconnected node." ); + equals( div.css("height"), "0px", "Height on disconnected node." ); div.css({ width: 4, height: 4 }); diff --git a/test/unit/data.js b/test/unit/data.js index 315043c..1a0f84c 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -79,7 +79,7 @@ test("jQuery.data", function() { }); test(".data()", function() { - expect(4); + expect(5); var div = jQuery("#foo"); strictEqual( div.data("foo"), undefined, "Make sure that missing result is undefined" ); @@ -90,6 +90,9 @@ test(".data()", function() { var nodiv = jQuery("#unfound"); equals( nodiv.data(), null, "data() on empty set returns null" ); + + var obj = { foo: "bar" }; + equals( jQuery(obj).data(), obj, "Retrieve data object from a wrapped JS object (#7524)" ); }) test(".data(String) and .data(String, Object)", function() { diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index 92cf17b..8255bf3 100644 --- a/test/unit/dimensions.js +++ b/test/unit/dimensions.js @@ -103,7 +103,7 @@ test("height() with function args", function() { }); test("innerWidth()", function() { - expect(3); + expect(4); var $div = jQuery("#nothiddendiv"); // set styles @@ -121,10 +121,15 @@ test("innerWidth()", function() { // reset styles $div.css({ display: "", border: "", padding: "", width: "", height: "" }); + + var div = jQuery( "
" ); + + // Temporarily require 0 for backwards compat - should be auto + equals( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." ); }); test("innerHeight()", function() { - expect(3); + expect(4); var $div = jQuery("#nothiddendiv"); // set styles @@ -142,10 +147,15 @@ test("innerHeight()", function() { // reset styles $div.css({ display: "", border: "", padding: "", width: "", height: "" }); + + var div = jQuery( "
" ); + + // Temporarily require 0 for backwards compat - should be auto + equals( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." ); }); test("outerWidth()", function() { - expect(6); + expect(7); var $div = jQuery("#nothiddendiv"); $div.css("width", 30); @@ -164,10 +174,15 @@ test("outerWidth()", function() { // reset styles $div.css({ position: "", display: "", border: "", padding: "", width: "", height: "" }); + + var div = jQuery( "
" ); + + // Temporarily require 0 for backwards compat - should be auto + equals( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." ); }); test("outerHeight()", function() { - expect(6); + expect(7); var $div = jQuery("#nothiddendiv"); $div.css("height", 30); @@ -185,4 +200,9 @@ test("outerHeight()", function() { // reset styles $div.css({ display: "", border: "", padding: "", width: "", height: "" }); + + var div = jQuery( "
" ); + + // Temporarily require 0 for backwards compat - should be auto + equals( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." ); }); diff --git a/test/unit/event.js b/test/unit/event.js index 54431dd..a647e5f 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -493,7 +493,7 @@ test("bind(name, false), unbind(name, false)", function() { }); test("bind()/trigger()/unbind() on plain object", function() { - expect( 7 ); + expect( 8 ); var obj = {}; @@ -503,8 +503,13 @@ test("bind()/trigger()/unbind() on plain object", function() { // Make sure it doesn't complain when no events are found jQuery(obj).unbind("test"); - jQuery(obj).bind("test", function(){ - ok( true, "Custom event run." ); + jQuery(obj).bind({ + test: function() { + ok( true, "Custom event run." ); + }, + submit: function() { + ok( true, "Custom submit event run." ); + } }); var events = jQuery(obj).data("__events__"); @@ -516,8 +521,10 @@ test("bind()/trigger()/unbind() on plain object", function() { // Should trigger 1 jQuery(obj).trigger("test"); + jQuery(obj).trigger("submit"); jQuery(obj).unbind("test"); + jQuery(obj).unbind("submit"); // Should trigger 0 jQuery(obj).trigger("test"); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index d4c4348..4805016 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -814,7 +814,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() { }); test("clone()", function() { - expect(31); + expect(32); equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' ); var clone = jQuery('#yahoo').clone(); equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' ); @@ -872,6 +872,8 @@ test("clone()", function() { form.appendChild( div ); equals( jQuery(form).clone().children().length, 1, "Make sure we just get the form back." ); + + equal( jQuery("body").clone().children()[0].id, "qunit-header", "Make sure cloning body works" ); }); if (!isLocal) { diff --git a/version.txt b/version.txt index 4ae0c26..7810cd6 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.4.4pre \ No newline at end of file +1.4.5pre \ No newline at end of file