core.js 11 KB

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