core.js 8.9 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.3.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. 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 = Array.isArray( copy ) ) ) ) {
  134. if ( copyIsArray ) {
  135. copyIsArray = false;
  136. clone = src && Array.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. isPlainObject: function( obj ) {
  162. var proto, Ctor;
  163. // Detect obvious negatives
  164. // Use toString instead of jQuery.type to catch host objects
  165. if ( !obj || toString.call( obj ) !== "[object Object]" ) {
  166. return false;
  167. }
  168. proto = getProto( obj );
  169. // Objects with no prototype (e.g., `Object.create( null )`) are plain
  170. if ( !proto ) {
  171. return true;
  172. }
  173. // Objects with prototype are plain iff they were constructed by a global Object function
  174. Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
  175. return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
  176. },
  177. isEmptyObject: function( obj ) {
  178. /* eslint-disable no-unused-vars */
  179. // See https://github.com/eslint/eslint/issues/6125
  180. var name;
  181. for ( name in obj ) {
  182. return false;
  183. }
  184. return true;
  185. },
  186. // Evaluates a script in a global context
  187. globalEval: function( code ) {
  188. DOMEval( code );
  189. },
  190. each: function( obj, callback ) {
  191. var length, i = 0;
  192. if ( isArrayLike( obj ) ) {
  193. length = obj.length;
  194. for ( ; i < length; i++ ) {
  195. if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
  196. break;
  197. }
  198. }
  199. } else {
  200. for ( i in obj ) {
  201. if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
  202. break;
  203. }
  204. }
  205. }
  206. return obj;
  207. },
  208. // Support: Android <=4.0 only
  209. trim: function( text ) {
  210. return text == null ?
  211. "" :
  212. ( text + "" ).replace( rtrim, "" );
  213. },
  214. // results is for internal usage only
  215. makeArray: function( arr, results ) {
  216. var ret = results || [];
  217. if ( arr != null ) {
  218. if ( isArrayLike( Object( arr ) ) ) {
  219. jQuery.merge( ret,
  220. typeof arr === "string" ?
  221. [ arr ] : arr
  222. );
  223. } else {
  224. push.call( ret, arr );
  225. }
  226. }
  227. return ret;
  228. },
  229. inArray: function( elem, arr, i ) {
  230. return arr == null ? -1 : indexOf.call( arr, elem, i );
  231. },
  232. // Support: Android <=4.0 only, PhantomJS 1 only
  233. // push.apply(_, arraylike) throws on ancient WebKit
  234. merge: function( first, second ) {
  235. var len = +second.length,
  236. j = 0,
  237. i = first.length;
  238. for ( ; j < len; j++ ) {
  239. first[ i++ ] = second[ j ];
  240. }
  241. first.length = i;
  242. return first;
  243. },
  244. grep: function( elems, callback, invert ) {
  245. var callbackInverse,
  246. matches = [],
  247. i = 0,
  248. length = elems.length,
  249. callbackExpect = !invert;
  250. // Go through the array, only saving the items
  251. // that pass the validator function
  252. for ( ; i < length; i++ ) {
  253. callbackInverse = !callback( elems[ i ], i );
  254. if ( callbackInverse !== callbackExpect ) {
  255. matches.push( elems[ i ] );
  256. }
  257. }
  258. return matches;
  259. },
  260. // arg is for internal usage only
  261. map: function( elems, callback, arg ) {
  262. var length, value,
  263. i = 0,
  264. ret = [];
  265. // Go through the array, translating each of the items to their new values
  266. if ( isArrayLike( elems ) ) {
  267. length = elems.length;
  268. for ( ; i < length; i++ ) {
  269. value = callback( elems[ i ], i, arg );
  270. if ( value != null ) {
  271. ret.push( value );
  272. }
  273. }
  274. // Go through every key on the object,
  275. } else {
  276. for ( i in elems ) {
  277. value = callback( elems[ i ], i, arg );
  278. if ( value != null ) {
  279. ret.push( value );
  280. }
  281. }
  282. }
  283. // Flatten any nested arrays
  284. return concat.apply( [], ret );
  285. },
  286. // A global GUID counter for objects
  287. guid: 1,
  288. // jQuery.support is not used in Core but other projects attach their
  289. // properties to it so it needs to exist.
  290. support: support
  291. } );
  292. if ( typeof Symbol === "function" ) {
  293. jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
  294. }
  295. // Populate the class2type map
  296. jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
  297. function( i, name ) {
  298. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  299. } );
  300. function isArrayLike( obj ) {
  301. // Support: real iOS 8.2 only (not reproducible in simulator)
  302. // `in` check used to prevent JIT error (gh-2145)
  303. // hasOwn isn't used here due to false negatives
  304. // regarding Nodelist length in IE
  305. var length = !!obj && "length" in obj && obj.length,
  306. type = toType( obj );
  307. if ( isFunction( obj ) || isWindow( obj ) ) {
  308. return false;
  309. }
  310. return type === "array" || length === 0 ||
  311. typeof length === "number" && length > 0 && ( length - 1 ) in obj;
  312. }
  313. return jQuery;
  314. } );