Commit 99191a51 authored by Timmy Willison's avatar Timmy Willison

Apply consistent ordering in all modules. -38 bytes. Order modules like...

Apply consistent ordering in all modules. -38 bytes. Order modules like functions > jQuery.extend > jQuery.fn.extend.
parent cd4a9cd7
...@@ -134,12 +134,156 @@ function ajaxExtend( target, src ) { ...@@ -134,12 +134,156 @@ function ajaxExtend( target, src ) {
return target; return target;
} }
// Attach a bunch of functions for handling common AJAX events /* Handles responses to an ajax request:
jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ){ * - finds the right dataType (mediates between content-type and expected dataType)
jQuery.fn[ type ] = function( fn ){ * - returns the corresponding response
return this.on( type, fn ); */
}; function ajaxHandleResponses( s, jqXHR, responses ) {
});
var ct, type, finalDataType, firstDataType,
contents = s.contents,
dataTypes = s.dataTypes;
// Remove auto dataType and get content-type in the process
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
}
}
// Check if we're dealing with a known content-type
if ( ct ) {
for ( type in contents ) {
if ( contents[ type ] && contents[ type ].test( ct ) ) {
dataTypes.unshift( type );
break;
}
}
}
// Check to see if we have a response for the expected dataType
if ( dataTypes[ 0 ] in responses ) {
finalDataType = dataTypes[ 0 ];
} else {
// Try convertible dataTypes
for ( type in responses ) {
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
finalDataType = type;
break;
}
if ( !firstDataType ) {
firstDataType = type;
}
}
// Or just use first one
finalDataType = finalDataType || firstDataType;
}
// If we found a dataType
// We add the dataType to the list if needed
// and return the corresponding response
if ( finalDataType ) {
if ( finalDataType !== dataTypes[ 0 ] ) {
dataTypes.unshift( finalDataType );
}
return responses[ finalDataType ];
}
}
/* Chain conversions given the request and the original response
* Also sets the responseXXX fields on the jqXHR instance
*/
function ajaxConvert( s, response, jqXHR, isSuccess ) {
var conv2, current, conv, tmp, prev,
converters = {},
// Work with a copy of dataTypes in case we need to modify it for conversion
dataTypes = s.dataTypes.slice();
// Create converters map with lowercased keys
if ( dataTypes[ 1 ] ) {
for ( conv in s.converters ) {
converters[ conv.toLowerCase() ] = s.converters[ conv ];
}
}
current = dataTypes.shift();
// Convert to each sequential dataType
while ( current ) {
if ( s.responseFields[ current ] ) {
jqXHR[ s.responseFields[ current ] ] = response;
}
// Apply the dataFilter if provided
if ( !prev && isSuccess && s.dataFilter ) {
response = s.dataFilter( response, s.dataType );
}
prev = current;
current = dataTypes.shift();
if ( current ) {
// There's only work to do if current dataType is non-auto
if ( current === "*" ) {
current = prev;
// Convert response if prev dataType is non-auto and differs from current
} else if ( prev !== "*" && prev !== current ) {
// Seek a direct converter
conv = converters[ prev + " " + current ] || converters[ "* " + current ];
// If none found, seek a pair
if ( !conv ) {
for ( conv2 in converters ) {
// If conv2 outputs current
tmp = conv2.split( " " );
if ( tmp[ 1 ] === current ) {
// If prev can be converted to accepted input
conv = converters[ prev + " " + tmp[ 0 ] ] ||
converters[ "* " + tmp[ 0 ] ];
if ( conv ) {
// Condense equivalence converters
if ( conv === true ) {
conv = converters[ conv2 ];
// Otherwise, insert the intermediate dataType
} else if ( converters[ conv2 ] !== true ) {
current = tmp[ 0 ];
dataTypes.unshift( tmp[ 1 ] );
}
break;
}
}
}
}
// Apply converter (if not an equivalence)
if ( conv !== true ) {
// Unless errors are allowed to bubble, catch and return them
if ( conv && s[ "throws" ] ) {
response = conv( response );
} else {
try {
response = conv( response );
} catch ( e ) {
return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
}
}
}
}
}
}
return { state: "success", data: response };
}
jQuery.extend({ jQuery.extend({
...@@ -650,156 +794,12 @@ jQuery.each( [ "get", "post" ], function( i, method ) { ...@@ -650,156 +794,12 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
}; };
}); });
/* Handles responses to an ajax request: // Attach a bunch of functions for handling common AJAX events
* - finds the right dataType (mediates between content-type and expected dataType) jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ){
* - returns the corresponding response jQuery.fn[ type ] = function( fn ){
*/ return this.on( type, fn );
function ajaxHandleResponses( s, jqXHR, responses ) { };
});
var ct, type, finalDataType, firstDataType,
contents = s.contents,
dataTypes = s.dataTypes;
// Remove auto dataType and get content-type in the process
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
}
}
// Check if we're dealing with a known content-type
if ( ct ) {
for ( type in contents ) {
if ( contents[ type ] && contents[ type ].test( ct ) ) {
dataTypes.unshift( type );
break;
}
}
}
// Check to see if we have a response for the expected dataType
if ( dataTypes[ 0 ] in responses ) {
finalDataType = dataTypes[ 0 ];
} else {
// Try convertible dataTypes
for ( type in responses ) {
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
finalDataType = type;
break;
}
if ( !firstDataType ) {
firstDataType = type;
}
}
// Or just use first one
finalDataType = finalDataType || firstDataType;
}
// If we found a dataType
// We add the dataType to the list if needed
// and return the corresponding response
if ( finalDataType ) {
if ( finalDataType !== dataTypes[ 0 ] ) {
dataTypes.unshift( finalDataType );
}
return responses[ finalDataType ];
}
}
/* Chain conversions given the request and the original response
* Also sets the responseXXX fields on the jqXHR instance
*/
function ajaxConvert( s, response, jqXHR, isSuccess ) {
var conv2, current, conv, tmp, prev,
converters = {},
// Work with a copy of dataTypes in case we need to modify it for conversion
dataTypes = s.dataTypes.slice();
// Create converters map with lowercased keys
if ( dataTypes[ 1 ] ) {
for ( conv in s.converters ) {
converters[ conv.toLowerCase() ] = s.converters[ conv ];
}
}
current = dataTypes.shift();
// Convert to each sequential dataType
while ( current ) {
if ( s.responseFields[ current ] ) {
jqXHR[ s.responseFields[ current ] ] = response;
}
// Apply the dataFilter if provided
if ( !prev && isSuccess && s.dataFilter ) {
response = s.dataFilter( response, s.dataType );
}
prev = current;
current = dataTypes.shift();
if ( current ) {
// There's only work to do if current dataType is non-auto
if ( current === "*" ) {
current = prev;
// Convert response if prev dataType is non-auto and differs from current
} else if ( prev !== "*" && prev !== current ) {
// Seek a direct converter
conv = converters[ prev + " " + current ] || converters[ "* " + current ];
// If none found, seek a pair
if ( !conv ) {
for ( conv2 in converters ) {
// If conv2 outputs current
tmp = conv2.split( " " );
if ( tmp[ 1 ] === current ) {
// If prev can be converted to accepted input
conv = converters[ prev + " " + tmp[ 0 ] ] ||
converters[ "* " + tmp[ 0 ] ];
if ( conv ) {
// Condense equivalence converters
if ( conv === true ) {
conv = converters[ conv2 ];
// Otherwise, insert the intermediate dataType
} else if ( converters[ conv2 ] !== true ) {
current = tmp[ 0 ];
dataTypes.unshift( tmp[ 1 ] );
}
break;
}
}
}
}
// Apply converter (if not an equivalence)
if ( conv !== true ) {
// Unless errors are allowed to bubble, catch and return them
if ( conv && s[ "throws" ] ) {
response = conv( response );
} else {
try {
response = conv( response );
} catch ( e ) {
return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
}
}
}
}
}
}
return { state: "success", data: response };
}
return jQuery; return jQuery;
}); });
...@@ -20,6 +20,35 @@ define([ ...@@ -20,6 +20,35 @@ define([
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/, var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
rmultiDash = /([A-Z])/g; rmultiDash = /([A-Z])/g;
function dataAttr( elem, key, data ) {
var name;
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
if ( data === undefined && elem.nodeType === 1 ) {
name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
data = elem.getAttribute( name );
if ( typeof data === "string" ) {
try {
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
// Only convert to a number if it doesn't change the string
+data + "" === data ? +data :
rbrace.test( data ) ? JSON.parse( data ) :
data;
} catch( e ) {}
// Make sure we set the data so it isn't changed later
data_user.set( elem, key, data );
} else {
data = undefined;
}
}
return data;
}
jQuery.extend({ jQuery.extend({
hasData: function( elem ) { hasData: function( elem ) {
return data_user.hasData( elem ) || data_priv.hasData( elem ); return data_user.hasData( elem ) || data_priv.hasData( elem );
...@@ -143,34 +172,5 @@ jQuery.fn.extend({ ...@@ -143,34 +172,5 @@ jQuery.fn.extend({
} }
}); });
function dataAttr( elem, key, data ) {
var name;
// If nothing was found internally, try to fetch any
// data from the HTML5 data-* attribute
if ( data === undefined && elem.nodeType === 1 ) {
name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
data = elem.getAttribute( name );
if ( typeof data === "string" ) {
try {
data = data === "true" ? true :
data === "false" ? false :
data === "null" ? null :
// Only convert to a number if it doesn't change the string
+data + "" === data ? +data :
rbrace.test( data ) ? JSON.parse( data ) :
data;
} catch( e ) {}
// Make sure we set the data so it isn't changed later
data_user.set( elem, key, data );
} else {
data = undefined;
}
}
return data;
}
return jQuery; return jQuery;
}); });
...@@ -2,10 +2,12 @@ define([ ...@@ -2,10 +2,12 @@ define([
"./core", "./core",
"./traversing" "./traversing"
], function( jQuery ) { ], function( jQuery ) {
// The number of elements contained in the matched element set // The number of elements contained in the matched element set
jQuery.fn.size = function() { jQuery.fn.size = function() {
return this.length; return this.length;
}; };
jQuery.fn.andSelf = jQuery.fn.addBack; jQuery.fn.andSelf = jQuery.fn.addBack;
}); });
...@@ -3,6 +3,7 @@ define([ ...@@ -3,6 +3,7 @@ define([
"./core/access", "./core/access",
"./css" "./css"
], function( jQuery, access ) { ], function( jQuery, access ) {
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) { jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
......
...@@ -77,6 +77,27 @@ function createFxNow() { ...@@ -77,6 +77,27 @@ function createFxNow() {
return ( fxNow = jQuery.now() ); return ( fxNow = jQuery.now() );
} }
// Generate parameters to create a standard animation
function genFx( type, includeWidth ) {
var which,
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
includeWidth = includeWidth? 1 : 0;
for( ; i < 4 ; i += 2 - includeWidth ) {
which = cssExpand[ i ];
attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
}
if ( includeWidth ) {
attrs.opacity = attrs.width = type;
}
return attrs;
}
function createTween( value, prop, animation ) { function createTween( value, prop, animation ) {
var tween, var tween,
collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ), collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
...@@ -91,6 +112,166 @@ function createTween( value, prop, animation ) { ...@@ -91,6 +112,166 @@ function createTween( value, prop, animation ) {
} }
} }
function defaultPrefilter( elem, props, opts ) {
/* jshint validthis: true */
var prop, value, toggle, tween, hooks, oldfire,
anim = this,
orig = {},
style = elem.style,
hidden = elem.nodeType && isHidden( elem ),
dataShow = data_priv.get( elem, "fxshow" );
// handle queue: false promises
if ( !opts.queue ) {
hooks = jQuery._queueHooks( elem, "fx" );
if ( hooks.unqueued == null ) {
hooks.unqueued = 0;
oldfire = hooks.empty.fire;
hooks.empty.fire = function() {
if ( !hooks.unqueued ) {
oldfire();
}
};
}
hooks.unqueued++;
anim.always(function() {
// doing this makes sure that the complete handler will be called
// before this completes
anim.always(function() {
hooks.unqueued--;
if ( !jQuery.queue( elem, "fx" ).length ) {
hooks.empty.fire();
}
});
});
}
// height/width overflow pass
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
// Make sure that nothing sneaks out
// Record all 3 overflow attributes because IE9-10 do not
// change the overflow attribute when overflowX and
// overflowY are set to the same value
opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
// Set display property to inline-block for height/width
// animations on inline elements that are having width/height animated
if ( jQuery.css( elem, "display" ) === "inline" &&
jQuery.css( elem, "float" ) === "none" ) {
style.display = "inline-block";
}
}
if ( opts.overflow ) {
style.overflow = "hidden";
anim.always(function() {
style.overflow = opts.overflow[ 0 ];
style.overflowX = opts.overflow[ 1 ];
style.overflowY = opts.overflow[ 2 ];
});
}
// show/hide pass
for ( prop in props ) {
value = props[ prop ];
if ( rfxtypes.exec( value ) ) {
delete props[ prop ];
toggle = toggle || value === "toggle";
if ( value === ( hidden ? "hide" : "show" ) ) {
// If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
hidden = true;
} else {
continue;
}
}
orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
}
}
if ( !jQuery.isEmptyObject( orig ) ) {
if ( dataShow ) {
if ( "hidden" in dataShow ) {
hidden = dataShow.hidden;
}
} else {
dataShow = data_priv.access( elem, "fxshow", {} );
}
// store state if its toggle - enables .stop().toggle() to "reverse"
if ( toggle ) {
dataShow.hidden = !hidden;
}
if ( hidden ) {
jQuery( elem ).show();
} else {
anim.done(function() {
jQuery( elem ).hide();
});
}
anim.done(function() {
var prop;
data_priv.remove( elem, "fxshow" );
for ( prop in orig ) {
jQuery.style( elem, prop, orig[ prop ] );
}
});
for ( prop in orig ) {
tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
if ( !( prop in dataShow ) ) {
dataShow[ prop ] = tween.start;
if ( hidden ) {
tween.end = tween.start;
tween.start = prop === "width" || prop === "height" ? 1 : 0;
}
}
}
}
}
function propFilter( props, specialEasing ) {
var index, name, easing, value, hooks;
// camelCase, specialEasing and expand cssHook pass
for ( index in props ) {
name = jQuery.camelCase( index );
easing = specialEasing[ name ];
value = props[ index ];
if ( jQuery.isArray( value ) ) {
easing = value[ 1 ];
value = props[ index ] = value[ 0 ];
}
if ( index !== name ) {
props[ name ] = value;
delete props[ index ];
}
hooks = jQuery.cssHooks[ name ];
if ( hooks && "expand" in hooks ) {
value = hooks.expand( value );
delete props[ name ];
// not quite $.extend, this wont overwrite keys already present.
// also - reusing 'index' from above because we have the correct "name"
for ( index in value ) {
if ( !( index in props ) ) {
props[ index ] = value[ index ];
specialEasing[ index ] = easing;
}
}
} else {
specialEasing[ name ] = easing;
}
}
}
function Animation( elem, properties, options ) { function Animation( elem, properties, options ) {
var result, var result,
stopped, stopped,
...@@ -195,43 +376,6 @@ function Animation( elem, properties, options ) { ...@@ -195,43 +376,6 @@ function Animation( elem, properties, options ) {
.always( animation.opts.always ); .always( animation.opts.always );
} }
function propFilter( props, specialEasing ) {
var index, name, easing, value, hooks;
// camelCase, specialEasing and expand cssHook pass
for ( index in props ) {
name = jQuery.camelCase( index );
easing = specialEasing[ name ];
value = props[ index ];
if ( jQuery.isArray( value ) ) {
easing = value[ 1 ];
value = props[ index ] = value[ 0 ];
}
if ( index !== name ) {
props[ name ] = value;
delete props[ index ];
}
hooks = jQuery.cssHooks[ name ];
if ( hooks && "expand" in hooks ) {
value = hooks.expand( value );
delete props[ name ];
// not quite $.extend, this wont overwrite keys already present.
// also - reusing 'index' from above because we have the correct "name"
for ( index in value ) {
if ( !( index in props ) ) {
props[ index ] = value[ index ];
specialEasing[ index ] = easing;
}
}
} else {
specialEasing[ name ] = easing;
}
}
}
jQuery.Animation = jQuery.extend( Animation, { jQuery.Animation = jQuery.extend( Animation, {
tweener: function( props, callback ) { tweener: function( props, callback ) {
...@@ -262,137 +406,37 @@ jQuery.Animation = jQuery.extend( Animation, { ...@@ -262,137 +406,37 @@ jQuery.Animation = jQuery.extend( Animation, {
} }
}); });
function defaultPrefilter( elem, props, opts ) { jQuery.speed = function( speed, easing, fn ) {
/* jshint validthis: true */ var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
var prop, value, toggle, tween, hooks, oldfire, complete: fn || !fn && easing ||
anim = this, jQuery.isFunction( speed ) && speed,
orig = {}, duration: speed,
style = elem.style, easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
hidden = elem.nodeType && isHidden( elem ), };
dataShow = data_priv.get( elem, "fxshow" );
// handle queue: false promises
if ( !opts.queue ) {
hooks = jQuery._queueHooks( elem, "fx" );
if ( hooks.unqueued == null ) {
hooks.unqueued = 0;
oldfire = hooks.empty.fire;
hooks.empty.fire = function() {
if ( !hooks.unqueued ) {
oldfire();
}
};
}
hooks.unqueued++;
anim.always(function() {
// doing this makes sure that the complete handler will be called
// before this completes
anim.always(function() {
hooks.unqueued--;
if ( !jQuery.queue( elem, "fx" ).length ) {
hooks.empty.fire();
}
});
});
}
// height/width overflow pass
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
// Make sure that nothing sneaks out
// Record all 3 overflow attributes because IE9-10 do not
// change the overflow attribute when overflowX and
// overflowY are set to the same value
opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
// Set display property to inline-block for height/width
// animations on inline elements that are having width/height animated
if ( jQuery.css( elem, "display" ) === "inline" &&
jQuery.css( elem, "float" ) === "none" ) {
style.display = "inline-block";
}
}
if ( opts.overflow ) {
style.overflow = "hidden";
anim.always(function() {
style.overflow = opts.overflow[ 0 ];
style.overflowX = opts.overflow[ 1 ];
style.overflowY = opts.overflow[ 2 ];
});
}
// show/hide pass opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
for ( prop in props ) { opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
value = props[ prop ];
if ( rfxtypes.exec( value ) ) {
delete props[ prop ];
toggle = toggle || value === "toggle";
if ( value === ( hidden ? "hide" : "show" ) ) {
// If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden // normalize opt.queue - true/undefined/null -> "fx"
if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) { if ( opt.queue == null || opt.queue === true ) {
hidden = true; opt.queue = "fx";
} else {
continue;
}
}
orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
}
} }
if ( !jQuery.isEmptyObject( orig ) ) { // Queueing
if ( dataShow ) { opt.old = opt.complete;
if ( "hidden" in dataShow ) {
hidden = dataShow.hidden;
}
} else {
dataShow = data_priv.access( elem, "fxshow", {} );
}
// store state if its toggle - enables .stop().toggle() to "reverse" opt.complete = function() {
if ( toggle ) { if ( jQuery.isFunction( opt.old ) ) {
dataShow.hidden = !hidden; opt.old.call( this );
}
if ( hidden ) {
jQuery( elem ).show();
} else {
anim.done(function() {
jQuery( elem ).hide();
});
} }
anim.done(function() {
var prop;
data_priv.remove( elem, "fxshow" ); if ( opt.queue ) {
for ( prop in orig ) { jQuery.dequeue( this, opt.queue );
jQuery.style( elem, prop, orig[ prop ] );
}
});
for ( prop in orig ) {
tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
if ( !( prop in dataShow ) ) {
dataShow[ prop ] = tween.start;
if ( hidden ) {
tween.end = tween.start;
tween.start = prop === "width" || prop === "height" ? 1 : 0;
}
}
} }
}
}
jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
var cssFn = jQuery.fn[ name ];
jQuery.fn[ name ] = function( speed, easing, callback ) {
return speed == null || typeof speed === "boolean" ?
cssFn.apply( this, arguments ) :
this.animate( genFx( name, true ), speed, easing, callback );
}; };
});
return opt;
};
jQuery.fn.extend({ jQuery.fn.extend({
fadeTo: function( speed, to, easing, callback ) { fadeTo: function( speed, to, easing, callback ) {
...@@ -514,26 +558,14 @@ jQuery.fn.extend({ ...@@ -514,26 +558,14 @@ jQuery.fn.extend({
} }
}); });
// Generate parameters to create a standard animation jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
function genFx( type, includeWidth ) { var cssFn = jQuery.fn[ name ];
var which, jQuery.fn[ name ] = function( speed, easing, callback ) {
attrs = { height: type }, return speed == null || typeof speed === "boolean" ?
i = 0; cssFn.apply( this, arguments ) :
this.animate( genFx( name, true ), speed, easing, callback );
// 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 });
includeWidth = includeWidth? 1 : 0;
for( ; i < 4 ; i += 2 - includeWidth ) {
which = cssExpand[ i ];
attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
}
if ( includeWidth ) {
attrs.opacity = attrs.width = type;
}
return attrs;
}
// Generate shortcuts for custom animations // Generate shortcuts for custom animations
jQuery.each({ jQuery.each({
...@@ -549,38 +581,6 @@ jQuery.each({ ...@@ -549,38 +581,6 @@ jQuery.each({
}; };
}); });
jQuery.speed = function( speed, easing, fn ) {
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
complete: fn || !fn && easing ||
jQuery.isFunction( speed ) && speed,
duration: speed,
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
};
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
// normalize opt.queue - true/undefined/null -> "fx"
if ( opt.queue == null || opt.queue === true ) {
opt.queue = "fx";
}
// Queueing
opt.old = opt.complete;
opt.complete = function() {
if ( jQuery.isFunction( opt.old ) ) {
opt.old.call( this );
}
if ( opt.queue ) {
jQuery.dequeue( this, opt.queue );
}
};
return opt;
};
jQuery.timers = []; jQuery.timers = [];
jQuery.fx.tick = function() { jQuery.fx.tick = function() {
var timer, var timer,
......
...@@ -2,12 +2,6 @@ ...@@ -2,12 +2,6 @@
// Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax // Keep in mind that a dependency array cannot be used with CommonJS+AMD syntax
define(function( require ){ define(function( require ){
// Dependencies not needed as variables
require( "./data/accepts" );
require( "./traversing" );
require( "./selector" );
require( "./event" );
var var
jQuery = require( "./core" ), jQuery = require( "./core" ),
concat = require( "./var/concat" ), concat = require( "./var/concat" ),
...@@ -47,331 +41,161 @@ wrapMap.optgroup = wrapMap.option; ...@@ -47,331 +41,161 @@ wrapMap.optgroup = wrapMap.option;
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
wrapMap.th = wrapMap.td; wrapMap.th = wrapMap.td;
jQuery.fn.extend({ // Dependencies not needed as variables
text: function( value ) { require( "./data/accepts" );
return access( this, function( value ) { require( "./traversing" );
return value === undefined ? require( "./selector" );
jQuery.text( this ) : require( "./event" );
this.empty().append( ( this[ 0 ] && this[ 0 ].ownerDocument || document ).createTextNode( value ) );
}, null, value, arguments.length );
},
append: function() {
return this.domManip( arguments, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
var target = manipulationTarget( this, elem );
target.appendChild( elem );
}
});
},
prepend: function() { // Support: 1.x compatibility
return this.domManip( arguments, function( elem ) { // Manipulating tables requires a tbody
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { function manipulationTarget( elem, content ) {
var target = manipulationTarget( this, elem ); return jQuery.nodeName( elem, "table" ) &&
target.insertBefore( elem, target.firstChild ); jQuery.nodeName( content.nodeType === 1 ? content : content.firstChild, "tr" ) ?
}
});
},
before: function() { elem.getElementsByTagName("tbody")[0] ||
return this.domManip( arguments, function( elem ) { elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
if ( this.parentNode ) { elem;
this.parentNode.insertBefore( elem, this ); }
}
});
},
after: function() { // Replace/restore the type attribute of script elements for safe DOM manipulation
return this.domManip( arguments, function( elem ) { function disableScript( elem ) {
if ( this.parentNode ) { elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
this.parentNode.insertBefore( elem, this.nextSibling ); return elem;
} }
}); function restoreScript( elem ) {
}, var match = rscriptTypeMasked.exec( elem.type );
remove: function( selector, keepData /* Internal Use Only */ ) { if ( match ) {
var elem, elem.type = match[ 1 ];
elems = selector ? jQuery.filter( selector, this ) : this, } else {
i = 0; elem.removeAttribute("type");
}
for ( ; (elem = elems[i]) != null; i++ ) { return elem;
if ( !keepData && elem.nodeType === 1 ) { }
jQuery.cleanData( getAll( elem ) );
}
if ( elem.parentNode ) { // Mark scripts as having already been evaluated
if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) { function setGlobalEval( elems, refElements ) {
setGlobalEval( getAll( elem, "script" ) ); var l = elems.length,
} i = 0;
elem.parentNode.removeChild( elem );
}
}
return this; for ( ; i < l; i++ ) {
}, data_priv.set(
elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
);
}
}
empty: function() { function cloneCopyEvent( src, dest ) {
var elem, var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
i = 0;
for ( ; (elem = this[i]) != null; i++ ) { if ( dest.nodeType !== 1 ) {
if ( elem.nodeType === 1 ) { return;
}
// Prevent memory leaks // 1. Copy private data: events, handlers, etc.
jQuery.cleanData( getAll( elem, false ) ); if ( data_priv.hasData( src ) ) {
pdataOld = data_priv.access( src );
pdataCur = data_priv.set( dest, pdataOld );
events = pdataOld.events;
// Remove any remaining nodes if ( events ) {
elem.textContent = ""; delete pdataCur.handle;
pdataCur.events = {};
for ( type in events ) {
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
jQuery.event.add( dest, type, events[ type ][ i ] );
}
} }
} }
}
return this; // 2. Copy user data
}, if ( data_user.hasData( src ) ) {
udataOld = data_user.access( src );
clone: function( dataAndEvents, deepDataAndEvents ) { udataCur = jQuery.extend( {}, udataOld );
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
return this.map( function () { data_user.set( dest, udataCur );
return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); }
}); }
},
html: function( value ) { function getAll( context, tag ) {
return access( this, function( value ) { var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
var elem = this[ 0 ] || {}, context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
i = 0, [];
l = this.length;
if ( value === undefined && elem.nodeType === 1 ) { return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
return elem.innerHTML; jQuery.merge( [ context ], ret ) :
} ret;
}
// See if we can take a shortcut and just use innerHTML // Support: IE >= 9
if ( typeof value === "string" && !rnoInnerhtml.test( value ) && function fixInput( src, dest ) {
!wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) { var nodeName = dest.nodeName.toLowerCase();
value = value.replace( rxhtmlTag, "<$1></$2>" ); // Fails to persist the checked state of a cloned checkbox or radio button.
if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
dest.checked = src.checked;
try { // Fails to return the selected option to the default selected state when cloning options
for ( ; i < l; i++ ) { } else if ( nodeName === "input" || nodeName === "textarea" ) {
elem = this[ i ] || {}; dest.defaultValue = src.defaultValue;
}
}
// Remove element nodes and prevent memory leaks jQuery.extend({
if ( elem.nodeType === 1 ) { clone: function( elem, dataAndEvents, deepDataAndEvents ) {
jQuery.cleanData( getAll( elem, false ) ); var i, l, srcElements, destElements,
elem.innerHTML = value; clone = elem.cloneNode( true ),
} inPage = jQuery.contains( elem.ownerDocument, elem );
}
elem = 0; // Support: IE >= 9
// Fix Cloning issues
if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
!jQuery.isXMLDoc( elem ) ) {
// If using innerHTML throws an exception, use the fallback method // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
} catch( e ) {} destElements = getAll( clone );
} srcElements = getAll( elem );
if ( elem ) { for ( i = 0, l = srcElements.length; i < l; i++ ) {
this.empty().append( value ); fixInput( srcElements[ i ], destElements[ i ] );
} }
}, null, value, arguments.length ); }
},
replaceWith: function() {
var
// Snapshot the DOM in case .domManip sweeps something relevant into its fragment
args = jQuery.map( this, function( elem ) {
return [ elem.nextSibling, elem.parentNode ];
}),
i = 0;
// Make the changes, replacing each context element with the new content // Copy the events from the original to the clone
this.domManip( arguments, function( elem ) { if ( dataAndEvents ) {
var next = args[ i++ ], if ( deepDataAndEvents ) {
parent = args[ i++ ]; srcElements = srcElements || getAll( elem );
destElements = destElements || getAll( clone );
if ( parent ) { for ( i = 0, l = srcElements.length; i < l; i++ ) {
// Don't use the snapshot next if it has moved (#13810) cloneCopyEvent( srcElements[ i ], destElements[ i ] );
if ( next && next.parentNode !== parent ) {
next = this.nextSibling;
} }
jQuery( this ).remove(); } else {
parent.insertBefore( elem, next ); cloneCopyEvent( elem, clone );
} }
// Allow new content to include elements from the context set }
}, true );
// Force removal if there was no new content (e.g., from empty arguments) // Preserve script evaluation history
return i ? this : this.remove(); destElements = getAll( clone, "script" );
}, if ( destElements.length > 0 ) {
setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
}
detach: function( selector ) { // Return the cloned set
return this.remove( selector, true ); return clone;
}, },
domManip: function( args, callback, allowIntersection ) { buildFragment: function( elems, context, scripts, selection ) {
var elem, tmp, tag, wrap, contains, j,
// Flatten any nested arrays i = 0,
args = concat.apply( [], args ); l = elems.length,
fragment = context.createDocumentFragment(),
var fragment, first, scripts, hasScripts, node, doc, nodes = [];
i = 0,
l = this.length,
set = this,
iNoClone = l - 1,
value = args[ 0 ],
isFunction = jQuery.isFunction( value );
// We can't cloneNode fragments that contain checked, in WebKit
if ( isFunction || !( l <= 1 || typeof value !== "string" || support.checkClone ||
!rchecked.test( value ) ) ) {
return this.each(function( index ) {
var self = set.eq( index );
if ( isFunction ) {
args[ 0 ] = value.call( this, index, self.html() );
}
self.domManip( args, callback, allowIntersection );
});
}
if ( l ) {
fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, !allowIntersection && this );
first = fragment.firstChild;
if ( fragment.childNodes.length === 1 ) {
fragment = first;
}
if ( first ) {
scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
hasScripts = scripts.length;
// Use the original fragment for the last item instead of the first because it can end up
// being emptied incorrectly in certain situations (#8070).
for ( ; i < l; i++ ) {
node = fragment;
if ( i !== iNoClone ) {
node = jQuery.clone( node, true, true );
// Keep references to cloned scripts for later restoration
if ( hasScripts ) {
// Support: QtWebKit
// jQuery.merge because push.apply(_, arraylike) throws
jQuery.merge( scripts, getAll( node, "script" ) );
}
}
callback.call( this[ i ], node, i );
}
if ( hasScripts ) {
doc = scripts[ scripts.length - 1 ].ownerDocument;
// Reenable scripts
jQuery.map( scripts, restoreScript );
// Evaluate executable scripts on first document insertion
for ( i = 0; i < hasScripts; i++ ) {
node = scripts[ i ];
if ( rscriptType.test( node.type || "" ) &&
!data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
if ( node.src ) {
// Optional AJAX dependency, but won't run scripts if not present
if ( jQuery._evalUrl ) {
jQuery._evalUrl( node.src );
}
} else {
jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
}
}
}
}
}
}
return this;
}
});
jQuery.each({
appendTo: "append",
prependTo: "prepend",
insertBefore: "before",
insertAfter: "after",
replaceAll: "replaceWith"
}, function( name, original ) {
jQuery.fn[ name ] = function( selector ) {
var elems,
ret = [],
insert = jQuery( selector ),
last = insert.length - 1,
i = 0;
for ( ; i <= last; i++ ) {
elems = i === last ? this : this.clone( true );
jQuery( insert[ i ] )[ original ]( elems );
// Support: QtWebKit
// .get() because push.apply(_, arraylike) throws
push.apply( ret, elems.get() );
}
return this.pushStack( ret );
};
});
jQuery.extend({
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
var i, l, srcElements, destElements,
clone = elem.cloneNode( true ),
inPage = jQuery.contains( elem.ownerDocument, elem );
// Support: IE >= 9
// Fix Cloning issues
if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
!jQuery.isXMLDoc( elem ) ) {
// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
destElements = getAll( clone );
srcElements = getAll( elem );
for ( i = 0, l = srcElements.length; i < l; i++ ) {
fixInput( srcElements[ i ], destElements[ i ] );
}
}
// Copy the events from the original to the clone
if ( dataAndEvents ) {
if ( deepDataAndEvents ) {
srcElements = srcElements || getAll( elem );
destElements = destElements || getAll( clone );
for ( i = 0, l = srcElements.length; i < l; i++ ) {
cloneCopyEvent( srcElements[ i ], destElements[ i ] );
}
} else {
cloneCopyEvent( elem, clone );
}
}
// Preserve script evaluation history
destElements = getAll( clone, "script" );
if ( destElements.length > 0 ) {
setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
}
// Return the cloned set
return clone;
},
buildFragment: function( elems, context, scripts, selection ) {
var elem, tmp, tag, wrap, contains, j,
i = 0,
l = elems.length,
fragment = context.createDocumentFragment(),
nodes = [];
for ( ; i < l; i++ ) { for ( ; i < l; i++ ) {
elem = elems[ i ]; elem = elems[ i ];
...@@ -487,104 +311,280 @@ jQuery.extend({ ...@@ -487,104 +311,280 @@ jQuery.extend({
} }
}); });
// Support: 1.x compatibility jQuery.fn.extend({
// Manipulating tables requires a tbody text: function( value ) {
function manipulationTarget( elem, content ) { return access( this, function( value ) {
return jQuery.nodeName( elem, "table" ) && return value === undefined ?
jQuery.nodeName( content.nodeType === 1 ? content : content.firstChild, "tr" ) ? jQuery.text( this ) :
this.empty().append( ( this[ 0 ] && this[ 0 ].ownerDocument || document ).createTextNode( value ) );
}, null, value, arguments.length );
},
elem.getElementsByTagName("tbody")[0] || append: function() {
elem.appendChild( elem.ownerDocument.createElement("tbody") ) : return this.domManip( arguments, function( elem ) {
elem; if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
} var target = manipulationTarget( this, elem );
target.appendChild( elem );
}
});
},
// Replace/restore the type attribute of script elements for safe DOM manipulation prepend: function() {
function disableScript( elem ) { return this.domManip( arguments, function( elem ) {
elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type; if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
return elem; var target = manipulationTarget( this, elem );
} target.insertBefore( elem, target.firstChild );
function restoreScript( elem ) { }
var match = rscriptTypeMasked.exec( elem.type ); });
},
if ( match ) { before: function() {
elem.type = match[ 1 ]; return this.domManip( arguments, function( elem ) {
} else { if ( this.parentNode ) {
elem.removeAttribute("type"); this.parentNode.insertBefore( elem, this );
} }
});
},
return elem; after: function() {
} return this.domManip( arguments, function( elem ) {
if ( this.parentNode ) {
this.parentNode.insertBefore( elem, this.nextSibling );
}
});
},
// Mark scripts as having already been evaluated remove: function( selector, keepData /* Internal Use Only */ ) {
function setGlobalEval( elems, refElements ) { var elem,
var l = elems.length, elems = selector ? jQuery.filter( selector, this ) : this,
i = 0; i = 0;
for ( ; i < l; i++ ) { for ( ; (elem = elems[i]) != null; i++ ) {
data_priv.set( if ( !keepData && elem.nodeType === 1 ) {
elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" ) jQuery.cleanData( getAll( elem ) );
); }
}
}
function cloneCopyEvent( src, dest ) { if ( elem.parentNode ) {
var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events; if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
setGlobalEval( getAll( elem, "script" ) );
}
elem.parentNode.removeChild( elem );
}
}
if ( dest.nodeType !== 1 ) { return this;
return; },
}
// 1. Copy private data: events, handlers, etc. empty: function() {
if ( data_priv.hasData( src ) ) { var elem,
pdataOld = data_priv.access( src ); i = 0;
pdataCur = data_priv.set( dest, pdataOld );
events = pdataOld.events;
if ( events ) { for ( ; (elem = this[i]) != null; i++ ) {
delete pdataCur.handle; if ( elem.nodeType === 1 ) {
pdataCur.events = {};
for ( type in events ) { // Prevent memory leaks
for ( i = 0, l = events[ type ].length; i < l; i++ ) { jQuery.cleanData( getAll( elem, false ) );
jQuery.event.add( dest, type, events[ type ][ i ] );
// Remove any remaining nodes
elem.textContent = "";
}
}
return this;
},
clone: function( dataAndEvents, deepDataAndEvents ) {
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
return this.map( function () {
return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
});
},
html: function( value ) {
return access( this, function( value ) {
var elem = this[ 0 ] || {},
i = 0,
l = this.length;
if ( value === undefined && elem.nodeType === 1 ) {
return elem.innerHTML;
}
// See if we can take a shortcut and just use innerHTML
if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
!wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
value = value.replace( rxhtmlTag, "<$1></$2>" );
try {
for ( ; i < l; i++ ) {
elem = this[ i ] || {};
// Remove element nodes and prevent memory leaks
if ( elem.nodeType === 1 ) {
jQuery.cleanData( getAll( elem, false ) );
elem.innerHTML = value;
}
}
elem = 0;
// If using innerHTML throws an exception, use the fallback method
} catch( e ) {}
}
if ( elem ) {
this.empty().append( value );
}
}, null, value, arguments.length );
},
replaceWith: function() {
var
// Snapshot the DOM in case .domManip sweeps something relevant into its fragment
args = jQuery.map( this, function( elem ) {
return [ elem.nextSibling, elem.parentNode ];
}),
i = 0;
// Make the changes, replacing each context element with the new content
this.domManip( arguments, function( elem ) {
var next = args[ i++ ],
parent = args[ i++ ];
if ( parent ) {
// Don't use the snapshot next if it has moved (#13810)
if ( next && next.parentNode !== parent ) {
next = this.nextSibling;
} }
jQuery( this ).remove();
parent.insertBefore( elem, next );
} }
// Allow new content to include elements from the context set
}, true );
// Force removal if there was no new content (e.g., from empty arguments)
return i ? this : this.remove();
},
detach: function( selector ) {
return this.remove( selector, true );
},
domManip: function( args, callback, allowIntersection ) {
// Flatten any nested arrays
args = concat.apply( [], args );
var fragment, first, scripts, hasScripts, node, doc,
i = 0,
l = this.length,
set = this,
iNoClone = l - 1,
value = args[ 0 ],
isFunction = jQuery.isFunction( value );
// We can't cloneNode fragments that contain checked, in WebKit
if ( isFunction || !( l <= 1 || typeof value !== "string" || support.checkClone ||
!rchecked.test( value ) ) ) {
return this.each(function( index ) {
var self = set.eq( index );
if ( isFunction ) {
args[ 0 ] = value.call( this, index, self.html() );
}
self.domManip( args, callback, allowIntersection );
});
} }
}
// 2. Copy user data if ( l ) {
if ( data_user.hasData( src ) ) { fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, !allowIntersection && this );
udataOld = data_user.access( src ); first = fragment.firstChild;
udataCur = jQuery.extend( {}, udataOld );
data_user.set( dest, udataCur ); if ( fragment.childNodes.length === 1 ) {
} fragment = first;
} }
if ( first ) {
scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
hasScripts = scripts.length;
function getAll( context, tag ) { // Use the original fragment for the last item instead of the first because it can end up
var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) : // being emptied incorrectly in certain situations (#8070).
context.querySelectorAll ? context.querySelectorAll( tag || "*" ) : for ( ; i < l; i++ ) {
[]; node = fragment;
return tag === undefined || tag && jQuery.nodeName( context, tag ) ? if ( i !== iNoClone ) {
jQuery.merge( [ context ], ret ) : node = jQuery.clone( node, true, true );
ret;
}
// Support: IE >= 9 // Keep references to cloned scripts for later restoration
function fixInput( src, dest ) { if ( hasScripts ) {
var nodeName = dest.nodeName.toLowerCase(); // Support: QtWebKit
// jQuery.merge because push.apply(_, arraylike) throws
jQuery.merge( scripts, getAll( node, "script" ) );
}
}
// Fails to persist the checked state of a cloned checkbox or radio button. callback.call( this[ i ], node, i );
if ( nodeName === "input" && rcheckableType.test( src.type ) ) { }
dest.checked = src.checked;
// Fails to return the selected option to the default selected state when cloning options if ( hasScripts ) {
} else if ( nodeName === "input" || nodeName === "textarea" ) { doc = scripts[ scripts.length - 1 ].ownerDocument;
dest.defaultValue = src.defaultValue;
// Reenable scripts
jQuery.map( scripts, restoreScript );
// Evaluate executable scripts on first document insertion
for ( i = 0; i < hasScripts; i++ ) {
node = scripts[ i ];
if ( rscriptType.test( node.type || "" ) &&
!data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
if ( node.src ) {
// Optional AJAX dependency, but won't run scripts if not present
if ( jQuery._evalUrl ) {
jQuery._evalUrl( node.src );
}
} else {
jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
}
}
}
}
}
}
return this;
} }
} });
jQuery.each({
appendTo: "append",
prependTo: "prepend",
insertBefore: "before",
insertAfter: "after",
replaceAll: "replaceWith"
}, function( name, original ) {
jQuery.fn[ name ] = function( selector ) {
var elems,
ret = [],
insert = jQuery( selector ),
last = insert.length - 1,
i = 0;
for ( ; i <= last; i++ ) {
elems = i === last ? this : this.clone( true );
jQuery( insert[ i ] )[ original ]( elems );
// Support: QtWebKit
// .get() because push.apply(_, arraylike) throws
push.apply( ret, elems.get() );
}
return this.pushStack( ret );
};
});
return jQuery; return jQuery;
}); });
...@@ -8,45 +8,14 @@ define([ ...@@ -8,45 +8,14 @@ define([
var docElem = window.document.documentElement; var docElem = window.document.documentElement;
jQuery.fn.offset = function( options ) { /**
if ( arguments.length ) { * Gets a window from an element
return options === undefined ? */
this : function getWindow( elem ) {
this.each(function( i ) { return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
jQuery.offset.setOffset( this, options, i ); }
});
}
var docElem, win,
elem = this[ 0 ],
box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
// If we don't have gBCR, just use 0,0 rather than error
// BlackBerry 5, iOS 3 (original iPhone)
if ( typeof elem.getBoundingClientRect !== strundefined ) {
box = elem.getBoundingClientRect();
}
win = getWindow( doc );
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
};
jQuery.offset = { jQuery.offset = {
setOffset: function( elem, options, i ) { setOffset: function( elem, options, i ) {
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition, var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
position = jQuery.css( elem, "position" ), position = jQuery.css( elem, "position" ),
...@@ -95,8 +64,43 @@ jQuery.offset = { ...@@ -95,8 +64,43 @@ jQuery.offset = {
} }
}; };
jQuery.fn.extend({ jQuery.fn.extend({
offset: function( options ) {
if ( arguments.length ) {
return options === undefined ?
this :
this.each(function( i ) {
jQuery.offset.setOffset( this, options, i );
});
}
var docElem, win,
elem = this[ 0 ],
box = { top: 0, left: 0 },
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
// If we don't have gBCR, just use 0,0 rather than error
// BlackBerry 5, iOS 3 (original iPhone)
if ( typeof elem.getBoundingClientRect !== strundefined ) {
box = elem.getBoundingClientRect();
}
win = getWindow( doc );
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
},
position: function() { position: function() {
if ( !this[ 0 ] ) { if ( !this[ 0 ] ) {
...@@ -147,13 +151,6 @@ jQuery.fn.extend({ ...@@ -147,13 +151,6 @@ jQuery.fn.extend({
} }
}); });
/**
* Gets a window from an element
*/
function getWindow( elem ) {
return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
}
// Create scrollLeft and scrollTop methods // Create scrollLeft and scrollTop methods
jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) { jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) {
var top = "pageYOffset" === prop; var top = "pageYOffset" === prop;
......
...@@ -11,36 +11,33 @@ var r20 = /%20/g, ...@@ -11,36 +11,33 @@ var r20 = /%20/g,
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i, rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
rsubmittable = /^(?:input|select|textarea|keygen)/i; rsubmittable = /^(?:input|select|textarea|keygen)/i;
jQuery.fn.extend({ function buildParams( prefix, obj, traditional, add ) {
serialize: function() { var name;
return jQuery.param( this.serializeArray() );
},
serializeArray: function() {
return this.map(function(){
// Can add propHook for "elements" to filter or add form elements
var elements = jQuery.prop( this, "elements" );
return elements ? jQuery.makeArray( elements ) : this;
})
.filter(function(){
var type = this.type;
// Use .is(":disabled") so that fieldset[disabled] works
return this.name && !jQuery( this ).is( ":disabled" ) &&
rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
( this.checked || !rcheckableType.test( type ) );
})
.map(function( i, elem ){
var val = jQuery( this ).val();
return val == null ? if ( jQuery.isArray( obj ) ) {
null : // Serialize array item.
jQuery.isArray( val ) ? jQuery.each( obj, function( i, v ) {
jQuery.map( val, function( val ){ if ( traditional || rbracket.test( prefix ) ) {
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; // Treat each array item as a scalar.
}) : add( prefix, v );
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
}).get(); } else {
// Item is non-scalar (array or object), encode its numeric index.
buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
}
});
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
// Serialize object item.
for ( name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
}
} else {
// Serialize scalar item.
add( prefix, obj );
} }
}); }
// Serialize an array of form elements or a set of // Serialize an array of form elements or a set of
// key/values into a query string // key/values into a query string
...@@ -77,33 +74,36 @@ jQuery.param = function( a, traditional ) { ...@@ -77,33 +74,36 @@ jQuery.param = function( a, traditional ) {
return s.join( "&" ).replace( r20, "+" ); return s.join( "&" ).replace( r20, "+" );
}; };
function buildParams( prefix, obj, traditional, add ) { jQuery.fn.extend({
var name; serialize: function() {
return jQuery.param( this.serializeArray() );
if ( jQuery.isArray( obj ) ) { },
// Serialize array item. serializeArray: function() {
jQuery.each( obj, function( i, v ) { return this.map(function(){
if ( traditional || rbracket.test( prefix ) ) { // Can add propHook for "elements" to filter or add form elements
// Treat each array item as a scalar. var elements = jQuery.prop( this, "elements" );
add( prefix, v ); return elements ? jQuery.makeArray( elements ) : this;
})
} else { .filter(function(){
// Item is non-scalar (array or object), encode its numeric index. var type = this.type;
buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add ); // Use .is(":disabled") so that fieldset[disabled] works
} return this.name && !jQuery( this ).is( ":disabled" ) &&
}); rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
( this.checked || !rcheckableType.test( type ) );
} else if ( !traditional && jQuery.type( obj ) === "object" ) { })
// Serialize object item. .map(function( i, elem ){
for ( name in obj ) { var val = jQuery( this ).val();
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
}
} else { return val == null ?
// Serialize scalar item. null :
add( prefix, obj ); jQuery.isArray( val ) ?
jQuery.map( val, function( val ){
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
}) :
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
}).get();
} }
} });
return jQuery; return jQuery;
}); });
...@@ -15,6 +15,79 @@ var isSimple = /^.[^:#\[\.,]*$/, ...@@ -15,6 +15,79 @@ var isSimple = /^.[^:#\[\.,]*$/,
prev: true prev: true
}; };
// Implement the identical functionality for filter and not
function winnow( elements, qualifier, not ) {
if ( jQuery.isFunction( qualifier ) ) {
return jQuery.grep( elements, function( elem, i ) {
/* jshint -W018 */
return !!qualifier.call( elem, i, elem ) !== not;
});
}
if ( qualifier.nodeType ) {
return jQuery.grep( elements, function( elem ) {
return ( elem === qualifier ) !== not;
});
}
if ( typeof qualifier === "string" ) {
if ( isSimple.test( qualifier ) ) {
return jQuery.filter( qualifier, elements, not );
}
qualifier = jQuery.filter( qualifier, elements );
}
return jQuery.grep( elements, function( elem ) {
return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
});
}
jQuery.extend({
filter: function( expr, elems, not ) {
var elem = elems[ 0 ];
if ( not ) {
expr = ":not(" + expr + ")";
}
return elems.length === 1 && elem.nodeType === 1 ?
jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
return elem.nodeType === 1;
}));
},
dir: function( elem, dir, until ) {
var matched = [],
truncate = until !== undefined;
while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
if ( elem.nodeType === 1 ) {
if ( truncate && jQuery( elem ).is( until ) ) {
break;
}
matched.push( elem );
}
}
return matched;
},
sibling: function( n, elem ) {
var matched = [];
for ( ; n; n = n.nextSibling ) {
if ( n.nodeType === 1 && n !== elem ) {
matched.push( n );
}
}
return matched;
}
});
jQuery.fn.extend({ jQuery.fn.extend({
find: function( selector ) { find: function( selector ) {
var i, var i,
...@@ -145,7 +218,6 @@ jQuery.fn.extend({ ...@@ -145,7 +218,6 @@ jQuery.fn.extend({
function sibling( cur, dir ) { function sibling( cur, dir ) {
while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {} while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
return cur; return cur;
} }
...@@ -215,78 +287,5 @@ jQuery.each({ ...@@ -215,78 +287,5 @@ jQuery.each({
}; };
}); });
jQuery.extend({
filter: function( expr, elems, not ) {
var elem = elems[ 0 ];
if ( not ) {
expr = ":not(" + expr + ")";
}
return elems.length === 1 && elem.nodeType === 1 ?
jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
return elem.nodeType === 1;
}));
},
dir: function( elem, dir, until ) {
var matched = [],
truncate = until !== undefined;
while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
if ( elem.nodeType === 1 ) {
if ( truncate && jQuery( elem ).is( until ) ) {
break;
}
matched.push( elem );
}
}
return matched;
},
sibling: function( n, elem ) {
var matched = [];
for ( ; n; n = n.nextSibling ) {
if ( n.nodeType === 1 && n !== elem ) {
matched.push( n );
}
}
return matched;
}
});
// Implement the identical functionality for filter and not
function winnow( elements, qualifier, not ) {
if ( jQuery.isFunction( qualifier ) ) {
return jQuery.grep( elements, function( elem, i ) {
/* jshint -W018 */
return !!qualifier.call( elem, i, elem ) !== not;
});
}
if ( qualifier.nodeType ) {
return jQuery.grep( elements, function( elem ) {
return ( elem === qualifier ) !== not;
});
}
if ( typeof qualifier === "string" ) {
if ( isSimple.test( qualifier ) ) {
return jQuery.filter( qualifier, elements, not );
}
qualifier = jQuery.filter( qualifier, elements );
}
return jQuery.grep( elements, function( elem ) {
return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
});
}
return jQuery; return jQuery;
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment