Removed documentation for oneXXX and unXXX methods (not yet implementation), added...
[jquery.git] / src / event / event.js
1 jQuery.fn.extend({
2
3         // We're overriding the old toggle function, so
4         // remember it for later
5         _toggle: jQuery.fn.toggle,
6         
7         /**
8          * Toggle between two function calls every other click.
9          * Whenever a matched element is clicked, the first specified function 
10          * is fired, when clicked again, the second is fired. All subsequent 
11          * clicks continue to rotate through the two functions.
12          *
13          * Use unbind("click") to remove.
14          *
15          * @example $("p").toggle(function(){
16          *   $(this).addClass("selected");
17          * },function(){
18          *   $(this).removeClass("selected");
19          * });
20          * 
21          * @name toggle
22          * @type jQuery
23          * @param Function even The function to execute on every even click.
24          * @param Function odd The function to execute on every odd click.
25          * @cat Events
26          */
27         toggle: function() {
28                 // save reference to arguments for access in closure
29                 var a = arguments;
30                 return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) {
31                         // Figure out which function to execute
32                         this.lastToggle = this.lastToggle == 0 ? 1 : 0;
33                         
34                         // Make sure that clicks stop
35                         e.preventDefault();
36                         
37                         // and execute the function
38                         return a[this.lastToggle].apply( this, [e] ) || false;
39                 }) :
40                 
41                 // Otherwise, execute the old toggle function
42                 this._toggle.apply( this, arguments );
43         },
44         
45         /**
46          * A method for simulating hovering (moving the mouse on, and off,
47          * an object). This is a custom method which provides an 'in' to a 
48          * frequent task.
49          *
50          * Whenever the mouse cursor is moved over a matched 
51          * element, the first specified function is fired. Whenever the mouse 
52          * moves off of the element, the second specified function fires. 
53          * Additionally, checks are in place to see if the mouse is still within 
54          * the specified element itself (for example, an image inside of a div), 
55          * and if it is, it will continue to 'hover', and not move out 
56          * (a common error in using a mouseout event handler).
57          *
58          * @example $("p").hover(function(){
59          *   $(this).addClass("over");
60          * },function(){
61          *   $(this).addClass("out");
62          * });
63          *
64          * @name hover
65          * @type jQuery
66          * @param Function over The function to fire whenever the mouse is moved over a matched element.
67          * @param Function out The function to fire whenever the mouse is moved off of a matched element.
68          * @cat Events
69          */
70         hover: function(f,g) {
71                 
72                 // A private function for haandling mouse 'hovering'
73                 function handleHover(e) {
74                         // Check if mouse(over|out) are still within the same parent element
75                         var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
76         
77                         // Traverse up the tree
78                         while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
79                         
80                         // If we actually just moused on to a sub-element, ignore it
81                         if ( p == this ) return false;
82                         
83                         // Execute the right function
84                         return (e.type == "mouseover" ? f : g).apply(this, [e]);
85                 }
86                 
87                 // Bind the function to the two event listeners
88                 return this.mouseover(handleHover).mouseout(handleHover);
89         },
90         
91         /**
92          * Bind a function to be executed whenever the DOM is ready to be
93          * traversed and manipulated. This is probably the most important 
94          * function included in the event module, as it can greatly improve
95          * the response times of your web applications.
96          *
97          * In a nutshell, this is a solid replacement for using window.onload, 
98          * and attaching a function to that. By using this method, your bound Function 
99          * will be called the instant the DOM is ready to be read and manipulated, 
100          * which is exactly what 99.99% of all Javascript code needs to run.
101          * 
102          * Please ensure you have no code in your <body> onload event handler, 
103          * otherwise $(document).ready() may not fire.
104          *
105          * You can have as many $(document).ready events on your page as you like.
106          * The functions are then executed in the order they were added.
107          *
108          * @example $(document).ready(function(){ Your code here... });
109          *
110          * @name ready
111          * @type jQuery
112          * @param Function fn The function to be executed when the DOM is ready.
113          * @cat Events
114          */
115         ready: function(f) {
116                 // If the DOM is already ready
117                 if ( jQuery.isReady )
118                         // Execute the function immediately
119                         f.apply( document );
120                         
121                 // Otherwise, remember the function for later
122                 else {
123                         // Add the function to the wait list
124                         jQuery.readyList.push( f );
125                 }
126         
127                 return this;
128         }
129 });
130
131 jQuery.extend({
132         /*
133          * All the code that makes DOM Ready work nicely.
134          */
135         isReady: false,
136         readyList: [],
137         
138         // Handle when the DOM is ready
139         ready: function() {
140                 // Make sure that the DOM is not already loaded
141                 if ( !jQuery.isReady ) {
142                         // Remember that the DOM is ready
143                         jQuery.isReady = true;
144                         
145                         // If there are functions bound, to execute
146                         if ( jQuery.readyList ) {
147                                 // Execute all of them
148                                 for ( var i = 0; i < jQuery.readyList.length; i++ )
149                                         jQuery.readyList[i].apply( document );
150                                 
151                                 // Reset the list of functions
152                                 jQuery.readyList = null;
153                         }
154                         // Remove event lisenter to avoid memory leak
155                         if ( jQuery.browser.mozilla || jQuery.browser.opera )
156                                 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
157                 }
158         }
159 });
160
161 new function(){
162
163                 /**
164                  * Bind a function to the scroll event of each matched element.
165                  *
166                  * @example $("p").scroll( function() { alert("Hello"); } );
167                  * @before <p>Hello</p>
168                  * @result <p onscroll="alert('Hello');">Hello</p>
169                  *
170                  * @name scroll
171                  * @type jQuery
172                  * @param Function fn A function to bind to the scroll event on each of the matched elements.
173                  * @cat Events/Browser
174                  */
175
176                 /**
177                  * Trigger the scroll event of each matched element. This causes all of the functions
178                  * that have been bound to thet scroll event to be executed.
179                  *
180                  * @example $("p").scroll();
181                  * @before <p onscroll="alert('Hello');">Hello</p>
182                  * @result alert('Hello');
183                  *
184                  * @name scroll
185                  * @type jQuery
186                  * @cat Events/Browser
187                  */
188
189                 /**
190                  * Bind a function to the submit event of each matched element.
191                  *
192                  * @example $("#myform").submit( function() {
193                  *   return $("input", this).val().length > 0;
194                  * } );
195                  * @before <form id="myform"><input /></form>
196                  * @desc Prevents the form submission when the input has no value entered.
197                  *
198                  * @name submit
199                  * @type jQuery
200                  * @param Function fn A function to bind to the submit event on each of the matched elements.
201                  * @cat Events/Form
202                  */
203
204                 /**
205                  * Trigger the submit event of each matched element. This causes all of the functions
206                  * that have been bound to thet submit event to be executed.
207                  *
208                  * Note: This does not execute the submit method of the form element! If you need to
209                  * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
210                  *
211                  * @example $("form").submit();
212                  * @desc Triggers all submit events registered for forms, but does not submit the form
213                  *
214                  * @name submit
215                  * @type jQuery
216                  * @cat Events/Form
217                  */
218
219                 /**
220                  * Bind a function to the focus event of each matched element.
221                  *
222                  * @example $("p").focus( function() { alert("Hello"); } );
223                  * @before <p>Hello</p>
224                  * @result <p onfocus="alert('Hello');">Hello</p>
225                  *
226                  * @name focus
227                  * @type jQuery
228                  * @param Function fn A function to bind to the focus event on each of the matched elements.
229                  * @cat Events/UI
230                  */
231
232                 /**
233                  * Trigger the focus event of each matched element. This causes all of the functions
234                  * that have been bound to thet focus event to be executed.
235                  *
236                  * Note: This does not execute the focus method of the underlying elements! If you need to
237                  * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
238                  *
239                  * @example $("p").focus();
240                  * @before <p onfocus="alert('Hello');">Hello</p>
241                  * @result alert('Hello');
242                  *
243                  * @name focus
244                  * @type jQuery
245                  * @cat Events/UI
246                  */
247
248                 /**
249                  * Bind a function to the keydown event of each matched element.
250                  *
251                  * @example $("p").keydown( function() { alert("Hello"); } );
252                  * @before <p>Hello</p>
253                  * @result <p onkeydown="alert('Hello');">Hello</p>
254                  *
255                  * @name keydown
256                  * @type jQuery
257                  * @param Function fn A function to bind to the keydown event on each of the matched elements.
258                  * @cat Events/Keyboard
259                  */
260
261                 /**
262                  * Trigger the keydown event of each matched element. This causes all of the functions
263                  * that have been bound to thet keydown event to be executed.
264                  *
265                  * @example $("p").keydown();
266                  * @before <p onkeydown="alert('Hello');">Hello</p>
267                  * @result alert('Hello');
268                  *
269                  * @name keydown
270                  * @type jQuery
271                  * @cat Events/Keyboard
272                  */
273
274                 /**
275                  * Bind a function to the dblclick event of each matched element.
276                  *
277                  * @example $("p").dblclick( function() { alert("Hello"); } );
278                  * @before <p>Hello</p>
279                  * @result <p ondblclick="alert('Hello');">Hello</p>
280                  *
281                  * @name dblclick
282                  * @type jQuery
283                  * @param Function fn A function to bind to the dblclick event on each of the matched elements.
284                  * @cat Events/Mouse
285                  */
286
287                 /**
288                  * Trigger the dblclick event of each matched element. This causes all of the functions
289                  * that have been bound to thet dblclick event to be executed.
290                  *
291                  * @example $("p").dblclick();
292                  * @before <p ondblclick="alert('Hello');">Hello</p>
293                  * @result alert('Hello');
294                  *
295                  * @name dblclick
296                  * @type jQuery
297                  * @cat Events/Mouse
298                  */
299
300                 /**
301                  * Bind a function to the keypress event of each matched element.
302                  *
303                  * @example $("p").keypress( function() { alert("Hello"); } );
304                  * @before <p>Hello</p>
305                  * @result <p onkeypress="alert('Hello');">Hello</p>
306                  *
307                  * @name keypress
308                  * @type jQuery
309                  * @param Function fn A function to bind to the keypress event on each of the matched elements.
310                  * @cat Events/Keyboard
311                  */
312
313                 /**
314                  * Trigger the keypress event of each matched element. This causes all of the functions
315                  * that have been bound to thet keypress event to be executed.
316                  *
317                  * @example $("p").keypress();
318                  * @before <p onkeypress="alert('Hello');">Hello</p>
319                  * @result alert('Hello');
320                  *
321                  * @name keypress
322                  * @type jQuery
323                  * @cat Events/Keyboard
324                  */
325
326                 /**
327                  * Bind a function to the error event of each matched element.
328                  *
329                  * @example $("p").error( function() { alert("Hello"); } );
330                  * @before <p>Hello</p>
331                  * @result <p onerror="alert('Hello');">Hello</p>
332                  *
333                  * @name error
334                  * @type jQuery
335                  * @param Function fn A function to bind to the error event on each of the matched elements.
336                  * @cat Events/Browser
337                  */
338
339                 /**
340                  * Trigger the error event of each matched element. This causes all of the functions
341                  * that have been bound to thet error event to be executed.
342                  *
343                  * @example $("p").error();
344                  * @before <p onerror="alert('Hello');">Hello</p>
345                  * @result alert('Hello');
346                  *
347                  * @name error
348                  * @type jQuery
349                  * @cat Events/Browser
350                  */
351
352                 /**
353                  * Bind a function to the blur event of each matched element.
354                  *
355                  * @example $("p").blur( function() { alert("Hello"); } );
356                  * @before <p>Hello</p>
357                  * @result <p onblur="alert('Hello');">Hello</p>
358                  *
359                  * @name blur
360                  * @type jQuery
361                  * @param Function fn A function to bind to the blur event on each of the matched elements.
362                  * @cat Events/UI
363                  */
364
365                 /**
366                  * Trigger the blur event of each matched element. This causes all of the functions
367                  * that have been bound to thet blur event to be executed.
368                  *
369                  * Note: This does not execute the blur method of the underlying elements! If you need to
370                  * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
371                  *
372                  * @example $("p").blur();
373                  * @before <p onblur="alert('Hello');">Hello</p>
374                  * @result alert('Hello');
375                  *
376                  * @name blur
377                  * @type jQuery
378                  * @cat Events/UI
379                  */
380
381                 /**
382                  * Bind a function to the load event of each matched element.
383                  *
384                  * @example $("p").load( function() { alert("Hello"); } );
385                  * @before <p>Hello</p>
386                  * @result <p onload="alert('Hello');">Hello</p>
387                  *
388                  * @name load
389                  * @type jQuery
390                  * @param Function fn A function to bind to the load event on each of the matched elements.
391                  * @cat Events/Browser
392                  */
393
394                 /**
395                  * Trigger the load event of each matched element. This causes all of the functions
396                  * that have been bound to thet load event to be executed.
397                  *
398                  * Marked as private: Calling load() without arguments throws exception because the ajax load
399                  * does not handle it.
400                  *
401                  * @example $("p").load();
402                  * @before <p onload="alert('Hello');">Hello</p>
403                  * @result alert('Hello');
404                  *
405                  * @name load
406                  * @private
407                  * @type jQuery
408                  * @cat Events/Browser
409                  */
410
411                 /**
412                  * Bind a function to the select event of each matched element.
413                  *
414                  * @example $("p").select( function() { alert("Hello"); } );
415                  * @before <p>Hello</p>
416                  * @result <p onselect="alert('Hello');">Hello</p>
417                  *
418                  * @name select
419                  * @type jQuery
420                  * @param Function fn A function to bind to the select event on each of the matched elements.
421                  * @cat Events/Form
422                  */
423
424                 /**
425                  * Trigger the select event of each matched element. This causes all of the functions
426                  * that have been bound to thet select event to be executed.
427                  *
428                  * @example $("p").select();
429                  * @before <p onselect="alert('Hello');">Hello</p>
430                  * @result alert('Hello');
431                  *
432                  * @name select
433                  * @type jQuery
434                  * @cat Events/Form
435                  */
436
437                 /**
438                  * Bind a function to the mouseup event of each matched element.
439                  *
440                  * @example $("p").mouseup( function() { alert("Hello"); } );
441                  * @before <p>Hello</p>
442                  * @result <p onmouseup="alert('Hello');">Hello</p>
443                  *
444                  * @name mouseup
445                  * @type jQuery
446                  * @param Function fn A function to bind to the mouseup event on each of the matched elements.
447                  * @cat Events/Mouse
448                  */
449
450                 /**
451                  * Trigger the mouseup event of each matched element. This causes all of the functions
452                  * that have been bound to thet mouseup event to be executed.
453                  *
454                  * @example $("p").mouseup();
455                  * @before <p onmouseup="alert('Hello');">Hello</p>
456                  * @result alert('Hello');
457                  *
458                  * @name mouseup
459                  * @type jQuery
460                  * @cat Events/Mouse
461                  */
462
463                 /**
464                  * Bind a function to the unload event of each matched element.
465                  *
466                  * @example $("p").unload( function() { alert("Hello"); } );
467                  * @before <p>Hello</p>
468                  * @result <p onunload="alert('Hello');">Hello</p>
469                  *
470                  * @name unload
471                  * @type jQuery
472                  * @param Function fn A function to bind to the unload event on each of the matched elements.
473                  * @cat Events/Browser
474                  */
475
476                 /**
477                  * Trigger the unload event of each matched element. This causes all of the functions
478                  * that have been bound to thet unload event to be executed.
479                  *
480                  * @example $("p").unload();
481                  * @before <p onunload="alert('Hello');">Hello</p>
482                  * @result alert('Hello');
483                  *
484                  * @name unload
485                  * @type jQuery
486                  * @cat Events/Browser
487                  */
488
489                 /**
490                  * Bind a function to the change event of each matched element.
491                  *
492                  * @example $("p").change( function() { alert("Hello"); } );
493                  * @before <p>Hello</p>
494                  * @result <p onchange="alert('Hello');">Hello</p>
495                  *
496                  * @name change
497                  * @type jQuery
498                  * @param Function fn A function to bind to the change event on each of the matched elements.
499                  * @cat Events/Form
500                  */
501
502                 /**
503                  * Trigger the change event of each matched element. This causes all of the functions
504                  * that have been bound to thet change event to be executed.
505                  *
506                  * @example $("p").change();
507                  * @before <p onchange="alert('Hello');">Hello</p>
508                  * @result alert('Hello');
509                  *
510                  * @name change
511                  * @type jQuery
512                  * @cat Events/Form
513                  */
514
515                 /**
516                  * Bind a function to the mouseout event of each matched element.
517                  *
518                  * @example $("p").mouseout( function() { alert("Hello"); } );
519                  * @before <p>Hello</p>
520                  * @result <p onmouseout="alert('Hello');">Hello</p>
521                  *
522                  * @name mouseout
523                  * @type jQuery
524                  * @param Function fn A function to bind to the mouseout event on each of the matched elements.
525                  * @cat Events/Mouse
526                  */
527
528                 /**
529                  * Trigger the mouseout event of each matched element. This causes all of the functions
530                  * that have been bound to thet mouseout event to be executed.
531                  *
532                  * @example $("p").mouseout();
533                  * @before <p onmouseout="alert('Hello');">Hello</p>
534                  * @result alert('Hello');
535                  *
536                  * @name mouseout
537                  * @type jQuery
538                  * @cat Events/Mouse
539                  */
540
541                 /**
542                  * Bind a function to the keyup event of each matched element.
543                  *
544                  * @example $("p").keyup( function() { alert("Hello"); } );
545                  * @before <p>Hello</p>
546                  * @result <p onkeyup="alert('Hello');">Hello</p>
547                  *
548                  * @name keyup
549                  * @type jQuery
550                  * @param Function fn A function to bind to the keyup event on each of the matched elements.
551                  * @cat Events/Keyboard
552                  */
553
554                 /**
555                  * Trigger the keyup event of each matched element. This causes all of the functions
556                  * that have been bound to thet keyup event to be executed.
557                  *
558                  * @example $("p").keyup();
559                  * @before <p onkeyup="alert('Hello');">Hello</p>
560                  * @result alert('Hello');
561                  *
562                  * @name keyup
563                  * @type jQuery
564                  * @cat Events/Keyboard
565                  */
566
567                 /**
568                  * Bind a function to the click event of each matched element.
569                  *
570                  * @example $("p").click( function() { alert("Hello"); } );
571                  * @before <p>Hello</p>
572                  * @result <p onclick="alert('Hello');">Hello</p>
573                  *
574                  * @name click
575                  * @type jQuery
576                  * @param Function fn A function to bind to the click event on each of the matched elements.
577                  * @cat Events/Mouse
578                  */
579
580                 /**
581                  * Trigger the click event of each matched element. This causes all of the functions
582                  * that have been bound to thet click event to be executed.
583                  *
584                  * @example $("p").click();
585                  * @before <p onclick="alert('Hello');">Hello</p>
586                  * @result alert('Hello');
587                  *
588                  * @name click
589                  * @type jQuery
590                  * @cat Events/Mouse
591                  */
592
593                 /**
594                  * Bind a function to the resize event of each matched element.
595                  *
596                  * @example $("p").resize( function() { alert("Hello"); } );
597                  * @before <p>Hello</p>
598                  * @result <p onresize="alert('Hello');">Hello</p>
599                  *
600                  * @name resize
601                  * @type jQuery
602                  * @param Function fn A function to bind to the resize event on each of the matched elements.
603                  * @cat Events/Browser
604                  */
605
606                 /**
607                  * Trigger the resize event of each matched element. This causes all of the functions
608                  * that have been bound to thet resize event to be executed.
609                  *
610                  * @example $("p").resize();
611                  * @before <p onresize="alert('Hello');">Hello</p>
612                  * @result alert('Hello');
613                  *
614                  * @name resize
615                  * @type jQuery
616                  * @cat Events/Browser
617                  */
618
619                 /**
620                  * Bind a function to the mousemove event of each matched element.
621                  *
622                  * @example $("p").mousemove( function() { alert("Hello"); } );
623                  * @before <p>Hello</p>
624                  * @result <p onmousemove="alert('Hello');">Hello</p>
625                  *
626                  * @name mousemove
627                  * @type jQuery
628                  * @param Function fn A function to bind to the mousemove event on each of the matched elements.
629                  * @cat Events/Mouse
630                  */
631
632                 /**
633                  * Trigger the mousemove event of each matched element. This causes all of the functions
634                  * that have been bound to thet mousemove event to be executed.
635                  *
636                  * @example $("p").mousemove();
637                  * @before <p onmousemove="alert('Hello');">Hello</p>
638                  * @result alert('Hello');
639                  *
640                  * @name mousemove
641                  * @type jQuery
642                  * @cat Events/Mouse
643                  */
644
645                 /**
646                  * Bind a function to the mousedown event of each matched element.
647                  *
648                  * @example $("p").mousedown( function() { alert("Hello"); } );
649                  * @before <p>Hello</p>
650                  * @result <p onmousedown="alert('Hello');">Hello</p>
651                  *
652                  * @name mousedown
653                  * @type jQuery
654                  * @param Function fn A function to bind to the mousedown event on each of the matched elements.
655                  * @cat Events/Mouse
656                  */
657
658                 /**
659                  * Trigger the mousedown event of each matched element. This causes all of the functions
660                  * that have been bound to thet mousedown event to be executed.
661                  *
662                  * @example $("p").mousedown();
663                  * @before <p onmousedown="alert('Hello');">Hello</p>
664                  * @result alert('Hello');
665                  *
666                  * @name mousedown
667                  * @type jQuery
668                  * @cat Events/Mouse
669                  */
670                  
671                 /**
672                  * Bind a function to the mouseover event of each matched element.
673                  *
674                  * @example $("p").mouseover( function() { alert("Hello"); } );
675                  * @before <p>Hello</p>
676                  * @result <p onmouseover="alert('Hello');">Hello</p>
677                  *
678                  * @name mouseover
679                  * @type jQuery
680                  * @param Function fn A function to bind to the mousedown event on each of the matched elements.
681                  * @cat Events/Mouse
682                  */
683
684                 /**
685                  * Trigger the mouseover event of each matched element. This causes all of the functions
686                  * that have been bound to thet mousedown event to be executed.
687                  *
688                  * @example $("p").mouseover();
689                  * @before <p onmouseover="alert('Hello');">Hello</p>
690                  * @result alert('Hello');
691                  *
692                  * @name mouseover
693                  * @type jQuery
694                  * @cat Events/Mouse
695                  */
696
697         var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
698                 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 
699                 "submit,keydown,keypress,keyup,error").split(",");
700
701         // Go through all the event names, but make sure that
702         // it is enclosed properly
703         for ( var i = 0; i < e.length; i++ ) new function(){
704                         
705                 var o = e[i];
706                 
707                 // Handle event binding
708                 jQuery.fn[o] = function(f){
709                         return f ? this.bind(o, f) : this.trigger(o);
710                 };
711                 
712                 // Handle event unbinding
713                 // TODO remove
714                 jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
715                 
716                 // Finally, handle events that only fire once
717                 // TODO remove
718                 jQuery.fn["one"+o] = function(f){
719                         // save cloned reference to this
720                         var element = jQuery(this);
721                         var handler = function() {
722                                 // unbind itself when executed
723                                 element.unbind(o, handler);
724                                 element = null;
725                                 // apply original handler with the same arguments
726                                 return f.apply(this, arguments);
727                         };
728                         return this.bind(o, handler);
729                 };
730                         
731         };
732         
733         // If Mozilla is used
734         if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
735                 // Use the handy event callback
736                 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
737         
738         // If IE is used, use the excellent hack by Matthias Miller
739         // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
740         } else if ( jQuery.browser.msie ) {
741         
742                 // Only works if you document.write() it
743                 document.write("<scr" + "ipt id=__ie_init defer=true " + 
744                         "src=//:><\/script>");
745         
746                 // Use the defer script hack
747                 var script = document.getElementById("__ie_init");
748                 if (script) // script does not exist if jQuery is loaded dynamically
749                         script.onreadystatechange = function() {
750                                 if ( this.readyState != "complete" ) return;
751                                 this.parentNode.removeChild( this );
752                                 jQuery.ready();
753                         };
754         
755                 // Clear from memory
756                 script = null;
757         
758         // If Safari  is used
759         } else if ( jQuery.browser.safari ) {
760                 // Continually check to see if the document.readyState is valid
761                 jQuery.safariTimer = setInterval(function(){
762                         // loaded and complete are both valid states
763                         if ( document.readyState == "loaded" || 
764                                 document.readyState == "complete" ) {
765         
766                                 // If either one are found, remove the timer
767                                 clearInterval( jQuery.safariTimer );
768                                 jQuery.safariTimer = null;
769         
770                                 // and execute any waiting functions
771                                 jQuery.ready();
772                         }
773                 }, 10);
774         } 
775
776         // A fallback to window.onload, that will always work
777         jQuery.event.add( window, "load", jQuery.ready );
778         
779 };
780
781 // Clean up after IE to avoid memory leaks
782 if (jQuery.browser.msie) jQuery(window).unload(function() {
783         var event = jQuery.event, global = event.global;
784         for (var type in global) {
785                 var els = global[type], i = els.length;
786                 if (i>0) do if (type != 'unload') event.remove(els[i-1], type); while (--i);
787         }
788 });