Switch to using String.prototype.trim from String.trim as it's more-widely available.
[jquery.git] / src / core.js
1 // Define a local copy of jQuery
2 var jQuery = function( selector, context ) {
3                 // The jQuery object is actually just the init constructor 'enhanced'
4                 return new jQuery.fn.init( selector, context );
5         },
6
7         // Map over jQuery in case of overwrite
8         _jQuery = window.jQuery,
9
10         // Map over the $ in case of overwrite
11         _$ = window.$,
12
13         // Use the correct document accordingly with window argument (sandbox)
14         document = window.document,
15
16         // A central reference to the root jQuery(document)
17         rootjQuery,
18
19         // A simple way to check for HTML strings or ID strings
20         // (both of which we optimize for)
21         quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w\-]+)$/,
22
23         // Is it a simple selector
24         isSimple = /^.[^:#\[\.,]*$/,
25
26         // Check if a string has a non-whitespace character in it
27         rnotwhite = /\S/,
28
29         // Used for trimming whitespace
30         trimLeft = /^\s+/,
31         trimRight = /\s+$/,
32
33         // Match a standalone tag
34         rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
35
36         // Keep a UserAgent string for use with jQuery.browser
37         userAgent = navigator.userAgent,
38
39         // For matching the engine and version of the browser
40         browserMatch,
41         
42         // Has the ready events already been bound?
43         readyBound = false,
44         
45         // The functions to execute on DOM ready
46         readyList = [],
47
48         // The ready event handler
49         DOMContentLoaded,
50
51         // Save a reference to some core methods
52         toString = Object.prototype.toString,
53         hasOwn = Object.prototype.hasOwnProperty,
54         push = Array.prototype.push,
55         slice = Array.prototype.slice,
56         trim = String.prototype.trim,
57         indexOf = Array.prototype.indexOf;
58
59 jQuery.fn = jQuery.prototype = {
60         init: function( selector, context ) {
61                 var match, elem, ret, doc;
62
63                 // Handle $(""), $(null), or $(undefined)
64                 if ( !selector ) {
65                         return this;
66                 }
67
68                 // Handle $(DOMElement)
69                 if ( selector.nodeType ) {
70                         this.context = this[0] = selector;
71                         this.length = 1;
72                         return this;
73                 }
74                 
75                 // The body element only exists once, optimize finding it
76                 if ( selector === "body" && !context ) {
77                         this.context = document;
78                         this[0] = document.body;
79                         this.selector = "body";
80                         this.length = 1;
81                         return this;
82                 }
83
84                 // Handle HTML strings
85                 if ( typeof selector === "string" ) {
86                         // Are we dealing with HTML string or an ID?
87                         match = quickExpr.exec( selector );
88
89                         // Verify a match, and that no context was specified for #id
90                         if ( match && (match[1] || !context) ) {
91
92                                 // HANDLE: $(html) -> $(array)
93                                 if ( match[1] ) {
94                                         doc = (context ? context.ownerDocument || context : document);
95
96                                         // If a single string is passed in and it's a single tag
97                                         // just do a createElement and skip the rest
98                                         ret = rsingleTag.exec( selector );
99
100                                         if ( ret ) {
101                                                 if ( jQuery.isPlainObject( context ) ) {
102                                                         selector = [ document.createElement( ret[1] ) ];
103                                                         jQuery.fn.attr.call( selector, context, true );
104
105                                                 } else {
106                                                         selector = [ doc.createElement( ret[1] ) ];
107                                                 }
108
109                                         } else {
110                                                 ret = buildFragment( [ match[1] ], [ doc ] );
111                                                 selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
112                                         }
113                                         
114                                         return jQuery.merge( this, selector );
115                                         
116                                 // HANDLE: $("#id")
117                                 } else {
118                                         elem = document.getElementById( match[2] );
119
120                                         if ( elem ) {
121                                                 // Handle the case where IE and Opera return items
122                                                 // by name instead of ID
123                                                 if ( elem.id !== match[2] ) {
124                                                         return rootjQuery.find( selector );
125                                                 }
126
127                                                 // Otherwise, we inject the element directly into the jQuery object
128                                                 this.length = 1;
129                                                 this[0] = elem;
130                                         }
131
132                                         this.context = document;
133                                         this.selector = selector;
134                                         return this;
135                                 }
136
137                         // HANDLE: $("TAG")
138                         } else if ( !context && /^\w+$/.test( selector ) ) {
139                                 this.selector = selector;
140                                 this.context = document;
141                                 selector = document.getElementsByTagName( selector );
142                                 return jQuery.merge( this, selector );
143
144                         // HANDLE: $(expr, $(...))
145                         } else if ( !context || context.jquery ) {
146                                 return (context || rootjQuery).find( selector );
147
148                         // HANDLE: $(expr, context)
149                         // (which is just equivalent to: $(context).find(expr)
150                         } else {
151                                 return jQuery( context ).find( selector );
152                         }
153
154                 // HANDLE: $(function)
155                 // Shortcut for document ready
156                 } else if ( jQuery.isFunction( selector ) ) {
157                         return rootjQuery.ready( selector );
158                 }
159
160                 if (selector.selector !== undefined) {
161                         this.selector = selector.selector;
162                         this.context = selector.context;
163                 }
164
165                 return jQuery.makeArray( selector, this );
166         },
167
168         // Start with an empty selector
169         selector: "",
170
171         // The current version of jQuery being used
172         jquery: "@VERSION",
173
174         // The default length of a jQuery object is 0
175         length: 0,
176
177         // The number of elements contained in the matched element set
178         size: function() {
179                 return this.length;
180         },
181
182         toArray: function() {
183                 return slice.call( this, 0 );
184         },
185
186         // Get the Nth element in the matched element set OR
187         // Get the whole matched element set as a clean array
188         get: function( num ) {
189                 return num == null ?
190
191                         // Return a 'clean' array
192                         this.toArray() :
193
194                         // Return just the object
195                         ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] );
196         },
197
198         // Take an array of elements and push it onto the stack
199         // (returning the new matched element set)
200         pushStack: function( elems, name, selector ) {
201                 // Build a new jQuery matched element set
202                 var ret = jQuery();
203
204                 if ( jQuery.isArray( elems ) ) {
205                         push.apply( ret, elems );
206                 
207                 } else {
208                         jQuery.merge( ret, elems );
209                 }
210
211                 // Add the old object onto the stack (as a reference)
212                 ret.prevObject = this;
213
214                 ret.context = this.context;
215
216                 if ( name === "find" ) {
217                         ret.selector = this.selector + (this.selector ? " " : "") + selector;
218                 } else if ( name ) {
219                         ret.selector = this.selector + "." + name + "(" + selector + ")";
220                 }
221
222                 // Return the newly-formed element set
223                 return ret;
224         },
225
226         // Execute a callback for every element in the matched set.
227         // (You can seed the arguments with an array of args, but this is
228         // only used internally.)
229         each: function( callback, args ) {
230                 return jQuery.each( this, callback, args );
231         },
232         
233         ready: function( fn ) {
234                 // Attach the listeners
235                 jQuery.bindReady();
236
237                 // If the DOM is already ready
238                 if ( jQuery.isReady ) {
239                         // Execute the function immediately
240                         fn.call( document, jQuery );
241
242                 // Otherwise, remember the function for later
243                 } else if ( readyList ) {
244                         // Add the function to the wait list
245                         readyList.push( fn );
246                 }
247
248                 return this;
249         },
250         
251         eq: function( i ) {
252                 return i === -1 ?
253                         this.slice( i ) :
254                         this.slice( i, +i + 1 );
255         },
256
257         first: function() {
258                 return this.eq( 0 );
259         },
260
261         last: function() {
262                 return this.eq( -1 );
263         },
264
265         slice: function() {
266                 return this.pushStack( slice.apply( this, arguments ),
267                         "slice", slice.call(arguments).join(",") );
268         },
269
270         map: function( callback ) {
271                 return this.pushStack( jQuery.map(this, function( elem, i ) {
272                         return callback.call( elem, i, elem );
273                 }));
274         },
275         
276         end: function() {
277                 return this.prevObject || jQuery(null);
278         },
279
280         // For internal use only.
281         // Behaves like an Array's method, not like a jQuery method.
282         push: push,
283         sort: [].sort,
284         splice: [].splice
285 };
286
287 // Give the init function the jQuery prototype for later instantiation
288 jQuery.fn.init.prototype = jQuery.fn;
289
290 jQuery.extend = jQuery.fn.extend = function() {
291         // copy reference to target object
292         var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy;
293
294         // Handle a deep copy situation
295         if ( typeof target === "boolean" ) {
296                 deep = target;
297                 target = arguments[1] || {};
298                 // skip the boolean and the target
299                 i = 2;
300         }
301
302         // Handle case when target is a string or something (possible in deep copy)
303         if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
304                 target = {};
305         }
306
307         // extend jQuery itself if only one argument is passed
308         if ( length === i ) {
309                 target = this;
310                 --i;
311         }
312
313         for ( ; i < length; i++ ) {
314                 // Only deal with non-null/undefined values
315                 if ( (options = arguments[ i ]) != null ) {
316                         // Extend the base object
317                         for ( name in options ) {
318                                 src = target[ name ];
319                                 copy = options[ name ];
320
321                                 // Prevent never-ending loop
322                                 if ( target === copy ) {
323                                         continue;
324                                 }
325
326                                 // Recurse if we're merging object literal values or arrays
327                                 if ( deep && copy && ( jQuery.isPlainObject(copy) || jQuery.isArray(copy) ) ) {
328                                         var clone = src && ( jQuery.isPlainObject(src) || jQuery.isArray(src) ) ? src
329                                                 : jQuery.isArray(copy) ? [] : {};
330
331                                         // Never move original objects, clone them
332                                         target[ name ] = jQuery.extend( deep, clone, copy );
333
334                                 // Don't bring in undefined values
335                                 } else if ( copy !== undefined ) {
336                                         target[ name ] = copy;
337                                 }
338                         }
339                 }
340         }
341
342         // Return the modified object
343         return target;
344 };
345
346 jQuery.extend({
347         noConflict: function( deep ) {
348                 window.$ = _$;
349
350                 if ( deep ) {
351                         window.jQuery = _jQuery;
352                 }
353
354                 return jQuery;
355         },
356         
357         // Is the DOM ready to be used? Set to true once it occurs.
358         isReady: false,
359         
360         // Handle when the DOM is ready
361         ready: function() {
362                 // Make sure that the DOM is not already loaded
363                 if ( !jQuery.isReady ) {
364                         // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
365                         if ( !document.body ) {
366                                 return setTimeout( jQuery.ready, 13 );
367                         }
368
369                         // Remember that the DOM is ready
370                         jQuery.isReady = true;
371
372                         // If there are functions bound, to execute
373                         if ( readyList ) {
374                                 // Execute all of them
375                                 var fn, i = 0;
376                                 while ( (fn = readyList[ i++ ]) ) {
377                                         fn.call( document, jQuery );
378                                 }
379
380                                 // Reset the list of functions
381                                 readyList = null;
382                         }
383
384                         // Trigger any bound ready events
385                         if ( jQuery.fn.triggerHandler ) {
386                                 jQuery( document ).triggerHandler( "ready" );
387                         }
388                 }
389         },
390         
391         bindReady: function() {
392                 if ( readyBound ) {
393                         return;
394                 }
395
396                 readyBound = true;
397
398                 // Catch cases where $(document).ready() is called after the
399                 // browser event has already occurred.
400                 if ( document.readyState === "complete" ) {
401                         return jQuery.ready();
402                 }
403
404                 // Mozilla, Opera and webkit nightlies currently support this event
405                 if ( document.addEventListener ) {
406                         // Use the handy event callback
407                         document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
408                         
409                         // A fallback to window.onload, that will always work
410                         window.addEventListener( "load", jQuery.ready, false );
411
412                 // If IE event model is used
413                 } else if ( document.attachEvent ) {
414                         // ensure firing before onload,
415                         // maybe late but safe also for iframes
416                         document.attachEvent("onreadystatechange", DOMContentLoaded);
417                         
418                         // A fallback to window.onload, that will always work
419                         window.attachEvent( "onload", jQuery.ready );
420
421                         // If IE and not a frame
422                         // continually check to see if the document is ready
423                         var toplevel = false;
424
425                         try {
426                                 toplevel = window.frameElement == null;
427                         } catch(e) {}
428
429                         if ( document.documentElement.doScroll && toplevel ) {
430                                 doScrollCheck();
431                         }
432                 }
433         },
434
435         // See test/unit/core.js for details concerning isFunction.
436         // Since version 1.3, DOM methods and functions like alert
437         // aren't supported. They return false on IE (#2968).
438         isFunction: function( obj ) {
439                 return toString.call(obj) === "[object Function]";
440         },
441
442         isArray: function( obj ) {
443                 return toString.call(obj) === "[object Array]";
444         },
445
446         isPlainObject: function( obj ) {
447                 // Must be an Object.
448                 // Because of IE, we also have to check the presence of the constructor property.
449                 // Make sure that DOM nodes and window objects don't pass through, as well
450                 if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) {
451                         return false;
452                 }
453                 
454                 // Not own constructor property must be Object
455                 if ( obj.constructor &&
456                         !hasOwn.call(obj, "constructor") &&
457                         !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
458                         return false;
459                 }
460                 
461                 // Own properties are enumerated firstly, so to speed up,
462                 // if last one is own, then all properties are own.
463         
464                 var key;
465                 for ( key in obj ) {}
466                 
467                 return key === undefined || hasOwn.call( obj, key );
468         },
469
470         isEmptyObject: function( obj ) {
471                 for ( var name in obj ) {
472                         return false;
473                 }
474                 return true;
475         },
476         
477         error: function( msg ) {
478                 throw msg;
479         },
480         
481         parseJSON: function( data ) {
482                 if ( typeof data !== "string" || !data ) {
483                         return null;
484                 }
485
486                 // Make sure leading/trailing whitespace is removed (IE can't handle it)
487                 data = jQuery.trim( data );
488                 
489                 // Make sure the incoming data is actual JSON
490                 // Logic borrowed from http://json.org/json2.js
491                 if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
492                         .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
493                         .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) {
494
495                         // Try to use the native JSON parser first
496                         return window.JSON && window.JSON.parse ?
497                                 window.JSON.parse( data ) :
498                                 (new Function("return " + data))();
499
500                 } else {
501                         jQuery.error( "Invalid JSON: " + data );
502                 }
503         },
504
505         noop: function() {},
506
507         // Evalulates a script in a global context
508         globalEval: function( data ) {
509                 if ( data && rnotwhite.test(data) ) {
510                         // Inspired by code by Andrea Giammarchi
511                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
512                         var head = document.getElementsByTagName("head")[0] || document.documentElement,
513                                 script = document.createElement("script");
514
515                         script.type = "text/javascript";
516
517                         if ( jQuery.support.scriptEval ) {
518                                 script.appendChild( document.createTextNode( data ) );
519                         } else {
520                                 script.text = data;
521                         }
522
523                         // Use insertBefore instead of appendChild to circumvent an IE6 bug.
524                         // This arises when a base node is used (#2709).
525                         head.insertBefore( script, head.firstChild );
526                         head.removeChild( script );
527                 }
528         },
529
530         nodeName: function( elem, name ) {
531                 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
532         },
533
534         // args is for internal usage only
535         each: function( object, callback, args ) {
536                 var name, i = 0,
537                         length = object.length,
538                         isObj = length === undefined || jQuery.isFunction(object);
539
540                 if ( args ) {
541                         if ( isObj ) {
542                                 for ( name in object ) {
543                                         if ( callback.apply( object[ name ], args ) === false ) {
544                                                 break;
545                                         }
546                                 }
547                         } else {
548                                 for ( ; i < length; ) {
549                                         if ( callback.apply( object[ i++ ], args ) === false ) {
550                                                 break;
551                                         }
552                                 }
553                         }
554
555                 // A special, fast, case for the most common use of each
556                 } else {
557                         if ( isObj ) {
558                                 for ( name in object ) {
559                                         if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
560                                                 break;
561                                         }
562                                 }
563                         } else {
564                                 for ( var value = object[0];
565                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {}
566                         }
567                 }
568
569                 return object;
570         },
571
572         // Use native String.trim function wherever possible
573         trim: trim ?
574                 function( text ) {
575                         return text == null ?
576                                 "" :
577                                 trim.call( text );
578                 } :
579
580                 // Otherwise use our own trimming functionality
581                 function( text ) {
582                         return text == null ?
583                                 "" :
584                                 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
585                 },
586
587         // results is for internal usage only
588         makeArray: function( array, results ) {
589                 var ret = results || [];
590
591                 if ( array != null ) {
592                         // The window, strings (and functions) also have 'length'
593                         // The extra typeof function check is to prevent crashes
594                         // in Safari 2 (See: #3039)
595                         if ( array.length == null || typeof array === "string" || jQuery.isFunction(array) || (typeof array !== "function" && array.setInterval) ) {
596                                 push.call( ret, array );
597                         } else {
598                                 jQuery.merge( ret, array );
599                         }
600                 }
601
602                 return ret;
603         },
604
605         inArray: function( elem, array ) {
606                 if ( array.indexOf ) {
607                         return array.indexOf( elem );
608                 }
609
610                 for ( var i = 0, length = array.length; i < length; i++ ) {
611                         if ( array[ i ] === elem ) {
612                                 return i;
613                         }
614                 }
615
616                 return -1;
617         },
618
619         merge: function( first, second ) {
620                 var i = first.length, j = 0;
621
622                 if ( typeof second.length === "number" ) {
623                         for ( var l = second.length; j < l; j++ ) {
624                                 first[ i++ ] = second[ j ];
625                         }
626                 
627                 } else {
628                         while ( second[j] !== undefined ) {
629                                 first[ i++ ] = second[ j++ ];
630                         }
631                 }
632
633                 first.length = i;
634
635                 return first;
636         },
637
638         grep: function( elems, callback, inv ) {
639                 var ret = [], retVal;
640                 inv = !!inv;
641
642                 // Go through the array, only saving the items
643                 // that pass the validator function
644                 for ( var i = 0, length = elems.length; i < length; i++ ) {
645                         retVal = !!callback( elems[ i ], i );
646                         if ( inv !== retVal ) {
647                                 ret.push( elems[ i ] );
648                         }
649                 }
650
651                 return ret;
652         },
653
654         // arg is for internal usage only
655         map: function( elems, callback, arg ) {
656                 var ret = [], value;
657
658                 // Go through the array, translating each of the items to their
659                 // new value (or values).
660                 for ( var i = 0, length = elems.length; i < length; i++ ) {
661                         value = callback( elems[ i ], i, arg );
662
663                         if ( value != null ) {
664                                 ret[ ret.length ] = value;
665                         }
666                 }
667
668                 return ret.concat.apply( [], ret );
669         },
670
671         // A global GUID counter for objects
672         guid: 1,
673
674         proxy: function( fn, proxy, thisObject ) {
675                 if ( arguments.length === 2 ) {
676                         if ( typeof proxy === "string" ) {
677                                 thisObject = fn;
678                                 fn = thisObject[ proxy ];
679                                 proxy = undefined;
680
681                         } else if ( proxy && !jQuery.isFunction( proxy ) ) {
682                                 thisObject = proxy;
683                                 proxy = undefined;
684                         }
685                 }
686
687                 if ( !proxy && fn ) {
688                         proxy = function() {
689                                 return fn.apply( thisObject || this, arguments );
690                         };
691                 }
692
693                 // Set the guid of unique handler to the same of original handler, so it can be removed
694                 if ( fn ) {
695                         proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
696                 }
697
698                 // So proxy can be declared as an argument
699                 return proxy;
700         },
701
702         // Use of jQuery.browser is frowned upon.
703         // More details: http://docs.jquery.com/Utilities/jQuery.browser
704         uaMatch: function( ua ) {
705                 ua = ua.toLowerCase();
706
707                 var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
708                         /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
709                         /(msie) ([\w.]+)/.exec( ua ) ||
710                         !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
711                         [];
712
713                 return { browser: match[1] || "", version: match[2] || "0" };
714         },
715
716         browser: {}
717 });
718
719 browserMatch = jQuery.uaMatch( userAgent );
720 if ( browserMatch.browser ) {
721         jQuery.browser[ browserMatch.browser ] = true;
722         jQuery.browser.version = browserMatch.version;
723 }
724
725 // Deprecated, use jQuery.browser.webkit instead
726 if ( jQuery.browser.webkit ) {
727         jQuery.browser.safari = true;
728 }
729
730 if ( indexOf ) {
731         jQuery.inArray = function( elem, array ) {
732                 return indexOf.call( array, elem );
733         };
734 }
735
736 // Verify that \s matches non-breaking spaces
737 // (IE fails on this test)
738 if ( !/\s/.test( "\xA0" ) ) {
739         trimLeft = /^[\s\xA0]+/;
740         trimRight = /[\s\xA0]+$/;
741 }
742
743 // All jQuery objects should point back to these
744 rootjQuery = jQuery(document);
745
746 // Cleanup functions for the document ready method
747 if ( document.addEventListener ) {
748         DOMContentLoaded = function() {
749                 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
750                 jQuery.ready();
751         };
752
753 } else if ( document.attachEvent ) {
754         DOMContentLoaded = function() {
755                 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
756                 if ( document.readyState === "complete" ) {
757                         document.detachEvent( "onreadystatechange", DOMContentLoaded );
758                         jQuery.ready();
759                 }
760         };
761 }
762
763 // The DOM ready check for Internet Explorer
764 function doScrollCheck() {
765         if ( jQuery.isReady ) {
766                 return;
767         }
768
769         try {
770                 // If IE is used, use the trick by Diego Perini
771                 // http://javascript.nwbox.com/IEContentLoaded/
772                 document.documentElement.doScroll("left");
773         } catch(e) {
774                 setTimeout( doScrollCheck, 1 );
775                 return;
776         }
777
778         // and execute any waiting functions
779         jQuery.ready();
780 }
781
782 function evalScript( i, elem ) {
783         if ( elem.src ) {
784                 jQuery.ajax({
785                         url: elem.src,
786                         async: false,
787                         dataType: "script"
788                 });
789         } else {
790                 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
791         }
792
793         if ( elem.parentNode ) {
794                 elem.parentNode.removeChild( elem );
795         }
796 }
797
798 // Mutifunctional method to get and set values to a collection
799 // The value/s can be optionally by executed if its a function
800 function access( elems, key, value, exec, fn, pass ) {
801         var length = elems.length;
802         
803         // Setting many attributes
804         if ( typeof key === "object" ) {
805                 for ( var k in key ) {
806                         access( elems, k, key[k], exec, fn, value );
807                 }
808                 return elems;
809         }
810         
811         // Setting one attribute
812         if ( value !== undefined ) {
813                 // Optionally, function values get executed if exec is true
814                 exec = !pass && exec && jQuery.isFunction(value);
815                 
816                 for ( var i = 0; i < length; i++ ) {
817                         fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
818                 }
819                 
820                 return elems;
821         }
822         
823         // Getting an attribute
824         return length ? fn( elems[0], key ) : undefined;
825 }
826
827 function now() {
828         return (new Date()).getTime();
829 }