diff options
author | louisremi <louisremi@louisremi-laptop.(none)> | 2011-04-14 11:46:29 +0200 |
---|---|---|
committer | louisremi <louisremi@louisremi-laptop.(none)> | 2011-04-14 11:46:29 +0200 |
commit | 8806435a77886dad8970e8f9ddba1ef728d779f8 (patch) | |
tree | b79019466022ad26e53abde5937f5cf0fa4b53fd /src | |
parent | 780b7983d0a2fbde5cedcdb431a1f2436b256d40 (diff) | |
parent | 38d6d9f6e03e544c3ea7a9f226c3f93d1d97c232 (diff) | |
download | jquery-8806435a77886dad8970e8f9ddba1ef728d779f8.tar.gz jquery-8806435a77886dad8970e8f9ddba1ef728d779f8.zip |
Merge branch 'master' of http://github.com/jquery/jquery into effectsCleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/ajax/jsonp.js | 30 | ||||
-rw-r--r-- | src/attributes.js | 2 | ||||
-rw-r--r-- | src/core.js | 49 | ||||
-rw-r--r-- | src/css.js | 35 | ||||
-rw-r--r-- | src/effects.js | 17 | ||||
-rw-r--r-- | src/event.js | 103 | ||||
-rw-r--r-- | src/manipulation.js | 18 | ||||
-rw-r--r-- | src/offset.js | 52 | ||||
-rw-r--r-- | src/queue.js | 95 | ||||
m--------- | src/sizzle | 0 | ||||
-rw-r--r-- | src/support.js | 14 | ||||
-rw-r--r-- | src/traversing.js | 11 |
12 files changed, 255 insertions, 171 deletions
diff --git a/src/ajax/jsonp.js b/src/ajax/jsonp.js index 4fb094011..6b0f95d5b 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() { diff --git a/src/attributes.js b/src/attributes.js index c34cd6193..5ccbf2cde 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -479,7 +479,7 @@ jQuery.each([ "selected", "checked", "readOnly", "disabled" ], function( i, name // Some attributes require a special call on IE if ( !jQuery.support.hrefNormalized ) { - jQuery.each([ "href", "src", "width", "height", "list" ], function( i, name ) { + jQuery.each([ "href", "src", "width", "height" ], function( i, name ) { jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], { get: function( elem ) { var ret = elem.getAttribute( name, 2 ); diff --git a/src/core.js b/src/core.js index d3641365b..89bbde5c0 100644 --- a/src/core.js +++ b/src/core.js @@ -358,9 +358,11 @@ 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; } @@ -436,7 +438,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 ); @@ -587,7 +589,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 ) { @@ -613,8 +615,11 @@ jQuery.extend({ } } } else { - for ( var value = object[0]; - i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} + for ( ; i < length; ) { + if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) { + break; + } + } } } @@ -645,7 +650,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 ); @@ -841,24 +846,24 @@ jQuery.extend({ }, sub: function() { - function jQuerySubclass( selector, context ) { - return new jQuerySubclass.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); + function jQuerySub( selector, context ) { + return new jQuerySub.fn.init( selector, 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 65ec20f57..c5c01ecac 100644 --- a/src/css.js +++ b/src/css.js @@ -93,7 +93,7 @@ jQuery.extend({ // convert relative number strings (+= or -=) to relative numbers. #7345 if ( type === "string" && rrelNum.test( value ) ) { - value = +value.replace( rrelNumFilter, '' ) + parseFloat( jQuery.css( elem, name ) ); + value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) ); } // If a number was passed in, add 'px' to the (except for certain CSS properties) @@ -122,11 +122,17 @@ jQuery.extend({ }, css: function( elem, name, extra ) { + var ret, hooks; + // Make sure that we're working with the right name - var ret, origName = jQuery.camelCase( name ), - hooks = jQuery.cssHooks[ origName ]; + name = jQuery.camelCase( name ); + hooks = jQuery.cssHooks[ name ]; + name = jQuery.cssProps[ name ] || name; - name = jQuery.cssProps[ origName ] || origName; + // cssFloat needs a special treatment + if ( name === "cssFloat" ) { + name = "float"; + } // If a hook was provided get the computed value from there if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) { @@ -134,7 +140,7 @@ jQuery.extend({ // Otherwise, if a way to get the computed value exists, use that } else if ( curCSS ) { - return curCSS( elem, name, origName ); + return curCSS( elem, name ); } }, @@ -225,27 +231,28 @@ 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" : ""; }, 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 style.zoom = 1; // Set the alpha filter to set the opacity - var opacity = jQuery.isNaN(value) ? + 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; + style.filter = ralpha.test( filter ) ? + filter.replace( ralpha, opacity ) : + filter + " " + opacity; } }; } @@ -273,7 +280,7 @@ jQuery(function() { }); if ( document.defaultView && document.defaultView.getComputedStyle ) { - getComputedStyle = function( elem, newName, name ) { + getComputedStyle = function( elem, name ) { var ret, defaultView, computedStyle; name = name.replace( rupper, "-$1" ).toLowerCase(); diff --git a/src/effects.js b/src/effects.js index 80c033abc..e4f37e0c9 100644 --- a/src/effects.js +++ b/src/effects.js @@ -152,13 +152,17 @@ jQuery.fn.extend({ var optall = jQuery.speed(speed, easing, callback); if ( jQuery.isEmptyObject( prop ) ) { - return this.each( optall.complete ); + return this.each( optall.complete, [ false ] ); } return this[ optall.queue === false ? "each" : "queue" ](function() { // XXX 'this' does not always have a nodeName when running the // test suite + if ( optall.queue === false ) { + jQuery._mark( this ); + } + var opt = jQuery.extend({}, optall), p, isElement = this.nodeType === 1, hidden = isElement && jQuery(this).is(":hidden"), @@ -268,6 +272,10 @@ jQuery.fn.extend({ } this.each(function() { + // clear marker counters if we know they won't be + if ( !gotoEnd ) { + jQuery._unmark( true, this ); + } // go in reverse order so anything added to the queue during the loop is ignored for ( var i = timers.length - 1; i >= 0; i-- ) { if ( timers[i].elem === this ) { @@ -319,10 +327,13 @@ jQuery.extend({ // Queueing opt.old = opt.complete; - opt.complete = function() { + opt.complete = function( noUnmark ) { if ( opt.queue !== false ) { - jQuery(this).dequeue(); + jQuery.dequeue( this ); + } else if ( noUnmark !== false ) { + jQuery._unmark( this ); } + if ( jQuery.isFunction( opt.old ) ) { opt.old.call( this ); } diff --git a/src/event.js b/src/event.js index ac0da6b7e..bfd263078 100644 --- a/src/event.js +++ b/src/event.js @@ -24,17 +24,6 @@ jQuery.event = { return; } - // TODO :: Use a try/catch until it's safe to pull this out (likely 1.6) - // Minor release fix for bug #8018 - try { - // For whatever reason, IE has trouble passing the window object - // around, causing it to be cloned in the process - if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) { - elem = window; - } - } - catch ( e ) {} - if ( handler === false ) { handler = returnFalse; } else if ( !handler ) { @@ -277,34 +266,53 @@ jQuery.event = { } } }, + + // Events that are safe to short-circuit if no handlers are attached. + // Native DOM events should not be added, they may have inline handlers. + customEvent: { + "getData": true, + "setData": true, + "changeData": true + }, trigger: function( event, data, elem ) { // Event object or event type var type = event.type || event, - namespaces = []; - - event = typeof event === "object" ? - // jQuery.Event object - event[ jQuery.expando ] ? event : - // Object literal - jQuery.extend( jQuery.Event(type), event ) : - // Just the event type (string) - jQuery.Event(type); + namespaces = [], + exclusive; if ( type.indexOf("!") >= 0 ) { - // Exclusive events trigger only for the bare event type (no namespaces) - event.type = type = type.slice(0, -1); - event.exclusive = true; + // Exclusive events trigger only for the exact event (no namespaces) + type = type.slice(0, -1); + exclusive = true; } + if ( type.indexOf(".") >= 0 ) { // Namespaced trigger; create a regexp to match event type in handle() namespaces = type.split("."); - event.type = type = namespaces.shift(); + type = namespaces.shift(); namespaces.sort(); } + + if ( jQuery.event.customEvent[ type ] && !jQuery.event.global[ type ] ) { + // No jQuery handlers for this event type, and it can't have inline handlers + return; + } + + // Caller can pass in an Event, Object, or just an event type string + event = typeof event === "object" ? + // jQuery.Event object + event[ jQuery.expando ] ? event : + // Object literal + 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; + // Handle a global trigger if ( !elem ) { // Don't bubble custom events when global (to avoid too much overhead) @@ -338,12 +346,12 @@ jQuery.event = { event.target = elem; // Clone any incoming data and prepend the event, creating the handler arg list - data = jQuery.makeArray( data ); + data = data ? jQuery.makeArray( data ) : []; data.unshift( event ); var cur = elem, // IE doesn't like method names with a colon (#3533, #8272) - ontype = type.indexOf(":") < 0? "on" + type : ""; + ontype = type.indexOf(":") < 0 ? "on" + type : ""; // Fire event on the current element, then bubble up the DOM tree do { @@ -355,7 +363,7 @@ jQuery.event = { } // Trigger an inline bound script - if ( ontype &&jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) { + if ( ontype && jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) { event.result = false; event.preventDefault(); } @@ -403,7 +411,7 @@ jQuery.event = { // Snapshot the handlers list since a called handler may add/remove events. var handlers = ((jQuery._data( this, "events" ) || {})[ event.type ] || []).slice(0), run_all = !event.exclusive && !event.namespace, - args = jQuery.makeArray( arguments ); + args = Array.prototype.slice.call( arguments, 0 ); // Use the fix-ed Event rather than the (read-only) native event args[0] = event; @@ -555,24 +563,16 @@ jQuery.removeEvent = document.removeEventListener ? } }; -jQuery.Event = function( src ) { +jQuery.Event = function( src, props ) { // Allow instantiation without the 'new' keyword if ( !this.preventDefault ) { - return new jQuery.Event( src ); + return new jQuery.Event( src, props ); } // Event object if ( src && src.type ) { this.originalEvent = src; - - // Push explicitly provided properties onto the event object - for ( var prop in src ) { - // Ensure we don't clobber jQuery.Event prototype - // with own properties. - if ( hasOwn.call( src, prop ) ) { - this[ prop ] = src[ prop ]; - } - } + this.type = src.type; // Events bubbling up the document may have been marked as prevented // by a handler lower down the tree; reflect the correct value. @@ -584,6 +584,11 @@ jQuery.Event = function( src ) { this.type = src; } + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + // timeStamp is buggy for some events on Firefox(#3843) // So we won't rely on the native value this.timeStamp = jQuery.now(); @@ -790,7 +795,7 @@ if ( !jQuery.support.changeBubbles ) { beforedeactivate: testChange, click: function( e ) { - var elem = e.target, type = elem.type; + var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : ""; if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) { testChange.call( this, e ); @@ -800,7 +805,7 @@ if ( !jQuery.support.changeBubbles ) { // Change has to be called before submit // Keydown will be called before keypress, which is used in submit-event delegation keydown: function( e ) { - var elem = e.target, type = elem.type; + var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : ""; if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") || (e.keyCode === 32 && (type === "checkbox" || type === "radio")) || @@ -955,7 +960,7 @@ jQuery.fn.extend({ undelegate: function( selector, types, fn ) { if ( arguments.length === 0 ) { - return this.unbind( "live" ); + return this.unbind( "live" ); } else { return this.die( types, null, fn, selector ); @@ -970,7 +975,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] ); @@ -1030,10 +1035,18 @@ jQuery.each(["live", "die"], function( i, name ) { return this; } + if ( name === "die" && !types && + origSelector && origSelector.charAt(0) === "." ) { + + context.unbind( origSelector ); + + return this; + } + if ( data === false || jQuery.isFunction( data ) ) { fn = data || returnFalse; data = undefined; - } + } types = (types || "").split(" "); diff --git a/src/manipulation.js b/src/manipulation.js index 758cdbae0..f519b4d35 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -9,6 +9,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, rnocache = /<(?:script|object|embed|option|style)/i, // checked="checked" or checked rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, + rscriptType = /\/(java|ecma)script/i, wrapMap = { option: [ 1, "<select multiple='multiple'>", "</select>" ], legend: [ 1, "<fieldset>", "</fieldset>" ], @@ -387,11 +388,15 @@ function cloneFixAttributes( src, dest ) { // clearAttributes removes the attributes, which we don't want, // but also removes the attachEvent events, which we *do* want - dest.clearAttributes(); + if ( dest.clearAttributes ) { + dest.clearAttributes(); + } // mergeAttributes, in contrast, only merges back on the // original attributes, not the events - dest.mergeAttributes(src); + if ( dest.mergeAttributes ) { + dest.mergeAttributes( src ); + } // IE6-8 fail to clone children inside object elements that use // the proprietary classid attribute value (rather than the type @@ -552,6 +557,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' @@ -629,13 +636,18 @@ 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 ) { - ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) ); + var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType ); + + ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) ); } fragment.appendChild( ret[i] ); } diff --git a/src/offset.js b/src/offset.js index a0cd7a156..31f2503a4 100644 --- a/src/offset.js +++ b/src/offset.js @@ -180,17 +180,19 @@ jQuery.offset = { curOffset = curElem.offset(), curCSSTop = jQuery.css( elem, "top" ), curCSSLeft = jQuery.css( elem, "left" ), - calculatePosition = (position === "absolute" || position === "fixed") && 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 either absolute or fixed 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 ); } @@ -259,29 +261,16 @@ jQuery.fn.extend({ jQuery.each( ["Left", "Top"], function( i, name ) { var method = "scroll" + name; - jQuery.fn[ method ] = function(val) { - var elem = this[0], win; + jQuery.fn[ method ] = function( val ) { + var elem, win; - if ( !elem ) { - return null; - } + if ( val === undefined ) { + elem = this[ 0 ]; - 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() - ); + if ( !elem ) { + return null; + } - } else { - this[ method ] = val; - } - }); - } else { win = getWindow( elem ); // Return the scroll offset @@ -290,6 +279,21 @@ 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() + ); + + } else { + this[ method ] = val; + } + }); }; }); diff --git a/src/queue.js b/src/queue.js index 701d06ade..ce2305426 100644 --- a/src/queue.js +++ b/src/queue.js @@ -1,27 +1,67 @@ (function( jQuery ) { -jQuery.extend({ - queue: function( elem, type, data ) { - if ( !elem ) { - return; - } +function handleQueueMarkDefer( elem, type, src ) { + var deferDataKey = type + "defer", + queueDataKey = type + "queue", + markDataKey = type + "mark", + defer = jQuery.data( elem, deferDataKey, undefined, true ); + if ( defer && + ( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) && + ( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) { + // Give room for hard-coded callbacks to fire first + // and eventually mark/queue something else on the element + setTimeout( function() { + if ( !jQuery.data( elem, queueDataKey, undefined, true ) && + !jQuery.data( elem, markDataKey, undefined, true ) ) { + jQuery.removeData( elem, deferDataKey, true ); + defer.resolve(); + } + }, 0 ); + } +} - type = (type || "fx") + "queue"; - var q = jQuery._data( elem, type ); +jQuery.extend({ - // Speed up dequeue by getting out quickly if this is just a lookup - if ( !data ) { - return q || []; + _mark: function( elem, type ) { + if ( elem ) { + type = (type || "fx") + "mark"; + jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true ); } + }, - if ( !q || jQuery.isArray(data) ) { - q = jQuery._data( elem, type, jQuery.makeArray(data) ); - - } else { - q.push( data ); + _unmark: function( force, elem, type ) { + if ( force !== true ) { + type = elem; + elem = force; + force = false; + } + if ( elem ) { + type = type || "fx"; + var key = type + "mark", + count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 ); + if ( count ) { + jQuery.data( elem, key, count, true ); + } else { + jQuery.removeData( elem, key, true ); + handleQueueMarkDefer( elem, type, "mark" ); + } } + }, - return q; + queue: function( elem, type, data ) { + if ( elem ) { + type = (type || "fx") + "queue"; + var q = jQuery.data( elem, type, undefined, true ); + // Speed up dequeue by getting out quickly if this is just a lookup + if ( data ) { + if ( !q || jQuery.isArray(data) ) { + q = jQuery.data( elem, type, jQuery.makeArray(data), true ); + } else { + q.push( data ); + } + } + return q || []; + } }, dequeue: function( elem, type ) { @@ -50,17 +90,7 @@ jQuery.extend({ if ( !queue.length ) { jQuery.removeData( elem, type + "queue", true ); - // Look if we have observers and resolve if needed - if (( defer = jQuery.data( elem, type + "defer", undefined, true ) )) { - // Give room for hard-coded callbacks to fire first - // and eventually add another animation on the element - setTimeout( function() { - if ( !jQuery.data( elem, type + "queue", undefined, true ) ) { - jQuery.removeData( elem, type + "defer", true ); - defer.resolve(); - } - }, 0 ); - } + handleQueueMarkDefer( elem, type, "queue" ); } } }); @@ -75,7 +105,7 @@ jQuery.fn.extend({ if ( data === undefined ) { return jQuery.queue( this[0], type ); } - return this.each(function( i ) { + return this.each(function() { var queue = jQuery.queue( this, type, data ); if ( type === "fx" && queue[0] !== "inprogress" ) { @@ -88,7 +118,6 @@ jQuery.fn.extend({ jQuery.dequeue( this, type ); }); }, - // Based off of the plugin by Clint Helfers, with permission. // http://blindsignals.com/index.php/2009/07/jquery-delay/ delay: function( time, type ) { @@ -102,11 +131,9 @@ jQuery.fn.extend({ }, time ); }); }, - clearQueue: function( type ) { return this.queue( type || "fx", [] ); }, - // Get a promise resolved when queues of a certain type // are emptied (fx is the type by default) promise: function( type, object ) { @@ -120,7 +147,8 @@ jQuery.fn.extend({ i = elements.length, count = 1, deferDataKey = type + "defer", - queueDataKey = type + "queue"; + queueDataKey = type + "queue", + markDataKey = type + "mark"; function resolve() { if ( !( --count ) ) { defer.resolveWith( elements, [ elements ] ); @@ -128,7 +156,8 @@ jQuery.fn.extend({ } while( i-- ) { if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) || - jQuery.data( elements[ i ], queueDataKey, undefined, true ) && + ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) || + jQuery.data( elements[ i ], markDataKey, undefined, true ) ) && jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) { count++; tmp.done( resolve ); diff --git a/src/sizzle b/src/sizzle -Subproject c50b0cddec48494ba882606d03e14cce647d243 +Subproject 69ecd019852c1421cbd81fe6ceb4e22a81022ea diff --git a/src/support.js b/src/support.js index 34960505a..1bd35cab2 100644 --- a/src/support.js +++ b/src/support.js @@ -8,6 +8,7 @@ jQuery.support = (function() { select, opt, input, + marginDiv, support, fragment, body, @@ -72,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", @@ -190,10 +191,12 @@ jQuery.support = (function() { // 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"; + marginDiv = document.createElement('div'); + marginDiv.style.width = "0"; + marginDiv.style.marginRight = "0"; + div.appendChild( marginDiv ); support.reliableMarginRight = - ( parseInt( document.defaultView.getComputedStyle(div).marginRight, 10 ) || 0 ) === 0; + ( parseInt( document.defaultView.getComputedStyle( marginDiv, null ).marginRight, 10 ) || 0 ) === 0; } // Remove the body element we added @@ -221,9 +224,6 @@ jQuery.support = (function() { } } - // release memory in IE - body = div = all = a = tds = undefined; - return support; })(); diff --git a/src/traversing.js b/src/traversing.js index fb5946bba..e0f40151d 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -73,9 +73,9 @@ jQuery.fn.extend({ }, is: function( selector ) { - return !!selector && (typeof selector === "string" ? + return !!selector && ( typeof selector === "string" ? jQuery.filter( selector, this ).length > 0 : - this.filter( selector ).length > 0); + this.filter( selector ).length > 0 ); }, closest: function( selectors, context ) { @@ -298,13 +298,18 @@ jQuery.extend({ // Implement the identical functionality for filter and not function winnow( elements, qualifier, keep ) { + + // Can't pass null or undefined to indexOf in Firefox 4 + // Set to 0 to skip string check + qualifier = qualifier || 0; + if ( jQuery.isFunction( qualifier ) ) { return jQuery.grep(elements, function( elem, i ) { var retVal = !!qualifier.call( elem, i, elem ); return retVal === keep; }); - } else if ( qualifier && qualifier.nodeType ) { + } else if ( qualifier.nodeType ) { return jQuery.grep(elements, function( elem, i ) { return (elem === qualifier) === keep; }); |