From df7dfc2404807dce2f97c21782eb3a14ced86d6b Mon Sep 17 00:00:00 2001 From: rjgotten Date: Sun, 17 Oct 2010 08:30:05 -0700 Subject: [PATCH 001/418] Check against the type attribute of script elements retrieved through getElementsByTagName() so that only those elements of type "text/javascript" are handled by 'clean'. Fixes #6180: jQuery.clean should not touch script tags that are not of type text/javascript --- src/manipulation.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 325f303a..2cd95ce9 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -146,7 +146,7 @@ jQuery.fn.extend({ return set; } }, - + // keepData is for internal use only--do not document remove: function( selector, keepData ) { for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { @@ -161,7 +161,7 @@ jQuery.fn.extend({ } } } - + return this; }, @@ -177,7 +177,7 @@ jQuery.fn.extend({ elem.removeChild( elem.firstChild ); } } - + return this; }, @@ -322,9 +322,9 @@ jQuery.fn.extend({ } else { results = jQuery.buildFragment( args, this, scripts ); } - + fragment = results.fragment; - + if ( fragment.childNodes.length === 1 ) { first = fragment = fragment.firstChild; } else { @@ -429,18 +429,18 @@ jQuery.each({ jQuery.fn[ name ] = function( selector ) { var ret = [], insert = jQuery( selector ), parent = this.length === 1 && this[0].parentNode; - + if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) { insert[ original ]( this[0] ); return this; - + } else { for ( var i = 0, l = insert.length; i < l; i++ ) { var elems = (i > 0 ? this.clone(true) : this).get(); jQuery( insert[i] )[ original ]( elems ); ret = ret.concat( elems ); } - + return this.pushStack( ret, name, insert.selector ); } }; @@ -528,10 +528,12 @@ jQuery.extend({ for ( i = 0; ret[i]; i++ ) { if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); - + } else { if ( ret[i].nodeType === 1 ) { - ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) ); + var jsTags = jQuery.makeArray( ret[i].getElementsByTagName( "script" )), + jsTags = jQuery.grep(jsTags, function(n, i) { return ( !n.type || n.type.toLowerCase() === "text/javascript" ) }); + ret.splice.apply( ret, [i + 1, 0].concat( jsTags )); } fragment.appendChild( ret[i] ); } @@ -540,22 +542,22 @@ jQuery.extend({ return ret; }, - + cleanData: function( elems ) { var data, id, cache = jQuery.cache, special = jQuery.event.special, deleteExpando = jQuery.support.deleteExpando; - + for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) { continue; } id = elem[ jQuery.expando ]; - + if ( id ) { data = cache[ id ]; - + if ( data && data.events ) { for ( var type in data.events ) { if ( special[ type ] ) { @@ -566,14 +568,14 @@ jQuery.extend({ } } } - + if ( deleteExpando ) { delete elem[ jQuery.expando ]; } else if ( elem.removeAttribute ) { elem.removeAttribute( jQuery.expando ); } - + delete cache[ id ]; } } From 689d63f4871d96300d492fa5ab9d25301070efba Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Tue, 19 Oct 2010 09:29:20 +0400 Subject: [PATCH 002/418] Return control of $ and jQuery only if it is really necessary. This make jQuery.noConflict() callable anytime. --- src/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 99521d91..f701a20c 100644 --- a/src/core.js +++ b/src/core.js @@ -373,9 +373,9 @@ jQuery.extend = jQuery.fn.extend = function() { jQuery.extend({ noConflict: function( deep ) { - window.$ = _$; + if ( window.$ === jQuery ) window.$ = _$; - if ( deep ) { + if ( deep && window.jQuery === jQuery ) { window.jQuery = _jQuery; } From 1ac7b459a4defb8238309ae47afb3637719cf8be Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Mon, 22 Nov 2010 08:12:12 +0400 Subject: [PATCH 003/418] respect source guidelines --- src/core.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index f701a20c..4cc5eea1 100644 --- a/src/core.js +++ b/src/core.js @@ -373,7 +373,9 @@ jQuery.extend = jQuery.fn.extend = function() { jQuery.extend({ noConflict: function( deep ) { - if ( window.$ === jQuery ) window.$ = _$; + if ( window.$ === jQuery ) { + window.$ = _$; + } if ( deep && window.jQuery === jQuery ) { window.jQuery = _jQuery; From dd79199a08b9b69d139606619b818c429e0540c3 Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Mon, 22 Nov 2010 08:12:12 +0400 Subject: [PATCH 004/418] fix to follow current source style --- src/core.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index f701a20c..4cc5eea1 100644 --- a/src/core.js +++ b/src/core.js @@ -373,7 +373,9 @@ jQuery.extend = jQuery.fn.extend = function() { jQuery.extend({ noConflict: function( deep ) { - if ( window.$ === jQuery ) window.$ = _$; + if ( window.$ === jQuery ) { + window.$ = _$; + } if ( deep && window.jQuery === jQuery ) { window.jQuery = _jQuery; From 9f8cd6c499844451468257140e71f611abb3a040 Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Tue, 14 Dec 2010 21:53:04 -0500 Subject: [PATCH 005/418] Fixing $.proxy to work like (and use) Function.prototype.bind (ticket #7783) http://bugs.jquery.com/ticket/7783 --- src/core.js | 49 +++++++++++++++++++++++++++++------------------ src/event.js | 44 ++++++++++++++++++++++++++---------------- test/unit/core.js | 11 ++++++++--- 3 files changed, 65 insertions(+), 39 deletions(-) diff --git a/src/core.js b/src/core.js index 346e52d7..74ec4ea0 100644 --- a/src/core.js +++ b/src/core.js @@ -740,31 +740,42 @@ jQuery.extend({ // A global GUID counter for objects guid: 1, - proxy: function( fn, proxy, thisObject ) { - if ( arguments.length === 2 ) { - if ( typeof proxy === "string" ) { - thisObject = fn; - fn = thisObject[ proxy ]; - proxy = undefined; + // Bind a function to a context, optionally partially applying any + // arguments. + proxy: function( fn, context ) { + var args, proxy; - } else if ( proxy && !jQuery.isFunction( proxy ) ) { - thisObject = proxy; - proxy = undefined; + // Quick check to determine if target is callable, in the spec + // this throws a TypeError, but we will just return undefined. + if ( ! jQuery.isFunction( fn ) ) { + return undefined; + } + + if ( jQuery.isFunction( Function.prototype.bind ) ) { + // Native bind + args = slice.call( arguments, 1 ); + proxy = Function.prototype.bind.apply( fn, args ); + } else { + // Simulated bind + args = slice.call( arguments, 2 ); + if ( args.length ) { + proxy = function() { + return arguments.length ? + fn.apply( context, args.concat( slice.call( arguments ) ) ) : + fn.apply( context, args ); + }; + } else { + proxy = function() { + return arguments.length ? + fn.apply( context, arguments ) : + fn.call( context ); + }; } } - if ( !proxy && fn ) { - proxy = function() { - return fn.apply( thisObject || this, arguments ); - }; - } - // Set the guid of unique handler to the same of original handler, so it can be removed - if ( fn ) { - proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; - } + proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; - // So proxy can be declared as an argument return proxy; }, diff --git a/src/event.js b/src/event.js index fd470e71..82e9b52d 100644 --- a/src/event.js +++ b/src/event.js @@ -891,6 +891,8 @@ if ( document.addEventListener ) { jQuery.each(["bind", "one"], function( i, name ) { jQuery.fn[ name ] = function( type, data, fn ) { + var handler; + // Handle object literals if ( typeof type === "object" ) { for ( var key in type ) { @@ -904,10 +906,15 @@ jQuery.each(["bind", "one"], function( i, name ) { data = undefined; } - var handler = name === "one" ? jQuery.proxy( fn, function( event ) { - jQuery( this ).unbind( event, handler ); - return fn.apply( this, arguments ); - }) : fn; + if ( name === "one" ) { + handler = function( event ) { + jQuery( this ).unbind( event, handler ); + return fn.apply( this, arguments ); + }; + handler.guid = fn.guid || jQuery.guid++; + } else { + handler = fn; + } if ( type === "unload" && name !== "one" ) { this.one( type, data, fn ); @@ -971,24 +978,27 @@ jQuery.fn.extend({ toggle: function( fn ) { // Save reference to arguments for access in closure var args = arguments, - i = 1; + guid = fn.guid || jQuery.guid++, + i = 0, + toggler = function( event ) { + // Figure out which function to execute + var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i; + jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 ); + + // Make sure that clicks stop + event.preventDefault(); + + // and execute the function + return args[ lastToggle ].apply( this, arguments ) || false; + }; // link all the functions, so any of them can unbind this click handler + toggler.guid = guid; while ( i < args.length ) { - jQuery.proxy( fn, args[ i++ ] ); + args[ i++ ].guid = guid; } - return this.click( jQuery.proxy( fn, function( event ) { - // Figure out which function to execute - var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i; - jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 ); - - // Make sure that clicks stop - event.preventDefault(); - - // and execute the function - return args[ lastToggle ].apply( this, arguments ) || false; - })); + return this.click( toggler ); }, hover: function( fnOver, fnOut ) { diff --git a/test/unit/core.js b/test/unit/core.js index 70577837..9f9078a4 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -858,7 +858,7 @@ test("jQuery.isEmptyObject", function(){ }); test("jQuery.proxy", function(){ - expect(4); + expect(5); var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); }; var thisObject = { foo: "bar", method: test }; @@ -872,8 +872,13 @@ test("jQuery.proxy", function(){ // Make sure it doesn't freak out equals( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." ); - // Use the string shortcut - jQuery.proxy( thisObject, "method" )(); + // Partial application + var test2 = function( a ){ equals( a, "pre-applied", "Ensure arguments can be pre-applied." ); }; + jQuery.proxy( test2, null, "pre-applied" )(); + + // Partial application w/ normal arguments + var test3 = function( a, b ){ equals( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; + jQuery.proxy( test3, null, "pre-applied" )( "normal" ); }); test("jQuery.parseJSON", function(){ From 5b1b57850cfd4c92a4f9231581dff7faac489566 Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Wed, 15 Dec 2010 18:31:10 -0500 Subject: [PATCH 006/418] Add a quick test to $.support for native bind. As per the suggestion by ajpiano: https://github.com/gf3/jquery/commit/9f8cd6c499844451468257140e71f611abb3a040#commitcomment-218658 --- src/core.js | 2 +- src/support.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 74ec4ea0..a6e2a46f 100644 --- a/src/core.js +++ b/src/core.js @@ -751,7 +751,7 @@ jQuery.extend({ return undefined; } - if ( jQuery.isFunction( Function.prototype.bind ) ) { + if ( jQuery.support.nativeBind ) { // Native bind args = slice.call( arguments, 1 ); proxy = Function.prototype.bind.apply( fn, args ); diff --git a/src/support.js b/src/support.js index 67b41c4a..2913d217 100644 --- a/src/support.js +++ b/src/support.js @@ -60,6 +60,9 @@ // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) optSelected: opt.selected, + // Test for native Function#bind. + nativeBind: jQuery.isFunction( Function.prototype.bind ), + // Will be defined later deleteExpando: true, optDisabled: false, From 1ebb5ab3e1c670e04024cd949fa6f341e93c4487 Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Thu, 16 Dec 2010 16:04:23 -0500 Subject: [PATCH 007/418] Added list of browsers that currently support Function#bind. --- src/support.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/support.js b/src/support.js index 2913d217..1fd1c2a6 100644 --- a/src/support.js +++ b/src/support.js @@ -60,7 +60,8 @@ // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) optSelected: opt.selected, - // Test for native Function#bind. + // Test for presence of native Function#bind. + // Currently in: Chrome 7, FireFox 4 nativeBind: jQuery.isFunction( Function.prototype.bind ), // Will be defined later From 6bc9fc7c10a6dd2c8c7132307e63323a1f59d35f Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Sat, 18 Dec 2010 19:17:37 -0500 Subject: [PATCH 008/418] Perf. improvement based on fearphage's suggestion (direct vs call vs apply). --- src/core.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index a6e2a46f..2ffcb911 100644 --- a/src/core.js +++ b/src/core.js @@ -754,7 +754,11 @@ jQuery.extend({ if ( jQuery.support.nativeBind ) { // Native bind args = slice.call( arguments, 1 ); - proxy = Function.prototype.bind.apply( fn, args ); + if ( args.length ) { + proxy = Function.prototype.bind.apply( fn, args ); + } else { + proxy = fn.bind( context ); + } } else { // Simulated bind args = slice.call( arguments, 2 ); From ade531cfaa194eb13fa6307368d1e715f3be8326 Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Sat, 18 Dec 2010 19:26:36 -0500 Subject: [PATCH 009/418] Noted which browsers don't support Function#bind. --- src/support.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/support.js b/src/support.js index 1fd1c2a6..55c19d80 100644 --- a/src/support.js +++ b/src/support.js @@ -61,7 +61,7 @@ optSelected: opt.selected, // Test for presence of native Function#bind. - // Currently in: Chrome 7, FireFox 4 + // Not in: >= Chrome 6, >= FireFox 3, Safari 5?, IE 9?, Opera 11? nativeBind: jQuery.isFunction( Function.prototype.bind ), // Will be defined later From 612a908514b6ad6ec35754b0193887b01ce2c9f2 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Sat, 1 Jan 2011 13:49:59 -0500 Subject: [PATCH 010/418] #7883 .delegate and .live should accept false as the fn arg, like bind --- src/event.js | 7 ++++++- test/unit/event.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/event.js b/src/event.js index 675e5fff..4d908b92 100644 --- a/src/event.js +++ b/src/event.js @@ -1023,10 +1023,15 @@ jQuery.each(["live", "die"], function( i, name ) { return this; } - if ( jQuery.isFunction( data ) ) { + if ( jQuery.isFunction( data ) || data === false ) { fn = data; data = undefined; } + + if ( fn === false ) { + fn = returnFalse; + } + types = (types || "").split(" "); diff --git a/test/unit/event.js b/test/unit/event.js index b4672a8b..01fbac57 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -527,6 +527,45 @@ test("bind(name, false), unbind(name, false)", function() { equals( main, 1, "Verify that the trigger happened correctly." ); }); +test("live(name, false), die(name, false)", function() { + expect(3); + + var main = 0; + jQuery("#main").live("click", function(e){ main++; }); + jQuery("#ap").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); + + main = 0; + jQuery("#ap").live("click", false); + jQuery("#ap").trigger("click"); + equals( main, 0, "Verify that no bubble happened." ); + + main = 0; + jQuery("#ap").die("click", false); + jQuery("#ap").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); +}); + +test("delegate(selector, name, false), undelegate(selector, name, false)", function() { + expect(3); + + var main = 0; + + jQuery("#main").delegate("#ap", "click", function(e){ main++; }); + jQuery("#ap").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); + + main = 0; + jQuery("#ap").delegate("#groups", "click", false); + jQuery("#groups").trigger("click"); + equals( main, 0, "Verify that no bubble happened." ); + + main = 0; + jQuery("#ap").undelegate("#groups", "click", false); + jQuery("#groups").trigger("click"); + equals( main, 1, "Verify that the trigger happened correctly." ); +}); + test("bind()/trigger()/unbind() on plain object", function() { expect( 8 ); From 037d6bd5c33cea91974bbfeaaa30d26e9dc94d48 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Sat, 1 Jan 2011 17:13:04 -0500 Subject: [PATCH 011/418] 4321 returns empty jquery object --- src/core.js | 3 ++- test/unit/core.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 0211808c..fcbd1c35 100644 --- a/src/core.js +++ b/src/core.js @@ -17,7 +17,8 @@ var jQuery = function( selector, context ) { // A simple way to check for HTML strings or ID strings // (both of which we optimize for) - quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/, + quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/, + // Is it a simple selector isSimple = /^.[^:#\[\.,]*$/, diff --git a/test/unit/core.js b/test/unit/core.js index 9367ab10..2563f17c 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -12,7 +12,7 @@ test("Basic requirements", function() { }); test("jQuery()", function() { - expect(24); + expect(25); strictEqual( commonJSDefined, jQuery, "CommonJS registered (Bug #7102)" ); @@ -22,6 +22,7 @@ test("jQuery()", function() { equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); equals( jQuery("").length, 0, "jQuery('') === jQuery([])" ); + equals( jQuery("#").length, 0, "jQuery('#') === jQuery([])" ); var obj = jQuery("div") equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); From 5f52e61d74678786e2f40d4edbeb2396661bb9bc Mon Sep 17 00:00:00 2001 From: rwldrn Date: Sat, 1 Jan 2011 17:18:47 -0500 Subject: [PATCH 012/418] 4321 jQuery('#') returns empty jquery object --- src/core.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core.js b/src/core.js index fcbd1c35..3a4d9e66 100644 --- a/src/core.js +++ b/src/core.js @@ -19,7 +19,6 @@ var jQuery = function( selector, context ) { // (both of which we optimize for) quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/, - // Is it a simple selector isSimple = /^.[^:#\[\.,]*$/, From d03d2e9f26f85366ad2e91b9e2c76a249d7bf7be Mon Sep 17 00:00:00 2001 From: Xavi Date: Sun, 9 Jan 2011 19:11:05 -0500 Subject: [PATCH 013/418] Bug 7931; Fixed bug that caused scrollTop and scrollLeft setters to return null when called on an empty jquery object --- src/offset.js | 28 ++++++++++++++-------------- test/unit/offset.js | 8 +++++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/offset.js b/src/offset.js index 2040c9d8..d53a8813 100644 --- a/src/offset.js +++ b/src/offset.js @@ -261,13 +261,9 @@ jQuery.each( ["Left", "Top"], function( i, name ) { var method = "scroll" + name; jQuery.fn[ method ] = function(val) { - var elem = this[0], win; + var elem, win; - if ( !elem ) { - return null; - } - - if ( val !== undefined ) { + if ( val != undefined ) { // Set the scroll offset return this.each(function() { win = getWindow( this ); @@ -282,15 +278,19 @@ jQuery.each( ["Left", "Top"], function( i, name ) { this[ method ] = val; } }); - } else { - win = getWindow( elem ); - - // Return the scroll offset - return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] : - jQuery.support.boxModel && win.document.documentElement[ method ] || - win.document.body[ method ] : - elem[ method ]; } + + elem = this[0]; + if( !elem ) { + return null + } + + win = getWindow( elem ); + // Return the scroll offset + return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] : + jQuery.support.boxModel && win.document.documentElement[ method ] || + win.document.body[ method ] : + elem[ method ]; }; }); diff --git a/test/unit/offset.js b/test/unit/offset.js index cfa14449..66676def 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -333,7 +333,7 @@ testoffset("table", function( jQuery ) { }); testoffset("scroll", function( jQuery, win ) { - expect(16); + expect(20); var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8; @@ -379,6 +379,12 @@ testoffset("scroll", function( jQuery, win ) { equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); + + // Tests scrollTop/Left with empty jquery objects + ok( jQuery().scrollTop(100) != null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); + ok( jQuery().scrollLeft(100) != null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); + ok( jQuery().scrollTop() === null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); + ok( jQuery().scrollLeft() === null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); }); testoffset("body", function( jQuery ) { From 628bacc3ce26a7a0e0462c2a2e0d764edf859c97 Mon Sep 17 00:00:00 2001 From: Xavi Date: Sun, 9 Jan 2011 20:12:29 -0500 Subject: [PATCH 014/418] Bug 7931; Added missing semicolon and replaced '!=' with '!==' to allow null through --- src/offset.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/offset.js b/src/offset.js index d53a8813..02f067eb 100644 --- a/src/offset.js +++ b/src/offset.js @@ -263,7 +263,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) { jQuery.fn[ method ] = function(val) { var elem, win; - if ( val != undefined ) { + if ( val !== undefined ) { // Set the scroll offset return this.each(function() { win = getWindow( this ); @@ -282,7 +282,7 @@ jQuery.each( ["Left", "Top"], function( i, name ) { elem = this[0]; if( !elem ) { - return null + return null; } win = getWindow( elem ); From 8d28f41f669168ebd436599f8b187c783fec4ba9 Mon Sep 17 00:00:00 2001 From: Xavi Date: Sun, 9 Jan 2011 20:34:15 -0500 Subject: [PATCH 015/418] Bug 7931; Replaced with and --- test/unit/offset.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/offset.js b/test/unit/offset.js index 66676def..20bd7079 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -381,10 +381,10 @@ testoffset("scroll", function( jQuery, win ) { equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); // Tests scrollTop/Left with empty jquery objects - ok( jQuery().scrollTop(100) != null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); - ok( jQuery().scrollLeft(100) != null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); - ok( jQuery().scrollTop() === null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); - ok( jQuery().scrollLeft() === null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); + notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); + notEqual( jQuery().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); + strictEqual( jQuery().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); + strictEqual( jQuery().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); }); testoffset("body", function( jQuery ) { From bed64e65cc658409961a7127b715643390919e6c Mon Sep 17 00:00:00 2001 From: Xavi Date: Sun, 9 Jan 2011 20:39:23 -0500 Subject: [PATCH 016/418] Bug 7931; Added unit tests for scrollTop/Left. --- test/unit/offset.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unit/offset.js b/test/unit/offset.js index 20bd7079..69bf6d5d 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -333,7 +333,7 @@ testoffset("table", function( jQuery ) { }); testoffset("scroll", function( jQuery, win ) { - expect(20); + expect(22); var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8; @@ -383,6 +383,8 @@ testoffset("scroll", function( jQuery, win ) { // Tests scrollTop/Left with empty jquery objects notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); notEqual( jQuery().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); + notEqual( jQuery().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" ); + notEqual( jQuery().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" ); strictEqual( jQuery().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" ); strictEqual( jQuery().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" ); }); From b78e3fc39f96d63a60ea66e3d066815626e633d8 Mon Sep 17 00:00:00 2001 From: Xavi Date: Sun, 9 Jan 2011 20:51:20 -0500 Subject: [PATCH 017/418] Bug 7931; Inverted logic in scrollTop/Left (i.e. made --- src/offset.js | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/offset.js b/src/offset.js index 02f067eb..660efa23 100644 --- a/src/offset.js +++ b/src/offset.js @@ -263,34 +263,34 @@ jQuery.each( ["Left", "Top"], function( i, name ) { jQuery.fn[ method ] = function(val) { var elem, win; - if ( val !== undefined ) { - // Set the scroll offset - return this.each(function() { - win = getWindow( this ); - - if ( win ) { - win.scrollTo( - !i ? val : jQuery(win).scrollLeft(), - i ? val : jQuery(win).scrollTop() - ); - - } else { - this[ method ] = val; - } - }); + if(val === undefined) { + elem = this[0]; + if( !elem ) { + return null; + } + + win = getWindow( elem ); + // Return the scroll offset + return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] : + jQuery.support.boxModel && win.document.documentElement[ method ] || + win.document.body[ method ] : + elem[ method ]; } - elem = this[0]; - if( !elem ) { - return null; - } - - win = getWindow( elem ); - // Return the scroll offset - return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] : - jQuery.support.boxModel && win.document.documentElement[ method ] || - win.document.body[ method ] : - elem[ method ]; + // Set the scroll offset + return this.each(function() { + win = getWindow( this ); + + if ( win ) { + win.scrollTo( + !i ? val : jQuery(win).scrollLeft(), + i ? val : jQuery(win).scrollTop() + ); + + } else { + this[ method ] = val; + } + }); }; }); From 75655e5758bc786989f26a98b09aabbfb88f66fd Mon Sep 17 00:00:00 2001 From: Sylvester Keil Date: Sat, 15 Jan 2011 13:56:20 +0100 Subject: [PATCH 018/418] Use parseFloat instead of parseInt to read CSS values. This fixes #7730 and #7885. --- src/offset.js | 8 +++++--- test/unit/offset.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/offset.js b/src/offset.js index 2040c9d8..94b67c77 100644 --- a/src/offset.js +++ b/src/offset.js @@ -187,11 +187,13 @@ jQuery.offset = { // need to be able to calculate position if either top or left is auto and position is absolute if ( calculatePosition ) { curPosition = curElem.position(); + curTop = curPosition.top; + curLeft = curPosition.left; + } else { + curTop = parseFloat( curCSSTop ) || 0; + curLeft = parseFloat( curCSSLeft ) || 0; } - curTop = calculatePosition ? curPosition.top : parseInt( curCSSTop, 10 ) || 0; - curLeft = calculatePosition ? curPosition.left : parseInt( curCSSLeft, 10 ) || 0; - if ( jQuery.isFunction( options ) ) { options = options.call( elem, i, curOffset ); } diff --git a/test/unit/offset.js b/test/unit/offset.js index cfa14449..1f8c3b15 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -422,6 +422,32 @@ test("offsetParent", function(){ equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); }); +test("fractions (see #7730 and #7885)", function() { + expect(2); + + jQuery('body').append('
'); + + var expected = { top: 1000, left: 1000 }; + var div = jQuery('#fractions'); + + div.css({ + position: 'absolute', + left: '1000.7432222px', + top: '1000.532325px', + width: 100, + height: 100 + }); + + div.offset(expected); + + var result = div.offset(); + + equals( result.top, expected.top, "Check top" ); + equals( result.left, expected.left, "Check left" ); + + div.remove(); +}); + function testoffset(name, fn) { test(name, function() { From 135a384cf3e4cc3671de4cfcced20f294a5667a8 Mon Sep 17 00:00:00 2001 From: Xavi Date: Tue, 18 Jan 2011 12:40:07 -0500 Subject: [PATCH 019/418] Bug 7931; cleaned up white space in accordance to style guide --- src/offset.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/offset.js b/src/offset.js index 660efa23..8696c205 100644 --- a/src/offset.js +++ b/src/offset.js @@ -260,15 +260,15 @@ jQuery.fn.extend({ jQuery.each( ["Left", "Top"], function( i, name ) { var method = "scroll" + name; - jQuery.fn[ method ] = function(val) { + jQuery.fn[ method ] = function( val ) { var elem, win; - if(val === undefined) { - elem = this[0]; + if( val === undefined ) { + elem = this[ 0 ]; if( !elem ) { return null; } - + win = getWindow( elem ); // Return the scroll offset return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] : @@ -276,17 +276,16 @@ jQuery.each( ["Left", "Top"], function( i, name ) { win.document.body[ method ] : elem[ method ]; } - + // Set the scroll offset return this.each(function() { win = getWindow( this ); if ( win ) { win.scrollTo( - !i ? val : jQuery(win).scrollLeft(), - i ? val : jQuery(win).scrollTop() + !i ? val : jQuery( win ).scrollLeft(), + i ? val : jQuery( win ).scrollTop() ); - } else { this[ method ] = val; } From 574ae3b1be555dbd5242532739cd8e0a34e0569c Mon Sep 17 00:00:00 2001 From: Gianni Chiappetta Date: Fri, 21 Jan 2011 10:33:50 -0500 Subject: [PATCH 020/418] added: Backcompatibility with old proxy syntax. --- src/core.js | 6 ++++++ test/unit/core.js | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index 3bdedf53..ea3506a6 100644 --- a/src/core.js +++ b/src/core.js @@ -739,6 +739,12 @@ jQuery.extend({ proxy: function( fn, context ) { var args, proxy; + // XXX BACKCOMPAT: Support old string method. + if ( typeof context === "string" ) { + fn = fn[ context ]; + context = arguments[0]; + } + // Quick check to determine if target is callable, in the spec // this throws a TypeError, but we will just return undefined. if ( ! jQuery.isFunction( fn ) ) { diff --git a/test/unit/core.js b/test/unit/core.js index 7638554a..332fc51e 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -869,7 +869,7 @@ test("jQuery.isEmptyObject", function(){ }); test("jQuery.proxy", function(){ - expect(5); + expect(6); var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); }; var thisObject = { foo: "bar", method: test }; @@ -890,6 +890,10 @@ test("jQuery.proxy", function(){ // Partial application w/ normal arguments var test3 = function( a, b ){ equals( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); }; jQuery.proxy( test3, null, "pre-applied" )( "normal" ); + + // Test old syntax + var test4 = { meth: function( a ){ equals( a, "boom", "Ensure old syntax works." ); } }; + jQuery.proxy( test4, "meth" )( "boom" ); }); test("jQuery.parseJSON", function(){ From ed48787ec58c12917faf47e3b95e043b2b6ded10 Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 24 Jan 2011 16:18:19 -0500 Subject: [PATCH 021/418] Fix bug #2773, jQuery.fn.is to accept JQuery and node objects, and a small fix for winnow getting an undefined selector --- src/traversing.js | 5 ++-- test/unit/traversing.js | 60 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/traversing.js b/src/traversing.js index 90601df5..f8d08fa9 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -60,7 +60,8 @@ jQuery.fn.extend({ }, is: function( selector ) { - return !!selector && jQuery.filter( selector, this ).length > 0; + return !!selector && (typeof selector === "string" ? jQuery.filter( selector, this ).length > 0 : + this.filter( selector ).length > 0); }, closest: function( selectors, context ) { @@ -286,7 +287,7 @@ function winnow( elements, qualifier, keep ) { return retVal === keep; }); - } else if ( qualifier.nodeType ) { + } else if ( qualifier && qualifier.nodeType ) { return jQuery.grep(elements, function( elem, i ) { return (elem === qualifier) === keep; }); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 56fed220..a74ee08b 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -13,8 +13,8 @@ test("find(String)", function() { same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); }); -test("is(String)", function() { - expect(26); +test("is(String|undefined)", function() { + expect(27); ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' ); ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' ); ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' ); @@ -33,11 +33,13 @@ test("is(String)", function() { ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' ); ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' ); ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); + ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' ); ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' ); ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' ); ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' ); - + ok( !jQuery('#foo').is({ plain: "object" }), 'Check passing invalid object' ); + // test is() with comma-seperated expressions ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); @@ -45,6 +47,49 @@ test("is(String)", function() { ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); }); +test("is(Object)", function() { + expect(18); + ok( jQuery('#form').is( jQuery('form') ), 'Check for element: A form is a form' ); + ok( !jQuery('#form').is( jQuery('div') ), 'Check for element: A form is not a div' ); + ok( jQuery('#mark').is( jQuery('.blog') ), 'Check for class: Expected class "blog"' ); + ok( !jQuery('#mark').is( jQuery('.link') ), 'Check for class: Did not expect class "link"' ); + ok( jQuery('#simon').is( jQuery('.blog.link') ), 'Check for multiple classes: Expected classes "blog" and "link"' ); + ok( !jQuery('#simon').is( jQuery('.blogTest') ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); + ok( jQuery('#en').is( jQuery('[lang="en"]') ), 'Check for attribute: Expected attribute lang to be "en"' ); + ok( !jQuery('#en').is( jQuery('[lang="de"]') ), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); + ok( jQuery('#text1').is( jQuery('[type="text"]') ), 'Check for attribute: Expected attribute type to be "text"' ); + ok( !jQuery('#text1').is( jQuery('[type="radio"]') ), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); + ok( jQuery('#text2').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected to be disabled' ); + ok( !jQuery('#text1').is( jQuery(':disabled') ), 'Check for pseudoclass: Expected not disabled' ); + ok( jQuery('#radio2').is( jQuery(':checked') ), 'Check for pseudoclass: Expected to be checked' ); + ok( !jQuery('#radio1').is( jQuery(':checked') ), 'Check for pseudoclass: Expected not checked' ); + ok( jQuery('#foo').is( jQuery(':has(p)') ), 'Check for child: Expected a child "p" element' ); + ok( !jQuery('#foo').is( jQuery(':has(ul)') ), 'Check for child: Did not expect "ul" element' ); + ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)') ), 'Check for childs: Expected "p", "a" and "code" child elements' ); + ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)') ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); +}); + +test("is(node Object)", function() { + expect(17); + ok( jQuery('#form').is( jQuery('form')[0] ), 'Check for element: A form is a form' ); + ok( !jQuery('#form').is( jQuery('div')[0] ), 'Check for element: A form is not a div' ); + ok( jQuery('#mark').is( jQuery('.blog')[0] ), 'Check for class: Expected class "blog"' ); + ok( !jQuery('#mark').is( jQuery('.link')[0] ), 'Check for class: Did not expect class "link"' ); + ok( jQuery('#simon').is( jQuery('.blog.link')[0] ), 'Check for multiple classes: Expected classes "blog" and "link"' ); + ok( !jQuery('#simon').is( jQuery('.blogTest')[0] ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); + ok( jQuery('#en').is( jQuery('[lang="en"]')[1] ), 'Check for attribute: Expected attribute lang to be "en"' ); + ok( !jQuery('#en').is( jQuery('[lang="de"]')[0] ), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); + ok( jQuery('#text1').is( jQuery('[type="text"]')[0] ), 'Check for attribute: Expected attribute type to be "text"' ); + ok( !jQuery('#text1').is( jQuery('[type="radio"]')[0] ), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); + ok( jQuery('#text2').is( jQuery(':disabled')[0] ), 'Check for pseudoclass: Expected to be disabled' ); + ok( !jQuery('#text1').is( jQuery(':disabled')[0] ), 'Check for pseudoclass: Expected not disabled' ); + ok( !jQuery('#radio1').is( jQuery(':checked')[0] ), 'Check for pseudoclass: Expected not checked' ); + ok( jQuery('#foo').is( jQuery(':has(p)')[4] ), 'Check for child: Expected a child "p" element' ); + ok( !jQuery('#foo').is( jQuery(':has(ul)')[0] ), 'Check for child: Did not expect "ul" element' ); + ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)')[4] ), 'Check for childs: Expected "p", "a" and "code" child elements' ); + ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)')[0] ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); +}); + test("index()", function() { expect(1); @@ -82,11 +127,16 @@ test("index(Object|String|undefined)", function() { equals( jQuery('#radio2').index('#form :text') , -1, "Check for index not found within a selector" ); }); -test("filter(Selector)", function() { - expect(5); +test("filter(Selector|undefined)", function() { + expect(9); same( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); + + same( jQuery('p').filter(null).get(), [], "filter(null) should return an empty jQuery object"); + same( jQuery('p').filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); + same( jQuery('p').filter(0).get(), [], "filter(0) should return an empty jQuery object"); + same( jQuery('p').filter('').get(), [], "filter('') should return an empty jQuery object"); // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); From 82626799cacef94a1b35d0a0b4d284b38104704b Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Sun, 6 Feb 2011 19:34:57 -0500 Subject: [PATCH 022/418] Changed $.sub internals to match sub naming, added some more spacing in some areas for readability --- src/core.js | 36 ++++++++++++++++++------------------ src/css.js | 14 +++++++------- src/event.js | 6 ++---- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/core.js b/src/core.js index 2e634723..1bc4c1cf 100644 --- a/src/core.js +++ b/src/core.js @@ -441,7 +441,7 @@ jQuery.extend({ } else if ( document.attachEvent ) { // ensure firing before onload, // maybe late but safe also for iframes - document.attachEvent("onreadystatechange", DOMContentLoaded); + document.attachEvent( "onreadystatechange", DOMContentLoaded ); // A fallback to window.onload, that will always work window.attachEvent( "onload", jQuery.ready ); @@ -598,7 +598,7 @@ jQuery.extend({ each: function( object, callback, args ) { var name, i = 0, length = object.length, - isObj = length === undefined || jQuery.isFunction(object); + isObj = length === undefined || jQuery.isFunction( object ); if ( args ) { if ( isObj ) { @@ -625,7 +625,7 @@ jQuery.extend({ } } else { for ( var value = object[0]; - i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} + i < length && callback.call( value, i, value ) !== false; value = object[ ++i ] ) {} } } @@ -656,7 +656,7 @@ jQuery.extend({ // The extra typeof function check is to prevent crashes // in Safari 2 (See: #3039) // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930 - var type = jQuery.type(array); + var type = jQuery.type( array ); if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) { push.call( ret, array ); @@ -982,24 +982,24 @@ jQuery.extend({ }, sub: function() { - function jQuerySubclass( selector, context ) { - return new jQuerySubclass.fn.init( selector, context ); + function jQuerySub( selector, context ) { + return new jQuerySub.fn.init( selector, context ); } - jQuery.extend( true, jQuerySubclass, this ); - jQuerySubclass.superclass = this; - jQuerySubclass.fn = jQuerySubclass.prototype = this(); - jQuerySubclass.fn.constructor = jQuerySubclass; - jQuerySubclass.subclass = this.subclass; - jQuerySubclass.fn.init = function init( selector, context ) { - if ( context && context instanceof jQuery && !(context instanceof jQuerySubclass) ) { - context = jQuerySubclass(context); + jQuery.extend( true, jQuerySub, this ); + jQuerySub.superclass = this; + jQuerySub.fn = jQuerySub.prototype = this(); + jQuerySub.fn.constructor = jQuerySub; + jQuerySub.sub = this.sub; + jQuerySub.fn.init = function init( selector, context ) { + if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) { + context = jQuerySub( context ); } - return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass ); + return jQuery.fn.init.call( this, selector, context, rootjQuerySub ); }; - jQuerySubclass.fn.init.prototype = jQuerySubclass.fn; - var rootjQuerySubclass = jQuerySubclass(document); - return jQuerySubclass; + jQuerySub.fn.init.prototype = jQuerySub.fn; + var rootjQuerySub = jQuerySub(document); + return jQuerySub; }, browser: {} diff --git a/src/css.js b/src/css.js index 19c6342d..968188d6 100644 --- a/src/css.js +++ b/src/css.js @@ -215,8 +215,8 @@ if ( !jQuery.support.opacity ) { jQuery.cssHooks.opacity = { get: function( elem, computed ) { // IE uses filters for opacity - return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ? - (parseFloat(RegExp.$1) / 100) + "" : + return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ? + ( parseFloat( RegExp.$1 ) / 100 ) + "" : computed ? "1" : ""; }, @@ -228,13 +228,13 @@ if ( !jQuery.support.opacity ) { style.zoom = 1; // Set the alpha filter to set the opacity - var opacity = jQuery.isNaN(value) ? - "" : - "alpha(opacity=" + value * 100 + ")", + var opacity = jQuery.isNaN( value ) ? + "" : + "alpha(opacity=" + value * 100 + ")", filter = style.filter || ""; - style.filter = ralpha.test(filter) ? - filter.replace(ralpha, opacity) : + style.filter = ralpha.test( filter ) ? + filter.replace( ralpha, opacity ) : style.filter + ' ' + opacity; } }; diff --git a/src/event.js b/src/event.js index 2d53562a..01b05149 100644 --- a/src/event.js +++ b/src/event.js @@ -294,11 +294,9 @@ jQuery.event = { } }, - // bubbling is internal - trigger: function( event, data, elem /*, bubbling */ ) { + trigger: function( event, data, elem, bubbling /* For Internal Use Only */ ) { // Event object or event type - var type = event.type || event, - bubbling = arguments[3]; + var type = event.type || event; if ( !bubbling ) { event = typeof event === "object" ? From c5264ce196c2f6d60b9d662a160f8e146c9aa23c Mon Sep 17 00:00:00 2001 From: louisremi Date: Wed, 23 Feb 2011 15:53:29 +0100 Subject: [PATCH 023/418] fix the regular expression that turns camel-case properties to lower-case ones for IE9. Fixes #8346 --- src/css.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/css.js b/src/css.js index 8a982312..86a5c71a 100644 --- a/src/css.js +++ b/src/css.js @@ -3,7 +3,7 @@ var ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, rdashAlpha = /-([a-z])/ig, - rupper = /([A-Z])/g, + rupper = /([A-Z]|^ms)/g, rnumpx = /^-?\d+(?:px)?$/i, rnum = /^-?\d/, From e27fcf42ce152ede15c8617bb5d31dfb2088470c Mon Sep 17 00:00:00 2001 From: louisremi Date: Wed, 23 Feb 2011 15:55:13 +0100 Subject: [PATCH 024/418] comments for workarounds are always welcome. --- src/css.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/css.js b/src/css.js index 86a5c71a..04e205eb 100644 --- a/src/css.js +++ b/src/css.js @@ -3,6 +3,7 @@ var ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, rdashAlpha = /-([a-z])/ig, + // fixed for IE9, see #8346 rupper = /([A-Z]|^ms)/g, rnumpx = /^-?\d+(?:px)?$/i, rnum = /^-?\d/, From 83d1a1fd56cf00cea40c73564ea53588984f7255 Mon Sep 17 00:00:00 2001 From: jeresig Date: Wed, 23 Feb 2011 13:55:45 -0500 Subject: [PATCH 025/418] Updating the source version to 1.5.2pre. --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index 8e03717d..0b767508 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.5.1 \ No newline at end of file +1.5.2pre \ No newline at end of file From 5d9db486c774c10293d0813c89dfdbd973120030 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 24 Feb 2011 00:32:30 +0100 Subject: [PATCH 026/418] Revert "Fixes #8353. Adds a catch block in resolveWith so that the finally block gets executed in IE7 and IE6." This reverts commit cacea6f7e778d42cda56066a6b1da8fb163410cc. --- src/core.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/core.js b/src/core.js index d77c818e..036b2db6 100644 --- a/src/core.js +++ b/src/core.js @@ -843,12 +843,6 @@ jQuery.extend({ callbacks.shift().apply( context, args ); } } - // We have to add a catch block for - // IE prior to 8 or else the finally - // block will never get executed - catch (e) { - throw e; - } finally { fired = [ context, args ]; firing = 0; From 58faec7cb7e820ef910b4850f5234da3989e6961 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 24 Feb 2011 06:37:37 +0100 Subject: [PATCH 027/418] Removes unnecessary parenthesis from regular expression. --- src/ajax/jsonp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index 2691591d..c70aeb7d 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -1,7 +1,7 @@ (function( jQuery ) { var jsc = jQuery.now(), - jsre = /(\=)\?(&|$)|()\?\?()/i; + jsre = /(\=)\?(&|$)|\?\?/i; // Default jsonp settings jQuery.ajaxSetup({ From 14e9da51f96a7a9b1a5c239c32f4abe20eb2b795 Mon Sep 17 00:00:00 2001 From: gnarf Date: Thu, 24 Feb 2011 13:10:33 -0600 Subject: [PATCH 028/418] A quick change to detect AIR urls --- src/ajax.js | 2 +- test/unit/ajax.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index 6414e8c2..4714afda 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -19,7 +19,7 @@ var r20 = /%20/g, rucHeadersFunc = function( _, $1, $2 ) { return $1 + $2.toUpperCase(); }, - rurl = /^([\w\+\.\-]+:)\/\/([^\/?#:]*)(?::(\d+))?/, + rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?|\/[^\/])/, // Keep a copy of the old load method _load = jQuery.fn.load, diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 335c2ac4..4ce15f8f 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2239,6 +2239,18 @@ test("jQuery.ajax - active counter", function() { ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); }); +test("jQuery.ajax - compatible with AIR urls"), function() { + expect( 1 ); + stop(); + $.ajax({ + url: "app:/testing", + beforeSend: function() { + ok( this.crossDomain, "Detected crossDomain for AIR Url" ); + return false; + } + }); +}); + } //} \ No newline at end of file From 71bd828d9f975fb1047b9fa2a78949cafd8006ac Mon Sep 17 00:00:00 2001 From: gnarf Date: Thu, 24 Feb 2011 13:21:05 -0600 Subject: [PATCH 029/418] Grouped up the test --- test/unit/ajax.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 4ce15f8f..2a2ac46a 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -492,7 +492,7 @@ test(".ajax() - hash", function() { test("jQuery ajax - cross-domain detection", function() { - expect( 4 ); + expect( 5 ); var loc = document.location, otherPort = loc.port === 666 ? 667 : 666, @@ -507,6 +507,14 @@ test("jQuery ajax - cross-domain detection", function() { } }); + jQuery.ajax({ + url: 'app:/path', + beforeSend: function( _ , s ) { + ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" ); + return false; + } + }); + jQuery.ajax({ dataType: "jsonp", url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ), @@ -2239,18 +2247,6 @@ test("jQuery.ajax - active counter", function() { ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active ); }); -test("jQuery.ajax - compatible with AIR urls"), function() { - expect( 1 ); - stop(); - $.ajax({ - url: "app:/testing", - beforeSend: function() { - ok( this.crossDomain, "Detected crossDomain for AIR Url" ); - return false; - } - }); -}); - } //} \ No newline at end of file From c8a887af066a62840ec1910604ddb7e0c38728e8 Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Sun, 27 Feb 2011 12:47:35 -0600 Subject: [PATCH 030/418] Bug 2616; Adding object support to jQuery.map --- src/core.js | 28 +++++++++++++++++++++------- test/unit/core.js | 12 +++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/core.js b/src/core.js index 036b2db6..3ff12085 100644 --- a/src/core.js +++ b/src/core.js @@ -712,15 +712,29 @@ jQuery.extend({ // arg is for internal usage only map: function( elems, callback, arg ) { - var ret = [], value; + var ret = [], + value, + length = elems.length, + // same object detection used in jQuery.each, not full-proof but very speedy. + isObj = length === undefined; - // Go through the array, translating each of the items to their - // new value (or values). - for ( var i = 0, length = elems.length; i < length; i++ ) { - value = callback( elems[ i ], i, arg ); + if ( isObj ) { + for ( key in elems ) { + value = callback( elems[ key ], key, arg ); - if ( value != null ) { - ret[ ret.length ] = value; + if ( value != null ) { + ret[ ret.length ] = value; + } + } + } else { + // Go through the array, translating each of the items to their + // new value (or values). + for ( var i = 0; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } } } diff --git a/test/unit/core.js b/test/unit/core.js index bce0de0f..d77e6a97 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -608,7 +608,7 @@ test("first()/last()", function() { }); test("map()", function() { - expect(2);//expect(6); + expect(6); same( jQuery("#ap").map(function(){ @@ -625,26 +625,24 @@ test("map()", function() { q("ap","ap","ap"), "Single Map" ); - - return;//these haven't been accepted yet - + //for #2616 var keys = jQuery.map( {a:1,b:2}, function( v, k ){ return k; - }, [ ] ); + }); equals( keys.join(""), "ab", "Map the keys from a hash to an array" ); var values = jQuery.map( {a:1,b:2}, function( v, k ){ return v; - }, [ ] ); + }); equals( values.join(""), "12", "Map the values from a hash to an array" ); var scripts = document.getElementsByTagName("script"); var mapped = jQuery.map( scripts, function( v, k ){ return v; - }, {length:0} ); + }); equals( mapped.length, scripts.length, "Map an array(-like) to a hash" ); From 025f2c63e487e069215b2a03ded2b98198904af9 Mon Sep 17 00:00:00 2001 From: louisremi Date: Tue, 1 Mar 2011 00:54:15 +0100 Subject: [PATCH 031/418] fixing both #8403 and #8401: jQuery \"bulldozes\" other IE filters when setting opacity --- src/css.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/css.js b/src/css.js index 8a982312..9fdba3b7 100644 --- a/src/css.js +++ b/src/css.js @@ -221,7 +221,8 @@ if ( !jQuery.support.opacity ) { }, set: function( elem, value ) { - var style = elem.style; + var style = elem.style, + currentStyle = elem.currentStyle; // IE has trouble with opacity if it does not have layout // Force it by setting the zoom level @@ -231,11 +232,11 @@ if ( !jQuery.support.opacity ) { var opacity = jQuery.isNaN(value) ? "" : "alpha(opacity=" + value * 100 + ")", - filter = style.filter || ""; + filter = currentStyle && currentStyle.filter || style.filter || ""; style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : - style.filter + ' ' + opacity; + filter + ' ' + opacity; } }; } From c1279895f3f33cacc08e508c2409b587c0e6a5a2 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 3 Mar 2011 15:16:47 +0100 Subject: [PATCH 032/418] Fix for #8421. Makes sure resolveWith can be called with only one parameter. --- src/core.js | 2 ++ test/unit/core.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/core.js b/src/core.js index 036b2db6..1e7250f6 100644 --- a/src/core.js +++ b/src/core.js @@ -837,6 +837,8 @@ jQuery.extend({ // resolve with given context and args resolveWith: function( context, args ) { if ( !cancelled && !fired && !firing ) { + // make sure args are available (#8421) + args = args || []; firing = 1; try { while( callbacks[ 0 ] ) { diff --git a/test/unit/core.js b/test/unit/core.js index bce0de0f..208b21c6 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -916,7 +916,7 @@ test("jQuery.parseJSON", function(){ test("jQuery._Deferred()", function() { - expect( 10 ); + expect( 11 ); var deferred, object, @@ -1005,6 +1005,12 @@ test("jQuery._Deferred()", function() { deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); }); + + // #8421 + deferred = jQuery._Deferred(); + deferred.resolveWith().done(function() { + ok( true, "Test resolveWith can be called with no argument" ); + }); }); test("jQuery.Deferred()", function() { @@ -1143,16 +1149,16 @@ test("jQuery.sub() - Static Methods", function(){ } }); Subclass.fn.extend({subClassMethod: function() { return this;}}); - + //Test Simple Subclass ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true'); ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!'); same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly'); equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods'); - + //Create a SubSubclass var SubSubclass = Subclass.sub(); - + //Make Sure the SubSubclass inherited properly ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true'); ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!'); @@ -1169,7 +1175,7 @@ test("jQuery.sub() - Static Methods", function(){ ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!'); ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly'); notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods'); - + //This shows that the modifications to the SubSubClass did not bubble back up to it's superclass ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true'); ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!'); From 2d0bc7ce72ab8d64da0506a88c8cc543ce3ceaba Mon Sep 17 00:00:00 2001 From: jaubourg Date: Thu, 3 Mar 2011 19:38:06 +0100 Subject: [PATCH 033/418] Moves Deferred-related code into a separate module. Context handling has been simplified in _Deferred.resolve and jQuery.when has been refactored for clarity (and minor optimization). --- Makefile | 1 + src/core.js | 174 +------------------------- src/deferred.js | 169 +++++++++++++++++++++++++ test/csp.php | 1 + test/data/offset/absolute.html | 1 + test/data/offset/body.html | 1 + test/data/offset/fixed.html | 1 + test/data/offset/relative.html | 1 + test/data/offset/scroll.html | 1 + test/data/offset/static.html | 1 + test/data/offset/table.html | 1 + test/index.html | 2 + test/localfile.html | 1 + test/networkerror.html | 1 + test/readywait.html | 1 + test/unit/core.js | 221 -------------------------------- test/unit/deferred.js | 222 +++++++++++++++++++++++++++++++++ 17 files changed, 407 insertions(+), 393 deletions(-) create mode 100644 src/deferred.js create mode 100644 test/unit/deferred.js diff --git a/Makefile b/Makefile index bf41bccc..a6aae425 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js BASE_FILES = ${SRC_DIR}/core.js\ + ${SRC_DIR}/deferred.js\ ${SRC_DIR}/support.js\ ${SRC_DIR}/data.js\ ${SRC_DIR}/queue.js\ diff --git a/src/core.js b/src/core.js index 1e7250f6..9312ee28 100644 --- a/src/core.js +++ b/src/core.js @@ -50,15 +50,9 @@ var jQuery = function( selector, context ) { // For matching the engine and version of the browser browserMatch, - // Has the ready events already been bound? - readyBound = false, - // The deferred used on DOM ready readyList, - // Promise methods - promiseMethods = "then done fail isResolved isRejected promise".split( " " ), - // The ready event handler DOMContentLoaded, @@ -408,11 +402,11 @@ jQuery.extend({ }, bindReady: function() { - if ( readyBound ) { + if ( readyList ) { return; } - readyBound = true; + readyList = jQuery._Deferred(); // Catch cases where $(document).ready() is called after the // browser event has already occurred. @@ -792,167 +786,6 @@ jQuery.extend({ return (new Date()).getTime(); }, - // Create a simple deferred (one callbacks list) - _Deferred: function() { - var // callbacks list - callbacks = [], - // stored [ context , args ] - fired, - // to avoid firing when already doing so - firing, - // flag to know if the deferred has been cancelled - cancelled, - // the deferred itself - deferred = { - - // done( f1, f2, ...) - done: function() { - if ( !cancelled ) { - var args = arguments, - i, - length, - elem, - type, - _fired; - if ( fired ) { - _fired = fired; - fired = 0; - } - for ( i = 0, length = args.length; i < length; i++ ) { - elem = args[ i ]; - type = jQuery.type( elem ); - if ( type === "array" ) { - deferred.done.apply( deferred, elem ); - } else if ( type === "function" ) { - callbacks.push( elem ); - } - } - if ( _fired ) { - deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] ); - } - } - return this; - }, - - // resolve with given context and args - resolveWith: function( context, args ) { - if ( !cancelled && !fired && !firing ) { - // make sure args are available (#8421) - args = args || []; - firing = 1; - try { - while( callbacks[ 0 ] ) { - callbacks.shift().apply( context, args ); - } - } - finally { - fired = [ context, args ]; - firing = 0; - } - } - return this; - }, - - // resolve with this as context and given arguments - resolve: function() { - deferred.resolveWith( jQuery.isFunction( this.promise ) ? this.promise() : this, arguments ); - return this; - }, - - // Has this deferred been resolved? - isResolved: function() { - return !!( firing || fired ); - }, - - // Cancel - cancel: function() { - cancelled = 1; - callbacks = []; - return this; - } - }; - - return deferred; - }, - - // Full fledged deferred (two callbacks list) - Deferred: function( func ) { - var deferred = jQuery._Deferred(), - failDeferred = jQuery._Deferred(), - promise; - // Add errorDeferred methods, then and promise - jQuery.extend( deferred, { - then: function( doneCallbacks, failCallbacks ) { - deferred.done( doneCallbacks ).fail( failCallbacks ); - return this; - }, - fail: failDeferred.done, - rejectWith: failDeferred.resolveWith, - reject: failDeferred.resolve, - isRejected: failDeferred.isResolved, - // Get a promise for this deferred - // If obj is provided, the promise aspect is added to the object - promise: function( obj ) { - if ( obj == null ) { - if ( promise ) { - return promise; - } - promise = obj = {}; - } - var i = promiseMethods.length; - while( i-- ) { - obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ]; - } - return obj; - } - } ); - // Make sure only one callback list will be used - deferred.done( failDeferred.cancel ).fail( deferred.cancel ); - // Unexpose cancel - delete deferred.cancel; - // Call given func if any - if ( func ) { - func.call( deferred, deferred ); - } - return deferred; - }, - - // Deferred helper - when: function( object ) { - var lastIndex = arguments.length, - deferred = lastIndex <= 1 && object && jQuery.isFunction( object.promise ) ? - object : - jQuery.Deferred(), - promise = deferred.promise(); - - if ( lastIndex > 1 ) { - var array = slice.call( arguments, 0 ), - count = lastIndex, - iCallback = function( index ) { - return function( value ) { - array[ index ] = arguments.length > 1 ? slice.call( arguments, 0 ) : value; - if ( !( --count ) ) { - deferred.resolveWith( promise, array ); - } - }; - }; - while( ( lastIndex-- ) ) { - object = array[ lastIndex ]; - if ( object && jQuery.isFunction( object.promise ) ) { - object.promise().then( iCallback(lastIndex), deferred.reject ); - } else { - --count; - } - } - if ( !count ) { - deferred.resolveWith( promise, array ); - } - } else if ( deferred !== object ) { - deferred.resolve( object ); - } - return promise; - }, - // Use of jQuery.browser is frowned upon. // More details: http://docs.jquery.com/Utilities/jQuery.browser uaMatch: function( ua ) { @@ -991,9 +824,6 @@ jQuery.extend({ browser: {} }); -// Create readyList deferred -readyList = jQuery._Deferred(); - // Populate the class2type map jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); diff --git a/src/deferred.js b/src/deferred.js new file mode 100644 index 00000000..f0d7c08c --- /dev/null +++ b/src/deferred.js @@ -0,0 +1,169 @@ +(function( jQuery ) { + +var // Promise methods + promiseMethods = "then done fail isResolved isRejected promise".split( " " ), + // Static reference to slice + sliceDeferred = [].slice; + +jQuery.extend({ + // Create a simple deferred (one callbacks list) + _Deferred: function() { + var // callbacks list + callbacks = [], + // stored [ context , args ] + fired, + // to avoid firing when already doing so + firing, + // flag to know if the deferred has been cancelled + cancelled, + // the deferred itself + deferred = { + + // done( f1, f2, ...) + done: function() { + if ( !cancelled ) { + var args = arguments, + i, + length, + elem, + type, + _fired; + if ( fired ) { + _fired = fired; + fired = 0; + } + for ( i = 0, length = args.length; i < length; i++ ) { + elem = args[ i ]; + type = jQuery.type( elem ); + if ( type === "array" ) { + deferred.done.apply( deferred, elem ); + } else if ( type === "function" ) { + callbacks.push( elem ); + } + } + if ( _fired ) { + deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] ); + } + } + return this; + }, + + // resolve with given context and args + resolveWith: function( context, args ) { + if ( !cancelled && !fired && !firing ) { + // make sure args are available (#8421) + args = args || []; + firing = 1; + try { + while( callbacks[ 0 ] ) { + callbacks.shift().apply( context, args ); + } + } + finally { + fired = [ context, args ]; + firing = 0; + } + } + return this; + }, + + // resolve with this as context and given arguments + resolve: function() { + deferred.resolveWith( this, arguments ); + return this; + }, + + // Has this deferred been resolved? + isResolved: function() { + return !!( firing || fired ); + }, + + // Cancel + cancel: function() { + cancelled = 1; + callbacks = []; + return this; + } + }; + + return deferred; + }, + + // Full fledged deferred (two callbacks list) + Deferred: function( func ) { + var deferred = jQuery._Deferred(), + failDeferred = jQuery._Deferred(), + promise; + // Add errorDeferred methods, then and promise + jQuery.extend( deferred, { + then: function( doneCallbacks, failCallbacks ) { + deferred.done( doneCallbacks ).fail( failCallbacks ); + return this; + }, + fail: failDeferred.done, + rejectWith: failDeferred.resolveWith, + reject: failDeferred.resolve, + isRejected: failDeferred.isResolved, + // Get a promise for this deferred + // If obj is provided, the promise aspect is added to the object + promise: function( obj ) { + if ( obj == null ) { + if ( promise ) { + return promise; + } + promise = obj = {}; + } + var i = promiseMethods.length; + while( i-- ) { + obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ]; + } + return obj; + } + } ); + // Make sure only one callback list will be used + deferred.done( failDeferred.cancel ).fail( deferred.cancel ); + // Unexpose cancel + delete deferred.cancel; + // Call given func if any + if ( func ) { + func.call( deferred, deferred ); + } + return deferred; + }, + + // Deferred helper + when: function( firstParam ) { + var args = arguments, + i = 0, + length = args.length, + count = length, + deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ? + firstParam : + jQuery.Deferred(); + function resolveFunc( i ) { + return function( value ) { + args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value; + if ( !( --count ) ) { + deferred.resolveWith( deferred, args ); + } + }; + } + if ( length > 1 ) { + for( ; i < length; i++ ) { + if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) { + args[ i ].promise().then( resolveFunc(i), deferred.reject ); + } else { + --count; + } + } + if ( !count ) { + deferred.resolveWith( deferred, args ); + } + } else if ( deferred !== firstParam ) { + deferred.resolveWith( deferred, length ? [ firstParam ] : [] ); + } + return deferred.promise(); + } +}); + +})( jQuery ); diff --git a/test/csp.php b/test/csp.php index acf8f32c..13c324ea 100644 --- a/test/csp.php +++ b/test/csp.php @@ -6,6 +6,7 @@ CSP Test Page + diff --git a/test/data/offset/absolute.html b/test/data/offset/absolute.html index b4db30a6..9d7990a3 100644 --- a/test/data/offset/absolute.html +++ b/test/data/offset/absolute.html @@ -16,6 +16,7 @@ #positionTest { position: absolute; } + diff --git a/test/data/offset/body.html b/test/data/offset/body.html index e3eb4f80..8dbf282d 100644 --- a/test/data/offset/body.html +++ b/test/data/offset/body.html @@ -9,6 +9,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } + diff --git a/test/data/offset/fixed.html b/test/data/offset/fixed.html index f93c20ff..3181718d 100644 --- a/test/data/offset/fixed.html +++ b/test/data/offset/fixed.html @@ -13,6 +13,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } + diff --git a/test/data/offset/relative.html b/test/data/offset/relative.html index 35864760..280a2fc0 100644 --- a/test/data/offset/relative.html +++ b/test/data/offset/relative.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } + diff --git a/test/data/offset/scroll.html b/test/data/offset/scroll.html index 50de95e0..a0d1f4d1 100644 --- a/test/data/offset/scroll.html +++ b/test/data/offset/scroll.html @@ -14,6 +14,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } + diff --git a/test/data/offset/static.html b/test/data/offset/static.html index b1fb9f15..a61b6d10 100644 --- a/test/data/offset/static.html +++ b/test/data/offset/static.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } + diff --git a/test/data/offset/table.html b/test/data/offset/table.html index 528e5303..11fb0e79 100644 --- a/test/data/offset/table.html +++ b/test/data/offset/table.html @@ -11,6 +11,7 @@ #marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; } + diff --git a/test/index.html b/test/index.html index d6213153..c7c2ae55 100644 --- a/test/index.html +++ b/test/index.html @@ -9,6 +9,7 @@ + @@ -31,6 +32,7 @@ + diff --git a/test/localfile.html b/test/localfile.html index 96e0f982..c552f214 100644 --- a/test/localfile.html +++ b/test/localfile.html @@ -5,6 +5,7 @@ jQuery Local File Test + diff --git a/test/networkerror.html b/test/networkerror.html index b06a6ba4..f98bf469 100644 --- a/test/networkerror.html +++ b/test/networkerror.html @@ -16,6 +16,7 @@ div { margin-top: 10px; } + diff --git a/test/readywait.html b/test/readywait.html index 8e0d3d53..4f124767 100644 --- a/test/readywait.html +++ b/test/readywait.html @@ -15,6 +15,7 @@ #expectedOutput { background-color: green } + diff --git a/test/unit/core.js b/test/unit/core.js index 208b21c6..6ee8724d 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -914,227 +914,6 @@ test("jQuery.parseJSON", function(){ } }); -test("jQuery._Deferred()", function() { - - expect( 11 ); - - var deferred, - object, - test; - - deferred = jQuery._Deferred(); - - test = false; - - deferred.done( function( value ) { - equals( value , "value" , "Test pre-resolve callback" ); - test = true; - } ); - - deferred.resolve( "value" ); - - ok( test , "Test pre-resolve callbacks called right away" ); - - test = false; - - deferred.done( function( value ) { - equals( value , "value" , "Test post-resolve callback" ); - test = true; - } ); - - ok( test , "Test post-resolve callbacks called right away" ); - - deferred.cancel(); - - test = true; - - deferred.done( function() { - ok( false , "Cancel was ignored" ); - test = false; - } ); - - ok( test , "Test cancel" ); - - deferred = jQuery._Deferred().resolve(); - - try { - deferred.done( function() { - throw "Error"; - } , function() { - ok( true , "Test deferred do not cancel on exception" ); - } ); - } catch( e ) { - strictEqual( e , "Error" , "Test deferred propagates exceptions"); - deferred.done(); - } - - test = ""; - deferred = jQuery._Deferred().done( function() { - - test += "A"; - - }, function() { - - test += "B"; - - } ).resolve(); - - strictEqual( test , "AB" , "Test multiple done parameters" ); - - test = ""; - - deferred.done( function() { - - deferred.done( function() { - - test += "C"; - - } ); - - test += "A"; - - }, function() { - - test += "B"; - } ); - - strictEqual( test , "ABC" , "Test done callbacks order" ); - - deferred = jQuery._Deferred(); - - deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { - ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); - }); - - // #8421 - deferred = jQuery._Deferred(); - deferred.resolveWith().done(function() { - ok( true, "Test resolveWith can be called with no argument" ); - }); -}); - -test("jQuery.Deferred()", function() { - - expect( 10 ); - - jQuery.Deferred( function( defer ) { - strictEqual( this , defer , "Defer passed as this & first argument" ); - this.resolve( "done" ); - }).then( function( value ) { - strictEqual( value , "done" , "Passed function executed" ); - }); - - jQuery.Deferred().resolve().then( function() { - ok( true , "Success on resolve" ); - }, function() { - ok( false , "Error on resolve" ); - }); - - jQuery.Deferred().reject().then( function() { - ok( false , "Success on reject" ); - }, function() { - ok( true , "Error on reject" ); - }); - - ( new jQuery.Deferred( function( defer ) { - strictEqual( this , defer , "Defer passed as this & first argument (new)" ); - this.resolve( "done" ); - }) ).then( function( value ) { - strictEqual( value , "done" , "Passed function executed (new)" ); - }); - - ( new jQuery.Deferred() ).resolve().then( function() { - ok( true , "Success on resolve (new)" ); - }, function() { - ok( false , "Error on resolve (new)" ); - }); - - ( new jQuery.Deferred() ).reject().then( function() { - ok( false , "Success on reject (new)" ); - }, function() { - ok( true , "Error on reject (new)" ); - }); - - var tmp = jQuery.Deferred(); - - strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" ); - strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" ); -}); - -test("jQuery.when()", function() { - - expect( 23 ); - - // Some other objects - jQuery.each( { - - "an empty string": "", - "a non-empty string": "some string", - "zero": 0, - "a number other than zero": 1, - "true": true, - "false": false, - "null": null, - "undefined": undefined, - "a plain object": {} - - } , function( message , value ) { - - ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) { - strictEqual( resolveValue , value , "Test the promise was resolved with " + message ); - } ).promise ) , "Test " + message + " triggers the creation of a new Promise" ); - - } ); - - ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) { - strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" ); - } ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" ); - - var cache, i; - - for( i = 1 ; i < 4 ; i++ ) { - jQuery.when( cache || jQuery.Deferred( function() { - this.resolve( i ); - }) ).then( function( value ) { - strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) ); - cache = value; - }, function() { - ok( false , "Fail called" ); - }); - } -}); - -test("jQuery.when() - joined", function() { - - expect(8); - - jQuery.when( 1, 2, 3 ).done( function( a, b, c ) { - strictEqual( a , 1 , "Test first param is first resolved value - non-observables" ); - strictEqual( b , 2 , "Test second param is second resolved value - non-observables" ); - strictEqual( c , 3 , "Test third param is third resolved value - non-observables" ); - }).fail( function() { - ok( false , "Test the created deferred was resolved - non-observables"); - }); - - var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ), - errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" ); - - jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) { - strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" ); - same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" ); - strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" ); - }).fail( function() { - ok( false , "Test the created deferred was resolved - resolved observable"); - }); - - jQuery.when( 1 , errorDeferred , 3 ).done( function() { - ok( false , "Test the created deferred was rejected - rejected observable"); - }).fail( function( error , errorParam ) { - strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" ); - strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" ); - }); -}); - test("jQuery.sub() - Static Methods", function(){ expect(18); var Subclass = jQuery.sub(); diff --git a/test/unit/deferred.js b/test/unit/deferred.js new file mode 100644 index 00000000..6ba4767a --- /dev/null +++ b/test/unit/deferred.js @@ -0,0 +1,222 @@ +module("deferred", { teardown: moduleTeardown }); + +test("jQuery._Deferred()", function() { + + expect( 11 ); + + var deferred, + object, + test; + + deferred = jQuery._Deferred(); + + test = false; + + deferred.done( function( value ) { + equals( value , "value" , "Test pre-resolve callback" ); + test = true; + } ); + + deferred.resolve( "value" ); + + ok( test , "Test pre-resolve callbacks called right away" ); + + test = false; + + deferred.done( function( value ) { + equals( value , "value" , "Test post-resolve callback" ); + test = true; + } ); + + ok( test , "Test post-resolve callbacks called right away" ); + + deferred.cancel(); + + test = true; + + deferred.done( function() { + ok( false , "Cancel was ignored" ); + test = false; + } ); + + ok( test , "Test cancel" ); + + deferred = jQuery._Deferred().resolve(); + + try { + deferred.done( function() { + throw "Error"; + } , function() { + ok( true , "Test deferred do not cancel on exception" ); + } ); + } catch( e ) { + strictEqual( e , "Error" , "Test deferred propagates exceptions"); + deferred.done(); + } + + test = ""; + deferred = jQuery._Deferred().done( function() { + + test += "A"; + + }, function() { + + test += "B"; + + } ).resolve(); + + strictEqual( test , "AB" , "Test multiple done parameters" ); + + test = ""; + + deferred.done( function() { + + deferred.done( function() { + + test += "C"; + + } ); + + test += "A"; + + }, function() { + + test += "B"; + } ); + + strictEqual( test , "ABC" , "Test done callbacks order" ); + + deferred = jQuery._Deferred(); + + deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) { + ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" ); + }); + + // #8421 + deferred = jQuery._Deferred(); + deferred.resolveWith().done(function() { + ok( true, "Test resolveWith can be called with no argument" ); + }); +}); + +test("jQuery.Deferred()", function() { + + expect( 10 ); + + jQuery.Deferred( function( defer ) { + strictEqual( this , defer , "Defer passed as this & first argument" ); + this.resolve( "done" ); + }).then( function( value ) { + strictEqual( value , "done" , "Passed function executed" ); + }); + + jQuery.Deferred().resolve().then( function() { + ok( true , "Success on resolve" ); + }, function() { + ok( false , "Error on resolve" ); + }); + + jQuery.Deferred().reject().then( function() { + ok( false , "Success on reject" ); + }, function() { + ok( true , "Error on reject" ); + }); + + ( new jQuery.Deferred( function( defer ) { + strictEqual( this , defer , "Defer passed as this & first argument (new)" ); + this.resolve( "done" ); + }) ).then( function( value ) { + strictEqual( value , "done" , "Passed function executed (new)" ); + }); + + ( new jQuery.Deferred() ).resolve().then( function() { + ok( true , "Success on resolve (new)" ); + }, function() { + ok( false , "Error on resolve (new)" ); + }); + + ( new jQuery.Deferred() ).reject().then( function() { + ok( false , "Success on reject (new)" ); + }, function() { + ok( true , "Error on reject (new)" ); + }); + + var tmp = jQuery.Deferred(); + + strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" ); + strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" ); +}); + +test("jQuery.when()", function() { + + expect( 23 ); + + // Some other objects + jQuery.each( { + + "an empty string": "", + "a non-empty string": "some string", + "zero": 0, + "a number other than zero": 1, + "true": true, + "false": false, + "null": null, + "undefined": undefined, + "a plain object": {} + + } , function( message , value ) { + + ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) { + strictEqual( resolveValue , value , "Test the promise was resolved with " + message ); + } ).promise ) , "Test " + message + " triggers the creation of a new Promise" ); + + } ); + + ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) { + strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" ); + } ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" ); + + var cache, i; + + for( i = 1 ; i < 4 ; i++ ) { + jQuery.when( cache || jQuery.Deferred( function() { + this.resolve( i ); + }) ).then( function( value ) { + strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) ); + cache = value; + }, function() { + ok( false , "Fail called" ); + }); + } +}); + +test("jQuery.when() - joined", function() { + + expect(8); + + jQuery.when( 1, 2, 3 ).done( function( a, b, c ) { + strictEqual( a , 1 , "Test first param is first resolved value - non-observables" ); + strictEqual( b , 2 , "Test second param is second resolved value - non-observables" ); + strictEqual( c , 3 , "Test third param is third resolved value - non-observables" ); + }).fail( function() { + ok( false , "Test the created deferred was resolved - non-observables"); + }); + + var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ), + errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" ); + + jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) { + strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" ); + same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" ); + strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" ); + }).fail( function() { + ok( false , "Test the created deferred was resolved - resolved observable"); + }); + + jQuery.when( 1 , errorDeferred , 3 ).done( function() { + ok( false , "Test the created deferred was rejected - rejected observable"); + }).fail( function( error , errorParam ) { + strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" ); + strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" ); + }); +}); From 55ec6a71d2378a5301af71c2c0080e15289c3f78 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Fri, 4 Mar 2011 21:16:40 -0500 Subject: [PATCH 034/418] Fixes #7340. Use a single capturing handler to simulate bubbling focusin/focusout event on non-IE browsers. Allow native DOM methods to fire events other than the currently active one back into jQuery. --- src/event.js | 32 +++++++++++++++++++++++--------- test/unit/event.js | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/event.js b/src/event.js index f7e0a08c..61c8a93f 100644 --- a/src/event.js +++ b/src/event.js @@ -70,10 +70,10 @@ jQuery.event = { } if ( !eventHandle ) { - elemData.handle = eventHandle = function() { + elemData.handle = eventHandle = function( e ) { // Handle the second event of a trigger and when // an event is called after a page has unloaded - return typeof jQuery !== "undefined" && !jQuery.event.triggered ? + return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ? jQuery.event.handle.apply( eventHandle.elem, arguments ) : undefined; }; @@ -380,7 +380,7 @@ jQuery.event = { target[ "on" + targetType ] = null; } - jQuery.event.triggered = true; + jQuery.event.triggered = event.type; target[ targetType ](); } @@ -391,7 +391,7 @@ jQuery.event = { target[ "on" + targetType ] = old; } - jQuery.event.triggered = false; + jQuery.event.triggered = undefined; } } }, @@ -868,19 +868,33 @@ function trigger( type, elem, args ) { // Create "bubbling" focus and blur events if ( document.addEventListener ) { jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler while someone wants focusin/focusout + var attaches = 0; + jQuery.event.special[ fix ] = { setup: function() { - this.addEventListener( orig, handler, true ); + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); + } }, teardown: function() { - this.removeEventListener( orig, handler, true ); + if ( --attaches === 0 ) { + document.removeEventListener( orig, handler, true ); + } } }; - function handler( e ) { - e = jQuery.event.fix( e ); + function handler( donor ) { + // Donor event is always a native one; fix it and switch its type. + // Let focusin/out handler cancel the donor focus/blur event. + var e = jQuery.event.fix( donor ); e.type = fix; - return jQuery.event.handle.call( this, e ); + e.originalEvent = {}; + jQuery.event.trigger( e, null, e.target ); + if ( e.isDefaultPrevented() ) { + donor.preventDefault(); + } } }); } diff --git a/test/unit/event.js b/test/unit/event.js index b7b26046..d5498792 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -1966,6 +1966,31 @@ test("window resize", function() { ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." ); }); +test("focusin bubbles", function() { + expect(4); + + var input = jQuery( '' ).prependTo( "body" ), + order = 0; + + jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){ + equals( 1, order++, "focusin on the body second" ); + }); + + input.bind( "focusin.focusinBubblesTest", function(){ + equals( 0, order++, "focusin on the element first" ); + }); + + // DOM focus method + input[0].focus(); + // jQuery trigger, which calls DOM focus + order = 0; + input[0].blur(); + input.trigger( "focus" ); + + input.remove(); + jQuery( "body" ).unbind( "focusin.focusinBubblesTest" ); +}); + /* test("jQuery(function($) {})", function() { stop(); From 5c2d70979c15bbda5c90e1634abe11d8c350abcb Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Sat, 5 Mar 2011 09:30:29 -0600 Subject: [PATCH 035/418] bug 6158; fixing replaceWith from throwing errors on empty elements --- src/manipulation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/manipulation.js b/src/manipulation.js index ba316971..a4a81de4 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -261,6 +261,9 @@ jQuery.fn.extend({ } }); } else { + if ( !this.length ) { + return this; + } return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ); } }, From c9ef09c800ba7b6510d9e3a68f053ae29409f621 Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Sat, 5 Mar 2011 09:46:12 -0600 Subject: [PATCH 036/418] bug 6158; fixing replaceWith from throwing errors on non existant elements --- src/manipulation.js | 7 +++---- test/unit/manipulation.js | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index a4a81de4..613faabb 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -261,10 +261,9 @@ jQuery.fn.extend({ } }); } else { - if ( !this.length ) { - return this; - } - return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ); + return ( this.length ) ? + this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) : + this; } }, diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 34425ed3..1169032c 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -739,7 +739,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() { }); var testReplaceWith = function(val) { - expect(20); + expect(21); jQuery('#yahoo').replaceWith(val( 'buga' )); ok( jQuery("#replace")[0], 'Replace element with string' ); ok( !jQuery("#yahoo")[0], 'Verify that original element is gone, after string' ); @@ -799,6 +799,9 @@ var testReplaceWith = function(val) { var set = jQuery("
").replaceWith(val("test")); equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equals( set.length, 1, "Replace the disconnected node." ); + + var non_existant = jQuery('#does-not-exist').replaceWith( val("should not throw an error") ); + equals( non_existant.length, 0, "Length of non existant element." ) var $div = jQuery("
").appendTo("body"); // TODO: Work on jQuery(...) inline script execution @@ -827,7 +830,7 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() { test("replaceWith(Function)", function() { testReplaceWith(functionReturningObj); - expect(21); + expect(22); var y = jQuery("#yahoo")[0]; From dd100bf5ac56d5d44afe45d73fe1824bd0135872 Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Sat, 5 Mar 2011 09:59:25 -0600 Subject: [PATCH 037/418] bug 6158; fixing replaceWith from throwing errors on non existant elements; fixing semicolon --- test/unit/manipulation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 1169032c..ff3dff16 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -799,9 +799,9 @@ var testReplaceWith = function(val) { var set = jQuery("
").replaceWith(val("test")); equals( set[0].nodeName.toLowerCase(), "span", "Replace the disconnected node." ); equals( set.length, 1, "Replace the disconnected node." ); - + var non_existant = jQuery('#does-not-exist').replaceWith( val("should not throw an error") ); - equals( non_existant.length, 0, "Length of non existant element." ) + equals( non_existant.length, 0, "Length of non existant element." ); var $div = jQuery("
").appendTo("body"); // TODO: Work on jQuery(...) inline script execution From 6c124d3dd47fb399c7512c5c3b3420e438c32b65 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Mon, 7 Mar 2011 00:42:09 +0100 Subject: [PATCH 038/418] Fixes #8423. Never set X-Requested-With header automagically for cross-domain requests. --- src/ajax/xhr.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index a6473dd8..5dbc33d3 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -92,11 +92,12 @@ if ( jQuery.support.ajax ) { xhr.overrideMimeType( s.mimeType ); } - // Requested-With header - // Not set for crossDomain requests with no content - // (see why at http://trac.dojotoolkit.org/ticket/9486) - // Won't change header if already provided - if ( !( s.crossDomain && !s.hasContent ) && !headers["X-Requested-With"] ) { + // X-Requested-With header + // For cross-domain requests, seeing as conditions for a preflight are + // akin to a jigsaw puzzle, we simply never set it to be sure. + // (it can always be set on a per-request basis or even using ajaxSetup) + // For same-domain requests, won't change header if already provided. + if ( !s.crossDomain && !headers["X-Requested-With"] ) { headers[ "X-Requested-With" ] = "XMLHttpRequest"; } From d4e4414451e15d23d7174e8eeddaa952ed0e4d73 Mon Sep 17 00:00:00 2001 From: jeresig Date: Sun, 6 Mar 2011 22:47:40 -0500 Subject: [PATCH 039/418] Very crude first pass at splitting apart the attr/prop logic. Also adding in attrHooks/propHooks. All of it is completely untested. --- src/attributes.js | 274 ++++++++++++++++++++++++++++------------------ 1 file changed, 168 insertions(+), 106 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index 59972105..e5425a05 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -3,38 +3,37 @@ var rclass = /[\n\t\r]/g, rspaces = /\s+/, rreturn = /\r/g, - rspecialurl = /^(?:href|src|style)$/, rtype = /^(?:button|input)$/i, rfocusable = /^(?:button|input|object|select|textarea)$/i, rclickable = /^a(?:rea)?$/i, rradiocheck = /^(?:radio|checkbox)$/i; -jQuery.props = { - "for": "htmlFor", - "class": "className", - readonly: "readOnly", - maxlength: "maxLength", - cellspacing: "cellSpacing", - rowspan: "rowSpan", - colspan: "colSpan", - tabindex: "tabIndex", - usemap: "useMap", - frameborder: "frameBorder" -}; - jQuery.fn.extend({ attr: function( name, value ) { return jQuery.access( this, name, value, true, jQuery.attr ); }, - removeAttr: function( name, fn ) { - return this.each(function(){ - jQuery.attr( this, name, "" ); + removeAttr: function( name ) { + return this.each(function() { if ( this.nodeType === 1 ) { this.removeAttribute( name ); } }); }, + + prop: function( name, value ) { + return jQuery.access( this, name, value, true, jQuery.prop ); + }, + + removeProp: function( name ) { + return this.each(function() { + // try/catch handles cases where IE balks (such as removing a property on window) + try { + this[ name ] = undefined; + delete this[ name ]; + } catch( e ) {} + }); + }, addClass: function( value ) { if ( jQuery.isFunction(value) ) { @@ -275,6 +274,21 @@ jQuery.extend({ height: true, offset: true }, + + // TODO: Check to see if any of these are needed anymore? + // If not, it may be good to standardize on all-lowercase names instead + attrFix: { + "for": "htmlFor", + "class": "className", + readonly: "readOnly", + maxlength: "maxLength", + cellspacing: "cellSpacing", + rowspan: "rowSpan", + colspan: "colSpan", + tabindex: "tabIndex", + usemap: "useMap", + frameborder: "frameBorder" + }, attr: function( elem, name, value, pass ) { // don't get/set attributes on text, comment and attribute nodes @@ -286,104 +300,152 @@ jQuery.extend({ return jQuery(elem)[name](value); } - var notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ), - // Whether we are setting (or getting) - set = value !== undefined; - + var ret, + notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ), + hooks; + // Try to normalize/fix the name - name = notxml && jQuery.props[ name ] || name; + name = notxml && jQuery.attrFix[ name ] || name; + + hooks = jQuery.attrHooks[ name ]; + + if ( value !== undefined ) { + + if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value )) !== undefined ) { + return ret; + + } else { + // convert the value to a string (all browsers do this but IE) see #1070 + value = "" + value; + + elem.setAttribute( name, value ); + + return value; + } + + } else { + + if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem )) !== undefined ) { + return ret; + + } else { + + if ( !jQuery.hasAttr( elem, name ) ) { + return undefined; + } - // 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 ); + var attr = elem.getAttribute( 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; - } + // Non-existent attributes return null, we normalize to undefined + return attr === null ? + undefined : + attr; + } + } + }, + + hasAttr: function( elem, name ) { + // Blackberry 4.7 returns "" from getAttribute #6938 + return elem.attributes[ name ] || (elem.hasAttribute && elem.hasAttribute( name )); + }, + + attrHooks: { + type: { + set: function( elem, value ) { + // We can't allow the type property to be changed (since it causes problems in IE) + if ( rtype.test( elem.nodeName ) && elem.parentNode ) { + jQuery.error( "type property can't be changed" ); } } + }, + + // 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/ + tabIndex: { + get: function( elem ) { + var attributeNode = elem.getAttributeNode( "tabIndex" ); - // 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 ); - } - - } else { - elem[ name ] = value; - } - } - - // 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; - } - - // 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" ); - - return attributeNode && attributeNode.specified ? - attributeNode.value : - rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? - 0 : - undefined; - } - + return attributeNode && attributeNode.specified ? + attributeNode.value : + rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? + 0 : + undefined; + } + } + }, + + // TODO: Check to see if we really need any here. + propFix: {}, + + prop: function( elem, name, value ) { + var ret, hooks; + + // Try to normalize/fix the name + name = notxml && jQuery.propFix[ name ] || name; + + hooks = jQuery.propHooks[ name ]; + + if ( value !== undefined ) { + if ( hooks && "set" in hooks && (ret = hooks.set( elem, value )) !== undefined ) { + return ret; + + } else { + return (elem[ name ] = value); + } + + } else { + if ( hooks && "get" in hooks && (ret = hooks.get( elem )) !== undefined ) { + return ret; + + } else { return elem[ name ]; } - - if ( !jQuery.support.style && notxml && name === "style" ) { - if ( set ) { - elem.style.cssText = "" + value; - } - - return elem.style.cssText; - } - - if ( set ) { - // convert the value to a string (all browsers do this but IE) see #1070 - elem.setAttribute( name, "" + value ); - } - - // Ensure that missing attributes return undefined - // Blackberry 4.7 returns "" from getAttribute #6938 - if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) { - return undefined; - } - - 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 ]; - } + }, + + propHooks: {} }); +// Some attributes require a special call on IE +if ( !jQuery.support.hrefNormalized ) { + jQuery.each([ "href", "src", "style" ], function( i, name ) { + jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { + get: function( elem ) { + return elem.getAttribute( name, 2 ); + } + }); + }); +} + +if ( !jQuery.support.style ) { + jQuery.attrHooks.style = { + get: function( elem ) { + return elem.style.cssText; + }, + + set: function( elem, value ) { + return (elem.style.cssText = "" + value); + } + }; +} + +// Safari mis-reports the default selected property of an option +// Accessing the parent's selectedIndex property fixes it +if ( !jQuery.support.optSelected ) { + jQuery.attrHooks.selected = { + get: function( elem ) { + var parent = elem.parentNode; + + if ( parent ) { + parent.selectedIndex; + + // Make sure that it also works with optgroups, see #5701 + if ( parent.parentNode ) { + parent.parentNode.selectedIndex; + } + } + } + }; +} + })( jQuery ); From c6b891fb1c909a2791ba7a4d745940858bd7b94f Mon Sep 17 00:00:00 2001 From: louisremi Date: Mon, 7 Mar 2011 14:43:08 +0100 Subject: [PATCH 040/418] Adding unit tests for #8403 --- test/data/testsuite.css | 2 +- test/unit/css.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/data/testsuite.css b/test/data/testsuite.css index cffaaa46..02900681 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -1,5 +1,5 @@ /* for testing opacity set in styles in IE */ -ol#empty { opacity: 0; filter:Alpha(opacity=0); } +ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); } div#fx-tests h4 { background: red; diff --git a/test/unit/css.js b/test/unit/css.js index 555f1357..87466187 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css", { teardown: moduleTeardown }); test("css(String|Hash)", function() { - expect(41); + expect(42); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -58,6 +58,7 @@ test("css(String|Hash)", function() { equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" ); jQuery('#empty').css({ opacity: '1' }); equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" ); + ok( ~jQuery('#empty')[0].currentStyle.filter.indexOf('gradient'), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" ); var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild'); From 2ac4067a639856a6035c3bd00aab132c9714b52d Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Wed, 9 Mar 2011 22:38:26 -0500 Subject: [PATCH 041/418] Fixes #8456. Make sure parent is not null before crawling into its lap, so mouseenter is triggered on a mouseover event. --- src/event.js | 2 +- test/unit/event.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/event.js b/src/event.js index f7e0a08c..2620646d 100644 --- a/src/event.js +++ b/src/event.js @@ -661,7 +661,7 @@ var withinElement = function( event ) { // Chrome does something similar, the parentNode property // can be accessed but is null. - if ( parent !== document && !parent.parentNode ) { + if ( parent && parent !== document && !parent.parentNode ) { return; } // Traverse up the tree diff --git a/test/unit/event.js b/test/unit/event.js index b7b26046..d66aaac9 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -683,6 +683,20 @@ test("hover()", function() { equals( times, 4, "hover handlers fired" ); }); +test("mouseover triggers mouseenter", function() { + expect(1); + + var count = 0, + elem = jQuery(""); + elem.mouseenter(function () { + count++; + }); + elem.trigger('mouseover'); + equals(count, 1, "make sure mouseover triggers a mouseenter" ); + + elem.remove(); +}); + test("trigger() shortcuts", function() { expect(6); From 515c56f9c6394a4ddadf29c55867f71dec6dcdb7 Mon Sep 17 00:00:00 2001 From: JessThrysoee Date: Fri, 11 Mar 2011 00:17:38 +0100 Subject: [PATCH 042/418] Make it possible to force the Ajax crossDomain option to false. --- src/ajax.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 4714afda..66b26cd7 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -310,6 +310,7 @@ jQuery.extend({ contentType: "application/x-www-form-urlencoded", processData: true, async: true, + crossDomain: null, /* timeout: 0, data: null, @@ -319,7 +320,6 @@ jQuery.extend({ cache: null, traditional: false, headers: {}, - crossDomain: null, */ accepts: { @@ -604,7 +604,7 @@ jQuery.extend({ s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax ); // Determine if a cross-domain request is in order - if ( !s.crossDomain ) { + if ( s.crossDomain == null ) { parts = rurl.exec( s.url.toLowerCase() ); s.crossDomain = !!( parts && ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] || From 11c26b3cc9bf84f93d34f45056d29a446baeb6c9 Mon Sep 17 00:00:00 2001 From: JessThrysoee Date: Fri, 11 Mar 2011 17:46:59 +0100 Subject: [PATCH 043/418] no need to specifically initialize crossDomain to null --- src/ajax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index 66b26cd7..4290e295 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -310,7 +310,6 @@ jQuery.extend({ contentType: "application/x-www-form-urlencoded", processData: true, async: true, - crossDomain: null, /* timeout: 0, data: null, @@ -320,6 +319,7 @@ jQuery.extend({ cache: null, traditional: false, headers: {}, + crossDomain: null, */ accepts: { From 8246347b7191e79ed09bf1fc4c4a0a58211cf345 Mon Sep 17 00:00:00 2001 From: timmywil Date: Sun, 13 Mar 2011 21:12:10 -0400 Subject: [PATCH 044/418] Starting with adding the test --- test/unit/traversing.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/traversing.js b/test/unit/traversing.js index f5108bde..9216bb5e 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -13,6 +13,15 @@ test("find(String)", function() { same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); }); +test("find(node|jQuery object)", function() { + expect( 2 ); + + var $blog = jQuery('.blogTest'), + blog = $blog[0]; + equals( jQuery('#foo').find( $blog ).text(), 'Yahoo', 'Find with blog jQuery object' ); + equals( jQuery('#foo').find( blog ).text(), 'Yahoo', 'Find with blog node' ); +}); + test("is(String)", function() { expect(26); ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' ); From 124acbfbc523614dc5835cfce2c82b867a59986f Mon Sep 17 00:00:00 2001 From: Jordan Boesch Date: Mon, 14 Mar 2011 14:17:02 -0600 Subject: [PATCH 045/418] removing parens --- src/manipulation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manipulation.js b/src/manipulation.js index 613faabb..27f81cc2 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -261,7 +261,7 @@ jQuery.fn.extend({ } }); } else { - return ( this.length ) ? + return this.length ? this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) : this; } From 714ae379db9dcb704c04080196a05d13a028f7a4 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 15 Mar 2011 19:20:03 +0100 Subject: [PATCH 046/418] Fixes #8509. Makes URL regexp less overzealous and ensures it recognizes URL schemes which do not contain a conformant hierarchical structure ( as per section 2.1.2 of http://www.ietf.org/rfc/rfc2718.txt ). Also adds about: and adobe air's app: and app-storage: to the list of local protocols and provides a failover in case document.location is illformed. Unit test added. --- src/ajax.js | 6 +++--- test/unit/ajax.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 4714afda..add3b373 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -7,7 +7,7 @@ var r20 = /%20/g, rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, // #7653, #8125, #8152: local protocol detection - rlocalProtocol = /(?:^file|^widget|\-extension):$/, + rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/, rnoContent = /^(?:GET|HEAD)$/, rprotocol = /^\/\//, rquery = /\?/, @@ -19,7 +19,7 @@ var r20 = /%20/g, rucHeadersFunc = function( _, $1, $2 ) { return $1 + $2.toUpperCase(); }, - rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?|\/[^\/])/, + rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/, // Keep a copy of the old load method _load = jQuery.fn.load, @@ -61,7 +61,7 @@ try { } // Segment location into parts -ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ); +ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport function addToPrefiltersOrTransports( structure ) { diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2a2ac46a..7c572a32 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -492,7 +492,7 @@ test(".ajax() - hash", function() { test("jQuery ajax - cross-domain detection", function() { - expect( 5 ); + expect( 6 ); var loc = document.location, otherPort = loc.port === 666 ? 667 : 666, @@ -508,6 +508,7 @@ test("jQuery ajax - cross-domain detection", function() { }); jQuery.ajax({ + dataType: "jsonp", url: 'app:/path', beforeSend: function( _ , s ) { ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" ); @@ -533,6 +534,15 @@ test("jQuery ajax - cross-domain detection", function() { } }); + jQuery.ajax({ + dataType: "jsonp", + url: "about:blank", + beforeSend: function( _ , s ) { + ok( s.crossDomain , "Test about:blank is detected as cross-domain" ); + return false; + } + }); + jQuery.ajax({ dataType: "jsonp", url: loc.protocol + "//" + loc.host, From 150d3decb54971a7378fb48d0b6970d3fb50ff95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Tue, 15 Mar 2011 20:16:09 +0100 Subject: [PATCH 047/418] Introduce submodules, closes #8536 Instead of the manual clone of sizzle and qunit, use git submodules instead. this will ensure that all future releases can be recreated by checking out an tag. --- .gitignore | 2 -- .gitmodules | 6 ++++++ Makefile | 34 ++++------------------------------ src/sizzle | 1 + test/qunit | 1 + 5 files changed, 12 insertions(+), 32 deletions(-) create mode 100644 .gitmodules create mode 160000 src/sizzle create mode 160000 test/qunit diff --git a/.gitignore b/.gitignore index a77d67a9..6cd54797 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,5 @@ dist *~ *.diff *.patch -test/qunit -src/sizzle /*.html .DS_Store diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..80ce2368 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "src/sizzle"] + path = src/sizzle + url = git://github.com/jeresig/sizzle.git +[submodule "test/qunit"] + path = test/qunit + url = git://github.com/jquery/qunit.git diff --git a/Makefile b/Makefile index a6aae425..e0d1da71 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,3 @@ -V ?= 0 - SRC_DIR = src TEST_DIR = test BUILD_DIR = build @@ -38,7 +36,6 @@ JQ = ${DIST_DIR}/jquery.js JQ_MIN = ${DIST_DIR}/jquery.min.js SIZZLE_DIR = ${SRC_DIR}/sizzle -QUNIT_DIR = ${TEST_DIR}/qunit JQ_VER = $(shell cat version.txt) VER = sed "s/@VERSION/${JQ_VER}/" @@ -51,32 +48,8 @@ all: jquery min lint ${DIST_DIR}: @@mkdir -p ${DIST_DIR} -ifeq ($(strip $(V)),0) -verbose = --quiet -else ifeq ($(strip $(V)),1) -verbose = -else -verbose = --verbose -endif - -define clone_or_pull --@@if test ! -d $(strip ${1})/.git; then \ - echo "Cloning $(strip ${1})..."; \ - git clone $(strip ${verbose}) --depth=1 $(strip ${2}) $(strip ${1}); \ - else \ - echo "Pulling $(strip ${1})..."; \ - git --git-dir=$(strip ${1})/.git pull $(strip ${verbose}) origin master; \ - fi - -endef - -${QUNIT_DIR}: - $(call clone_or_pull, ${QUNIT_DIR}, git://github.com/jquery/qunit.git) - -${SIZZLE_DIR}: - $(call clone_or_pull, ${SIZZLE_DIR}, git://github.com/jeresig/sizzle.git) - -init: ${QUNIT_DIR} ${SIZZLE_DIR} +init: + @@if [ -d .git ]; then git submodule update --init --recursive; fi jquery: init ${JQ} jq: init ${JQ} @@ -122,7 +95,8 @@ clean: @@echo "Removing built copy of Sizzle" @@rm -f src/selector.js - @@echo "Removing cloned directories" +distclean: clean + @@echo "Removing submodules" @@rm -rf test/qunit src/sizzle .PHONY: all jquery lint min init jq clean diff --git a/src/sizzle b/src/sizzle new file mode 160000 index 00000000..ef19279f --- /dev/null +++ b/src/sizzle @@ -0,0 +1 @@ +Subproject commit ef19279f54ba49242c6461d47577c703f4f4e80e diff --git a/test/qunit b/test/qunit new file mode 160000 index 00000000..d404faf8 --- /dev/null +++ b/test/qunit @@ -0,0 +1 @@ +Subproject commit d404faf8f587fcbe6b8907943022e6318dd51e0c From cd2ca7b5918b3cedfed497ac7d86bfd2c5f92a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Tue, 15 Mar 2011 21:25:51 +0100 Subject: [PATCH 048/418] pull submodules make command Adding an helper funciton to pull the latest from all registered submodules --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index e0d1da71..7b67f7af 100644 --- a/Makefile +++ b/Makefile @@ -99,4 +99,9 @@ distclean: clean @@echo "Removing submodules" @@rm -rf test/qunit src/sizzle +# update the submodules to the latest at the most logical branch +pull_submodules: + @@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" + @@git submodule summary + .PHONY: all jquery lint min init jq clean From bd4468886d97edfb53342e1a10acb300d081ed27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Tue, 15 Mar 2011 21:42:58 +0100 Subject: [PATCH 049/418] adding pull command --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 7b67f7af..84816a19 100644 --- a/Makefile +++ b/Makefile @@ -104,4 +104,7 @@ pull_submodules: @@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" @@git submodule summary +pull: pull_submodules + @@git pull ${REMOTE} ${BRANCH} + .PHONY: all jquery lint min init jq clean From 51abb3dc071fd86afd346ec5c340734f5c61064f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Fri, 4 Mar 2011 23:33:20 +0100 Subject: [PATCH 050/418] Changing dependice order for minify to prevent reminify unless jquery.js has been updated, no minification should occur closes: #8519 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 84816a19..7b87c9f5 100644 --- a/Makefile +++ b/Makefile @@ -75,9 +75,9 @@ lint: jquery echo "You must have NodeJS installed in order to test jQuery against JSLint."; \ fi -min: ${JQ_MIN} +min: jquery ${JQ_MIN} -${JQ_MIN}: jquery +${JQ_MIN}: ${JQ} @@if test ! -z ${JS_ENGINE}; then \ echo "Minifying jQuery" ${JQ_MIN}; \ ${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \ From 7a69e34a5cd4df37762cbee9c9468c96c0ac3017 Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 16 Mar 2011 01:16:32 -0400 Subject: [PATCH 051/418] 2773: first pass adding node/jQuery object support to jQuery.fn.find; unit tests added --- src/core.js | 2 +- src/traversing.js | 23 ++++++++++++++++++----- test/unit/traversing.js | 25 ++++++++++++++++++++----- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/core.js b/src/core.js index 9312ee28..812ecde5 100644 --- a/src/core.js +++ b/src/core.js @@ -88,7 +88,7 @@ jQuery.fn = jQuery.prototype = { if ( selector === "body" && !context && document.body ) { this.context = document; this[0] = document.body; - this.selector = "body"; + this.selector = selector; this.length = 1; return this; } diff --git a/src/traversing.js b/src/traversing.js index fe2e33d8..fa6aae2f 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -17,17 +17,30 @@ var runtil = /Until$/, jQuery.fn.extend({ find: function( selector ) { - var ret = this.pushStack( "", "find", selector ), - length = 0; + var self = this, + ret, i, l; - for ( var i = 0, l = this.length; i < l; i++ ) { + if ( typeof selector !== "string" ) { + return jQuery( selector ).filter(function() { + for ( i = 0, l = self.length; i < l; i++ ) { + if ( jQuery.contains( self[ i ], this ) ) { + return true; + } + } + }); + } + + ret = this.pushStack( "", "find", selector ); + + var length, n, r; + for ( i = 0, l = this.length; i < l; i++ ) { length = ret.length; jQuery.find( selector, this[i], ret ); if ( i > 0 ) { // Make sure that the results are unique - for ( var n = length; n < ret.length; n++ ) { - for ( var r = 0; r < length; r++ ) { + for ( n = length; n < ret.length; n++ ) { + for ( r = 0; r < length; r++ ) { if ( ret[r] === ret[n] ) { ret.splice(n--, 1); break; diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 9216bb5e..76b93d84 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -14,12 +14,27 @@ test("find(String)", function() { }); test("find(node|jQuery object)", function() { - expect( 2 ); + expect( 11 ); + + var $foo = jQuery('#foo'), + $blog = jQuery('.blogTest'), + $first = jQuery('#first'), + $two = $blog.add( $first ), + $fooTwo = $foo.add( $blog ); + + equals( $foo.find( $blog ).text(), 'Yahoo', 'Find with blog jQuery object' ); + equals( $foo.find( $blog[0] ).text(), 'Yahoo', 'Find with blog node' ); + equals( $foo.find( $first ).length, 0, '#first is not in #foo' ); + equals( $foo.find( $first[0]).length, 0, '#first not in #foo (node)' ); + ok( $foo.find( $two ).is('.blogTest'), 'Find returns only nodes within #foo' ); + ok( $fooTwo.find( $blog ).is('.blogTest'), 'Blog is part of the collection, but also within foo' ); + ok( $fooTwo.find( $blog[0] ).is('.blogTest'), 'Blog is part of the collection, but also within foo(node)' ); + + equals( $two.find( $foo ).length, 0, 'Foo is not in two elements' ); + equals( $two.find( $foo[0] ).length, 0, 'Foo is not in two elements(node)' ); + equals( $two.find( $first ).length, 0, 'first is in the collection and not within two' ); + equals( $two.find( $first ).length, 0, 'first is in the collection and not within two(node)' ); - var $blog = jQuery('.blogTest'), - blog = $blog[0]; - equals( jQuery('#foo').find( $blog ).text(), 'Yahoo', 'Find with blog jQuery object' ); - equals( jQuery('#foo').find( blog ).text(), 'Yahoo', 'Find with blog node' ); }); test("is(String)", function() { From 929792834f77e075e4b5397fb4b25b1a2dcbd49a Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 16 Mar 2011 14:41:26 -0400 Subject: [PATCH 052/418] Organizing vars --- src/traversing.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/traversing.js b/src/traversing.js index fa6aae2f..30d60435 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -18,7 +18,7 @@ var runtil = /Until$/, jQuery.fn.extend({ find: function( selector ) { var self = this, - ret, i, l; + i, l; if ( typeof selector !== "string" ) { return jQuery( selector ).filter(function() { @@ -30,9 +30,8 @@ jQuery.fn.extend({ }); } - ret = this.pushStack( "", "find", selector ); - - var length, n, r; + var ret = this.pushStack( "", "find", selector ), + length, n, r; for ( i = 0, l = this.length; i < l; i++ ) { length = ret.length; jQuery.find( selector, this[i], ret ); From a2faed347de389d6f667a4e98576398db88d1a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Thu, 17 Mar 2011 19:50:53 +0100 Subject: [PATCH 053/418] Merge when updating submodules on make When running make, the submodule update will remove all local changes. Adding flag --rebase or --merge does solve the issue. rebase will probably make it cleaner, but it might stop on conflict, thus --merge will result in fewer (probably none). --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 84816a19..525d3a19 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ ${DIST_DIR}: @@mkdir -p ${DIST_DIR} init: - @@if [ -d .git ]; then git submodule update --init --recursive; fi + @@if [ -d .git ]; then git submodule update --init --recursive --merge; fi jquery: init ${JQ} jq: init ${JQ} From 22738e0e4b988f8ce2cb341b137ba0fe4646d3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Thu, 17 Mar 2011 20:15:44 +0100 Subject: [PATCH 054/418] Remove jq target remove obsolete jq target --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 525d3a19..3223b8da 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,6 @@ init: @@if [ -d .git ]; then git submodule update --init --recursive --merge; fi jquery: init ${JQ} -jq: init ${JQ} ${JQ}: ${MODULES} | ${DIST_DIR} @@echo "Building" ${JQ} From 4f9e78616ecd9ca403a25ee0e3dc71781484e553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Thu, 17 Mar 2011 20:14:15 +0100 Subject: [PATCH 055/418] Change makefile order to only update submodules on 'all' target insterad of always update the submodules, now only "make all" will run that, thus an "make jquery" will not update them --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 3223b8da..9ef44cff 100644 --- a/Makefile +++ b/Makefile @@ -42,16 +42,13 @@ VER = sed "s/@VERSION/${JQ_VER}/" DATE=$(shell git log -1 --pretty=format:%ad) -all: jquery min lint +all: update_submodules jquery min lint @@echo "jQuery build complete." ${DIST_DIR}: @@mkdir -p ${DIST_DIR} -init: - @@if [ -d .git ]; then git submodule update --init --recursive --merge; fi - -jquery: init ${JQ} +jquery: ${JQ} ${JQ}: ${MODULES} | ${DIST_DIR} @@echo "Building" ${JQ} @@ -98,6 +95,10 @@ distclean: clean @@echo "Removing submodules" @@rm -rf test/qunit src/sizzle +# change pointers for submodules and update them to what is specified in jQuery +update_submodules: + @@if [ -d .git ]; then git submodule update --init --recursive --merge; fi + # update the submodules to the latest at the most logical branch pull_submodules: @@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" From b4acb7ae819563c3b75bbdabfaf2662fd24b06e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Thu, 17 Mar 2011 20:16:19 +0100 Subject: [PATCH 056/418] updating phony rules --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9ef44cff..d377c4cf 100644 --- a/Makefile +++ b/Makefile @@ -107,4 +107,4 @@ pull_submodules: pull: pull_submodules @@git pull ${REMOTE} ${BRANCH} -.PHONY: all jquery lint min init jq clean +.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull From e2dd8916eef1daba1a56a5ff1fbb44cb3385f4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Thu, 17 Mar 2011 20:26:45 +0100 Subject: [PATCH 057/418] Adding core target Adding core target to do jquery, minimization and lint --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d377c4cf..99e742d6 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,9 @@ VER = sed "s/@VERSION/${JQ_VER}/" DATE=$(shell git log -1 --pretty=format:%ad) -all: update_submodules jquery min lint +all: update_submodules core + +core: jquery min lint @@echo "jQuery build complete." ${DIST_DIR}: @@ -107,4 +109,4 @@ pull_submodules: pull: pull_submodules @@git pull ${REMOTE} ${BRANCH} -.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull +.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull core From 8a1156da9b835d826bfb4b82c41bcdd0d87aff05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Thu, 17 Mar 2011 20:40:07 +0100 Subject: [PATCH 058/418] merge doesn't work when init sadly the merge strategy doesn't work when doing an initial clone, circumvent that --- Makefile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 99e742d6..2c7bb808 100644 --- a/Makefile +++ b/Makefile @@ -98,8 +98,16 @@ distclean: clean @@rm -rf test/qunit src/sizzle # change pointers for submodules and update them to what is specified in jQuery +# --merge doesn't work when doing an initial clone, thus test if we have non-existing +# submodules, then do an real update update_submodules: - @@if [ -d .git ]; then git submodule update --init --recursive --merge; fi + @@if [ -d .git ]; then \ + if git submodule status | grep -q -E '^-'; then \ + git submodule update --init --recursive; \ + else \ + git submodule update --init --recursive --merge; \ + fi; \ + fi; # update the submodules to the latest at the most logical branch pull_submodules: From 2407690ef9b3ec59920917935dc1a312f6c2b56e Mon Sep 17 00:00:00 2001 From: Dan Heberden Date: Mon, 21 Mar 2011 08:10:27 -0700 Subject: [PATCH 059/418] Fixes 2616; Pull in #252 by jboesch: jQuery.map with object support --- test/qunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/qunit b/test/qunit index d404faf8..cc8460c7 160000 --- a/test/qunit +++ b/test/qunit @@ -1 +1 @@ -Subproject commit d404faf8f587fcbe6b8907943022e6318dd51e0c +Subproject commit cc8460c7b44f023c4f84ab1810b72bf6c6ee4542 From e38f074d14fd65b3f8b0e1bd7956cd75b3dafe2b Mon Sep 17 00:00:00 2001 From: Dan Heberden Date: Mon, 21 Mar 2011 08:39:53 -0700 Subject: [PATCH 060/418] jQuery.map to conform with style guidelines - improved size/DRY code --- src/core.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/core.js b/src/core.js index 1077d38c..a0dd7b5b 100644 --- a/src/core.js +++ b/src/core.js @@ -706,29 +706,31 @@ jQuery.extend({ // arg is for internal usage only map: function( elems, callback, arg ) { - var ret = [], - value, + var ret = [], value, i = 0, length = elems.length, // same object detection used in jQuery.each, not full-proof but very speedy. isObj = length === undefined; - - if ( isObj ) { - for ( key in elems ) { - value = callback( elems[ key ], key, arg ); - + + // the work for the loops - run elems[x] through callback + inLoop = function( key ) { + value = callback( elems[ key ], key, arg ); + if ( value != null ) { ret[ ret.length ] = value; } } - } else { - // Go through the array, translating each of the items to their - // new value (or values). - for ( var i = 0; i < length; i++ ) { - value = callback( elems[ i ], i, arg ); - if ( value != null ) { - ret[ ret.length ] = value; - } + // Go thorugh every key on the object + if ( isObj ) { + for ( key in elems ) { + inLoop( key ); + } + + // Go through the array, translating each of the items to their + // new value (or values). + } else { + for ( ; i < length; i++ ) { + inLoop( i ); } } From d832f4f71ec51e67d4cae2557221ef582818f607 Mon Sep 17 00:00:00 2001 From: Dan Heberden Date: Mon, 21 Mar 2011 12:12:31 -0700 Subject: [PATCH 061/418] jQuery.map to iterate over objects with a .length property --- src/core.js | 40 ++++++++++++++++++++-------------------- test/unit/core.js | 12 +++++++----- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/core.js b/src/core.js index a0dd7b5b..951f1b55 100644 --- a/src/core.js +++ b/src/core.js @@ -704,33 +704,33 @@ jQuery.extend({ return ret; }, - // arg is for internal usage only + // arg is for internal usage only map: function( elems, callback, arg ) { - var ret = [], value, i = 0, - length = elems.length, - // same object detection used in jQuery.each, not full-proof but very speedy. - isObj = length === undefined; - - // the work for the loops - run elems[x] through callback - inLoop = function( key ) { - value = callback( elems[ key ], key, arg ); - + var value, ret = [], + i = 0, + length = elems.length, + // process .length if it's just an object member + isArray = length !== undefined && ( elems[ length - 1 ] || jQuery.isArray( elems ) ); + + // Go through the array, translating each of the items to their + // new value (or values). + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + if ( value != null ) { ret[ ret.length ] = value; } } - // Go thorugh every key on the object - if ( isObj ) { + // Go thorugh every key on the object, + } else { for ( key in elems ) { - inLoop( key ); - } - - // Go through the array, translating each of the items to their - // new value (or values). - } else { - for ( ; i < length; i++ ) { - inLoop( i ); + value = callback( elems[ key ], key, arg ); + + if ( value != null ) { + ret[ ret.length ] = value; + } } } diff --git a/test/unit/core.js b/test/unit/core.js index c1ffe10b..08d80400 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -608,7 +608,7 @@ test("first()/last()", function() { }); test("map()", function() { - expect(6); + expect(7); same( jQuery("#ap").map(function(){ @@ -630,26 +630,28 @@ test("map()", function() { var keys = jQuery.map( {a:1,b:2}, function( v, k ){ return k; }); - equals( keys.join(""), "ab", "Map the keys from a hash to an array" ); var values = jQuery.map( {a:1,b:2}, function( v, k ){ return v; }); - equals( values.join(""), "12", "Map the values from a hash to an array" ); + + // object with length prop + var values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){ + return v; + }); + equals( values.join(""), "123", "Map the values from a hash with a length property to an array" ); var scripts = document.getElementsByTagName("script"); var mapped = jQuery.map( scripts, function( v, k ){ return v; }); - equals( mapped.length, scripts.length, "Map an array(-like) to a hash" ); var flat = jQuery.map( Array(4), function( v, k ){ return k % 2 ? k : [k,k,k];//try mixing array and regular returns }); - equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" ); }); From 00dd6013b6b53455ef7b788801a5dc0616651580 Mon Sep 17 00:00:00 2001 From: Dan Heberden Date: Mon, 21 Mar 2011 12:24:53 -0700 Subject: [PATCH 062/418] Clean up tab spacing --- src/core.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core.js b/src/core.js index 951f1b55..49c191b9 100644 --- a/src/core.js +++ b/src/core.js @@ -707,10 +707,10 @@ jQuery.extend({ // arg is for internal usage only map: function( elems, callback, arg ) { var value, ret = [], - i = 0, - length = elems.length, - // process .length if it's just an object member - isArray = length !== undefined && ( elems[ length - 1 ] || jQuery.isArray( elems ) ); + i = 0, + length = elems.length, + // process .length if it's just an object member + isArray = length !== undefined && ( elems[ length - 1 ] || jQuery.isArray( elems ) ); // Go through the array, translating each of the items to their // new value (or values). From e09d8898d8a8df27bb72ebc64a4cd08c11f21ddd Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 21 Mar 2011 20:59:20 -0400 Subject: [PATCH 063/418] Add node and jQuery object support to $.fn.closest --- src/traversing.js | 20 ++++++++++++-------- test/unit/traversing.js | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/traversing.js b/src/traversing.js index 30d60435..49197c1f 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -32,6 +32,7 @@ jQuery.fn.extend({ var ret = this.pushStack( "", "find", selector ), length, n, r; + for ( i = 0, l = this.length; i < l; i++ ) { length = ret.length; jQuery.find( selector, this[i], ret ); @@ -77,7 +78,8 @@ jQuery.fn.extend({ closest: function( selectors, context ) { var ret = [], i, l, cur = this[0]; - + + // Array if ( jQuery.isArray( selectors ) ) { var match, selector, matches = {}, @@ -87,8 +89,8 @@ jQuery.fn.extend({ for ( i = 0, l = selectors.length; i < l; i++ ) { selector = selectors[i]; - if ( !matches[selector] ) { - matches[selector] = jQuery.expr.match.POS.test( selector ) ? + if ( !matches[ selector ] ) { + matches[ selector ] = POS.test( selector ) ? jQuery( selector, context || this.context ) : selector; } @@ -96,9 +98,9 @@ jQuery.fn.extend({ while ( cur && cur.ownerDocument && cur !== context ) { for ( selector in matches ) { - match = matches[selector]; + match = matches[ selector ]; - if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) { + if ( match.jquery ? match.index( cur ) > -1 : jQuery( cur ).is( match ) ) { ret.push({ selector: selector, elem: cur, level: level }); } } @@ -110,9 +112,11 @@ jQuery.fn.extend({ return ret; } - - var pos = POS.test( selectors ) ? - jQuery( selectors, context || this.context ) : null; + + // String + var pos = POS.test( selectors ) || typeof selectors !== "string" ? + jQuery( selectors, context || this.context ) : + 0; for ( i = 0, l = this.length; i < l; i++ ) { cur = this[i]; diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 76b93d84..bd05f470 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -182,6 +182,20 @@ test("closest(Array)", function() { same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); }); +test("closest(jQuery)", function() { + expect(7); + var $child = jQuery("#nothiddendivchild"), + $parent = jQuery("#nothiddendiv"), + $main = jQuery("#main"); + ok( $child.closest( $parent ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') )" ); + ok( $child.closest( $parent[0] ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') ) :: node" ); + ok( $child.closest( $child ).is('#nothiddendivchild'), "child is included" ); + ok( $child.closest( $child[0] ).is('#nothiddendivchild'), "child is included :: node" ); + equals( $child.closest( document.createElement('div') ).length, 0, "created element is not related" ); + equals( $child.closest( $main ).length, 0, "Main not a parent of child" ); + equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); +}); + test("not(Selector)", function() { expect(7); equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" ); From 50e8837207bbfb251af33280b8ef333f16c18e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20F=C3=BCrstenberg?= Date: Tue, 22 Mar 2011 23:18:15 +0100 Subject: [PATCH 064/418] Makefile: pull_submodules cleaning Empirical testing confirms that pulling the url again is enough --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2c7bb808..b9fa6188 100644 --- a/Makefile +++ b/Makefile @@ -111,7 +111,7 @@ update_submodules: # update the submodules to the latest at the most logical branch pull_submodules: - @@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)" + @@git submodule foreach "git pull \$$(git config remote.origin.url)" @@git submodule summary pull: pull_submodules From b8013581ced78fb6c2005e76b44211e01fc2e466 Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 23 Mar 2011 15:56:05 -0400 Subject: [PATCH 065/418] Closest unit tests: add one for passing a jQuery collection with multiple elements --- test/unit/traversing.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unit/traversing.js b/test/unit/traversing.js index bd05f470..adca5f40 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -183,10 +183,11 @@ test("closest(Array)", function() { }); test("closest(jQuery)", function() { - expect(7); + expect(8); var $child = jQuery("#nothiddendivchild"), $parent = jQuery("#nothiddendiv"), - $main = jQuery("#main"); + $main = jQuery("#main"), + $body = jQuery("body"); ok( $child.closest( $parent ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') )" ); ok( $child.closest( $parent[0] ).is('#nothiddendiv'), "closest( jQuery('#nothiddendiv') ) :: node" ); ok( $child.closest( $child ).is('#nothiddendivchild'), "child is included" ); @@ -194,6 +195,7 @@ test("closest(jQuery)", function() { equals( $child.closest( document.createElement('div') ).length, 0, "created element is not related" ); equals( $child.closest( $main ).length, 0, "Main not a parent of child" ); equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); + ok( $child.closest( $body.add($parent) ).is('#nothiddendiv'), "Closest ancestor retrieved." ); }); test("not(Selector)", function() { From 85232c97bf1f129b2bc246cf674dc3d5582aaecb Mon Sep 17 00:00:00 2001 From: timmywil Date: Wed, 23 Mar 2011 16:04:12 -0400 Subject: [PATCH 066/418] Traversing unit tests: added tests for passing invalid arguments to $.fn.not (should have no effect on existing object rather than return an empty object as filter does) --- test/unit/traversing.js | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 9eb0d78b..7d15f4c1 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -47,8 +47,8 @@ test("is(String|undefined)", function() { ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' ); }); -test("is(Object)", function() { - expect(18); +test("is(jQuery)", function() { + expect(24); ok( jQuery('#form').is( jQuery('form') ), 'Check for element: A form is a form' ); ok( !jQuery('#form').is( jQuery('div') ), 'Check for element: A form is not a div' ); ok( jQuery('#mark').is( jQuery('.blog') ), 'Check for class: Expected class "blog"' ); @@ -67,27 +67,14 @@ test("is(Object)", function() { ok( !jQuery('#foo').is( jQuery(':has(ul)') ), 'Check for child: Did not expect "ul" element' ); ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)') ), 'Check for childs: Expected "p", "a" and "code" child elements' ); ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)') ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); -}); - -test("is(node Object)", function() { - expect(17); + + // Some raw elements ok( jQuery('#form').is( jQuery('form')[0] ), 'Check for element: A form is a form' ); ok( !jQuery('#form').is( jQuery('div')[0] ), 'Check for element: A form is not a div' ); ok( jQuery('#mark').is( jQuery('.blog')[0] ), 'Check for class: Expected class "blog"' ); ok( !jQuery('#mark').is( jQuery('.link')[0] ), 'Check for class: Did not expect class "link"' ); ok( jQuery('#simon').is( jQuery('.blog.link')[0] ), 'Check for multiple classes: Expected classes "blog" and "link"' ); ok( !jQuery('#simon').is( jQuery('.blogTest')[0] ), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' ); - ok( jQuery('#en').is( jQuery('[lang="en"]')[1] ), 'Check for attribute: Expected attribute lang to be "en"' ); - ok( !jQuery('#en').is( jQuery('[lang="de"]')[0] ), 'Check for attribute: Expected attribute lang to be "en", not "de"' ); - ok( jQuery('#text1').is( jQuery('[type="text"]')[0] ), 'Check for attribute: Expected attribute type to be "text"' ); - ok( !jQuery('#text1').is( jQuery('[type="radio"]')[0] ), 'Check for attribute: Expected attribute type to be "text", not "radio"' ); - ok( jQuery('#text2').is( jQuery(':disabled')[0] ), 'Check for pseudoclass: Expected to be disabled' ); - ok( !jQuery('#text1').is( jQuery(':disabled')[0] ), 'Check for pseudoclass: Expected not disabled' ); - ok( !jQuery('#radio1').is( jQuery(':checked')[0] ), 'Check for pseudoclass: Expected not checked' ); - ok( jQuery('#foo').is( jQuery(':has(p)')[4] ), 'Check for child: Expected a child "p" element' ); - ok( !jQuery('#foo').is( jQuery(':has(ul)')[0] ), 'Check for child: Did not expect "ul" element' ); - ok( jQuery('#foo').is( jQuery(':has(p):has(a):has(code)')[4] ), 'Check for childs: Expected "p", "a" and "code" child elements' ); - ok( !jQuery('#foo').is( jQuery(':has(p):has(a):has(code):has(ol)')[0] ), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' ); }); test("index()", function() { @@ -208,8 +195,8 @@ test("closest(Array)", function() { same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); }); -test("not(Selector)", function() { - expect(7); +test("not(Selector|undefined)", function() { + expect(11); equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" ); same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); @@ -218,6 +205,12 @@ test("not(Selector)", function() { same( jQuery('#ap *').not('code').get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); same( jQuery('#ap *').not('code, #mark').get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); same( jQuery('#ap *').not('#mark, code').get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); + + var all = jQuery('p').get(); + same( jQuery('p').not(null).get(), all, "not(null) should have no effect"); + same( jQuery('p').not(undefined).get(), all, "not(undefined) should have no effect"); + same( jQuery('p').not(0).get(), all, "not(0) should have no effect"); + same( jQuery('p').not('').get(), all, "not('') should have no effect"); }); test("not(Element)", function() { From c3c507e900fceb419628157504004ab2813b7d01 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Thu, 24 Mar 2011 15:41:46 -0400 Subject: [PATCH 067/418] Added css hook to work around bug in WebKit computed margin-right. Fixes #3333 - .css("marginRight") is incorrect in WebKit --- src/css.js | 19 +++++++++++++++++++ src/support.js | 14 +++++++++++++- test/unit/css.js | 12 ++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/css.js b/src/css.js index 8a982312..d6b48813 100644 --- a/src/css.js +++ b/src/css.js @@ -240,6 +240,25 @@ if ( !jQuery.support.opacity ) { }; } +jQuery(function() { + // This hook cannot be added until DOM ready because the support test + // for it is not run until after DOM ready + if ( !jQuery.support.reliableMarginRight ) { + jQuery.cssHooks.marginRight = { + get: function( elem, computed ) { + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + // Work around by temporarily setting element display to inline-block + var ret = "0px", + display = elem.style.display; + elem.style.display = "inline-block"; + ret = getComputedStyle( elem, "margin-right", "margin-right" ); + elem.style.display = display; + return ret; + } + } + } +}); + if ( document.defaultView && document.defaultView.getComputedStyle ) { getComputedStyle = function( elem, newName, name ) { var ret, defaultView, computedStyle; diff --git a/src/support.js b/src/support.js index 7470b33e..939ad4fc 100644 --- a/src/support.js +++ b/src/support.js @@ -67,7 +67,8 @@ boxModel: null, inlineBlockNeedsLayout: false, shrinkWrapBlocks: false, - reliableHiddenOffsets: true + reliableHiddenOffsets: true, + reliableMarginRight: true }; input.checked = true; @@ -188,6 +189,17 @@ jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0; div.innerHTML = ""; + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. For more + // info see bug #3333 + // Fails in WebKit before Feb 2011 nightlies + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + if ( document.defaultView && document.defaultView.getComputedStyle ) { + div.style.width = "1px"; + div.style.marginRight = "0"; + jQuery.support.reliableMarginRight = ( parseInt(document.defaultView.getComputedStyle(div).marginRight, 10) || 0 ) === 0; + } + body.removeChild( div ).style.display = "none"; div = tds = null; }); diff --git a/test/unit/css.js b/test/unit/css.js index 555f1357..8ae8fcb3 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -333,3 +333,15 @@ test("internal ref to elem.runtimeStyle (bug #7608)", function () { ok( result, "elem.runtimeStyle does not throw exception" ); }); + +test("marginRight computed style (bug #3333)", function() { + expect(1); + + var $div = jQuery("#foo"); + $div.css({ + width: "1px", + marginRight: 0 + }); + + equals($div.css("marginRight"), "0px"); +}); From e8f4629b924cae0b0f1847d2368031f06bc08149 Mon Sep 17 00:00:00 2001 From: Michael Murray Date: Thu, 24 Mar 2011 19:02:38 -0400 Subject: [PATCH 068/418] Offset setter for fixed position elements in Webkit. Fixes #8316. --- src/offset.js | 4 ++-- test/unit/offset.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/offset.js b/src/offset.js index 1003c400..18261bb5 100644 --- a/src/offset.js +++ b/src/offset.js @@ -181,10 +181,10 @@ jQuery.offset = { curOffset = curElem.offset(), curCSSTop = jQuery.css( elem, "top" ), curCSSLeft = jQuery.css( elem, "left" ), - calculatePosition = (position === "absolute" && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1), + calculatePosition = ((position === "absolute" || position === "fixed") && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1), props = {}, curPosition = {}, curTop, curLeft; - // need to be able to calculate position if either top or left is auto and position is absolute + // need to be able to calculate position if either top or left is auto and position is either absolute or fixed if ( calculatePosition ) { curPosition = curElem.position(); } diff --git a/test/unit/offset.js b/test/unit/offset.js index 329d69f9..b7f72a0c 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -422,6 +422,21 @@ test("offsetParent", function(){ equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); }); +testoffset("bug_8316", function( jQuery ){ + expect(2); + + var tests = [ + { id:'#elem', top: 100, left: 100 } + ]; + + jQuery.each(tests, function(){ + var el = jQuery(this.id); + el.offset({ top: this.top, left: this.left}); + equals(Math.round(el.offset().top), this.top); + equals(Math.round(el.offset().left), this.left); + }); +}); + function testoffset(name, fn) { test(name, function() { @@ -447,7 +462,7 @@ function testoffset(name, fn) { function loadFixture() { var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ), iframe = jQuery(' diff --git a/test/unit/event.js b/test/unit/event.js index b46ef9eb..491396f9 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -776,6 +776,9 @@ test("trigger() shortcuts", function() { // manually clean up detached elements elem.remove(); + + // test that special handlers do not blow up with VML elements (#7071) + jQuery("#oval").click().keydown(); }); test("trigger() bubbling", function() { From 352715bd0802e2df041f86e1a82669574183ec04 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 12 Apr 2011 17:46:15 -0400 Subject: [PATCH 220/418] Use explicit "new jQuery.Event" to avoid double-function-call overhead. --- src/event.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/event.js b/src/event.js index b8a2e37e..5e2baf0d 100644 --- a/src/event.js +++ b/src/event.js @@ -314,9 +314,9 @@ jQuery.event = { // jQuery.Event object event[ jQuery.expando ] ? event : // Object literal - jQuery.extend( jQuery.Event(type), event ) : + jQuery.extend( new jQuery.Event(type), event ) : // Just the event type (string) - jQuery.Event(type); + new jQuery.Event(type); event.namespace = namespaces.join("."); event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); event.exclusive = exclusive; @@ -989,7 +989,7 @@ jQuery.fn.extend({ triggerHandler: function( type, data ) { if ( this[0] ) { - var event = jQuery.Event( type ); + var event = new jQuery.Event( type ); event.preventDefault(); event.stopPropagation(); jQuery.event.trigger( event, data, this[0] ); From 73f9ab67058d2dc14ab81c62bd9b228b0e1cad93 Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 12 Apr 2011 18:30:21 -0400 Subject: [PATCH 221/418] JSLint failed due to function created within for loop --- src/manipulation.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/manipulation.js b/src/manipulation.js index 52d59d83..711cb5e8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -553,6 +553,8 @@ jQuery.extend({ }, clean: function( elems, context, fragment, scripts ) { + var checkScriptType; + context = context || document; // !context.createElement fails in IE with an error but returns typeof 'object' @@ -630,15 +632,16 @@ jQuery.extend({ } if ( fragment ) { + checkScriptType = function( elem ) { + return !elem.type || rscriptType.test( elem.type ); + }; for ( i = 0; ret[i]; i++ ) { if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); } else { if ( ret[i].nodeType === 1 ) { - var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), function( elem ) { - return !elem.type || rscriptType.test( elem.type ); - }); + var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType ); ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) ); } From 9e71ad1b120e2b20c7430c017629877ba277f667 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Tue, 12 Apr 2011 18:32:23 -0400 Subject: [PATCH 222/418] Explicitly set event.type in case we chopped out a namespace or exclusive flag. --- src/event.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/event.js b/src/event.js index 5e2baf0d..f6cd97cc 100644 --- a/src/event.js +++ b/src/event.js @@ -317,6 +317,7 @@ jQuery.event = { jQuery.extend( new jQuery.Event(type), event ) : // Just the event type (string) new jQuery.Event(type); + event.type = type; event.namespace = namespaces.join("."); event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)"); event.exclusive = exclusive; From 81de96af740f8d397585d8a6fc2a3765dfd16d49 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Tue, 12 Apr 2011 17:27:45 -0400 Subject: [PATCH 223/418] Fixes #8099 using iframe to capture an element's real default display; suggested by lrbabe/louisremi --- src/effects.js | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/effects.js b/src/effects.js index e7987d21..bdd0715e 100644 --- a/src/effects.js +++ b/src/effects.js @@ -548,35 +548,24 @@ if ( jQuery.expr && jQuery.expr.filters ) { } function defaultDisplay( nodeName ) { - var iframe, iframeDoc, iframeNode, display; if ( !elemdisplay[ nodeName ] ) { - iframe = defaultDisplay.iframe.clone()[ 0 ]; + var iframe, iframeDoc, iframeNode, display, elem; - iframe.style.display = "none"; + iframe = defaultDisplay.iframe.clone()[ 0 ]; document.body.appendChild( iframe ); - iframeDoc = iframe.contentWindow && iframe.contentWindow || - iframe.contentDocument.document && iframe.contentDocument.document || - iframe.contentDocument; + iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; - iframeNode = jQuery( "<" + nodeName + ">" ).appendTo( jQuery( "body", iframeDoc.document ) ); + iframeDoc.open(); + iframeDoc.write(""); + elem = iframeDoc.createElement( nodeName ); + iframeDoc.body.appendChild( elem ); + iframeDoc.close(); - if ( !iframeNode.length ) { - // this will only occur in IE - iframeDoc.document.open(); - iframeDoc.document.write(""); - elem = iframeDoc.document.createElement( nodeName ); - iframeDoc.document.body.appendChild( elem ); - iframeDoc.document.close(); - - iframeNode = jQuery( elem ); - } - - // firefox returns undefined from css("display") - display = iframeNode.css("display") || iframeNode[ 0 ].style.display; + display = jQuery( elem ).css( "display" ); if ( display === "none" || display === "" ) { display = "block"; @@ -591,6 +580,12 @@ function defaultDisplay( nodeName ) { return elemdisplay[ nodeName ]; } -defaultDisplay.iframe = jQuery(" diff --git a/test/unit/attributes.js b/test/unit/attributes.js index c78a2961..2bcc5046 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -492,6 +492,7 @@ test("val()", function() { var testVal = function(valueObj) { expect(8); + QUnit.reset(); jQuery("#text1").val(valueObj( "test" )); equals( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" ); @@ -504,15 +505,16 @@ var testVal = function(valueObj) { jQuery("#text1").val(valueObj( null )); equals( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" ); - jQuery("#select1").val(valueObj( "3" )); - equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" ); + var $select1 = jQuery("#select1"); + $select1.val(valueObj( "3" )); + equals( $select1.val(), "3", "Check for modified (via val(String)) value of select element" ); - jQuery("#select1").val(valueObj( 2 )); - equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" ); + $select1.val(valueObj( 2 )); + equals( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" ); - jQuery("#select1").append(""); - jQuery("#select1").val(valueObj( 4 )); - equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" ); + $select1.append(""); + $select1.val(valueObj( 4 )); + equals( $select1.val(), "4", "Should be possible to set the val() to a newly created option" ); // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); diff --git a/test/unit/event.js b/test/unit/event.js index 491396f9..8ffbcd5b 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -778,6 +778,8 @@ test("trigger() shortcuts", function() { elem.remove(); // test that special handlers do not blow up with VML elements (#7071) + jQuery('').appendTo('head'); + jQuery(' ').appendTo('#form'); jQuery("#oval").click().keydown(); }); From 4344d0841756f8572c56490f12739ac204f40966 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 13 Apr 2011 18:35:38 +0200 Subject: [PATCH 226/418] Fixes #8635 again (fix was lost in rewrite). Also removes unnecessary "manual" garbage collection. --- src/support.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/support.js b/src/support.js index 6b19c083..1bd35cab 100644 --- a/src/support.js +++ b/src/support.js @@ -73,7 +73,7 @@ jQuery.support = (function() { // Make sure that a selected-by-default option has a working selected property. // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) optSelected: opt.selected, - + // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7) getSetAttribute: div.className !== "t", @@ -196,7 +196,7 @@ jQuery.support = (function() { marginDiv.style.marginRight = "0"; div.appendChild( marginDiv ); support.reliableMarginRight = - ( parseInt( document.defaultView.getComputedStyle( marginDiv ).marginRight, 10 ) || 0 ) === 0; + ( parseInt( document.defaultView.getComputedStyle( marginDiv, null ).marginRight, 10 ) || 0 ) === 0; } // Remove the body element we added @@ -224,9 +224,6 @@ jQuery.support = (function() { } } - // release memory in IE - body = div = all = a = tds = undefined; - return support; })(); From 4ad9b44deada9da9639f53b1ca3cc4cf2ebf2df2 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 13 Apr 2011 19:27:19 +0200 Subject: [PATCH 227/418] Ensures callback placeholders are tested for and eventually replaced in data only when contentType is application/x-www-form-urlencoded and data is a string. Removes json to jsonp promotion when jsonp or jsonpCallback options are present. Uses new Deferred.always method to bind cleanUp function. --- src/ajax/jsonp.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index 4fb09401..6b0f95d5 100644 --- a/src/ajax/jsonp.js +++ b/src/ajax/jsonp.js @@ -14,13 +14,12 @@ jQuery.ajaxSetup({ // Detect, normalize options and install callbacks for jsonp requests jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { - var dataIsString = ( typeof s.data === "string" ); + var inspectData = s.contentType === "application/x-www-form-urlencoded" && + ( typeof s.data === "string" ); if ( s.dataTypes[ 0 ] === "jsonp" || - originalSettings.jsonpCallback || - originalSettings.jsonp != null || s.jsonp !== false && ( jsre.test( s.url ) || - dataIsString && jsre.test( s.data ) ) ) { + inspectData && jsre.test( s.data ) ) ) { var responseContainer, jsonpCallback = s.jsonpCallback = @@ -28,20 +27,12 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { previous = window[ jsonpCallback ], url = s.url, data = s.data, - replace = "$1" + jsonpCallback + "$2", - cleanUp = function() { - // Set callback back to previous value - window[ jsonpCallback ] = previous; - // Call if it was a function and we have a response - if ( responseContainer && jQuery.isFunction( previous ) ) { - window[ jsonpCallback ]( responseContainer[ 0 ] ); - } - }; + replace = "$1" + jsonpCallback + "$2"; if ( s.jsonp !== false ) { url = url.replace( jsre, replace ); if ( s.url === url ) { - if ( dataIsString ) { + if ( inspectData ) { data = data.replace( jsre, replace ); } if ( s.data === data ) { @@ -59,8 +50,15 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { responseContainer = [ response ]; }; - // Install cleanUp function - jqXHR.then( cleanUp, cleanUp ); + // Clean-up function + jqXHR.always(function() { + // Set callback back to previous value + window[ jsonpCallback ] = previous; + // Call if it was a function and we have a response + if ( responseContainer && jQuery.isFunction( previous ) ) { + window[ jsonpCallback ]( responseContainer[ 0 ] ); + } + }); // Use data converter to retrieve json after script execution s.converters["script json"] = function() { From 4fde550cb62219d7edd14653888608fbbf39c22a Mon Sep 17 00:00:00 2001 From: rwldrn Date: Wed, 13 Apr 2011 13:43:52 -0400 Subject: [PATCH 228/418] Ticket #8099 Conditional iframe approache, caches both iframe and iframedoc for reuse --- src/effects.js | 63 +++++++++++++++++++++++++++----------------- test/unit/effects.js | 8 ++++-- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/effects.js b/src/effects.js index bdd0715e..828798cb 100644 --- a/src/effects.js +++ b/src/effects.js @@ -551,41 +551,56 @@ function defaultDisplay( nodeName ) { if ( !elemdisplay[ nodeName ] ) { - var iframe, iframeDoc, iframeNode, display, elem; + var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ), + display = elem.css( "display" ); - iframe = defaultDisplay.iframe.clone()[ 0 ]; - - document.body.appendChild( iframe ); - - iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; - - iframeDoc.open(); - iframeDoc.write(""); - elem = iframeDoc.createElement( nodeName ); - iframeDoc.body.appendChild( elem ); - iframeDoc.close(); - - display = jQuery( elem ).css( "display" ); + elem.remove(); if ( display === "none" || display === "" ) { - display = "block"; + + var iframe = defaultDisplay.iframe, + iframeDoc = defaultDisplay.iframeDoc; + + // No iframe to use yet, so create it + if ( !defaultDisplay.iframe ) { + + iframe = document.createElement( "iframe" ); + iframe.width = iframe.height = 0; + + document.body.appendChild( iframe ); + + iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; + iframeDoc.write(""); + + // Cache iframe element + defaultDisplay.iframe = iframe; + defaultDisplay.iframeDoc = iframeDoc; + } else { + + // Reuse previous iframe + document.body.appendChild( iframe ); + + } + + elem = iframeDoc.createElement( nodeName ); + + iframeDoc.body.appendChild( elem ); + + display = jQuery( elem ).css( "display" ); + + iframe.parentNode.removeChild( iframe ); } // Store the correct default display elemdisplay[ nodeName ] = display; - - iframe.parentNode.removeChild( iframe ); } return elemdisplay[ nodeName ]; } -defaultDisplay.iframe = jQuery("
-
+

See this blog entry for more information.

Here are some links in a normal paragraph: Google, diff --git a/test/unit/ajax.js b/test/unit/ajax.js index a8a5fa0d..9f084136 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1782,7 +1782,7 @@ test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() { passed++; if ( passed == 2 ) { ok( true, "Check local and global callbacks after timeout" ); - jQuery("#main").unbind("ajaxError"); + jQuery("#qunit-fixture").unbind("ajaxError"); start(); } }; @@ -1792,7 +1792,7 @@ test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() { start(); }; - jQuery("#main").ajaxError(pass); + jQuery("#qunit-fixture").ajaxError(pass); jQuery.ajax({ type: "GET", diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 8ea27aa3..a497effa 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -108,7 +108,7 @@ test("attr(String)", function() { equals( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" ); // using innerHTML in IE causes href attribute to be serialized to the full path - jQuery("").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#main"); + jQuery("").attr({ "id": "tAnchor5", "href": "#5" }).appendTo("#qunit-fixture"); equals( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" ); // list attribute is readonly by default in browsers that support it @@ -599,7 +599,7 @@ test("val(Function) with incoming value", function() { test("val(select) after form.reset() (Bug #2551)", function() { expect(3); - jQuery("

").appendTo("#main"); + jQuery("
").appendTo("#qunit-fixture"); jQuery("#kkk").val( "gf" ); diff --git a/test/unit/core.js b/test/unit/core.js index 8d29575a..cc744e7b 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -29,7 +29,7 @@ test("jQuery()", function() { equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); - var main = jQuery("#main"); + var main = jQuery("#qunit-fixture"); same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); /* @@ -115,54 +115,54 @@ test("selector state", function() { equals( test.selector, "", "Body Selector" ); equals( test.context, document.body, "Body Context" ); - test = jQuery("#main"); - equals( test.selector, "#main", "#main Selector" ); - equals( test.context, document, "#main Context" ); + test = jQuery("#qunit-fixture"); + equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equals( test.context, document, "#qunit-fixture Context" ); test = jQuery("#notfoundnono"); equals( test.selector, "#notfoundnono", "#notfoundnono Selector" ); equals( test.context, document, "#notfoundnono Context" ); - test = jQuery("#main", document); - equals( test.selector, "#main", "#main Selector" ); - equals( test.context, document, "#main Context" ); + test = jQuery("#qunit-fixture", document); + equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equals( test.context, document, "#qunit-fixture Context" ); - test = jQuery("#main", document.body); - equals( test.selector, "#main", "#main Selector" ); - equals( test.context, document.body, "#main Context" ); + test = jQuery("#qunit-fixture", document.body); + equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equals( test.context, document.body, "#qunit-fixture Context" ); // Test cloning test = jQuery(test); - equals( test.selector, "#main", "#main Selector" ); - equals( test.context, document.body, "#main Context" ); + equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); + equals( test.context, document.body, "#qunit-fixture Context" ); - test = jQuery(document.body).find("#main"); - equals( test.selector, "#main", "#main find Selector" ); - equals( test.context, document.body, "#main find Context" ); + test = jQuery(document.body).find("#qunit-fixture"); + equals( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" ); + equals( test.context, document.body, "#qunit-fixture find Context" ); - test = jQuery("#main").filter("div"); - equals( test.selector, "#main.filter(div)", "#main filter Selector" ); - equals( test.context, document, "#main filter Context" ); + test = jQuery("#qunit-fixture").filter("div"); + equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" ); + equals( test.context, document, "#qunit-fixture filter Context" ); - test = jQuery("#main").not("div"); - equals( test.selector, "#main.not(div)", "#main not Selector" ); - equals( test.context, document, "#main not Context" ); + test = jQuery("#qunit-fixture").not("div"); + equals( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" ); + equals( test.context, document, "#qunit-fixture not Context" ); - test = jQuery("#main").filter("div").not("div"); - equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" ); - equals( test.context, document, "#main filter, not Context" ); + test = jQuery("#qunit-fixture").filter("div").not("div"); + equals( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" ); + equals( test.context, document, "#qunit-fixture filter, not Context" ); - test = jQuery("#main").filter("div").not("div").end(); - equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" ); - equals( test.context, document, "#main filter, not, end Context" ); + test = jQuery("#qunit-fixture").filter("div").not("div").end(); + equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" ); + equals( test.context, document, "#qunit-fixture filter, not, end Context" ); - test = jQuery("#main").parent("body"); - equals( test.selector, "#main.parent(body)", "#main parent Selector" ); - equals( test.context, document, "#main parent Context" ); + test = jQuery("#qunit-fixture").parent("body"); + equals( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" ); + equals( test.context, document, "#qunit-fixture parent Context" ); - test = jQuery("#main").eq(0); - equals( test.selector, "#main.slice(0,1)", "#main eq Selector" ); - equals( test.context, document, "#main eq Context" ); + test = jQuery("#qunit-fixture").eq(0); + equals( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" ); + equals( test.context, document, "#qunit-fixture eq Context" ); var d = "
"; equals( @@ -228,7 +228,7 @@ test("noConflict", function() { equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); equals( $, original$, "Make sure $ was reverted." ); - ok( $$("#main").html("test"), "Make sure that jQuery still works." ); + ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." ); jQuery = $$; }); @@ -571,29 +571,29 @@ test("end()", function() { test("length", function() { expect(1); - equals( jQuery("#main p").length, 6, "Get Number of Elements Found" ); + equals( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" ); }); test("size()", function() { expect(1); - equals( jQuery("#main p").size(), 6, "Get Number of Elements Found" ); + equals( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" ); }); test("get()", function() { expect(1); - same( jQuery("#main p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); + same( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); }); test("toArray()", function() { expect(1); - same( jQuery("#main p").toArray(), + same( jQuery("#qunit-fixture p").toArray(), q("firstp","ap","sndp","en","sap","first"), "Convert jQuery object to an Array" ) }) test("get(Number)", function() { expect(2); - equals( jQuery("#main p").get(0), document.getElementById("firstp"), "Get A Single Element" ); + equals( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" ); strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" ); }); diff --git a/test/unit/css.js b/test/unit/css.js index 33bc1548..60e8744c 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -3,7 +3,7 @@ module("css", { teardown: moduleTeardown }); test("css(String|Hash)", function() { expect( 42 ); - equals( jQuery("#main").css("display"), "block", "Check for css property \"display\""); + equals( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\""); ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible"); jQuery("#nothiddendiv").css({display: "none"}); diff --git a/test/unit/data.js b/test/unit/data.js index 888f71cb..8b5ce961 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -316,7 +316,7 @@ test("data-* attributes", function() { div.remove(); - child.appendTo("#main"); + child.appendTo("#qunit-fixture"); equals( child.data("myobj"), "old data", "Value accessed from data-* attribute"); child.data("myobj", "replaced"); @@ -406,7 +406,7 @@ test("data-* attributes", function() { } var metadata = "
  1. Some stuff
  2. Some stuff
  3. Some stuff
  4. Some stuff
", - elem = jQuery(metadata).appendTo("#main"); + elem = jQuery(metadata).appendTo("#qunit-fixture"); elem.find("li").each(testData); elem.remove(); diff --git a/test/unit/effects.js b/test/unit/effects.js index 8b7cf467..5b93b83b 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -2,7 +2,7 @@ module("effects", { teardown: moduleTeardown }); test("sanity check", function() { expect(1); - ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" ); + ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" ); }); test("show()", function() { @@ -14,7 +14,7 @@ test("show()", function() { equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." ); - var div = jQuery("
").hide().appendTo("#main").show(); + var div = jQuery("
").hide().appendTo("#qunit-fixture").show(); equal( div.css("display"), "block", "Make sure pre-hidden divs show" ); @@ -32,7 +32,7 @@ test("show()", function() { hiddendiv.css("display",""); - var pass = true, div = jQuery("#main div"); + var pass = true, div = jQuery("#qunit-fixture div"); div.show().each(function(){ if ( this.style.display == "none" ) pass = false; }); @@ -62,7 +62,7 @@ test("show()", function() { }); // #show-tests * is set display: none in CSS - jQuery("#main").append("

"); + jQuery("#qunit-fixture").append("

"); var old = jQuery("#test-table").show().css("display") !== "table"; jQuery("#test-table").remove(); @@ -96,7 +96,7 @@ test("show(Number) - other displays", function() { stop(); // #show-tests * is set display: none in CSS - jQuery("#main").append("

"); + jQuery("#qunit-fixture").append("

"); var old = jQuery("#test-table").show().css("display") !== "table", num = 0; @@ -138,7 +138,7 @@ test("Persist correct display value", function() { stop(); // #show-tests * is set display: none in CSS - jQuery("#main").append("
foo
"); + jQuery("#qunit-fixture").append("
foo
"); var $span = jQuery("#show-tests span"), displayNone = $span.css("display"), @@ -581,7 +581,7 @@ jQuery.checkOverflowDisplay = function(){ } test( "jQuery.fx.prototype.cur()", 6, function() { - var div = jQuery( "
" ).appendTo( "#main" ).css({ + var div = jQuery( "
" ).appendTo( "#qunit-fixture" ).css({ color: "#ABC", border: "5px solid black", left: "auto", @@ -954,7 +954,7 @@ test("hide hidden elements (bug #7141)", function() { expect(3); QUnit.reset(); - var div = jQuery("
").appendTo("#main"); + var div = jQuery("
").appendTo("#qunit-fixture"); equals( div.css("display"), "none", "Element is hidden by default" ); div.hide(); ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); @@ -969,7 +969,7 @@ test("hide hidden elements, with animation (bug #7141)", function() { QUnit.reset(); stop(); - var div = jQuery("
").appendTo("#main"); + var div = jQuery("
").appendTo("#qunit-fixture"); equals( div.css("display"), "none", "Element is hidden by default" ); div.hide(1, function () { ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" ); @@ -982,7 +982,7 @@ test("hide hidden elements, with animation (bug #7141)", function() { test("animate unit-less properties (#4966)", 2, function() { stop(); - var div = jQuery( "
" ).appendTo( "#main" ); + var div = jQuery( "
" ).appendTo( "#qunit-fixture" ); equal( div.css( "z-index" ), "0", "z-index is 0" ); div.animate({ zIndex: 2 }, function() { equal( div.css( "z-index" ), "2", "z-index is 2" ); diff --git a/test/unit/event.js b/test/unit/event.js index a1aee191..454ada3b 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -169,7 +169,7 @@ test("bind(), namespace with special add", function() { }); // Should trigger 2 - div.appendTo("#main").remove(); + div.appendTo("#qunit-fixture").remove(); delete jQuery.event.special.test; }); @@ -307,7 +307,7 @@ test("live/delegate immediate propagation", function() { test("bind/delegate bubbling, isDefaultPrevented", function() { expect(2); var $anchor2 = jQuery( "#anchor2" ), - $main = jQuery( "#main" ), + $main = jQuery( "#qunit-fixture" ), fakeClick = function($jq) { // Use a native click so we don't get jQuery simulated bubbling if ( document.createEvent ) { @@ -415,7 +415,7 @@ test("bind(), namespaced events, cloned events", 18, function() { }).trigger("tester"); // Make sure events stick with appendTo'd elements (which are cloned) #2027 - jQuery("test").click(function(){ return false; }).appendTo("#main"); + jQuery("test").click(function(){ return false; }).appendTo("#qunit-fixture"); ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" ); }); @@ -538,7 +538,7 @@ test("bind(name, false), unbind(name, false)", function() { expect(3); var main = 0; - jQuery("#main").bind("click", function(e){ main++; }); + jQuery("#qunit-fixture").bind("click", function(e){ main++; }); jQuery("#ap").trigger("click"); equals( main, 1, "Verify that the trigger happened correctly." ); @@ -553,14 +553,14 @@ test("bind(name, false), unbind(name, false)", function() { equals( main, 1, "Verify that the trigger happened correctly." ); // manually clean up events from elements outside the fixture - jQuery("#main").unbind("click"); + jQuery("#qunit-fixture").unbind("click"); }); test("live(name, false), die(name, false)", function() { expect(3); var main = 0; - jQuery("#main").live("click", function(e){ main++; }); + jQuery("#qunit-fixture").live("click", function(e){ main++; }); jQuery("#ap").trigger("click"); equals( main, 1, "Verify that the trigger happened correctly." ); @@ -573,7 +573,7 @@ test("live(name, false), die(name, false)", function() { jQuery("#ap").die("click", false); jQuery("#ap").trigger("click"); equals( main, 1, "Verify that the trigger happened correctly." ); - jQuery("#main").die("click"); + jQuery("#qunit-fixture").die("click"); }); test("delegate(selector, name, false), undelegate(selector, name, false)", function() { @@ -581,7 +581,7 @@ test("delegate(selector, name, false), undelegate(selector, name, false)", funct var main = 0; - jQuery("#main").delegate("#ap", "click", function(e){ main++; }); + jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; }); jQuery("#ap").trigger("click"); equals( main, 1, "Verify that the trigger happened correctly." ); @@ -594,7 +594,7 @@ test("delegate(selector, name, false), undelegate(selector, name, false)", funct jQuery("#ap").undelegate("#groups", "click", false); jQuery("#groups").trigger("click"); equals( main, 1, "Verify that the trigger happened correctly." ); - jQuery("#main").undelegate("#ap", "click"); + jQuery("#qunit-fixture").undelegate("#ap", "click"); }); test("bind()/trigger()/unbind() on plain object", function() { @@ -798,7 +798,7 @@ test("trigger() bubbling", function() { jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } }); jQuery("html").bind("click", function(e){ html++; }); jQuery("body").bind("click", function(e){ body++; }); - jQuery("#main").bind("click", function(e){ main++; }); + jQuery("#qunit-fixture").bind("click", function(e){ main++; }); jQuery("#ap").bind("click", function(){ ap++; return false; }); jQuery("html").trigger("click"); @@ -812,7 +812,7 @@ test("trigger() bubbling", function() { equals( html, 2, "Body bubble" ); equals( body, 1, "Body bubble" ); - jQuery("#main").trigger("click"); + jQuery("#qunit-fixture").trigger("click"); equals( win, 3, "Main bubble" ); equals( doc, 3, "Main bubble" ); equals( html, 3, "Main bubble" ); @@ -828,7 +828,7 @@ test("trigger() bubbling", function() { // manually clean up events from elements outside the fixture jQuery(document).unbind("click"); - jQuery("html, body, #main").unbind("click"); + jQuery("html, body, #qunit-fixture").unbind("click"); }); test("trigger(type, [data], [fn])", function() { @@ -872,7 +872,7 @@ test("trigger(type, [data], [fn])", function() { pass = true; try { - jQuery("#main table:first").bind("test:test", function(){}).trigger("test:test"); + jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test"); } catch (e) { pass = false; } @@ -1189,11 +1189,11 @@ test(".live()/.die()", function() { jQuery("div").die("submit"); // Test binding with a different context - var clicked = 0, container = jQuery("#main")[0]; + var clicked = 0, container = jQuery("#qunit-fixture")[0]; jQuery("#foo", container).live("click", function(e){ clicked++; }); jQuery("div").trigger("click"); jQuery("#foo").trigger("click"); - jQuery("#main").trigger("click"); + jQuery("#qunit-fixture").trigger("click"); jQuery("body").trigger("click"); equals( clicked, 2, "live with a context" ); @@ -1716,11 +1716,11 @@ test(".delegate()/.undelegate()", function() { jQuery("#body").undelegate("div", "submit"); // Test binding with a different context - var clicked = 0, container = jQuery("#main")[0]; - jQuery("#main").delegate("#foo", "click", function(e){ clicked++; }); + var clicked = 0, container = jQuery("#qunit-fixture")[0]; + jQuery("#qunit-fixture").delegate("#foo", "click", function(e){ clicked++; }); jQuery("div").trigger("click"); jQuery("#foo").trigger("click"); - jQuery("#main").trigger("click"); + jQuery("#qunit-fixture").trigger("click"); jQuery("body").trigger("click"); equals( clicked, 2, "delegate with a context" ); @@ -1728,7 +1728,7 @@ test(".delegate()/.undelegate()", function() { ok( jQuery._data(container, "events").live, "delegate with a context" ); // Test unbinding with a different context - jQuery("#main").undelegate("#foo", "click"); + jQuery("#qunit-fixture").undelegate("#foo", "click"); jQuery("#foo").trigger("click"); equals( clicked, 2, "undelegate with a context"); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index de65daa1..e0fb369a 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -483,19 +483,19 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() { var div = jQuery("
").click(function(){ ok(true, "Running a cloned click."); }); - div.appendTo("#main, #moretests"); + div.appendTo("#qunit-fixture, #moretests"); - jQuery("#main div:last").click(); + jQuery("#qunit-fixture div:last").click(); jQuery("#moretests div:last").click(); QUnit.reset(); - var div = jQuery("
").appendTo("#main, #moretests"); + var div = jQuery("
").appendTo("#qunit-fixture, #moretests"); equals( div.length, 2, "appendTo returns the inserted elements" ); div.addClass("test"); - ok( jQuery("#main div:last").hasClass("test"), "appendTo element was modified after the insertion" ); + ok( jQuery("#qunit-fixture div:last").hasClass("test"), "appendTo element was modified after the insertion" ); ok( jQuery("#moretests div:last").hasClass("test"), "appendTo element was modified after the insertion" ); QUnit.reset(); @@ -507,10 +507,10 @@ test("appendTo(String|Element|Array<Element>|jQuery)", function() { div = jQuery("#moretests div"); - var num = jQuery("#main div").length; - div.remove().appendTo("#main"); + var num = jQuery("#qunit-fixture div").length; + div.remove().appendTo("#qunit-fixture"); - equals( jQuery("#main div").length, num, "Make sure all the removed divs were inserted." ); + equals( jQuery("#qunit-fixture div").length, num, "Make sure all the removed divs were inserted." ); QUnit.reset(); }); @@ -750,7 +750,7 @@ var testReplaceWith = function(val) { ok( !jQuery("#yahoo")[0], "Verify that original element is gone, after element" ); QUnit.reset(); - jQuery("#main").append("
"); + jQuery("#qunit-fixture").append("
"); jQuery("#baz").replaceWith("Baz"); equals( jQuery("#bar").text(),"Baz", "Replace element with text" ); ok( !jQuery("#baz")[0], "Verify that original element is gone, after element" ); @@ -813,14 +813,14 @@ var testReplaceWith = function(val) { QUnit.reset(); - jQuery("#main").append("
"); - equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + jQuery("#qunit-fixture").append("
"); + equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); jQuery("#replaceWith").replaceWith( val("
") ); - equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); jQuery("#replaceWith").replaceWith( val("
") ); - equals( jQuery("#main").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); + equals( jQuery("#qunit-fixture").find("div[id=replaceWith]").length, 1, "Make sure only one div exists." ); } test("replaceWith(String|Element|Array<Element>|jQuery)", function() { @@ -881,7 +881,7 @@ test("jQuery.clone() (#8017)", function() { ok( jQuery.clone && jQuery.isFunction( jQuery.clone ) , "jQuery.clone() utility exists and is a function."); - var main = jQuery("#main")[0], + var main = jQuery("#qunit-fixture")[0], clone = jQuery.clone( main ); equals( main.childNodes.length, clone.childNodes.length, "Simple child length to ensure a large dom tree copies correctly" ); @@ -890,7 +890,7 @@ test("jQuery.clone() (#8017)", function() { test("clone() (#8070)", function () { expect(2); - jQuery("").appendTo("#main"); + jQuery("").appendTo("#qunit-fixture"); var selects = jQuery(".test8070"); selects.append(""); @@ -1062,7 +1062,7 @@ var testHtml = function(valueObj) { jQuery.scriptorder = 0; - var div = jQuery("#main > div"); + var div = jQuery("#qunit-fixture > div"); div.html(valueObj("test")); var pass = true; for ( var i = 0; i < div.size(); i++ ) { @@ -1079,10 +1079,10 @@ var testHtml = function(valueObj) { ok( /^\xA0$|^ $/.test( space ), "Make sure entities are passed through correctly." ); equals( jQuery("
").html(valueObj("&"))[0].innerHTML, "&", "Make sure entities are passed through correctly." ); - jQuery("#main").html(valueObj("")); + jQuery("#qunit-fixture").html(valueObj("")); - equals( jQuery("#main").children().length, 1, "Make sure there is a child element." ); - equals( jQuery("#main").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." ); + equals( jQuery("#qunit-fixture").children().length, 1, "Make sure there is a child element." ); + equals( jQuery("#qunit-fixture").children()[0].nodeName.toUpperCase(), "STYLE", "And that a style element was inserted." ); QUnit.reset(); // using contents will get comments regular, text, and comment nodes @@ -1093,9 +1093,9 @@ var testHtml = function(valueObj) { j.find("b").removeData(); equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "bold", "Check node,textnode,comment with html()" ); - jQuery("#main").html(valueObj("")); + jQuery("#qunit-fixture select").html(valueObj("")); + equals( jQuery("#qunit-fixture select").val(), "O2", "Selected option correct" ); var $div = jQuery("
"); equals( $div.html(valueObj( 5 )).html(), "5", "Setting a number as html" ); @@ -1113,23 +1113,23 @@ var testHtml = function(valueObj) { QUnit.reset(); - jQuery("#main").html(valueObj("
")); + jQuery("#qunit-fixture").html(valueObj("
")); - var child = jQuery("#main").find("script"); + var child = jQuery("#qunit-fixture").find("script"); equals( child.length, 2, "Make sure that two non-JavaScript script tags are left." ); equals( child[0].type, "something/else", "Verify type of script tag." ); equals( child[1].type, "something/else", "Verify type of script tag." ); - jQuery("#main").html(valueObj("")); - jQuery("#main").html(valueObj("")); - jQuery("#main").html(valueObj("")); + jQuery("#qunit-fixture").html(valueObj("")); + jQuery("#qunit-fixture").html(valueObj("")); + jQuery("#qunit-fixture").html(valueObj("")); - jQuery("#main").html(valueObj("")); + jQuery("#qunit-fixture").html(valueObj("")); - jQuery("#main").html(valueObj("foo
")); + jQuery("#qunit-fixture").html(valueObj("foo
")); - jQuery("#main").html(valueObj(" + + + + + + + + + + + + + + + + + + + + + + + + +

jQuery Test Suite

+

+
+

+
    + + +
    +
    +
    + + +
    +
    +

    See this blog entry for more information.

    +

    + Here are some links in a normal paragraph: Google, + Google Groups (Link). + This link has class="blog": + diveintomark + +

    +
    +

    Everything inside the red border is inside a div with id="foo".

    +

    This is a normal link: Yahoo

    +

    This link has class="blog": Simon Willison's Weblog

    + +
    + +

    Try them out:

    +
      +
        +
        + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + test element +
        + Float test. + +
        + + +
        +
        + +
        + + + + +
        + +
        + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
        +
        +
        + +
        +
        hi there
        +
        +
        +
        +
        + +
        +
          +
        1. Rice
        2. +
        3. Beans
        4. +
        5. Blinis
        6. +
        7. Tofu
        8. +
        + +
        I'm hungry. I should...
        + ...Eat lots of food... | + ...Eat a little food... | + ...Eat no food... + ...Eat a burger... + ...Eat some funyuns... + ...Eat some funyuns... +
        + +
        + + +
        + +
        + 1 + 2 +
        +
        +
        +
        +
        +
        fadeIn
        fadeIn
        +
        fadeOut
        fadeOut
        + +
        show
        show
        +
        hide
        hide
        + +
        togglein
        togglein
        +
        toggleout
        toggleout
        + + +
        slideUp
        slideUp
        +
        slideDown
        slideDown
        + +
        slideToggleIn
        slideToggleIn
        +
        slideToggleOut
        slideToggleOut
        + +
        fadeToggleIn
        fadeToggleIn
        +
        fadeToggleOut
        fadeToggleOut
        + +
        fadeTo
        fadeTo
        +
        + +
        +
        + + From ea24cd106b86dae2411e5b87c367f6ff5163aee8 Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 2 May 2011 17:53:55 -0400 Subject: [PATCH 314/418] Avoid changing html in two places; add minified jQuery as an option to the main test page --- test/data/testrunner.js | 3 - test/data/versioncheck.js | 8 ++ test/index.built.html | 264 -------------------------------------- test/index.html | 6 +- 4 files changed, 13 insertions(+), 268 deletions(-) create mode 100644 test/data/versioncheck.js delete mode 100644 test/index.built.html diff --git a/test/data/testrunner.js b/test/data/testrunner.js index 1da67651..6d44b460 100644 --- a/test/data/testrunner.js +++ b/test/data/testrunner.js @@ -28,9 +28,6 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. // QUnit Aliases (function() { - window.equals = window.equal; window.same = window.deepEqual; - })(); - diff --git a/test/data/versioncheck.js b/test/data/versioncheck.js new file mode 100644 index 00000000..f4b7790d --- /dev/null +++ b/test/data/versioncheck.js @@ -0,0 +1,8 @@ +// Run minified source from dist (do make first) +// Should be loaded before QUnit but after src +(function() { + if ( /jquery\=min/.test( window.location.search ) ) { + jQuery.noConflict( true ); + document.write(unescape("%3Cscript%20src%3D%27../dist/jquery.min.js%27%3E%3C/script%3E")); + } +})(); \ No newline at end of file diff --git a/test/index.built.html b/test/index.built.html deleted file mode 100644 index aad27a1f..00000000 --- a/test/index.built.html +++ /dev/null @@ -1,264 +0,0 @@ - - - - - jQuery Test Suite - Fully Built and Compressed - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        jQuery Test Suite

        -

        -
        -

        -
          - - -
          -
          -
          - - -
          -
          -

          See this blog entry for more information.

          -

          - Here are some links in a normal paragraph: Google, - Google Groups (Link). - This link has class="blog": - diveintomark - -

          -
          -

          Everything inside the red border is inside a div with id="foo".

          -

          This is a normal link: Yahoo

          -

          This link has class="blog": Simon Willison's Weblog

          - -
          - -

          Try them out:

          -
            -
              -
              - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - test element -
              - Float test. - -
              - - -
              -
              - -
              - - - - -
              - -
              - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
              -
              -
              - -
              -
              hi there
              -
              -
              -
              -
              - -
              -
                -
              1. Rice
              2. -
              3. Beans
              4. -
              5. Blinis
              6. -
              7. Tofu
              8. -
              - -
              I'm hungry. I should...
              - ...Eat lots of food... | - ...Eat a little food... | - ...Eat no food... - ...Eat a burger... - ...Eat some funyuns... - ...Eat some funyuns... -
              - -
              - - -
              - -
              - 1 - 2 -
              -
              -
              -
              -
              -
              fadeIn
              fadeIn
              -
              fadeOut
              fadeOut
              - -
              show
              show
              -
              hide
              hide
              - -
              togglein
              togglein
              -
              toggleout
              toggleout
              - - -
              slideUp
              slideUp
              -
              slideDown
              slideDown
              - -
              slideToggleIn
              slideToggleIn
              -
              slideToggleOut
              slideToggleOut
              - -
              fadeToggleIn
              fadeToggleIn
              -
              fadeToggleOut
              fadeToggleOut
              - -
              fadeTo
              fadeTo
              -
              - -
              -
              - - diff --git a/test/index.html b/test/index.html index b19673d9..1a4d0582 100644 --- a/test/index.html +++ b/test/index.html @@ -28,6 +28,8 @@ + + @@ -48,7 +50,9 @@ -

              jQuery Test Suite

              +

              jQuery Test Suite + (minified) +

              From 6d2fd57f452398123f8edefa25eef8045d1b586e Mon Sep 17 00:00:00 2001 From: timmywil Date: Mon, 2 May 2011 18:14:12 -0400 Subject: [PATCH 315/418] Fix QUnit Header links --- test/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.html b/test/index.html index 1a4d0582..3d421a56 100644 --- a/test/index.html +++ b/test/index.html @@ -50,7 +50,7 @@ -

              jQuery Test Suite +

              jQuery Test Suite (minified)

              From 4ac2fdda2c26e9b64502b9ef50748427bed2f3c6 Mon Sep 17 00:00:00 2001 From: timmywil Date: Tue, 3 May 2011 14:48:36 -0400 Subject: [PATCH 316/418] Fix setting value attributes on option elements. Fixes #9071. --- src/attributes.js | 2 +- test/unit/attributes.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index 017a32da..2da2e163 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -199,7 +199,7 @@ jQuery.fn.extend({ hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ]; // If set returns undefined, fall back to normal setting - if ( !hooks || ("set" in hooks && hooks.set( this, val, "value" ) === undefined) ) { + if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) { this.value = val; } }); diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 37e854d0..b1cfe3db 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -447,7 +447,7 @@ test("removeProp(String)", function() { }); test("val()", function() { - expect(25); + expect(26); document.getElementById("text1").value = "bla"; equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); @@ -513,6 +513,8 @@ test("val()", function() { var $button = jQuery("").insertAfter("#button"); equals( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" ); equals( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" ); + + equals( jQuery("