--- a/js/jquery-1.5.js +++ b/js/jquery-1.5.js @@ -1,5 +1,5 @@ /*! - * jQuery JavaScript Library v1.5 + * jQuery JavaScript Library v1.5.2 * http://jquery.com/ * * Copyright 2011, John Resig @@ -11,7 +11,7 @@ * Copyright 2011, The Dojo Foundation * Released under the MIT, BSD, and GPL Licenses. * - * Date: Mon Jan 31 08:31:29 2011 -0500 + * Date: Thu Mar 31 15:28:23 2011 -0400 */ (function( window, undefined ) { @@ -69,14 +69,8 @@ // 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, @@ -202,7 +196,7 @@ selector: "", // The current version of jQuery being used - jquery: "1.5", + jquery: "1.5.2", // The default length of a jQuery object is 0 length: 0, @@ -313,7 +307,7 @@ jQuery.fn.init.prototype = jQuery.fn; jQuery.extend = jQuery.fn.extend = function() { - var options, name, src, copy, copyIsArray, clone, + var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, @@ -427,11 +421,11 @@ }, 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. @@ -585,10 +579,8 @@ if ( data && rnotwhite.test(data) ) { // Inspired by code by Andrea Giammarchi // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html - var head = document.getElementsByTagName("head")[0] || document.documentElement, - script = document.createElement("script"); - - script.type = "text/javascript"; + var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement, + script = document.createElement( "script" ); if ( jQuery.support.scriptEval() ) { script.appendChild( document.createTextNode( data ) ); @@ -813,6 +805,123 @@ return (new Date()).getTime(); }, + // Use of jQuery.browser is frowned upon. + // More details: http://docs.jquery.com/Utilities/jQuery.browser + uaMatch: function( ua ) { + ua = ua.toLowerCase(); + + var match = rwebkit.exec( ua ) || + ropera.exec( ua ) || + rmsie.exec( ua ) || + ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || + []; + + return { browser: match[1] || "", version: match[2] || "0" }; + }, + + 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); + } + + return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass ); + }; + jQuerySubclass.fn.init.prototype = jQuerySubclass.fn; + var rootjQuerySubclass = jQuerySubclass(document); + return jQuerySubclass; + }, + + browser: {} +}); + +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + +browserMatch = jQuery.uaMatch( userAgent ); +if ( browserMatch.browser ) { + jQuery.browser[ browserMatch.browser ] = true; + jQuery.browser.version = browserMatch.version; +} + +// Deprecated, use jQuery.browser.webkit instead +if ( jQuery.browser.webkit ) { + jQuery.browser.safari = true; +} + +if ( indexOf ) { + jQuery.inArray = function( elem, array ) { + return indexOf.call( array, elem ); + }; +} + +// IE doesn't match non-breaking spaces with \s +if ( rnotwhite.test( "\xA0" ) ) { + trimLeft = /^[\s\xA0]+/; + trimRight = /[\s\xA0]+$/; +} + +// All jQuery objects should point back to these +rootjQuery = jQuery(document); + +// Cleanup functions for the document ready method +if ( document.addEventListener ) { + DOMContentLoaded = function() { + document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); + jQuery.ready(); + }; + +} else if ( document.attachEvent ) { + DOMContentLoaded = function() { + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( document.readyState === "complete" ) { + document.detachEvent( "onreadystatechange", DOMContentLoaded ); + jQuery.ready(); + } + }; +} + +// The DOM ready check for Internet Explorer +function doScrollCheck() { + if ( jQuery.isReady ) { + return; + } + + try { + // If IE is used, use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + document.documentElement.doScroll("left"); + } catch(e) { + setTimeout( doScrollCheck, 1 ); + return; + } + + // and execute any waiting functions + jQuery.ready(); +} + +// Expose jQuery to the global object +return 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 @@ -858,6 +967,8 @@ // 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 ] ) { @@ -874,7 +985,7 @@ // resolve with this as context and given arguments resolve: function() { - deferred.resolveWith( jQuery.isFunction( this.promise ) ? this.promise() : this, arguments ); + deferred.resolveWith( this, arguments ); return this; }, @@ -911,22 +1022,22 @@ isRejected: failDeferred.isResolved, // Get a promise for this deferred // If obj is provided, the promise aspect is added to the object - promise: function( obj , i /* internal */ ) { + promise: function( obj ) { if ( obj == null ) { if ( promise ) { return promise; } promise = obj = {}; } - i = promiseMethods.length; + var i = promiseMethods.length; while( i-- ) { - obj[ promiseMethods[ i ] ] = deferred[ promiseMethods[ i ] ]; + obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ]; } return obj; } } ); // Make sure only one callback list will be used - deferred.then( failDeferred.cancel, deferred.cancel ); + deferred.done( failDeferred.cancel ).fail( deferred.cancel ); // Unexpose cancel delete deferred.cancel; // Call given func if any @@ -937,143 +1048,44 @@ }, // Deferred helper - when: function( object ) { + when: function( firstParam ) { var args = arguments, + i = 0, length = args.length, - deferred = length <= 1 && object && jQuery.isFunction( object.promise ) ? - object : - jQuery.Deferred(), - promise = deferred.promise(), - resolveArray; - + 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 ) ) { + // Strange bug in FF4: + // Values changed onto the arguments object sometimes end up as undefined values + // outside the $.when method. Cloning the object into a fresh array solves the issue + deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) ); + } + }; + } if ( length > 1 ) { - resolveArray = new Array( length ); - jQuery.each( args, function( index, element ) { - jQuery.when( element ).then( function( value ) { - resolveArray[ index ] = arguments.length > 1 ? slice.call( arguments, 0 ) : value; - if( ! --length ) { - deferred.resolveWith( promise, resolveArray ); - } - }, deferred.reject ); - } ); - } 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 ) { - ua = ua.toLowerCase(); - - var match = rwebkit.exec( ua ) || - ropera.exec( ua ) || - rmsie.exec( ua ) || - ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || - []; - - return { browser: match[1] || "", version: match[2] || "0" }; - }, - - 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); - } - - return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass ); - }; - jQuerySubclass.fn.init.prototype = jQuerySubclass.fn; - var rootjQuerySubclass = jQuerySubclass(document); - return jQuerySubclass; - }, - - browser: {} + 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(); + } }); -// 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(); -}); - -browserMatch = jQuery.uaMatch( userAgent ); -if ( browserMatch.browser ) { - jQuery.browser[ browserMatch.browser ] = true; - jQuery.browser.version = browserMatch.version; -} - -// Deprecated, use jQuery.browser.webkit instead -if ( jQuery.browser.webkit ) { - jQuery.browser.safari = true; -} - -if ( indexOf ) { - jQuery.inArray = function( elem, array ) { - return indexOf.call( array, elem ); - }; -} - -// IE doesn't match non-breaking spaces with \s -if ( rnotwhite.test( "\xA0" ) ) { - trimLeft = /^[\s\xA0]+/; - trimRight = /[\s\xA0]+$/; -} - -// All jQuery objects should point back to these -rootjQuery = jQuery(document); - -// Cleanup functions for the document ready method -if ( document.addEventListener ) { - DOMContentLoaded = function() { - document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); - jQuery.ready(); - }; - -} else if ( document.attachEvent ) { - DOMContentLoaded = function() { - // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). - if ( document.readyState === "complete" ) { - document.detachEvent( "onreadystatechange", DOMContentLoaded ); - jQuery.ready(); - } - }; -} - -// The DOM ready check for Internet Explorer -function doScrollCheck() { - if ( jQuery.isReady ) { - return; - } - - try { - // If IE is used, use the trick by Diego Perini - // http://javascript.nwbox.com/IEContentLoaded/ - document.documentElement.doScroll("left"); - } catch(e) { - setTimeout( doScrollCheck, 1 ); - return; - } - - // and execute any waiting functions - jQuery.ready(); -} - -// Expose jQuery to the global object -return (window.jQuery = window.$ = jQuery); - -})(); + (function() { @@ -1088,7 +1100,8 @@ var all = div.getElementsByTagName("*"), a = div.getElementsByTagName("a")[0], select = document.createElement("select"), - opt = select.appendChild( document.createElement("option") ); + opt = select.appendChild( document.createElement("option") ), + input = div.getElementsByTagName("input")[0]; // Can't get basic test support if ( !all || !all.length || !a ) { @@ -1127,7 +1140,7 @@ // Make sure that if no value is specified for a checkbox // that it defaults to "on". // (WebKit defaults to "" instead) - checkOn: div.getElementsByTagName("input")[0].value === "on", + checkOn: input.value === "on", // 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) @@ -1137,48 +1150,50 @@ deleteExpando: true, optDisabled: false, checkClone: false, - _scriptEval: null, noCloneEvent: true, + noCloneChecked: true, boxModel: null, inlineBlockNeedsLayout: false, shrinkWrapBlocks: false, - reliableHiddenOffsets: true + reliableHiddenOffsets: true, + reliableMarginRight: true }; + + input.checked = true; + jQuery.support.noCloneChecked = input.cloneNode( true ).checked; // Make sure that the options inside disabled selects aren't marked as disabled // (WebKit marks them as diabled) select.disabled = true; jQuery.support.optDisabled = !opt.disabled; + var _scriptEval = null; jQuery.support.scriptEval = function() { - if ( jQuery.support._scriptEval === null ) { + if ( _scriptEval === null ) { var root = document.documentElement, script = document.createElement("script"), id = "script" + jQuery.now(); - script.type = "text/javascript"; + // Make sure that the execution of code works by injecting a script + // tag with appendChild/createTextNode + // (IE doesn't support this, fails, and uses .text instead) try { script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); } catch(e) {} root.insertBefore( script, root.firstChild ); - // Make sure that the execution of code works by injecting a script - // tag with appendChild/createTextNode - // (IE doesn't support this, fails, and uses .text instead) if ( window[ id ] ) { - jQuery.support._scriptEval = true; + _scriptEval = true; delete window[ id ]; } else { - jQuery.support._scriptEval = false; + _scriptEval = false; } root.removeChild( script ); - // release memory in IE - root = script = id = null; - } - - return jQuery.support._scriptEval; + } + + return _scriptEval; }; // Test to see if it's possible to delete an expando from an element @@ -1190,7 +1205,7 @@ jQuery.support.deleteExpando = false; } - if ( div.attachEvent && div.fireEvent ) { + if ( !div.addEventListener && div.attachEvent && div.fireEvent ) { div.attachEvent("onclick", function click() { // Cloning a node shouldn't copy over any // bound event handlers (IE does this) @@ -1260,6 +1275,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, null).marginRight, 10) || 0 ) === 0; + } + body.removeChild( div ).style.display = "none"; div = tds = null; }); @@ -1283,8 +1309,6 @@ el.setAttribute(eventName, "return;"); isSupported = typeof el[eventName] === "function"; } - el = null; - return isSupported; }; @@ -1321,7 +1345,7 @@ hasData: function( elem ) { elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; - return !!elem && !jQuery.isEmptyObject(elem); + return !!elem && !isEmptyDataObject( elem ); }, data: function( elem, name, data, pvt /* Internal Use Only */ ) { @@ -1361,11 +1385,18 @@ if ( !cache[ id ] ) { cache[ id ] = {}; + + // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery + // metadata on plain JS objects when the object is serialized using + // JSON.stringify + if ( !isNode ) { + cache[ id ].toJSON = jQuery.noop; + } } // An object can be passed to jQuery.data instead of a key/value pair; this gets // shallow copied over onto the existing cache - if ( typeof name === "object" ) { + if ( typeof name === "object" || typeof name === "function" ) { if ( pvt ) { cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name); } else { @@ -1427,7 +1458,7 @@ // If there is no data left in the cache, we want to continue // and let the cache object itself get destroyed - if ( !jQuery.isEmptyObject(thisCache) ) { + if ( !isEmptyDataObject(thisCache) ) { return; } } @@ -1439,7 +1470,7 @@ // Don't destroy the parent cache unless the internal data object // had been the only thing left in it - if ( !jQuery.isEmptyObject(cache[ id ]) ) { + if ( !isEmptyDataObject(cache[ id ]) ) { return; } } @@ -1460,6 +1491,13 @@ // data if it existed if ( internalCache ) { cache[ id ] = {}; + // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery + // metadata on plain JS objects when the object is serialized using + // JSON.stringify + if ( !isNode ) { + cache[ id ].toJSON = jQuery.noop; + } + cache[ id ][ internalKey ] = internalCache; // Otherwise, we need to eliminate the expando on the node to avoid @@ -1588,6 +1626,19 @@ return data; } +// TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON +// property to be considered empty objects; this property always exists in +// order to make sure JSON.stringify does not expose internal metadata +function isEmptyDataObject( obj ) { + for ( var name in obj ) { + if ( name !== "toJSON" ) { + return false; + } + } + + return true; +} + @@ -1888,6 +1939,11 @@ } } + // Fixes Bug #2551 -- select.val() broken in IE after form.reset() + if ( one && !values.length && options.length ) { + return jQuery( options[ index ] ).val(); + } + return values; } @@ -2081,8 +2137,7 @@ rescape = /[^\w\s.|`]/g, fcleanup = function( nm ) { return nm.replace(rescape, "\\$&"); - }, - eventKey = "events"; + }; /* * A number of helper functions used for managing events. @@ -2098,17 +2153,22 @@ return; } - // 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; - } + // 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 ) { // Fixes bug #7229. Fix recommended by jdalton - return; + return; } var handleObjIn, handleObj; @@ -2132,31 +2192,18 @@ return; } - var events = elemData[ eventKey ], + var events = elemData.events, eventHandle = elemData.handle; - if ( typeof events === "function" ) { - // On plain objects events is a fn that holds the the data - // which prevents this data from being JSON serialized - // the function does not need to be called, it just contains the data - eventHandle = events.handle; - events = events.events; - - } else if ( !events ) { - if ( !elem.nodeType ) { - // On plain objects, create a fn that acts as the holder - // of the values to avoid JSON serialization of event data - elemData[ eventKey ] = elemData = function(){}; - } - + if ( !events ) { elemData.events = events = {}; } 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; }; @@ -2249,15 +2296,10 @@ var ret, type, fn, j, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType, elemData = jQuery.hasData( elem ) && jQuery._data( elem ), - events = elemData && elemData[ eventKey ]; + events = elemData && elemData.events; if ( !elemData || !events ) { return; - } - - if ( typeof events === "function" ) { - elemData = events; - events = events.events; } // types is actually an event object here @@ -2359,10 +2401,7 @@ delete elemData.events; delete elemData.handle; - if ( typeof elemData === "function" ) { - jQuery.removeData( elem, eventKey, true ); - - } else if ( jQuery.isEmptyObject( elemData ) ) { + if ( jQuery.isEmptyObject( elemData ) ) { jQuery.removeData( elem, undefined, true ); } } @@ -2403,7 +2442,7 @@ // points to jQuery.expando var internalKey = jQuery.expando, internalCache = this[ internalKey ]; - if ( internalCache && internalCache.events && internalCache.events[type] ) { + if ( internalCache && internalCache.events && internalCache.events[ type ] ) { jQuery.event.trigger( event, data, internalCache.handle.elem ); } }); @@ -2429,9 +2468,7 @@ event.currentTarget = elem; // Trigger the event, it is assumed that "handle" is a function - var handle = elem.nodeType ? - jQuery._data( elem, "handle" ) : - (jQuery._data( elem, eventKey ) || {}).handle; + var handle = jQuery._data( elem, "handle" ); if ( handle ) { handle.apply( elem, data ); @@ -2473,7 +2510,7 @@ target[ "on" + targetType ] = null; } - jQuery.event.triggered = true; + jQuery.event.triggered = event.type; target[ targetType ](); } @@ -2484,7 +2521,7 @@ target[ "on" + targetType ] = old; } - jQuery.event.triggered = false; + jQuery.event.triggered = undefined; } } }, @@ -2509,11 +2546,7 @@ event.namespace = event.namespace || namespace_sort.join("."); - events = jQuery._data(this, eventKey); - - if ( typeof events === "function" ) { - events = events.events; - } + events = jQuery._data(this, "events"); handlers = (events || {})[ event.type ]; @@ -2680,7 +2713,7 @@ // Events bubbling up the document may have been marked as prevented // by a handler lower down the tree; reflect the correct value. - this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false || + this.isDefaultPrevented = (src.defaultPrevented || src.returnValue === false || src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse; // Event type @@ -2755,6 +2788,12 @@ // Firefox sometimes assigns relatedTarget a XUL element // which we cannot access the parentNode property of try { + + // Chrome does something similar, the parentNode property + // can be accessed but is null. + if ( parent && parent !== document && !parent.parentNode ) { + return; + } // Traverse up the tree while ( parent && parent !== this ) { parent = parent.parentNode; @@ -2805,8 +2844,7 @@ type = elem.type; if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) { - e.liveFired = undefined; - return trigger( "submit", this, arguments ); + trigger( "submit", this, arguments ); } }); @@ -2815,8 +2853,7 @@ type = elem.type; if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) { - e.liveFired = undefined; - return trigger( "submit", this, arguments ); + trigger( "submit", this, arguments ); } }); @@ -2879,7 +2916,7 @@ if ( data != null || val ) { e.type = "change"; e.liveFired = undefined; - return jQuery.event.trigger( e, arguments[1], elem ); + jQuery.event.trigger( e, arguments[1], elem ); } }; @@ -2893,7 +2930,7 @@ var elem = e.target, type = elem.type; if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) { - return testChange.call( this, e ); + testChange.call( this, e ); } }, @@ -2905,7 +2942,7 @@ if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") || (e.keyCode === 32 && (type === "checkbox" || type === "radio")) || type === "select-multiple" ) { - return testChange.call( this, e ); + testChange.call( this, e ); } }, @@ -2944,26 +2981,50 @@ } function trigger( type, elem, args ) { - args[0].type = type; - return jQuery.event.handle.apply( elem, args ); + // Piggyback on a donor event to simulate a different one. + // Fake originalEvent to avoid donor's stopPropagation, but if the + // simulated event prevents default then we do the same on the donor. + // Don't pass args or remember liveFired; they apply to the donor event. + var event = jQuery.extend( {}, args[ 0 ] ); + event.type = type; + event.originalEvent = {}; + event.liveFired = undefined; + jQuery.event.handle.call( elem, event ); + if ( event.isDefaultPrevented() ) { + args[ 0 ].preventDefault(); + } } // 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 ); - }, - teardown: function() { - this.removeEventListener( orig, handler, true ); + if ( attaches++ === 0 ) { + document.addEventListener( orig, handler, true ); + } + }, + teardown: function() { + 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(); + } } }); } @@ -3148,11 +3209,7 @@ var stop, maxLevel, related, match, handleObj, elem, j, i, l, data, close, namespace, ret, elems = [], selectors = [], - events = jQuery._data( this, eventKey ); - - if ( typeof events === "function" ) { - events = events.events; - } + events = jQuery._data( this, "events" ); // Make sure we avoid non-left-click bubbling in Firefox (#3861) and disabled elements in IE (#6911) if ( event.liveFired === this || !events || !events.live || event.target.disabled || event.button && event.type === "click" ) { @@ -3186,7 +3243,7 @@ for ( j = 0; j < live.length; j++ ) { handleObj = live[j]; - if ( close.selector === handleObj.selector && (!namespace || namespace.test( handleObj.namespace )) ) { + if ( close.selector === handleObj.selector && (!namespace || namespace.test( handleObj.namespace )) && !close.elem.disabled ) { elem = close.elem; related = null; @@ -3269,7 +3326,9 @@ done = 0, toString = Object.prototype.toString, hasDuplicate = false, - baseHasDuplicate = true; + baseHasDuplicate = true, + rBackslash = /\\/g, + rNonWord = /\W/; // Here we check if the JavaScript engine is using some sort of // optimization where it does not always call our comparision @@ -3468,7 +3527,7 @@ match.splice( 1, 1 ); if ( left.substr( left.length - 1 ) !== "\\" ) { - match[1] = (match[1] || "").replace(/\\/g, ""); + match[1] = (match[1] || "").replace( rBackslash, "" ); set = Expr.find[ type ]( match, context, isXML ); if ( set != null ) { @@ -3607,13 +3666,16 @@ attrHandle: { href: function( elem ) { return elem.getAttribute( "href" ); + }, + type: function( elem ) { + return elem.getAttribute( "type" ); } }, relative: { "+": function(checkSet, part){ var isPartStr = typeof part === "string", - isTag = isPartStr && !/\W/.test( part ), + isTag = isPartStr && !rNonWord.test( part ), isPartStrNotTag = isPartStr && !isTag; if ( isTag ) { @@ -3641,7 +3703,7 @@ i = 0, l = checkSet.length; - if ( isPartStr && !/\W/.test( part ) ) { + if ( isPartStr && !rNonWord.test( part ) ) { part = part.toLowerCase(); for ( ; i < l; i++ ) { @@ -3675,7 +3737,7 @@ doneName = done++, checkFn = dirCheck; - if ( typeof part === "string" && !/\W/.test(part) ) { + if ( typeof part === "string" && !rNonWord.test( part ) ) { part = part.toLowerCase(); nodeCheck = part; checkFn = dirNodeCheck; @@ -3689,7 +3751,7 @@ doneName = done++, checkFn = dirCheck; - if ( typeof part === "string" && !/\W/.test( part ) ) { + if ( typeof part === "string" && !rNonWord.test( part ) ) { part = part.toLowerCase(); nodeCheck = part; checkFn = dirNodeCheck; @@ -3732,7 +3794,7 @@ }, preFilter: { CLASS: function( match, curLoop, inplace, result, not, isXML ) { - match = " " + match[1].replace(/\\/g, "") + " "; + match = " " + match[1].replace( rBackslash, "" ) + " "; if ( isXML ) { return match; @@ -3755,11 +3817,11 @@ }, ID: function( match ) { - return match[1].replace(/\\/g, ""); + return match[1].replace( rBackslash, "" ); }, TAG: function( match, curLoop ) { - return match[1].toLowerCase(); + return match[1].replace( rBackslash, "" ).toLowerCase(); }, CHILD: function( match ) { @@ -3790,14 +3852,14 @@ }, ATTR: function( match, curLoop, inplace, result, not, isXML ) { - var name = match[1] = match[1].replace(/\\/g, ""); + var name = match[1] = match[1].replace( rBackslash, "" ); if ( !isXML && Expr.attrMap[name] ) { match[1] = Expr.attrMap[name]; } // Handle if an un-quoted value was used - match[4] = ( match[4] || match[5] || "" ).replace(/\\/g, ""); + match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" ); if ( match[2] === "~=" ) { match[4] = " " + match[4] + " "; @@ -3852,7 +3914,9 @@ selected: function( elem ) { // Accessing this property makes selected-by-default // options in Safari work properly - elem.parentNode.selectedIndex; + if ( elem.parentNode ) { + elem.parentNode.selectedIndex; + } return elem.selected === true; }, @@ -3874,8 +3938,12 @@ }, text: function( elem ) { - return "text" === elem.type; + var attr = elem.getAttribute( "type" ), type = elem.type; + // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc) + // use getAttribute instead to test this case + return "text" === type && ( attr === type || attr === null ); }, + radio: function( elem ) { return "radio" === elem.type; }, @@ -4407,7 +4475,8 @@ // and working up from there (Thanks to Andrew Dupont for the technique) // IE 8 doesn't work on object elements } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { - var old = context.getAttribute( "id" ), + var oldContext = context, + old = context.getAttribute( "id" ), nid = old || id, hasParent = context.parentNode, relativeHierarchySelector = /^\s*[+~]/.test( query ); @@ -4429,7 +4498,7 @@ } catch(pseudoError) { } finally { if ( !old ) { - context.removeAttribute( "id" ); + oldContext.removeAttribute( "id" ); } } } @@ -4449,19 +4518,23 @@ (function(){ var html = document.documentElement, - matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector, - pseudoWorks = false; - - try { - // This should fail with an exception - // Gecko does not error, returns false instead - matches.call( document.documentElement, "[test!='']:sizzle" ); + matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector; + + if ( matches ) { + // Check to see if it's possible to do matchesSelector + // on a disconnected node (IE 9 fails this) + var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ), + pseudoWorks = false; + + try { + // This should fail with an exception + // Gecko does not error, returns false instead + matches.call( document.documentElement, "[test!='']:sizzle" ); - } catch( pseudoError ) { - pseudoWorks = true; - } - - if ( matches ) { + } catch( pseudoError ) { + pseudoWorks = true; + } + Sizzle.matchesSelector = function( node, expr ) { // Make sure that attribute selectors are quoted expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']"); @@ -4469,7 +4542,15 @@ if ( !Sizzle.isXML( node ) ) { try { if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) { - return matches.call( node, expr ); + var ret = matches.call( node, expr ); + + // IE 9's matchesSelector returns false on disconnected nodes + if ( ret || !disconnectedMatch || + // As well, disconnected nodes are said to be in a document + // fragment in IE 9, so check for that + node.document && node.document.nodeType !== 11 ) { + return ret; + } } } catch(e) {} } @@ -4845,11 +4926,11 @@ }, function( name, fn ) { jQuery.fn[ name ] = function( until, selector ) { var ret = jQuery.map( this, fn, until ), - // The variable 'args' was introduced in - // https://github.com/jquery/jquery/commit/52a0238 - // to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed. - // http://code.google.com/p/v8/issues/detail?id=1050 - args = slice.call(arguments); + // The variable 'args' was introduced in + // https://github.com/jquery/jquery/commit/52a0238 + // to work around a bug in Chrome 10 (Dev) and should be removed when the bug is fixed. + // http://code.google.com/p/v8/issues/detail?id=1050 + args = slice.call(arguments); if ( !runtil.test( name ) ) { selector = until; @@ -4959,7 +5040,7 @@ rtbody = /", "" ], @@ -5111,7 +5192,7 @@ } if ( elem.parentNode ) { - elem.parentNode.removeChild( elem ); + elem.parentNode.removeChild( elem ); } } } @@ -5136,7 +5217,7 @@ }, clone: function( dataAndEvents, deepDataAndEvents ) { - dataAndEvents = dataAndEvents == null ? true : dataAndEvents; + dataAndEvents = dataAndEvents == null ? false : dataAndEvents; deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; return this.map( function () { @@ -5213,7 +5294,9 @@ } }); } else { - 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; } }, @@ -5305,8 +5388,8 @@ } var internalKey = jQuery.expando, - oldData = jQuery.data( src ), - curData = jQuery.data( dest, oldData ); + oldData = jQuery.data( src ), + curData = jQuery.data( dest, oldData ); // Switch to use the internal data object, if it exists, for the next // stage of data copying @@ -5320,7 +5403,7 @@ for ( var type in events ) { for ( var i = 0, l = events[ type ].length; i < l; i++ ) { - jQuery.event.add( dest, type, events[ type ][ i ], events[ type ][ i ].data ); + jQuery.event.add( dest, type + ( events[ type ][ i ].namespace ? "." : "" ) + events[ type ][ i ].namespace, events[ type ][ i ], events[ type ][ i ].data ); } } } @@ -5441,6 +5524,18 @@ }; }); +function getAll( elem ) { + if ( "getElementsByTagName" in elem ) { + return elem.getElementsByTagName( "*" ); + + } else if ( "querySelectorAll" in elem ) { + return elem.querySelectorAll( "*" ); + + } else { + return []; + } +} + jQuery.extend({ clone: function( elem, dataAndEvents, deepDataAndEvents ) { var clone = elem.cloneNode(true), @@ -5448,17 +5543,20 @@ destElements, i; - if ( !jQuery.support.noCloneEvent && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { + if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) && + (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { // IE copies events bound via attachEvent when using cloneNode. // Calling detachEvent on the clone will also remove the events // from the original. In order to get around this, we use some // proprietary methods to clear the events. Thanks to MooTools // guys for this hotness. + cloneFixAttributes( elem, clone ); + // Using Sizzle here is crazy slow, so we use getElementsByTagName // instead - srcElements = elem.getElementsByTagName("*"); - destElements = clone.getElementsByTagName("*"); + srcElements = getAll( elem ); + destElements = getAll( clone ); // Weird iteration because IE will replace the length property // with an element if you are cloning the body and one of the @@ -5466,30 +5564,25 @@ for ( i = 0; srcElements[i]; ++i ) { cloneFixAttributes( srcElements[i], destElements[i] ); } - - cloneFixAttributes( elem, clone ); } // Copy the events from the original to the clone if ( dataAndEvents ) { - cloneCopyEvent( elem, clone ); - if ( deepDataAndEvents && "getElementsByTagName" in elem ) { - - srcElements = elem.getElementsByTagName("*"); - destElements = clone.getElementsByTagName("*"); - - if ( srcElements.length ) { - for ( i = 0; srcElements[i]; ++i ) { - cloneCopyEvent( srcElements[i], destElements[i] ); - } - } - } - } + if ( deepDataAndEvents ) { + srcElements = getAll( elem ); + destElements = getAll( clone ); + + for ( i = 0; srcElements[i]; ++i ) { + cloneCopyEvent( srcElements[i], destElements[i] ); + } + } + } + // Return the cloned set return clone; - }, +}, clean: function( elems, context, fragment, scripts ) { context = context || document; @@ -5650,7 +5743,8 @@ var ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, rdashAlpha = /-([a-z])/ig, - rupper = /([A-Z])/g, + // fixed for IE9, see #8346 + rupper = /([A-Z]|^ms)/g, rnumpx = /^-?\d+(?:px)?$/i, rnum = /^-?\d/, @@ -5887,6 +5981,28 @@ }; } +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; + jQuery.swap( elem, { "display": "inline-block" }, function() { + if ( computed ) { + ret = curCSS( elem, "margin-right", "marginRight" ); + } else { + ret = elem.style.marginRight; + } + }); + return ret; + } + }; + } +}); + if ( document.defaultView && document.defaultView.getComputedStyle ) { getComputedStyle = function( elem, newName, name ) { var ret, defaultView, computedStyle; @@ -5910,7 +6026,7 @@ if ( document.documentElement.currentStyle ) { currentStyle = function( elem, name ) { - var left, + var left, ret = elem.currentStyle && elem.currentStyle[ name ], rsLeft = elem.runtimeStyle && elem.runtimeStyle[ name ], style = elem.style; @@ -5988,8 +6104,10 @@ rbracket = /\[\]$/, rCRLF = /\r?\n/g, rhash = /#.*$/, - rheaders = /^(.*?):\s*(.*?)\r?$/mg, // IE leaves an \r character at EOL + 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 = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/, rnoContent = /^(?:GET|HEAD)$/, rprotocol = /^\/\//, rquery = /\?/, @@ -5997,7 +6115,11 @@ rselectTextarea = /^(?:select|textarea)/i, rspacesAjax = /\s+/, rts = /([?&])_=[^&]*/, - rurl = /^(\w+:)\/\/([^\/?#:]+)(?::(\d+))?/, + rucHeaders = /(^|\-)([a-z])/g, + rucHeadersFunc = function( _, $1, $2 ) { + return $1 + $2.toUpperCase(); + }, + rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/, // Keep a copy of the old load method _load = jQuery.fn.load, @@ -6018,7 +6140,28 @@ * 2) the catchall symbol "*" can be used * 3) selection will start with transport dataType and THEN go to "*" if needed */ - transports = {}; + transports = {}, + + // Document location + ajaxLocation, + + // Document location segments + ajaxLocParts; + +// #8138, IE may throw an exception when accessing +// a field from document.location if document.domain has been set +try { + ajaxLocation = document.location.href; +} catch( e ) { + // Use the href attribute of an A element + // since IE will modify it given document.location + ajaxLocation = document.createElement( "a" ); + ajaxLocation.href = ""; + ajaxLocation = ajaxLocation.href; +} + +// Segment location into parts +ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport function addToPrefiltersOrTransports( structure ) { @@ -6057,7 +6200,7 @@ } //Base inspection function for prefilters and transports -function inspectPrefiltersOrTransports( structure, options, originalOptions, jXHR, +function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR, dataType /* internal */, inspected /* internal */ ) { dataType = dataType || options.dataTypes[ 0 ]; @@ -6072,16 +6215,16 @@ selection; for(; i < length && ( executeOnly || !selection ); i++ ) { - selection = list[ i ]( options, originalOptions, jXHR ); + selection = list[ i ]( options, originalOptions, jqXHR ); // If we got redirected to another dataType - // we try there if not done already + // we try there if executing only and not done already if ( typeof selection === "string" ) { - if ( inspected[ selection ] ) { + if ( !executeOnly || inspected[ selection ] ) { selection = undefined; } else { options.dataTypes.unshift( selection ); selection = inspectPrefiltersOrTransports( - structure, options, originalOptions, jXHR, selection, inspected ); + structure, options, originalOptions, jqXHR, selection, inspected ); } } } @@ -6089,7 +6232,7 @@ // we try the catchall dataType if not done already if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) { selection = inspectPrefiltersOrTransports( - structure, options, originalOptions, jXHR, "*", inspected ); + structure, options, originalOptions, jqXHR, "*", inspected ); } // unnecessary when only executing (prefilters) // but it'll be ignored by the caller in that case @@ -6121,7 +6264,7 @@ if ( jQuery.isFunction( params ) ) { // We assume that it's the callback callback = params; - params = null; + params = undefined; // Otherwise, build a param string } else if ( typeof params === "object" ) { @@ -6139,14 +6282,14 @@ dataType: "html", data: params, // Complete callback (responseText is used internally) - complete: function( jXHR, status, responseText ) { - // Store the response as specified by the jXHR object - responseText = jXHR.responseText; + complete: function( jqXHR, status, responseText ) { + // Store the response as specified by the jqXHR object + responseText = jqXHR.responseText; // If successful, inject the HTML into all the matched elements - if ( jXHR.isResolved() ) { + if ( jqXHR.isResolved() ) { // #4825: Get the actual response in case // a dataFilter is present in ajaxSettings - jXHR.done(function( r ) { + jqXHR.done(function( r ) { responseText = r; }); // See if a selector was specified @@ -6165,7 +6308,7 @@ } if ( callback ) { - self.each( callback, [ responseText, status, jXHR ] ); + self.each( callback, [ responseText, status, jqXHR ] ); } } }); @@ -6213,7 +6356,7 @@ if ( jQuery.isFunction( data ) ) { type = type || callback; callback = data; - data = null; + data = undefined; } return jQuery.ajax({ @@ -6229,22 +6372,39 @@ jQuery.extend({ getScript: function( url, callback ) { - return jQuery.get( url, null, callback, "script" ); + return jQuery.get( url, undefined, callback, "script" ); }, getJSON: function( url, data, callback ) { return jQuery.get( url, data, callback, "json" ); }, - ajaxSetup: function( settings ) { - jQuery.extend( true, jQuery.ajaxSettings, settings ); - if ( settings.context ) { - jQuery.ajaxSettings.context = settings.context; - } + // Creates a full fledged settings object into target + // with both ajaxSettings and settings fields. + // If target is omitted, writes into ajaxSettings. + ajaxSetup: function ( target, settings ) { + if ( !settings ) { + // Only one parameter, we extend ajaxSettings + settings = target; + target = jQuery.extend( true, jQuery.ajaxSettings, settings ); + } else { + // target was provided, we extend into it + jQuery.extend( true, target, jQuery.ajaxSettings, settings ); + } + // Flatten fields we don't want deep extended + for( var field in { context: 1, url: 1 } ) { + if ( field in settings ) { + target[ field ] = settings[ field ]; + } else if( field in jQuery.ajaxSettings ) { + target[ field ] = jQuery.ajaxSettings[ field ]; + } + } + return target; }, ajaxSettings: { - url: location.href, + url: ajaxLocation, + isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ), global: true, type: "GET", contentType: "application/x-www-form-urlencoded", @@ -6259,7 +6419,6 @@ cache: null, traditional: false, headers: {}, - crossDomain: null, */ accepts: { @@ -6306,9 +6465,8 @@ // Main method ajax: function( url, options ) { - // If options is not an object, - // we simulate pre-1.5 signature - if ( typeof options !== "object" ) { + // If url is an object, simulate pre-1.5 signature + if ( typeof url === "object" ) { options = url; url = undefined; } @@ -6317,19 +6475,22 @@ options = options || {}; var // Create the final options object - s = jQuery.extend( true, {}, jQuery.ajaxSettings, options ), - // Callbacks contexts - // We force the original context if it exists - // or take it from jQuery.ajaxSettings otherwise - // (plain objects used as context get extended) - callbackContext = - ( s.context = ( "context" in options ? options : jQuery.ajaxSettings ).context ) || s, - globalEventContext = callbackContext === s ? jQuery.event : jQuery( callbackContext ), + s = jQuery.ajaxSetup( {}, options ), + // Callbacks context + callbackContext = s.context || s, + // Context for global events + // It's the callbackContext if one was provided in the options + // and if it's a DOM node or a jQuery collection + globalEventContext = callbackContext !== s && + ( callbackContext.nodeType || callbackContext instanceof jQuery ) ? + jQuery( callbackContext ) : jQuery.event, // Deferreds deferred = jQuery.Deferred(), completeDeferred = jQuery._Deferred(), // Status-dependent callbacks statusCode = s.statusCode || {}, + // ifModified key + ifModifiedKey, // Headers (they are sent all at once) requestHeaders = {}, // Response headers @@ -6340,22 +6501,22 @@ // timeout handle timeoutTimer, // Cross-domain detection vars - loc = document.location, - protocol = loc.protocol || "http:", parts, - // The jXHR state + // The jqXHR state state = 0, + // To know if global events are to be dispatched + fireGlobals, // Loop variable i, // Fake xhr - jXHR = { + jqXHR = { readyState: 0, // Caches the header setRequestHeader: function( name, value ) { - if ( state === 0 ) { - requestHeaders[ name.toLowerCase() ] = value; + if ( !state ) { + requestHeaders[ name.toLowerCase().replace( rucHeaders, rucHeadersFunc ) ] = value; } return this; }, @@ -6377,7 +6538,15 @@ } match = responseHeaders[ key.toLowerCase() ]; } - return match || null; + return match === undefined ? null : match; + }, + + // Overrides response content-type header + overrideMimeType: function( type ) { + if ( !state ) { + s.mimeType = type; + } + return this; }, // Cancel the request @@ -6394,7 +6563,7 @@ // Callback for when everything is done // It is defined here because jslint complains if it is declared // at the end of the function (which would be more logical and readable) - function done( status, statusText, responses, headers) { + function done( status, statusText, responses, headers ) { // Called once if ( state === 2 ) { @@ -6410,19 +6579,19 @@ } // Dereference transport for early garbage collection - // (no matter how long the jXHR object will be used) + // (no matter how long the jqXHR object will be used) transport = undefined; // Cache response headers responseHeadersString = headers || ""; // Set readyState - jXHR.readyState = status ? 4 : 0; + jqXHR.readyState = status ? 4 : 0; var isSuccess, success, error, - response = responses ? ajaxHandleResponses( s, jXHR, responses ) : undefined, + response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined, lastModified, etag; @@ -6432,11 +6601,11 @@ // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. if ( s.ifModified ) { - if ( ( lastModified = jXHR.getResponseHeader( "Last-Modified" ) ) ) { - jQuery.lastModified[ s.url ] = lastModified; - } - if ( ( etag = jXHR.getResponseHeader( "Etag" ) ) ) { - jQuery.etag[ s.url ] = etag; + if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) { + jQuery.lastModified[ ifModifiedKey ] = lastModified; + } + if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) { + jQuery.etag[ ifModifiedKey ] = etag; } } @@ -6463,7 +6632,7 @@ // We extract error from statusText // then normalize statusText and status for non-aborts error = statusText; - if( status ) { + if( !statusText || status ) { statusText = "error"; if ( status < 0 ) { status = 0; @@ -6472,30 +6641,30 @@ } // Set data for the fake xhr object - jXHR.status = status; - jXHR.statusText = statusText; + jqXHR.status = status; + jqXHR.statusText = statusText; // Success/Error if ( isSuccess ) { - deferred.resolveWith( callbackContext, [ success, statusText, jXHR ] ); + deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] ); } else { - deferred.rejectWith( callbackContext, [ jXHR, statusText, error ] ); + deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] ); } // Status-dependent callbacks - jXHR.statusCode( statusCode ); + jqXHR.statusCode( statusCode ); statusCode = undefined; - if ( s.global ) { + if ( fireGlobals ) { globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ), - [ jXHR, s, isSuccess ? success : error ] ); + [ jqXHR, s, isSuccess ? success : error ] ); } // Complete - completeDeferred.resolveWith( callbackContext, [ jXHR, statusText ] ); - - if ( s.global ) { - globalEventContext.trigger( "ajaxComplete", [ jXHR, s] ); + completeDeferred.resolveWith( callbackContext, [ jqXHR, statusText ] ); + + if ( fireGlobals ) { + globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] ); // Handle the global AJAX counter if ( !( --jQuery.active ) ) { jQuery.event.trigger( "ajaxStop" ); @@ -6504,13 +6673,13 @@ } // Attach deferreds - deferred.promise( jXHR ); - jXHR.success = jXHR.done; - jXHR.error = jXHR.fail; - jXHR.complete = completeDeferred.done; + deferred.promise( jqXHR ); + jqXHR.success = jqXHR.done; + jqXHR.error = jqXHR.fail; + jqXHR.complete = completeDeferred.done; // Status-dependent callbacks - jXHR.statusCode = function( map ) { + jqXHR.statusCode = function( map ) { if ( map ) { var tmp; if ( state < 2 ) { @@ -6518,8 +6687,8 @@ statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ]; } } else { - tmp = map[ jXHR.status ]; - jXHR.then( tmp, tmp ); + tmp = map[ jqXHR.status ]; + jqXHR.then( tmp, tmp ); } } return this; @@ -6528,18 +6697,18 @@ // Remove hash character (#7531: and string promotion) // Add protocol if not provided (#5866: IE7 issue with protocol-less urls) // We also use the url parameter if available - s.url = ( "" + ( url || s.url ) ).replace( rhash, "" ).replace( rprotocol, protocol + "//" ); + s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" ); // Extract dataTypes list 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 ] != protocol || parts[ 2 ] != loc.hostname || + ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] || ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) != - ( loc.port || ( protocol === "http:" ? 80 : 443 ) ) ) + ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) ) ); } @@ -6549,7 +6718,15 @@ } // Apply prefilters - inspectPrefiltersOrTransports( prefilters, s, options, jXHR ); + inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); + + // If request was aborted inside a prefiler, stop there + if ( state === 2 ) { + return false; + } + + // We can fire global events as of now if asked to + fireGlobals = s.global; // Uppercase the type s.type = s.type.toUpperCase(); @@ -6558,7 +6735,7 @@ s.hasContent = !rnoContent.test( s.type ); // Watch for a new set of requests - if ( s.global && jQuery.active++ === 0 ) { + if ( fireGlobals && jQuery.active++ === 0 ) { jQuery.event.trigger( "ajaxStart" ); } @@ -6570,6 +6747,9 @@ s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data; } + // Get ifModifiedKey before adding the anti-cache parameter + ifModifiedKey = s.url; + // Add anti-cache in url if needed if ( s.cache === false ) { @@ -6584,77 +6764,77 @@ // Set the correct header, if data is being sent if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) { - requestHeaders[ "content-type" ] = s.contentType; + requestHeaders[ "Content-Type" ] = s.contentType; } // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. if ( s.ifModified ) { - if ( jQuery.lastModified[ s.url ] ) { - requestHeaders[ "if-modified-since" ] = jQuery.lastModified[ s.url ]; - } - if ( jQuery.etag[ s.url ] ) { - requestHeaders[ "if-none-match" ] = jQuery.etag[ s.url ]; + ifModifiedKey = ifModifiedKey || s.url; + if ( jQuery.lastModified[ ifModifiedKey ] ) { + requestHeaders[ "If-Modified-Since" ] = jQuery.lastModified[ ifModifiedKey ]; + } + if ( jQuery.etag[ ifModifiedKey ] ) { + requestHeaders[ "If-None-Match" ] = jQuery.etag[ ifModifiedKey ]; } } // Set the Accepts header for the server, depending on the dataType - requestHeaders.accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? + requestHeaders.Accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) : s.accepts[ "*" ]; // Check for headers option for ( i in s.headers ) { - requestHeaders[ i.toLowerCase() ] = s.headers[ i ]; + jqXHR.setRequestHeader( i, s.headers[ i ] ); } // Allow custom headers/mimetypes and early abort - if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jXHR, s ) === false || state === 2 ) ) { + if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { // Abort if not done already - done( 0, "abort" ); - // Return false - jXHR = false; - + jqXHR.abort(); + return false; + + } + + // Install callbacks on deferreds + for ( i in { success: 1, error: 1, complete: 1 } ) { + jqXHR[ i ]( s[ i ] ); + } + + // Get transport + transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR ); + + // If no transport, we auto-abort + if ( !transport ) { + done( -1, "No Transport" ); } else { - - // Install callbacks on deferreds - for ( i in { success: 1, error: 1, complete: 1 } ) { - jXHR[ i ]( s[ i ] ); - } - - // Get transport - transport = inspectPrefiltersOrTransports( transports, s, options, jXHR ); - - // If no transport, we auto-abort - if ( !transport ) { - done( -1, "No Transport" ); - } else { - // Set state as sending - state = jXHR.readyState = 1; - // Send global event - if ( s.global ) { - globalEventContext.trigger( "ajaxSend", [ jXHR, s ] ); - } - // Timeout - if ( s.async && s.timeout > 0 ) { - timeoutTimer = setTimeout( function(){ - jXHR.abort( "timeout" ); - }, s.timeout ); - } - - try { - transport.send( requestHeaders, done ); - } catch (e) { - // Propagate exception as error if not done - if ( status < 2 ) { - done( -1, e ); - // Simply rethrow otherwise - } else { - jQuery.error( e ); - } - } - } - } - return jXHR; + jqXHR.readyState = 1; + // Send global event + if ( fireGlobals ) { + globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); + } + // Timeout + if ( s.async && s.timeout > 0 ) { + timeoutTimer = setTimeout( function(){ + jqXHR.abort( "timeout" ); + }, s.timeout ); + } + + try { + state = 1; + transport.send( requestHeaders, done ); + } catch (e) { + // Propagate exception as error if not done + if ( status < 2 ) { + done( -1, e ); + // Simply rethrow otherwise + } else { + jQuery.error( e ); + } + } + } + + return jqXHR; }, // Serialize an array of form elements or a set of @@ -6673,7 +6853,7 @@ } // If an array was passed in, assume that it is an array of form elements. - if ( jQuery.isArray( a ) || a.jquery ) { + if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { // Serialize the form elements jQuery.each( a, function() { add( this.name, this.value ); @@ -6720,9 +6900,9 @@ // Serialize object item. } else { - jQuery.each( obj, function( k, v ) { - buildParams( prefix + "[" + k + "]", v, traditional, add ); - }); + for ( var name in obj ) { + buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); + } } } else { @@ -6749,7 +6929,7 @@ * - finds the right dataType (mediates between content-type and expected dataType) * - returns the corresponding response */ -function ajaxHandleResponses( s, jXHR, responses ) { +function ajaxHandleResponses( s, jqXHR, responses ) { var contents = s.contents, dataTypes = s.dataTypes, @@ -6762,7 +6942,7 @@ // Fill responseXXX fields for( type in responseFields ) { if ( type in responses ) { - jXHR[ responseFields[type] ] = responses[ type ]; + jqXHR[ responseFields[type] ] = responses[ type ]; } } @@ -6770,7 +6950,7 @@ while( dataTypes[ 0 ] === "*" ) { dataTypes.shift(); if ( ct === undefined ) { - ct = jXHR.getResponseHeader( "content-type" ); + ct = s.mimeType || jqXHR.getResponseHeader( "content-type" ); } } @@ -6822,8 +7002,9 @@ } var dataTypes = s.dataTypes, - converters = s.converters, + converters = {}, i, + key, length = dataTypes.length, tmp, // Current and previous dataTypes @@ -6839,6 +7020,16 @@ // For each dataType in the chain for( i = 1; i < length; i++ ) { + + // Create converters map + // with lowercased keys + if ( i === 1 ) { + for( key in s.converters ) { + if( typeof key === "string" ) { + converters[ key.toLowerCase() ] = s.converters[ key ]; + } + } + } // Get the dataTypes prev = current; @@ -6891,7 +7082,7 @@ var jsc = jQuery.now(), - jsre = /(\=)\?(&|$)|()\?\?()/i; + jsre = /(\=)\?(&|$)|\?\?/i; // Default jsonp settings jQuery.ajaxSetup({ @@ -6902,9 +7093,9 @@ }); // Detect, normalize options and install callbacks for jsonp requests -jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, dataIsString /* internal */ ) { - - dataIsString = ( typeof s.data === "string" ); +jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { + + var dataIsString = ( typeof s.data === "string" ); if ( s.dataTypes[ 0 ] === "jsonp" || originalSettings.jsonpCallback || @@ -6918,7 +7109,15 @@ previous = window[ jsonpCallback ], url = s.url, data = s.data, - replace = "$1" + jsonpCallback + "$2"; + 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 ] ); + } + }; if ( s.jsonp !== false ) { url = url.replace( jsre, replace ); @@ -6936,32 +7135,17 @@ s.url = url; s.data = data; + // Install callback window[ jsonpCallback ] = function( response ) { responseContainer = [ response ]; }; - s.complete = [ function() { - - // Set callback back to previous value - window[ jsonpCallback ] = previous; - - // Call if it was a function and we have a response - if ( previous) { - if ( responseContainer && jQuery.isFunction( previous ) ) { - window[ jsonpCallback ] ( responseContainer[ 0 ] ); - } - } else { - // else, more memory leak avoidance - try{ - delete window[ jsonpCallback ]; - } catch( e ) {} - } - - }, s.complete ]; + // Install cleanUp function + jqXHR.then( cleanUp, cleanUp ); // Use data converter to retrieve json after script execution s.converters["script json"] = function() { - if ( ! responseContainer ) { + if ( !responseContainer ) { jQuery.error( jsonpCallback + " was not called" ); } return responseContainer[ 0 ]; @@ -6981,10 +7165,10 @@ // Install script dataType jQuery.ajaxSetup({ accepts: { - script: "text/javascript, application/javascript" + script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript" }, contents: { - script: /javascript/ + script: /javascript|ecmascript/ }, converters: { "text script": function( text ) { @@ -7012,7 +7196,7 @@ if ( s.crossDomain ) { var script, - head = document.getElementsByTagName( "head" )[ 0 ] || document.documentElement; + head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement; return { @@ -7067,17 +7251,35 @@ -var // Next active xhr id +var // #5280: next active xhr id and list of active xhrs' callbacks xhrId = jQuery.now(), - - // active xhrs - xhrs = {}, - - // #5280: see below - xhrUnloadAbortInstalled, + xhrCallbacks, // XHR used to determine supports properties testXHR; + +// #5280: Internet Explorer will keep connections alive if we don't abort on unload +function xhrOnUnloadAbort() { + jQuery( window ).unload(function() { + // Abort all pending requests + for ( var key in xhrCallbacks ) { + xhrCallbacks[ key ]( 0, 1 ); +