ffffng/app/bower_components/jquery/src/core.js

477 lines
11 KiB
JavaScript
Raw Normal View History

2017-05-13 13:25:33 +02:00
/* global Symbol */
// Defining this global in .eslintrc.json would create a danger of using the global
// unguarded in another place, it seems safer to define global only for this module
define( [
2014-05-12 20:08:19 +02:00
"./var/arr",
2017-05-13 13:25:33 +02:00
"./var/document",
"./var/getProto",
2014-05-12 20:08:19 +02:00
"./var/slice",
"./var/concat",
"./var/push",
"./var/indexOf",
"./var/class2type",
"./var/toString",
"./var/hasOwn",
2017-05-13 13:25:33 +02:00
"./var/fnToString",
"./var/ObjectFunctionString",
"./var/support",
"./core/DOMEval"
], function( arr, document, getProto, slice, concat, push, indexOf,
class2type, toString, hasOwn, fnToString, ObjectFunctionString,
support, DOMEval ) {
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
"use strict";
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
var
version = "3.2.1",
2014-05-12 20:08:19 +02:00
// Define a local copy of jQuery
jQuery = function( selector, context ) {
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// The jQuery object is actually just the init constructor 'enhanced'
// Need init if jQuery is called (just allow error to be thrown if not included)
return new jQuery.fn.init( selector, context );
},
2017-05-13 13:25:33 +02:00
// Support: Android <=4.0 only
2014-05-12 20:08:19 +02:00
// Make sure we trim BOM and NBSP
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
// Matches dashed string for camelizing
rmsPrefix = /^-ms-/,
2017-05-13 13:25:33 +02:00
rdashAlpha = /-([a-z])/g,
2014-05-12 20:08:19 +02:00
// Used by jQuery.camelCase as callback to replace()
fcamelCase = function( all, letter ) {
return letter.toUpperCase();
};
jQuery.fn = jQuery.prototype = {
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// The current version of jQuery being used
jquery: version,
constructor: jQuery,
// The default length of a jQuery object is 0
length: 0,
toArray: function() {
return slice.call( this );
},
// Get the Nth element in the matched element set OR
// Get the whole matched element set as a clean array
get: function( num ) {
2017-05-13 13:25:33 +02:00
// Return all the elements in a clean array
if ( num == null ) {
return slice.call( this );
}
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
// Return just the one element from the set
return num < 0 ? this[ num + this.length ] : this[ num ];
2014-05-12 20:08:19 +02:00
},
// Take an array of elements and push it onto the stack
// (returning the new matched element set)
pushStack: function( elems ) {
// Build a new jQuery matched element set
var ret = jQuery.merge( this.constructor(), elems );
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
// Return the newly-formed element set
return ret;
},
// Execute a callback for every element in the matched set.
2017-05-13 13:25:33 +02:00
each: function( callback ) {
return jQuery.each( this, callback );
2014-05-12 20:08:19 +02:00
},
map: function( callback ) {
2017-05-13 13:25:33 +02:00
return this.pushStack( jQuery.map( this, function( elem, i ) {
2014-05-12 20:08:19 +02:00
return callback.call( elem, i, elem );
2017-05-13 13:25:33 +02:00
} ) );
2014-05-12 20:08:19 +02:00
},
slice: function() {
return this.pushStack( slice.apply( this, arguments ) );
},
first: function() {
return this.eq( 0 );
},
last: function() {
return this.eq( -1 );
},
eq: function( i ) {
var len = this.length,
j = +i + ( i < 0 ? len : 0 );
2017-05-13 13:25:33 +02:00
return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );
2014-05-12 20:08:19 +02:00
},
end: function() {
2017-05-13 13:25:33 +02:00
return this.prevObject || this.constructor();
2014-05-12 20:08:19 +02:00
},
// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
push: push,
sort: arr.sort,
splice: arr.splice
};
jQuery.extend = jQuery.fn.extend = function() {
var options, name, src, copy, copyIsArray, clone,
2017-05-13 13:25:33 +02:00
target = arguments[ 0 ] || {},
2014-05-12 20:08:19 +02:00
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
2016-05-16 13:33:49 +02:00
// Skip the boolean and the target
2014-05-12 20:08:19 +02:00
target = arguments[ i ] || {};
i++;
}
// Handle case when target is a string or something (possible in deep copy)
2017-05-13 13:25:33 +02:00
if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
2014-05-12 20:08:19 +02:00
target = {};
}
2016-05-16 13:33:49 +02:00
// Extend jQuery itself if only one argument is passed
2014-05-12 20:08:19 +02:00
if ( i === length ) {
target = this;
i--;
}
for ( ; i < length; i++ ) {
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// Only deal with non-null/undefined values
2017-05-13 13:25:33 +02:00
if ( ( options = arguments[ i ] ) != null ) {
2014-05-12 20:08:19 +02:00
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
// Prevent never-ending loop
if ( target === copy ) {
continue;
}
// Recurse if we're merging plain objects or arrays
2017-05-13 13:25:33 +02:00
if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
( copyIsArray = Array.isArray( copy ) ) ) ) {
2014-05-12 20:08:19 +02:00
if ( copyIsArray ) {
copyIsArray = false;
2017-05-13 13:25:33 +02:00
clone = src && Array.isArray( src ) ? src : [];
2014-05-12 20:08:19 +02:00
} else {
2017-05-13 13:25:33 +02:00
clone = src && jQuery.isPlainObject( src ) ? src : {};
2014-05-12 20:08:19 +02:00
}
// Never move original objects, clone them
target[ name ] = jQuery.extend( deep, clone, copy );
// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
}
}
}
// Return the modified object
return target;
};
2017-05-13 13:25:33 +02:00
jQuery.extend( {
2014-05-12 20:08:19 +02:00
// Unique for each copy of jQuery on the page
expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
// Assume jQuery is ready without the ready module
isReady: true,
error: function( msg ) {
throw new Error( msg );
},
noop: function() {},
isFunction: function( obj ) {
2017-05-13 13:25:33 +02:00
return jQuery.type( obj ) === "function";
2014-05-12 20:08:19 +02:00
},
isWindow: function( obj ) {
return obj != null && obj === obj.window;
},
isNumeric: function( obj ) {
2017-05-13 13:25:33 +02:00
// As of jQuery 3.0, isNumeric is limited to
// strings and numbers (primitives or objects)
// that can be coerced to finite numbers (gh-2662)
var type = jQuery.type( obj );
return ( type === "number" || type === "string" ) &&
// parseFloat NaNs numeric-cast false positives ("")
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
// subtraction forces infinities to NaN
!isNaN( obj - parseFloat( obj ) );
2014-05-12 20:08:19 +02:00
},
isPlainObject: function( obj ) {
2017-05-13 13:25:33 +02:00
var proto, Ctor;
// Detect obvious negatives
// Use toString instead of jQuery.type to catch host objects
if ( !obj || toString.call( obj ) !== "[object Object]" ) {
2014-05-12 20:08:19 +02:00
return false;
}
2017-05-13 13:25:33 +02:00
proto = getProto( obj );
// Objects with no prototype (e.g., `Object.create( null )`) are plain
if ( !proto ) {
return true;
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
// Objects with prototype are plain iff they were constructed by a global Object function
Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
2014-05-12 20:08:19 +02:00
},
isEmptyObject: function( obj ) {
2017-05-13 13:25:33 +02:00
/* eslint-disable no-unused-vars */
// See https://github.com/eslint/eslint/issues/6125
2014-05-12 20:08:19 +02:00
var name;
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
for ( name in obj ) {
return false;
}
return true;
},
type: function( obj ) {
if ( obj == null ) {
return obj + "";
}
2017-05-13 13:25:33 +02:00
// Support: Android <=2.3 only (functionish RegExp)
2014-05-12 20:08:19 +02:00
return typeof obj === "object" || typeof obj === "function" ?
2017-05-13 13:25:33 +02:00
class2type[ toString.call( obj ) ] || "object" :
2014-05-12 20:08:19 +02:00
typeof obj;
},
// Evaluates a script in a global context
globalEval: function( code ) {
2017-05-13 13:25:33 +02:00
DOMEval( code );
2014-05-12 20:08:19 +02:00
},
// Convert dashed to camelCase; used by the css and data modules
2017-05-13 13:25:33 +02:00
// Support: IE <=9 - 11, Edge 12 - 13
2014-05-12 20:08:19 +02:00
// Microsoft forgot to hump their vendor prefix (#9572)
camelCase: function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},
2017-05-13 13:25:33 +02:00
each: function( obj, callback ) {
var length, i = 0;
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
if ( isArrayLike( obj ) ) {
length = obj.length;
for ( ; i < length; i++ ) {
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
break;
2014-05-12 20:08:19 +02:00
}
}
} else {
2017-05-13 13:25:33 +02:00
for ( i in obj ) {
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
break;
2014-05-12 20:08:19 +02:00
}
}
}
return obj;
},
2017-05-13 13:25:33 +02:00
// Support: Android <=4.0 only
2014-05-12 20:08:19 +02:00
trim: function( text ) {
return text == null ?
"" :
( text + "" ).replace( rtrim, "" );
},
// results is for internal usage only
makeArray: function( arr, results ) {
var ret = results || [];
if ( arr != null ) {
2017-05-13 13:25:33 +02:00
if ( isArrayLike( Object( arr ) ) ) {
2014-05-12 20:08:19 +02:00
jQuery.merge( ret,
typeof arr === "string" ?
[ arr ] : arr
);
} else {
push.call( ret, arr );
}
}
return ret;
},
inArray: function( elem, arr, i ) {
return arr == null ? -1 : indexOf.call( arr, elem, i );
},
2017-05-13 13:25:33 +02:00
// Support: Android <=4.0 only, PhantomJS 1 only
// push.apply(_, arraylike) throws on ancient WebKit
2014-05-12 20:08:19 +02:00
merge: function( first, second ) {
var len = +second.length,
j = 0,
i = first.length;
for ( ; j < len; j++ ) {
first[ i++ ] = second[ j ];
}
first.length = i;
return first;
},
grep: function( elems, callback, invert ) {
var callbackInverse,
matches = [],
i = 0,
length = elems.length,
callbackExpect = !invert;
// Go through the array, only saving the items
// that pass the validator function
for ( ; i < length; i++ ) {
callbackInverse = !callback( elems[ i ], i );
if ( callbackInverse !== callbackExpect ) {
matches.push( elems[ i ] );
}
}
return matches;
},
// arg is for internal usage only
map: function( elems, callback, arg ) {
2017-05-13 13:25:33 +02:00
var length, value,
2014-05-12 20:08:19 +02:00
i = 0,
ret = [];
// Go through the array, translating each of the items to their new values
2017-05-13 13:25:33 +02:00
if ( isArrayLike( elems ) ) {
length = elems.length;
2014-05-12 20:08:19 +02:00
for ( ; i < length; i++ ) {
value = callback( elems[ i ], i, arg );
if ( value != null ) {
ret.push( value );
}
}
// Go through every key on the object,
} else {
for ( i in elems ) {
value = callback( elems[ i ], i, arg );
if ( value != null ) {
ret.push( value );
}
}
}
// Flatten any nested arrays
return concat.apply( [], ret );
},
// A global GUID counter for objects
guid: 1,
// Bind a function to a context, optionally partially applying any
// arguments.
proxy: function( fn, context ) {
var tmp, args, proxy;
if ( typeof context === "string" ) {
tmp = fn[ context ];
context = fn;
fn = tmp;
}
// Quick check to determine if target is callable, in the spec
// this throws a TypeError, but we will just return undefined.
if ( !jQuery.isFunction( fn ) ) {
return undefined;
}
// Simulated bind
args = slice.call( arguments, 2 );
proxy = function() {
return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
};
// Set the guid of unique handler to the same of original handler, so it can be removed
proxy.guid = fn.guid = fn.guid || jQuery.guid++;
return proxy;
},
now: Date.now,
// jQuery.support is not used in Core but other projects attach their
// properties to it so it needs to exist.
support: support
2017-05-13 13:25:33 +02:00
} );
if ( typeof Symbol === "function" ) {
jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
}
2014-05-12 20:08:19 +02:00
// Populate the class2type map
2017-05-13 13:25:33 +02:00
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
function( i, name ) {
2014-05-12 20:08:19 +02:00
class2type[ "[object " + name + "]" ] = name.toLowerCase();
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
function isArrayLike( obj ) {
2016-05-16 13:33:49 +02:00
2017-05-13 13:25:33 +02:00
// Support: real iOS 8.2 only (not reproducible in simulator)
2016-05-16 13:33:49 +02:00
// `in` check used to prevent JIT error (gh-2145)
// hasOwn isn't used here due to false negatives
// regarding Nodelist length in IE
2017-05-13 13:25:33 +02:00
var length = !!obj && "length" in obj && obj.length,
2014-05-12 20:08:19 +02:00
type = jQuery.type( obj );
if ( type === "function" || jQuery.isWindow( obj ) ) {
return false;
}
return type === "array" || length === 0 ||
typeof length === "number" && length > 0 && ( length - 1 ) in obj;
}
return jQuery;
2017-05-13 13:25:33 +02:00
} );