Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

495 lines
11KB

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