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