core.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. "./var/isFunction",
  19. "./var/isWindow",
  20. "./core/DOMEval",
  21. "./core/toType"
  22. ], function( arr, document, getProto, slice, concat, push, indexOf,
  23. class2type, toString, hasOwn, fnToString, ObjectFunctionString,
  24. support, isFunction, isWindow, DOMEval, toType ) {
  25. "use strict";
  26. var
  27. version = "3.4.1",
  28. // Define a local copy of jQuery
  29. jQuery = function( selector, context ) {
  30. // The jQuery object is actually just the init constructor 'enhanced'
  31. // Need init if jQuery is called (just allow error to be thrown if not included)
  32. return new jQuery.fn.init( selector, context );
  33. },
  34. // Support: Android <=4.0 only
  35. // Make sure we trim BOM and NBSP
  36. rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
  37. jQuery.fn = jQuery.prototype = {
  38. // The current version of jQuery being used
  39. jquery: version,
  40. constructor: jQuery,
  41. // The default length of a jQuery object is 0
  42. length: 0,
  43. toArray: function() {
  44. return slice.call( this );
  45. },
  46. // Get the Nth element in the matched element set OR
  47. // Get the whole matched element set as a clean array
  48. get: function( num ) {
  49. // Return all the elements in a clean array
  50. if ( num == null ) {
  51. return slice.call( this );
  52. }
  53. // Return just the one element from the set
  54. return num < 0 ? this[ num + this.length ] : this[ num ];
  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" && !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. copy = options[ name ];
  126. // Prevent Object.prototype pollution
  127. // Prevent never-ending loop
  128. if ( name === "__proto__" || target === copy ) {
  129. continue;
  130. }
  131. // Recurse if we're merging plain objects or arrays
  132. if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
  133. ( copyIsArray = Array.isArray( copy ) ) ) ) {
  134. src = target[ name ];
  135. // Ensure proper type for the source value
  136. if ( copyIsArray && !Array.isArray( src ) ) {
  137. clone = [];
  138. } else if ( !copyIsArray && !jQuery.isPlainObject( src ) ) {
  139. clone = {};
  140. } else {
  141. clone = src;
  142. }
  143. copyIsArray = false;
  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. isPlainObject: function( obj ) {
  166. var proto, Ctor;
  167. // Detect obvious negatives
  168. // Use toString instead of jQuery.type to catch host objects
  169. if ( !obj || toString.call( obj ) !== "[object Object]" ) {
  170. return false;
  171. }
  172. proto = getProto( obj );
  173. // Objects with no prototype (e.g., `Object.create( null )`) are plain
  174. if ( !proto ) {
  175. return true;
  176. }
  177. // Objects with prototype are plain iff they were constructed by a global Object function
  178. Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
  179. return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
  180. },
  181. isEmptyObject: function( obj ) {
  182. var name;
  183. for ( name in obj ) {
  184. return false;
  185. }
  186. return true;
  187. },
  188. // Evaluates a script in a global context
  189. globalEval: function( code, options ) {
  190. DOMEval( code, { nonce: options && options.nonce } );
  191. },
  192. each: function( obj, callback ) {
  193. var length, i = 0;
  194. if ( isArrayLike( obj ) ) {
  195. length = obj.length;
  196. for ( ; i < length; i++ ) {
  197. if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
  198. break;
  199. }
  200. }
  201. } else {
  202. for ( i in obj ) {
  203. if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
  204. break;
  205. }
  206. }
  207. }
  208. return obj;
  209. },
  210. // Support: Android <=4.0 only
  211. trim: function( text ) {
  212. return text == null ?
  213. "" :
  214. ( text + "" ).replace( rtrim, "" );
  215. },
  216. // results is for internal usage only
  217. makeArray: function( arr, results ) {
  218. var ret = results || [];
  219. if ( arr != null ) {
  220. if ( isArrayLike( Object( arr ) ) ) {
  221. jQuery.merge( ret,
  222. typeof arr === "string" ?
  223. [ arr ] : arr
  224. );
  225. } else {
  226. push.call( ret, arr );
  227. }
  228. }
  229. return ret;
  230. },
  231. inArray: function( elem, arr, i ) {
  232. return arr == null ? -1 : indexOf.call( arr, elem, i );
  233. },
  234. // Support: Android <=4.0 only, PhantomJS 1 only
  235. // push.apply(_, arraylike) throws on ancient WebKit
  236. merge: function( first, second ) {
  237. var len = +second.length,
  238. j = 0,
  239. i = first.length;
  240. for ( ; j < len; j++ ) {
  241. first[ i++ ] = second[ j ];
  242. }
  243. first.length = i;
  244. return first;
  245. },
  246. grep: function( elems, callback, invert ) {
  247. var callbackInverse,
  248. matches = [],
  249. i = 0,
  250. length = elems.length,
  251. callbackExpect = !invert;
  252. // Go through the array, only saving the items
  253. // that pass the validator function
  254. for ( ; i < length; i++ ) {
  255. callbackInverse = !callback( elems[ i ], i );
  256. if ( callbackInverse !== callbackExpect ) {
  257. matches.push( elems[ i ] );
  258. }
  259. }
  260. return matches;
  261. },
  262. // arg is for internal usage only
  263. map: function( elems, callback, arg ) {
  264. var length, value,
  265. i = 0,
  266. ret = [];
  267. // Go through the array, translating each of the items to their new values
  268. if ( isArrayLike( elems ) ) {
  269. length = elems.length;
  270. for ( ; i < length; i++ ) {
  271. value = callback( elems[ i ], i, arg );
  272. if ( value != null ) {
  273. ret.push( value );
  274. }
  275. }
  276. // Go through every key on the object,
  277. } else {
  278. for ( i in elems ) {
  279. value = callback( elems[ i ], i, arg );
  280. if ( value != null ) {
  281. ret.push( value );
  282. }
  283. }
  284. }
  285. // Flatten any nested arrays
  286. return concat.apply( [], ret );
  287. },
  288. // A global GUID counter for objects
  289. guid: 1,
  290. // jQuery.support is not used in Core but other projects attach their
  291. // properties to it so it needs to exist.
  292. support: support
  293. } );
  294. if ( typeof Symbol === "function" ) {
  295. jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
  296. }
  297. // Populate the class2type map
  298. jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
  299. function( i, name ) {
  300. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  301. } );
  302. function isArrayLike( obj ) {
  303. // Support: real iOS 8.2 only (not reproducible in simulator)
  304. // `in` check used to prevent JIT error (gh-2145)
  305. // hasOwn isn't used here due to false negatives
  306. // regarding Nodelist length in IE
  307. var length = !!obj && "length" in obj && obj.length,
  308. type = toType( obj );
  309. if ( isFunction( obj ) || isWindow( obj ) ) {
  310. return false;
  311. }
  312. return type === "array" || length === 0 ||
  313. typeof length === "number" && length > 0 && ( length - 1 ) in obj;
  314. }
  315. return jQuery;
  316. } );