2 * A number of helper functions used for managing events.
3 * Many of the ideas behind this code orignated from
4 * Dean Edwards' addEvent library.
8 // Bind an event to an element
9 // Original by Dean Edwards
10 add: function(element, type, handler, data) {
11 // For whatever reason, IE has trouble passing the window object
12 // around, causing it to be cloned in the process
13 if ( jQuery.browser.msie && element.setInterval != undefined )
16 // if data is passed, bind to handler
20 // Make sure that the function being executed has a unique ID
22 handler.guid = this.guid++;
24 // Init the element's event structure
28 // Get the current list of functions bound to this event
29 var handlers = element.events[type];
31 // If it hasn't been initialized yet
33 // Init the event handler queue
34 handlers = element.events[type] = {};
36 // Remember an existing handler, if it's already there
37 if (element["on" + type])
38 handlers[0] = element["on" + type];
41 // Add the function to the element's handler list
42 handlers[handler.guid] = handler;
44 // And bind the global event handler to the element
45 element["on" + type] = this.handle;
47 // Remember the function in a global list (for triggering)
48 if (!this.global[type])
49 this.global[type] = [];
50 this.global[type].push( element );
56 // Detach an event or set of events from an element
57 remove: function(element, type, handler) {
59 if ( type && type.type )
60 delete element.events[ type.type ][ type.handler.guid ];
61 else if (type && element.events[type])
63 delete element.events[type][handler.guid];
65 for ( var i in element.events[type] )
66 delete element.events[type][i];
68 for ( var j in element.events )
69 this.remove( element, j );
72 trigger: function(type,data,element) {
73 // Clone the incoming data, if any
74 data = jQuery.makeArray(data || []);
76 // Handle a global trigger
78 var g = this.global[type];
80 for ( var i = 0, gl = g.length; i < gl; i++ )
81 this.trigger( type, data, g[i] );
83 // Handle triggering a single element
84 } else if ( element["on" + type] ) {
85 // Pass along a fake event
86 data.unshift( this.fix({ type: type, target: element }) );
89 element["on" + type].apply( element, data );
93 handle: function(event) {
94 if ( typeof jQuery == "undefined" ) return false;
96 // Empty object is for triggered events with no data
97 event = jQuery.event.fix( event || window.event || {} );
99 // returned undefined or false
102 var c = this.events[event.type];
104 var args = [].slice.call( arguments, 1 );
105 args.unshift( event );
108 // Pass in a reference to the handler function itself
109 // So that we can later remove it
110 args[0].handler = c[j];
111 args[0].data = c[j].data;
113 if ( c[j].apply( this, args ) === false ) {
114 event.preventDefault();
115 event.stopPropagation();
120 // Clean up added properties in IE to prevent memory leak
121 if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = event.handler = event.data = null;
126 fix: function(event) {
127 // Fix target property, if necessary
128 if ( !event.target && event.srcElement )
129 event.target = event.srcElement;
131 // Calculate pageX/Y if missing and clientX/Y available
132 if ( typeof event.pageX == "undefined" && typeof event.clientX != "undefined" ) {
133 var e = document.documentElement, b = document.body;
134 event.pageX = event.clientX + (e.scrollLeft || b.scrollLeft);
135 event.pageY = event.clientY + (e.scrollTop || b.scrollTop);
138 // check if target is a textnode (safari)
139 if (event.target.nodeType == 3) {
140 // store a copy of the original event object
141 // and clone because target is read only
142 var originalEvent = event;
143 event = jQuery.extend({}, originalEvent);
145 // get parentnode from textnode
146 event.target = originalEvent.target.parentNode;
148 // add preventDefault and stopPropagation since
149 // they will not work on the clone
150 event.preventDefault = function() {
151 return originalEvent.preventDefault();
153 event.stopPropagation = function() {
154 return originalEvent.stopPropagation();
158 // fix preventDefault and stopPropagation
159 if (!event.preventDefault)
160 event.preventDefault = function() {
161 this.returnValue = false;
164 if (!event.stopPropagation)
165 event.stopPropagation = function() {
166 this.cancelBubble = true;
176 * Binds a handler to a particular event (like click) for each matched element.
177 * The event handler is passed an event object that you can use to prevent
178 * default behaviour. To stop both default action and event bubbling, your handler
179 * has to return false.
181 * In most cases, you can define your event handlers as anonymous functions
182 * (see first example). In cases where that is not possible, you can pass additional
183 * data as the second paramter (and the handler function as the third), see
186 * @example $("p").bind( "click", function() {
187 * alert( $(this).text() );
189 * @before <p>Hello</p>
190 * @result alert("Hello")
192 * @example var handler = function(event) {
193 * alert(event.data.foo);
195 * $("p").bind( "click", {foo: "bar"}, handler)
196 * @result alert("bar")
197 * @desc Pass some additional data to the event handler.
199 * @example $("form").bind( "submit", function() { return false; } )
200 * @desc Cancel a default action and prevent it from bubbling by returning false
201 * from your function.
203 * @example $("form").bind( "submit", function(event) {
204 * event.preventDefault();
206 * @desc Cancel only the default action by using the preventDefault method.
209 * @example $("form").bind( "submit", function(event) {
210 * event.stopPropagation();
212 * @desc Stop only an event from bubbling by using the stopPropagation method.
216 * @param String type An event type
217 * @param Object data (optional) Additional data passed to the event handler as event.data
218 * @param Function fn A function to bind to the event on each of the set of matched elements
221 bind: function( type, data, fn ) {
222 return this.each(function(){
223 jQuery.event.add( this, type, fn || data, data );
228 * Binds a handler to a particular event (like click) for each matched element.
229 * The handler is executed only once for each element. Otherwise, the same rules
230 * as described in bind() apply.
231 The event handler is passed an event object that you can use to prevent
232 * default behaviour. To stop both default action and event bubbling, your handler
233 * has to return false.
235 * In most cases, you can define your event handlers as anonymous functions
236 * (see first example). In cases where that is not possible, you can pass additional
237 * data as the second paramter (and the handler function as the third), see
240 * @example $("p").one( "click", function() {
241 * alert( $(this).text() );
243 * @before <p>Hello</p>
244 * @result alert("Hello")
248 * @param String type An event type
249 * @param Object data (optional) Additional data passed to the event handler as event.data
250 * @param Function fn A function to bind to the event on each of the set of matched elements
253 one: function( type, data, fn ) {
254 return this.each(function(){
255 jQuery.event.add( this, type, function(event) {
256 jQuery(this).unbind(event);
257 return (fn || data).apply( this, arguments);
263 * The opposite of bind, removes a bound event from each of the matched
264 * elements. You must pass the identical function that was used in the original
267 * @example $("p").unbind( "click", function() { alert("Hello"); } )
268 * @before <p onclick="alert('Hello');">Hello</p>
269 * @result [ <p>Hello</p> ]
273 * @param String type An event type
274 * @param Function fn A function to unbind from the event on each of the set of matched elements
279 * Removes all bound events of a particular type from each of the matched
282 * @example $("p").unbind( "click" )
283 * @before <p onclick="alert('Hello');">Hello</p>
284 * @result [ <p>Hello</p> ]
288 * @param String type An event type
293 * Removes all bound events from each of the matched elements.
295 * @example $("p").unbind()
296 * @before <p onclick="alert('Hello');">Hello</p>
297 * @result [ <p>Hello</p> ]
303 unbind: function( type, fn ) {
304 return this.each(function(){
305 jQuery.event.remove( this, type, fn );
310 * Trigger a type of event on every matched element.
312 * @example $("p").trigger("click")
313 * @before <p click="alert('hello')">Hello</p>
314 * @result alert('hello')
318 * @param String type An event type to trigger.
321 trigger: function( type, data ) {
322 return this.each(function(){
323 jQuery.event.trigger( type, data, this );
327 // We're overriding the old toggle function, so
328 // remember it for later
329 _toggle: jQuery.fn.toggle,
332 * Toggle between two function calls every other click.
333 * Whenever a matched element is clicked, the first specified function
334 * is fired, when clicked again, the second is fired. All subsequent
335 * clicks continue to rotate through the two functions.
337 * Use unbind("click") to remove.
339 * @example $("p").toggle(function(){
340 * $(this).addClass("selected");
342 * $(this).removeClass("selected");
347 * @param Function even The function to execute on every even click.
348 * @param Function odd The function to execute on every odd click.
352 // save reference to arguments for access in closure
354 return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) {
355 // Figure out which function to execute
356 this.lastToggle = this.lastToggle == 0 ? 1 : 0;
358 // Make sure that clicks stop
361 // and execute the function
362 return a[this.lastToggle].apply( this, [e] ) || false;
365 // Otherwise, execute the old toggle function
366 this._toggle.apply( this, arguments );
370 * A method for simulating hovering (moving the mouse on, and off,
371 * an object). This is a custom method which provides an 'in' to a
374 * Whenever the mouse cursor is moved over a matched
375 * element, the first specified function is fired. Whenever the mouse
376 * moves off of the element, the second specified function fires.
377 * Additionally, checks are in place to see if the mouse is still within
378 * the specified element itself (for example, an image inside of a div),
379 * and if it is, it will continue to 'hover', and not move out
380 * (a common error in using a mouseout event handler).
382 * @example $("p").hover(function(){
383 * $(this).addClass("over");
385 * $(this).addClass("out");
390 * @param Function over The function to fire whenever the mouse is moved over a matched element.
391 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
394 hover: function(f,g) {
396 // A private function for handling mouse 'hovering'
397 function handleHover(e) {
398 // Check if mouse(over|out) are still within the same parent element
399 var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
401 // Traverse up the tree
402 while ( p && p != this ) try { p = p.parentNode } catch(e) { p = this; };
404 // If we actually just moused on to a sub-element, ignore it
405 if ( p == this ) return false;
407 // Execute the right function
408 return (e.type == "mouseover" ? f : g).apply(this, [e]);
411 // Bind the function to the two event listeners
412 return this.mouseover(handleHover).mouseout(handleHover);
416 * Bind a function to be executed whenever the DOM is ready to be
417 * traversed and manipulated. This is probably the most important
418 * function included in the event module, as it can greatly improve
419 * the response times of your web applications.
421 * In a nutshell, this is a solid replacement for using window.onload,
422 * and attaching a function to that. By using this method, your bound Function
423 * will be called the instant the DOM is ready to be read and manipulated,
424 * which is exactly what 99.99% of all Javascript code needs to run.
426 * Please ensure you have no code in your <body> onload event handler,
427 * otherwise $(document).ready() may not fire.
429 * You can have as many $(document).ready events on your page as you like.
430 * The functions are then executed in the order they were added.
432 * @example $(document).ready(function(){ Your code here... });
436 * @param Function fn The function to be executed when the DOM is ready.
440 // If the DOM is already ready
441 if ( jQuery.isReady )
442 // Execute the function immediately
445 // Otherwise, remember the function for later
447 // Add the function to the wait list
448 jQuery.readyList.push( f );
457 * All the code that makes DOM Ready work nicely.
462 // Handle when the DOM is ready
464 // Make sure that the DOM is not already loaded
465 if ( !jQuery.isReady ) {
466 // Remember that the DOM is ready
467 jQuery.isReady = true;
469 // If there are functions bound, to execute
470 if ( jQuery.readyList ) {
471 // Execute all of them
472 for ( var i = 0; i < jQuery.readyList.length; i++ )
473 jQuery.readyList[i].apply( document );
475 // Reset the list of functions
476 jQuery.readyList = null;
478 // Remove event lisenter to avoid memory leak
479 if ( jQuery.browser.mozilla || jQuery.browser.opera )
480 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
488 * Bind a function to the scroll event of each matched element.
490 * @example $("p").scroll( function() { alert("Hello"); } );
491 * @before <p>Hello</p>
492 * @result <p onscroll="alert('Hello');">Hello</p>
496 * @param Function fn A function to bind to the scroll event on each of the matched elements.
497 * @cat Events/Browser
501 * Trigger the scroll event of each matched element. This causes all of the functions
502 * that have been bound to thet scroll event to be executed.
504 * @example $("p").scroll();
505 * @before <p onscroll="alert('Hello');">Hello</p>
506 * @result alert('Hello');
510 * @cat Events/Browser
514 * Bind a function to the submit event of each matched element.
516 * @example $("#myform").submit( function() {
517 * return $("input", this).val().length > 0;
519 * @before <form id="myform"><input /></form>
520 * @desc Prevents the form submission when the input has no value entered.
524 * @param Function fn A function to bind to the submit event on each of the matched elements.
529 * Trigger the submit event of each matched element. This causes all of the functions
530 * that have been bound to thet submit event to be executed.
532 * Note: This does not execute the submit method of the form element! If you need to
533 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
535 * @example $("form").submit();
536 * @desc Triggers all submit events registered for forms, but does not submit the form
544 * Bind a function to the focus event of each matched element.
546 * @example $("p").focus( function() { alert("Hello"); } );
547 * @before <p>Hello</p>
548 * @result <p onfocus="alert('Hello');">Hello</p>
552 * @param Function fn A function to bind to the focus event on each of the matched elements.
557 * Trigger the focus event of each matched element. This causes all of the functions
558 * that have been bound to thet focus event to be executed.
560 * Note: This does not execute the focus method of the underlying elements! If you need to
561 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
563 * @example $("p").focus();
564 * @before <p onfocus="alert('Hello');">Hello</p>
565 * @result alert('Hello');
573 * Bind a function to the keydown event of each matched element.
575 * @example $("p").keydown( function() { alert("Hello"); } );
576 * @before <p>Hello</p>
577 * @result <p onkeydown="alert('Hello');">Hello</p>
581 * @param Function fn A function to bind to the keydown event on each of the matched elements.
582 * @cat Events/Keyboard
586 * Trigger the keydown event of each matched element. This causes all of the functions
587 * that have been bound to thet keydown event to be executed.
589 * @example $("p").keydown();
590 * @before <p onkeydown="alert('Hello');">Hello</p>
591 * @result alert('Hello');
595 * @cat Events/Keyboard
599 * Bind a function to the dblclick event of each matched element.
601 * @example $("p").dblclick( function() { alert("Hello"); } );
602 * @before <p>Hello</p>
603 * @result <p ondblclick="alert('Hello');">Hello</p>
607 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
612 * Trigger the dblclick event of each matched element. This causes all of the functions
613 * that have been bound to thet dblclick event to be executed.
615 * @example $("p").dblclick();
616 * @before <p ondblclick="alert('Hello');">Hello</p>
617 * @result alert('Hello');
625 * Bind a function to the keypress event of each matched element.
627 * @example $("p").keypress( function() { alert("Hello"); } );
628 * @before <p>Hello</p>
629 * @result <p onkeypress="alert('Hello');">Hello</p>
633 * @param Function fn A function to bind to the keypress event on each of the matched elements.
634 * @cat Events/Keyboard
638 * Trigger the keypress event of each matched element. This causes all of the functions
639 * that have been bound to thet keypress event to be executed.
641 * @example $("p").keypress();
642 * @before <p onkeypress="alert('Hello');">Hello</p>
643 * @result alert('Hello');
647 * @cat Events/Keyboard
651 * Bind a function to the error event of each matched element.
653 * @example $("p").error( function() { alert("Hello"); } );
654 * @before <p>Hello</p>
655 * @result <p onerror="alert('Hello');">Hello</p>
659 * @param Function fn A function to bind to the error event on each of the matched elements.
660 * @cat Events/Browser
664 * Trigger the error event of each matched element. This causes all of the functions
665 * that have been bound to thet error event to be executed.
667 * @example $("p").error();
668 * @before <p onerror="alert('Hello');">Hello</p>
669 * @result alert('Hello');
673 * @cat Events/Browser
677 * Bind a function to the blur event of each matched element.
679 * @example $("p").blur( function() { alert("Hello"); } );
680 * @before <p>Hello</p>
681 * @result <p onblur="alert('Hello');">Hello</p>
685 * @param Function fn A function to bind to the blur event on each of the matched elements.
690 * Trigger the blur event of each matched element. This causes all of the functions
691 * that have been bound to thet blur event to be executed.
693 * Note: This does not execute the blur method of the underlying elements! If you need to
694 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
696 * @example $("p").blur();
697 * @before <p onblur="alert('Hello');">Hello</p>
698 * @result alert('Hello');
706 * Bind a function to the load event of each matched element.
708 * @example $("p").load( function() { alert("Hello"); } );
709 * @before <p>Hello</p>
710 * @result <p onload="alert('Hello');">Hello</p>
714 * @param Function fn A function to bind to the load event on each of the matched elements.
715 * @cat Events/Browser
719 * Trigger the load event of each matched element. This causes all of the functions
720 * that have been bound to thet load event to be executed.
722 * Marked as private: Calling load() without arguments throws exception because the ajax load
723 * does not handle it.
725 * @example $("p").load();
726 * @before <p onload="alert('Hello');">Hello</p>
727 * @result alert('Hello');
732 * @cat Events/Browser
736 * Bind a function to the select event of each matched element.
738 * @example $("p").select( function() { alert("Hello"); } );
739 * @before <p>Hello</p>
740 * @result <p onselect="alert('Hello');">Hello</p>
744 * @param Function fn A function to bind to the select event on each of the matched elements.
749 * Trigger the select event of each matched element. This causes all of the functions
750 * that have been bound to thet select event to be executed.
752 * @example $("p").select();
753 * @before <p onselect="alert('Hello');">Hello</p>
754 * @result alert('Hello');
762 * Bind a function to the mouseup event of each matched element.
764 * @example $("p").mouseup( function() { alert("Hello"); } );
765 * @before <p>Hello</p>
766 * @result <p onmouseup="alert('Hello');">Hello</p>
770 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
775 * Trigger the mouseup event of each matched element. This causes all of the functions
776 * that have been bound to thet mouseup event to be executed.
778 * @example $("p").mouseup();
779 * @before <p onmouseup="alert('Hello');">Hello</p>
780 * @result alert('Hello');
788 * Bind a function to the unload event of each matched element.
790 * @example $("p").unload( function() { alert("Hello"); } );
791 * @before <p>Hello</p>
792 * @result <p onunload="alert('Hello');">Hello</p>
796 * @param Function fn A function to bind to the unload event on each of the matched elements.
797 * @cat Events/Browser
801 * Trigger the unload event of each matched element. This causes all of the functions
802 * that have been bound to thet unload event to be executed.
804 * @example $("p").unload();
805 * @before <p onunload="alert('Hello');">Hello</p>
806 * @result alert('Hello');
810 * @cat Events/Browser
814 * Bind a function to the change event of each matched element.
816 * @example $("p").change( function() { alert("Hello"); } );
817 * @before <p>Hello</p>
818 * @result <p onchange="alert('Hello');">Hello</p>
822 * @param Function fn A function to bind to the change event on each of the matched elements.
827 * Trigger the change event of each matched element. This causes all of the functions
828 * that have been bound to thet change event to be executed.
830 * @example $("p").change();
831 * @before <p onchange="alert('Hello');">Hello</p>
832 * @result alert('Hello');
840 * Bind a function to the mouseout event of each matched element.
842 * @example $("p").mouseout( function() { alert("Hello"); } );
843 * @before <p>Hello</p>
844 * @result <p onmouseout="alert('Hello');">Hello</p>
848 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
853 * Trigger the mouseout event of each matched element. This causes all of the functions
854 * that have been bound to thet mouseout event to be executed.
856 * @example $("p").mouseout();
857 * @before <p onmouseout="alert('Hello');">Hello</p>
858 * @result alert('Hello');
866 * Bind a function to the keyup event of each matched element.
868 * @example $("p").keyup( function() { alert("Hello"); } );
869 * @before <p>Hello</p>
870 * @result <p onkeyup="alert('Hello');">Hello</p>
874 * @param Function fn A function to bind to the keyup event on each of the matched elements.
875 * @cat Events/Keyboard
879 * Trigger the keyup event of each matched element. This causes all of the functions
880 * that have been bound to thet keyup event to be executed.
882 * @example $("p").keyup();
883 * @before <p onkeyup="alert('Hello');">Hello</p>
884 * @result alert('Hello');
888 * @cat Events/Keyboard
892 * Bind a function to the click event of each matched element.
894 * @example $("p").click( function() { alert("Hello"); } );
895 * @before <p>Hello</p>
896 * @result <p onclick="alert('Hello');">Hello</p>
900 * @param Function fn A function to bind to the click event on each of the matched elements.
905 * Trigger the click event of each matched element. This causes all of the functions
906 * that have been bound to thet click event to be executed.
908 * @example $("p").click();
909 * @before <p onclick="alert('Hello');">Hello</p>
910 * @result alert('Hello');
918 * Bind a function to the resize event of each matched element.
920 * @example $("p").resize( function() { alert("Hello"); } );
921 * @before <p>Hello</p>
922 * @result <p onresize="alert('Hello');">Hello</p>
926 * @param Function fn A function to bind to the resize event on each of the matched elements.
927 * @cat Events/Browser
931 * Trigger the resize event of each matched element. This causes all of the functions
932 * that have been bound to thet resize event to be executed.
934 * @example $("p").resize();
935 * @before <p onresize="alert('Hello');">Hello</p>
936 * @result alert('Hello');
940 * @cat Events/Browser
944 * Bind a function to the mousemove event of each matched element.
946 * @example $("p").mousemove( function() { alert("Hello"); } );
947 * @before <p>Hello</p>
948 * @result <p onmousemove="alert('Hello');">Hello</p>
952 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
957 * Trigger the mousemove event of each matched element. This causes all of the functions
958 * that have been bound to thet mousemove event to be executed.
960 * @example $("p").mousemove();
961 * @before <p onmousemove="alert('Hello');">Hello</p>
962 * @result alert('Hello');
970 * Bind a function to the mousedown event of each matched element.
972 * @example $("p").mousedown( function() { alert("Hello"); } );
973 * @before <p>Hello</p>
974 * @result <p onmousedown="alert('Hello');">Hello</p>
978 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
983 * Trigger the mousedown event of each matched element. This causes all of the functions
984 * that have been bound to thet mousedown event to be executed.
986 * @example $("p").mousedown();
987 * @before <p onmousedown="alert('Hello');">Hello</p>
988 * @result alert('Hello');
996 * Bind a function to the mouseover event of each matched element.
998 * @example $("p").mouseover( function() { alert("Hello"); } );
999 * @before <p>Hello</p>
1000 * @result <p onmouseover="alert('Hello');">Hello</p>
1004 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
1009 * Trigger the mouseover event of each matched element. This causes all of the functions
1010 * that have been bound to thet mousedown event to be executed.
1012 * @example $("p").mouseover();
1013 * @before <p onmouseover="alert('Hello');">Hello</p>
1014 * @result alert('Hello');
1021 var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
1022 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
1023 "submit,keydown,keypress,keyup,error").split(",");
1025 // Go through all the event names, but make sure that
1026 // it is enclosed properly
1027 for ( var i = 0; i < e.length; i++ ) new function(){
1031 // Handle event binding
1032 jQuery.fn[o] = function(f){
1033 return f ? this.bind(o, f) : this.trigger(o);
1038 // If Mozilla is used
1039 if ( jQuery.browser.mozilla || jQuery.browser.opera )
1040 // Use the handy event callback
1041 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
1043 // If IE is used, use the excellent hack by Matthias Miller
1044 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
1045 else if ( jQuery.browser.msie ) {
1047 // Only works if you document.write() it
1048 document.write("<scr" + "ipt id=__ie_init defer=true " +
1049 "src=//:><\/script>");
1051 // Use the defer script hack
1052 var script = document.getElementById("__ie_init");
1054 // script does not exist if jQuery is loaded dynamically
1056 script.onreadystatechange = function() {
1057 if ( this.readyState != "complete" ) return;
1058 this.parentNode.removeChild( this );
1062 // Clear from memory
1065 // If Safari is used
1066 } else if ( jQuery.browser.safari )
1067 // Continually check to see if the document.readyState is valid
1068 jQuery.safariTimer = setInterval(function(){
1069 // loaded and complete are both valid states
1070 if ( document.readyState == "loaded" ||
1071 document.readyState == "complete" ) {
1073 // If either one are found, remove the timer
1074 clearInterval( jQuery.safariTimer );
1075 jQuery.safariTimer = null;
1077 // and execute any waiting functions
1082 // A fallback to window.onload, that will always work
1083 jQuery.event.add( window, "load", jQuery.ready );
1087 // Clean up after IE to avoid memory leaks
1088 if (jQuery.browser.msie)
1089 jQuery(window).bind("unload", function() {
1090 var global = jQuery.event.global;
1091 for ( var type in global ) {
1092 var els = global[type], i = els.length;
1093 if ( i && type != 'unload' )
1095 jQuery.event.remove(els[i-1], type);