core.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /* global Symbol */
  2. // Defining this global in .eslintrc.json would create a danger of using the global
  3. // unguarded in another place, it seems safer to define global only for this module
  4. define( [
  5. "./var/arr",
  6. "./var/document",
  7. "./var/getProto",
  8. "./var/slice",
  9. "./var/concat",
  10. "./var/push",
  11. "./var/indexOf",
  12. "./var/class2type",
  13. "./var/toString",
  14. "./var/hasOwn",
  15. "./var/fnToString",
  16. "./var/ObjectFunctionString",
  17. "./var/support",
  18. "./core/DOMEval"
  19. ], function( arr, document, getProto, slice, concat, push, indexOf,
  20. class2type, toString, hasOwn, fnToString, ObjectFunctionString,
  21. support, DOMEval ) {
  22. "use strict";
  23. var
  24. version = "3.1.1",
  25. // Define a local copy of jQuery
  26. jQuery = function( selector, context ) {
  27. // The jQuery object is actually just the init constructor 'enhanced'
  28. // Need init if jQuery is called (just allow error to be thrown if not included)
  29. return new jQuery.fn.init( selector, context );
  30. },
  31. // Support: Android <=4.0 only
  32. // Make sure we trim BOM and NBSP
  33. rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
  34. // Matches dashed string for camelizing
  35. rmsPrefix = /^-ms-/,
  36. rdashAlpha = /-([a-z])/g,
  37. // Used by jQuery.camelCase as callback to replace()
  38. fcamelCase = function( all, letter ) {
  39. return letter.toUpperCase();
  40. };
  41. jQuery.fn = jQuery.prototype = {
  42. // The current version of jQuery being used
  43. jquery: version,
  44. constructor: jQuery,
  45. // The default length of a jQuery object is 0
  46. length: 0,
  47. toArray: function() {
  48. return slice.call( this );
  49. },
  50. // Get the Nth element in the matched element set OR
  51. // Get the whole matched element set as a clean array
  52. get: function( num ) {
  53. // Return all the elements in a clean array
  54. if ( num == null ) {
  55. return slice.call( this );
  56. }
  57. // Return just the one element from the set
  58. return num < 0 ? this[ num + this.length ] : this[ num ];
  59. },
  60. // Take an array of elements and push it onto the stack
  61. // (returning the new matched element set)
  62. pushStack: function( elems ) {
  63. // Build a new jQuery matched element set
  64. var ret = jQuery.merge( this.constructor(), elems );
  65. // Add the old object onto the stack (as a reference)
  66. ret.prevObject = this;
  67. // Return the newly-formed element set
  68. return ret;
  69. },
  70. // Execute a callback for every element in the matched set.
  71. each: function( callback ) {
  72. return jQuery.each( this, callback );
  73. },
  74. map: function( callback ) {
  75. return this.pushStack( jQuery.map( this, function( elem, i ) {
  76. return callback.call( elem, i, elem );
  77. } ) );
  78. },
  79. slice: function() {
  80. return this.pushStack( slice.apply( this, arguments ) );
  81. },
  82. first: function() {
  83. return this.eq( 0 );
  84. },
  85. last: function() {
  86. return this.eq( -1 );
  87. },
  88. eq: function( i ) {
  89. var len = this.length,
  90. j = +i + ( i < 0 ? len : 0 );
  91. return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );
  92. },
  93. end: function() {
  94. return this.prevObject || this.constructor();
  95. },
  96. // For internal use only.
  97. // Behaves like an Array's method, not like a jQuery method.
  98. push: push,
  99. sort: arr.sort,
  100. splice: arr.splice
  101. };
  102. jQuery.extend = jQuery.fn.extend = function() {
  103. var options, name, src, copy, copyIsArray, clone,
  104. target = arguments[ 0 ] || {},
  105. i = 1,
  106. length = arguments.length,
  107. deep = false;
  108. // Handle a deep copy situation
  109. if ( typeof target === "boolean" ) {
  110. deep = target;
  111. // Skip the boolean and the target
  112. target = arguments[ i ] || {};
  113. i++;
  114. }
  115. // Handle case when target is a string or something (possible in deep copy)
  116. if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
  117. target = {};
  118. }
  119. // Extend jQuery itself if only one argument is passed
  120. if ( i === length ) {
  121. target = this;
  122. i--;
  123. }
  124. for ( ; i < length; i++ ) {
  125. // Only deal with non-null/undefined values
  126. if ( ( options = arguments[ i ] ) != null ) {
  127. // Extend the base object
  128. for ( name in options ) {
  129. src = target[ name ];
  130. copy = options[ name ];
  131. // Prevent never-ending loop
  132. if ( target === copy ) {
  133. continue;
  134. }
  135. // Recurse if we're merging plain objects or arrays
  136. if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
  137. ( copyIsArray = jQuery.isArray( copy ) ) ) ) {
  138. if ( copyIsArray ) {
  139. copyIsArray = false;
  140. clone = src && jQuery.isArray( src ) ? src : [];
  141. } else {
  142. clone = src && jQuery.isPlainObject( src ) ? src : {};
  143. }
  144. // Never move original objects, clone them
  145. target[ name ] = jQuery.extend( deep, clone, copy );
  146. // Don't bring in undefined values
  147. } else if ( copy !== undefined ) {
  148. target[ name ] = copy;
  149. }
  150. }
  151. }
  152. }
  153. // Return the modified object
  154. return target;
  155. };
  156. jQuery.extend( {
  157. // Unique for each copy of jQuery on the page
  158. expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
  159. // Assume jQuery is ready without the ready module
  160. isReady: true,
  161. error: function( msg ) {
  162. throw new Error( msg );
  163. },
  164. noop: function() {},
  165. isFunction: function( obj ) {
  166. return jQuery.type( obj ) === "function";
  167. },
  168. isArray: Array.isArray,
  169. isWindow: function( obj ) {
  170. return obj != null && obj === obj.window;
  171. },
  172. isNumeric: function( obj ) {
  173. // As of jQuery 3.0, isNumeric is limited to
  174. // strings and numbers (primitives or objects)
  175. // that can be coerced to finite numbers (gh-2662)
  176. var type = jQuery.type( obj );
  177. return ( type === "number" || type === "string" ) &&
  178. // parseFloat NaNs numeric-cast false positives ("")
  179. // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  180. // subtraction forces infinities to NaN
  181. !isNaN( obj - parseFloat( obj ) );
  182. },
  183. isPlainObject: function( obj ) {
  184. var proto, Ctor;
  185. // Detect obvious negatives
  186. // Use toString instead of jQuery.type to catch host objects
  187. if ( !obj || toString.call( obj ) !== "[object Object]" ) {
  188. return false;
  189. }
  190. proto = getProto( obj );
  191. // Objects with no prototype (e.g., `Object.create( null )`) are plain
  192. if ( !proto ) {
  193. return true;
  194. }
  195. // Objects with prototype are plain iff they were constructed by a global Object function
  196. Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
  197. return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
  198. },
  199. isEmptyObject: function( obj ) {
  200. /* eslint-disable no-unused-vars */
  201. // See https://github.com/eslint/eslint/issues/6125
  202. var name;
  203. for ( name in obj ) {
  204. return false;
  205. }
  206. return true;
  207. },
  208. type: function( obj ) {
  209. if ( obj == null ) {
  210. return obj + "";
  211. }
  212. // Support: Android <=2.3 only (functionish RegExp)
  213. return typeof obj === "object" || typeof obj === "function" ?
  214. class2type[ toString.call( obj ) ] || "object" :
  215. typeof obj;
  216. },
  217. // Evaluates a script in a global context
  218. globalEval: function( code ) {
  219. DOMEval( code );
  220. },
  221. // Convert dashed to camelCase; used by the css and data modules
  222. // Support: IE <=9 - 11, Edge 12 - 13
  223. // Microsoft forgot to hump their vendor prefix (#9572)
  224. camelCase: function( string ) {
  225. return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
  226. },
  227. nodeName: function( elem, name ) {
  228. return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
  229. },
  230. each: function( obj, callback ) {
  231. var length, i = 0;
  232. if ( isArrayLike( obj ) ) {
  233. length = obj.length;
  234. for ( ; i < length; i++ ) {
  235. if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
  236. break;
  237. }
  238. }
  239. } else {
  240. for ( i in obj ) {
  241. if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
  242. break;
  243. }
  244. }
  245. }
  246. return obj;
  247. },
  248. // Support: Android <=4.0 only
  249. trim: function( text ) {
  250. return text == null ?
  251. "" :
  252. ( text + "" ).replace( rtrim, "" );
  253. },
  254. // results is for internal usage only
  255. makeArray: function( arr, results ) {
  256. var ret = results || [];
  257. if ( arr != null ) {
  258. if ( isArrayLike( Object( arr ) ) ) {
  259. jQuery.merge( ret,
  260. typeof arr === "string" ?
  261. [ arr ] : arr
  262. );
  263. } else {
  264. push.call( ret, arr );
  265. }
  266. }
  267. return ret;
  268. },
  269. inArray: function( elem, arr, i ) {
  270. return arr == null ? -1 : indexOf.call( arr, elem, i );
  271. },
  272. // Support: Android <=4.0 only, PhantomJS 1 only
  273. // push.apply(_, arraylike) throws on ancient WebKit
  274. merge: function( first, second ) {
  275. var len = +second.length,
  276. j = 0,
  277. i = first.length;
  278. for ( ; j < len; j++ ) {
  279. first[ i++ ] = second[ j ];
  280. }
  281. first.length = i;
  282. return first;
  283. },
  284. grep: function( elems, callback, invert ) {
  285. var callbackInverse,
  286. matches = [],
  287. i = 0,
  288. length = elems.length,
  289. callbackExpect = !invert;
  290. // Go through the array, only saving the items
  291. // that pass the validator function
  292. for ( ; i < length; i++ ) {
  293. callbackInverse = !callback( elems[ i ], i );
  294. if ( callbackInverse !== callbackExpect ) {
  295. matches.push( elems[ i ] );
  296. }
  297. }
  298. return matches;
  299. },
  300. // arg is for internal usage only
  301. map: function( elems, callback, arg ) {
  302. var length, value,
  303. i = 0,
  304. ret = [];
  305. // Go through the array, translating each of the items to their new values
  306. if ( isArrayLike( elems ) ) {
  307. length = elems.length;
  308. for ( ; i < length; i++ ) {
  309. value = callback( elems[ i ], i, arg );
  310. if ( value != null ) {
  311. ret.push( value );
  312. }
  313. }
  314. // Go through every key on the object,
  315. } else {
  316. for ( i in elems ) {
  317. value = callback( elems[ i ], i, arg );
  318. if ( value != null ) {
  319. ret.push( value );
  320. }
  321. }
  322. }
  323. // Flatten any nested arrays
  324. return concat.apply( [], ret );
  325. },
  326. // A global GUID counter for objects
  327. guid: 1,
  328. // Bind a function to a context, optionally partially applying any
  329. // arguments.
  330. proxy: function( fn, context ) {
  331. var tmp, args, proxy;
  332. if ( typeof context === "string" ) {
  333. tmp = fn[ context ];
  334. context = fn;
  335. fn = tmp;
  336. }
  337. // Quick check to determine if target is callable, in the spec
  338. // this throws a TypeError, but we will just return undefined.
  339. if ( !jQuery.isFunction( fn ) ) {
  340. return undefined;
  341. }
  342. // Simulated bind
  343. args = slice.call( arguments, 2 );
  344. proxy = function() {
  345. return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
  346. };
  347. // Set the guid of unique handler to the same of original handler, so it can be removed
  348. proxy.guid = fn.guid = fn.guid || jQuery.guid++;
  349. return proxy;
  350. },
  351. now: Date.now,
  352. // jQuery.support is not used in Core but other projects attach their
  353. // properties to it so it needs to exist.
  354. support: support
  355. } );
  356. if ( typeof Symbol === "function" ) {
  357. jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
  358. }
  359. // Populate the class2type map
  360. jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
  361. function( i, name ) {
  362. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  363. } );
  364. function isArrayLike( obj ) {
  365. // Support: real iOS 8.2 only (not reproducible in simulator)
  366. // `in` check used to prevent JIT error (gh-2145)
  367. // hasOwn isn't used here due to false negatives
  368. // regarding Nodelist length in IE
  369. var length = !!obj && "length" in obj && obj.length,
  370. type = jQuery.type( obj );
  371. if ( type === "function" || jQuery.isWindow( obj ) ) {
  372. return false;
  373. }
  374. return type === "array" || length === 0 ||
  375. typeof length === "number" && length > 0 && ( length - 1 ) in obj;
  376. }
  377. return jQuery;
  378. } );