Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: gnarf/jquery
...
head fork: gnarf/jquery
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 3 files changed
  • 0 commit comments
  • 4 contributors
Showing with 67 additions and 63 deletions.
  1. +1 −1  grunt.js
  2. +54 −51 src/ajax/jsonp.js
  3. +12 −11 src/effects.js
View
2  grunt.js
@@ -100,7 +100,7 @@ module.exports = function( grunt ) {
// Default grunt.
grunt.registerTask( "default", "selector build lint min compare_size" );
- grunt.loadNpmTasks("grunt-compare-size");
+ grunt.loadNpmTasks("grunt-compare-size");
// Build src/selector.js
grunt.registerMultiTask( "selector", "Build src/selector.js", function() {
View
105 src/ajax/jsonp.js
@@ -1,14 +1,15 @@
(function( jQuery ) {
-var jsc = jQuery.now(),
- jsre = /(\=)\?(&|$)|\?\?/i,
- jscallbacks = [];
+var oldCallbacks = [],
+ rquestion = /\?/,
+ rjsonp = /(=)\?(?=&|$)|\?\?/,
+ nonce = jQuery.now();
// Default jsonp settings
jQuery.ajaxSetup({
jsonp: "callback",
jsonpCallback: function() {
- var callback = jscallbacks.pop() || ( jQuery.expando + "_" + ( jsc++ ) );
+ var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
this[ callback ] = true;
return callback;
}
@@ -17,68 +18,70 @@ jQuery.ajaxSetup({
// Detect, normalize options and install callbacks for jsonp requests
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
- var inspectData = ( typeof s.data === "string" ) && /^application\/x\-www\-form\-urlencoded/.test( s.contentType );
-
- if ( s.dataTypes[ 0 ] === "jsonp" ||
- s.jsonp !== false && ( jsre.test( s.url ) ||
- inspectData && jsre.test( s.data ) ) ) {
-
- var responseContainer,
- jsonpCallback = s.jsonpCallback =
- jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
- previous = window[ jsonpCallback ],
- url = s.url,
- data = s.data,
- replace = "$1" + jsonpCallback + "$2";
-
- if ( s.jsonp !== false ) {
- url = url.replace( jsre, replace );
- if ( s.url === url ) {
- if ( inspectData ) {
- data = data.replace( jsre, replace );
- }
- if ( s.data === data ) {
- // Add callback manually
- url += (/\?/.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
- }
- }
+ var callbackName, overwritten, responseContainer,
+ data = s.data,
+ url = s.url,
+ hasCallback = s.jsonp !== false,
+ replaceInUrl = hasCallback && rjsonp.test( url ),
+ replaceInData = hasCallback && !replaceInUrl && typeof data === "string" &&
+ !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") &&
+ rjsonp.test( data );
+
+ // Handle iff the expected data type is "jsonp" or we have a parameter to set
+ if ( s.dataTypes[ 0 ] === "jsonp" || replaceInUrl || replaceInData ) {
+
+ // Get callback name, remembering preexisting value associated with it
+ callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
+ s.jsonpCallback() :
+ s.jsonpCallback;
+ overwritten = window[ callbackName ];
+
+ // Insert callback into url or form data
+ if ( replaceInUrl ) {
+ s.url = url.replace( rjsonp, "$1" + callbackName );
+ } else if ( replaceInData ) {
+ s.data = data.replace( rjsonp, "$1" + callbackName );
+ } else if ( hasCallback ) {
+ s.url += ( rquestion.test( url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
}
- s.url = url;
- s.data = data;
+ // Use data converter to retrieve json after script execution
+ s.converters["script json"] = function() {
+ if ( !responseContainer ) {
+ jQuery.error( callbackName + " was not called" );
+ }
+ return responseContainer[ 0 ];
+ };
+
+ // force json dataType
+ s.dataTypes[ 0 ] = "json";
// Install callback
- window[ jsonpCallback ] = function( response ) {
- responseContainer = [ response ];
+ window[ callbackName ] = function() {
+ responseContainer = arguments;
};
- // Clean-up function
+ // Clean-up function (fires after converters)
jqXHR.always(function() {
- // Set callback back to previous value
- window[ jsonpCallback ] = previous;
+ // Restore preexisting value
+ window[ callbackName ] = overwritten;
+
// Save back as free
- if ( s[ jsonpCallback ] ) {
+ if ( s[ callbackName ] ) {
// make sure that re-using the options doesn't screw things around
s.jsonpCallback = originalSettings.jsonpCallback;
+
// save the callback name for future use
- jscallbacks.push( jsonpCallback );
- }
- // Call if it was a function and we have a response
- if ( responseContainer && jQuery.isFunction( previous ) ) {
- window[ jsonpCallback ]( responseContainer[ 0 ] );
+ oldCallbacks.push( callbackName );
}
- });
- // Use data converter to retrieve json after script execution
- s.converters["script json"] = function() {
- if ( !responseContainer ) {
- jQuery.error( jsonpCallback + " was not called" );
+ // Call if it was a function and we have a response
+ if ( responseContainer && jQuery.isFunction( overwritten ) ) {
+ overwritten( responseContainer[ 0 ] );
}
- return responseContainer[ 0 ];
- };
- // force json dataType
- s.dataTypes[ 0 ] = "json";
+ responseContainer = overwritten = undefined;
+ });
// Delegate to script
return "script";
View
23 src/effects.js
@@ -5,7 +5,7 @@ var fxNow, timerId, iframe, iframeDoc,
rfxtypes = /^(?:toggle|show|hide)$/,
rfxnum = /^([\-+]=)?((?:\d*\.)?\d+)([a-z%]*)$/i,
rrun = /\.run$/,
- preFilters = [],
+ animationPrefilters = [],
tweeners = {
"*": [function( prop, value ) {
var end, unit,
@@ -60,7 +60,7 @@ function Animation( elem, properties, options ) {
var result,
index = 0,
tweenerIndex = 0,
- length = preFilters.length,
+ length = animationPrefilters.length,
finished = jQuery.Deferred(),
deferred = jQuery.Deferred().always(function( ended ) {
// remove cirular reference
@@ -123,7 +123,7 @@ function Animation( elem, properties, options ) {
propFilter( props );
for ( ; index < length ; index++ ) {
- result = preFilters[ index ].call( animation,
+ result = animationPrefilters[ index ].call( animation,
elem, props, animation.opts );
if ( result ) {
return result;
@@ -191,16 +191,16 @@ jQuery.Animation = jQuery.extend( Animation, {
}
},
- preFilter: function( callback, prepend ) {
+ prefilter: function( callback, prepend ) {
if ( prepend ) {
- preFilters.unshift( callback );
+ animationPrefilters.unshift( callback );
} else {
- preFilters.push( callback );
+ animationPrefilters.push( callback );
}
}
});
-Animation.preFilter(function( elem, props, opts ) {
+Animation.prefilter(function( elem, props, opts ) {
var index, value,
style = elem.style;
@@ -249,7 +249,7 @@ Animation.preFilter(function( elem, props, opts ) {
});
// special case show/hide prefilter
-Animation.preFilter(function( elem, props, opts ) {
+Animation.prefilter(function( elem, props, opts ) {
var index, prop, value, length, dataShow, tween,
orig = {},
handled = [],
@@ -259,7 +259,7 @@ Animation.preFilter(function( elem, props, opts ) {
value = props[ index ];
if ( rfxtypes.exec( value ) ) {
delete props[ index ];
- if ( hidden ? value === "hide" : value === "show" ) {
+ if ( value === ( hidden ? "hide" : "show" ) ) {
continue;
}
handled.push( index );
@@ -536,10 +536,11 @@ function genFx( type, includeWidth ) {
attrs = { height: type },
i = 0;
+ // if we include width, step value is 1 to do all cssExpand values,
+ // if we don't include width, step value is 2 to skip over Left and Right
for( ; i < 4 ; i += 2 - includeWidth ) {
which = jQuery.cssExpand[ i ];
- attrs[ "margin" + which ] = type;
- attrs[ "padding" + which ] = type;
+ attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
}
if ( includeWidth ) {

No commit comments for this range

Something went wrong with that request. Please try again.