UPDATE 4.4.0.0
[phpmyadmin.git] / js / jquery / src / jquery / core.js
blobd3501041ede6919ae7a532e621f5a45209359b74
1 define([
2         "./var/deletedIds",
3         "./var/slice",
4         "./var/concat",
5         "./var/push",
6         "./var/indexOf",
7         "./var/class2type",
8         "./var/toString",
9         "./var/hasOwn",
10         "./var/support"
11 ], function( deletedIds, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {
13 var
14         version = "@VERSION",
16         // Define a local copy of jQuery
17         jQuery = function( selector, context ) {
18                 // The jQuery object is actually just the init constructor 'enhanced'
19                 // Need init if jQuery is called (just allow error to be thrown if not included)
20                 return new jQuery.fn.init( selector, context );
21         },
23         // Support: Android<4.1, IE<9
24         // Make sure we trim BOM and NBSP
25         rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
27         // Matches dashed string for camelizing
28         rmsPrefix = /^-ms-/,
29         rdashAlpha = /-([\da-z])/gi,
31         // Used by jQuery.camelCase as callback to replace()
32         fcamelCase = function( all, letter ) {
33                 return letter.toUpperCase();
34         };
36 jQuery.fn = jQuery.prototype = {
37         // The current version of jQuery being used
38         jquery: version,
40         constructor: jQuery,
42         // Start with an empty selector
43         selector: "",
45         // The default length of a jQuery object is 0
46         length: 0,
48         toArray: function() {
49                 return slice.call( this );
50         },
52         // Get the Nth element in the matched element set OR
53         // Get the whole matched element set as a clean array
54         get: function( num ) {
55                 return num != null ?
57                         // Return just the one element from the set
58                         ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
60                         // Return all the elements in a clean array
61                         slice.call( this );
62         },
64         // Take an array of elements and push it onto the stack
65         // (returning the new matched element set)
66         pushStack: function( elems ) {
68                 // Build a new jQuery matched element set
69                 var ret = jQuery.merge( this.constructor(), elems );
71                 // Add the old object onto the stack (as a reference)
72                 ret.prevObject = this;
73                 ret.context = this.context;
75                 // Return the newly-formed element set
76                 return ret;
77         },
79         // Execute a callback for every element in the matched set.
80         // (You can seed the arguments with an array of args, but this is
81         // only used internally.)
82         each: function( callback, args ) {
83                 return jQuery.each( this, callback, args );
84         },
86         map: function( callback ) {
87                 return this.pushStack( jQuery.map(this, function( elem, i ) {
88                         return callback.call( elem, i, elem );
89                 }));
90         },
92         slice: function() {
93                 return this.pushStack( slice.apply( this, arguments ) );
94         },
96         first: function() {
97                 return this.eq( 0 );
98         },
100         last: function() {
101                 return this.eq( -1 );
102         },
104         eq: function( i ) {
105                 var len = this.length,
106                         j = +i + ( i < 0 ? len : 0 );
107                 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
108         },
110         end: function() {
111                 return this.prevObject || this.constructor(null);
112         },
114         // For internal use only.
115         // Behaves like an Array's method, not like a jQuery method.
116         push: push,
117         sort: deletedIds.sort,
118         splice: deletedIds.splice
121 jQuery.extend = jQuery.fn.extend = function() {
122         var src, copyIsArray, copy, name, options, clone,
123                 target = arguments[0] || {},
124                 i = 1,
125                 length = arguments.length,
126                 deep = false;
128         // Handle a deep copy situation
129         if ( typeof target === "boolean" ) {
130                 deep = target;
132                 // skip the boolean and the target
133                 target = arguments[ i ] || {};
134                 i++;
135         }
137         // Handle case when target is a string or something (possible in deep copy)
138         if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
139                 target = {};
140         }
142         // extend jQuery itself if only one argument is passed
143         if ( i === length ) {
144                 target = this;
145                 i--;
146         }
148         for ( ; i < length; i++ ) {
149                 // Only deal with non-null/undefined values
150                 if ( (options = arguments[ i ]) != null ) {
151                         // Extend the base object
152                         for ( name in options ) {
153                                 src = target[ name ];
154                                 copy = options[ name ];
156                                 // Prevent never-ending loop
157                                 if ( target === copy ) {
158                                         continue;
159                                 }
161                                 // Recurse if we're merging plain objects or arrays
162                                 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
163                                         if ( copyIsArray ) {
164                                                 copyIsArray = false;
165                                                 clone = src && jQuery.isArray(src) ? src : [];
167                                         } else {
168                                                 clone = src && jQuery.isPlainObject(src) ? src : {};
169                                         }
171                                         // Never move original objects, clone them
172                                         target[ name ] = jQuery.extend( deep, clone, copy );
174                                 // Don't bring in undefined values
175                                 } else if ( copy !== undefined ) {
176                                         target[ name ] = copy;
177                                 }
178                         }
179                 }
180         }
182         // Return the modified object
183         return target;
186 jQuery.extend({
187         // Unique for each copy of jQuery on the page
188         expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
190         // Assume jQuery is ready without the ready module
191         isReady: true,
193         error: function( msg ) {
194                 throw new Error( msg );
195         },
197         noop: function() {},
199         // See test/unit/core.js for details concerning isFunction.
200         // Since version 1.3, DOM methods and functions like alert
201         // aren't supported. They return false on IE (#2968).
202         isFunction: function( obj ) {
203                 return jQuery.type(obj) === "function";
204         },
206         isArray: Array.isArray || function( obj ) {
207                 return jQuery.type(obj) === "array";
208         },
210         isWindow: function( obj ) {
211                 /* jshint eqeqeq: false */
212                 return obj != null && obj == obj.window;
213         },
215         isNumeric: function( obj ) {
216                 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
217                 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
218                 // subtraction forces infinities to NaN
219                 return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0;
220         },
222         isEmptyObject: function( obj ) {
223                 var name;
224                 for ( name in obj ) {
225                         return false;
226                 }
227                 return true;
228         },
230         isPlainObject: function( obj ) {
231                 var key;
233                 // Must be an Object.
234                 // Because of IE, we also have to check the presence of the constructor property.
235                 // Make sure that DOM nodes and window objects don't pass through, as well
236                 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
237                         return false;
238                 }
240                 try {
241                         // Not own constructor property must be Object
242                         if ( obj.constructor &&
243                                 !hasOwn.call(obj, "constructor") &&
244                                 !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
245                                 return false;
246                         }
247                 } catch ( e ) {
248                         // IE8,9 Will throw exceptions on certain host objects #9897
249                         return false;
250                 }
252                 // Support: IE<9
253                 // Handle iteration over inherited properties before own properties.
254                 if ( support.ownLast ) {
255                         for ( key in obj ) {
256                                 return hasOwn.call( obj, key );
257                         }
258                 }
260                 // Own properties are enumerated firstly, so to speed up,
261                 // if last one is own, then all properties are own.
262                 for ( key in obj ) {}
264                 return key === undefined || hasOwn.call( obj, key );
265         },
267         type: function( obj ) {
268                 if ( obj == null ) {
269                         return obj + "";
270                 }
271                 return typeof obj === "object" || typeof obj === "function" ?
272                         class2type[ toString.call(obj) ] || "object" :
273                         typeof obj;
274         },
276         // Evaluates a script in a global context
277         // Workarounds based on findings by Jim Driscoll
278         // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
279         globalEval: function( data ) {
280                 if ( data && jQuery.trim( data ) ) {
281                         // We use execScript on Internet Explorer
282                         // We use an anonymous function so that context is window
283                         // rather than jQuery in Firefox
284                         ( window.execScript || function( data ) {
285                                 window[ "eval" ].call( window, data );
286                         } )( data );
287                 }
288         },
290         // Convert dashed to camelCase; used by the css and data modules
291         // Microsoft forgot to hump their vendor prefix (#9572)
292         camelCase: function( string ) {
293                 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
294         },
296         nodeName: function( elem, name ) {
297                 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
298         },
300         // args is for internal usage only
301         each: function( obj, callback, args ) {
302                 var value,
303                         i = 0,
304                         length = obj.length,
305                         isArray = isArraylike( obj );
307                 if ( args ) {
308                         if ( isArray ) {
309                                 for ( ; i < length; i++ ) {
310                                         value = callback.apply( obj[ i ], args );
312                                         if ( value === false ) {
313                                                 break;
314                                         }
315                                 }
316                         } else {
317                                 for ( i in obj ) {
318                                         value = callback.apply( obj[ i ], args );
320                                         if ( value === false ) {
321                                                 break;
322                                         }
323                                 }
324                         }
326                 // A special, fast, case for the most common use of each
327                 } else {
328                         if ( isArray ) {
329                                 for ( ; i < length; i++ ) {
330                                         value = callback.call( obj[ i ], i, obj[ i ] );
332                                         if ( value === false ) {
333                                                 break;
334                                         }
335                                 }
336                         } else {
337                                 for ( i in obj ) {
338                                         value = callback.call( obj[ i ], i, obj[ i ] );
340                                         if ( value === false ) {
341                                                 break;
342                                         }
343                                 }
344                         }
345                 }
347                 return obj;
348         },
350         // Support: Android<4.1, IE<9
351         trim: function( text ) {
352                 return text == null ?
353                         "" :
354                         ( text + "" ).replace( rtrim, "" );
355         },
357         // results is for internal usage only
358         makeArray: function( arr, results ) {
359                 var ret = results || [];
361                 if ( arr != null ) {
362                         if ( isArraylike( Object(arr) ) ) {
363                                 jQuery.merge( ret,
364                                         typeof arr === "string" ?
365                                         [ arr ] : arr
366                                 );
367                         } else {
368                                 push.call( ret, arr );
369                         }
370                 }
372                 return ret;
373         },
375         inArray: function( elem, arr, i ) {
376                 var len;
378                 if ( arr ) {
379                         if ( indexOf ) {
380                                 return indexOf.call( arr, elem, i );
381                         }
383                         len = arr.length;
384                         i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
386                         for ( ; i < len; i++ ) {
387                                 // Skip accessing in sparse arrays
388                                 if ( i in arr && arr[ i ] === elem ) {
389                                         return i;
390                                 }
391                         }
392                 }
394                 return -1;
395         },
397         merge: function( first, second ) {
398                 var len = +second.length,
399                         j = 0,
400                         i = first.length;
402                 while ( j < len ) {
403                         first[ i++ ] = second[ j++ ];
404                 }
406                 // Support: IE<9
407                 // Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists)
408                 if ( len !== len ) {
409                         while ( second[j] !== undefined ) {
410                                 first[ i++ ] = second[ j++ ];
411                         }
412                 }
414                 first.length = i;
416                 return first;
417         },
419         grep: function( elems, callback, invert ) {
420                 var callbackInverse,
421                         matches = [],
422                         i = 0,
423                         length = elems.length,
424                         callbackExpect = !invert;
426                 // Go through the array, only saving the items
427                 // that pass the validator function
428                 for ( ; i < length; i++ ) {
429                         callbackInverse = !callback( elems[ i ], i );
430                         if ( callbackInverse !== callbackExpect ) {
431                                 matches.push( elems[ i ] );
432                         }
433                 }
435                 return matches;
436         },
438         // arg is for internal usage only
439         map: function( elems, callback, arg ) {
440                 var value,
441                         i = 0,
442                         length = elems.length,
443                         isArray = isArraylike( elems ),
444                         ret = [];
446                 // Go through the array, translating each of the items to their new values
447                 if ( isArray ) {
448                         for ( ; i < length; i++ ) {
449                                 value = callback( elems[ i ], i, arg );
451                                 if ( value != null ) {
452                                         ret.push( value );
453                                 }
454                         }
456                 // Go through every key on the object,
457                 } else {
458                         for ( i in elems ) {
459                                 value = callback( elems[ i ], i, arg );
461                                 if ( value != null ) {
462                                         ret.push( value );
463                                 }
464                         }
465                 }
467                 // Flatten any nested arrays
468                 return concat.apply( [], ret );
469         },
471         // A global GUID counter for objects
472         guid: 1,
474         // Bind a function to a context, optionally partially applying any
475         // arguments.
476         proxy: function( fn, context ) {
477                 var args, proxy, tmp;
479                 if ( typeof context === "string" ) {
480                         tmp = fn[ context ];
481                         context = fn;
482                         fn = tmp;
483                 }
485                 // Quick check to determine if target is callable, in the spec
486                 // this throws a TypeError, but we will just return undefined.
487                 if ( !jQuery.isFunction( fn ) ) {
488                         return undefined;
489                 }
491                 // Simulated bind
492                 args = slice.call( arguments, 2 );
493                 proxy = function() {
494                         return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
495                 };
497                 // Set the guid of unique handler to the same of original handler, so it can be removed
498                 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
500                 return proxy;
501         },
503         now: function() {
504                 return +( new Date() );
505         },
507         // jQuery.support is not used in Core but other projects attach their
508         // properties to it so it needs to exist.
509         support: support
512 // Populate the class2type map
513 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
514         class2type[ "[object " + name + "]" ] = name.toLowerCase();
517 function isArraylike( obj ) {
518         var length = obj.length,
519                 type = jQuery.type( obj );
521         if ( type === "function" || jQuery.isWindow( obj ) ) {
522                 return false;
523         }
525         if ( obj.nodeType === 1 && length ) {
526                 return true;
527         }
529         return type === "array" || length === 0 ||
530                 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
533 return jQuery;