core.js 11 KB

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