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 // Make sure that the function being executed has a unique ID
18 handler.guid = this.guid++;
20 // if data is passed, bind to handler
21 if( data != undefined ) {
22 // Create temporary function pointer to original handler
25 // Create unique handler function, wrapped around original handler
26 handler = function() {
27 // Pass arguments and context to original handler
28 return fn.apply(this, arguments);
31 // Store data in unique handler
34 // Set the guid of unique handler to the same of original handler, so it can be removed
35 handler.guid = fn.guid;
38 // Init the element's event structure
43 element.$handle = function() {
44 // returned undefined or false
47 // Handle the second event of a trigger and when
48 // an event is called after a page has unloaded
49 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
52 val = jQuery.event.handle.apply(element, arguments);
57 // Get the current list of functions bound to this event
58 var handlers = element.$events[type];
60 // Init the event handler queue
62 handlers = element.$events[type] = {};
64 // And bind the global event handler to the element
65 if (element.addEventListener)
66 element.addEventListener(type, element.$handle, false);
68 element.attachEvent("on" + type, element.$handle);
71 // Add the function to the element's handler list
72 handlers[handler.guid] = handler;
74 // Keep track of which events have been used, for global triggering
75 this.global[type] = true;
81 // Detach an event or set of events from an element
82 remove: function(element, type, handler) {
83 var events = element.$events, ret, index;
86 // type is actually an event object here
87 if ( type && type.type ) {
88 handler = type.handler;
93 for ( type in events )
94 this.remove( element, type );
96 } else if ( events[type] ) {
97 // remove the given handler for the given type
99 delete events[type][handler.guid];
101 // remove all handlers for the given type
103 for ( handler in element.$events[type] )
104 delete events[type][handler];
106 // remove generic event handler if no more handlers exist
107 for ( ret in events[type] ) break;
109 if (element.removeEventListener)
110 element.removeEventListener(type, element.$handle, false);
112 element.detachEvent("on" + type, element.$handle);
118 // Remove the expando if it's no longer used
119 for ( ret in events ) break;
121 element.$handle = element.$events = null;
125 trigger: function(type, data, element, native, extra) {
126 // Clone the incoming data, if any
127 data = jQuery.makeArray(data || []);
129 // Handle a global trigger
131 // Only trigger if we've ever bound an event for it
132 if ( this.global[type] )
133 jQuery("*").add([window, document]).trigger(type, data);
135 // Handle triggering a single element
137 var val, ret, fn = jQuery.isFunction( element[ type ] || null );
139 // Pass along a fake event
140 data.unshift( this.fix({ type: type, target: element }) );
143 if ( jQuery.isFunction( element.$handle ) )
144 val = element.$handle.apply( element, data );
146 // Handle triggering native .onfoo handlers
147 if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false )
150 // Handle triggering of extra function
151 if ( extra && extra.apply( element, data ) === false )
154 // Trigger the native events (except for clicks on links)
155 if ( fn && native !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
156 this.triggered = true;
160 this.triggered = false;
166 handle: function(event) {
167 // returned undefined or false
170 // Empty object is for triggered events with no data
171 event = jQuery.event.fix( event || window.event || {} );
173 var c = this.$events && this.$events[event.type], args = Array.prototype.slice.call( arguments, 1 );
174 args.unshift( event );
177 // Pass in a reference to the handler function itself
178 // So that we can later remove it
179 args[0].handler = c[j];
180 args[0].data = c[j].data;
182 var tmp = c[j].apply( this, args );
187 if ( tmp === false ) {
188 event.preventDefault();
189 event.stopPropagation();
193 // Clean up added properties in IE to prevent memory leak
194 if (jQuery.browser.msie)
195 event.target = event.preventDefault = event.stopPropagation =
196 event.handler = event.data = null;
201 fix: function(event) {
202 // store a copy of the original event object
203 // and clone to set read-only properties
204 var originalEvent = event;
205 event = jQuery.extend({}, originalEvent);
207 // add preventDefault and stopPropagation since
208 // they will not work on the clone
209 event.preventDefault = function() {
210 // if preventDefault exists run it on the original event
211 if (originalEvent.preventDefault)
212 originalEvent.preventDefault();
213 // otherwise set the returnValue property of the original event to false (IE)
214 originalEvent.returnValue = false;
216 event.stopPropagation = function() {
217 // if stopPropagation exists run it on the original event
218 if (originalEvent.stopPropagation)
219 originalEvent.stopPropagation();
220 // otherwise set the cancelBubble property of the original event to true (IE)
221 originalEvent.cancelBubble = true;
224 // Fix target property, if necessary
225 if ( !event.target && event.srcElement )
226 event.target = event.srcElement;
228 // check if target is a textnode (safari)
229 if (jQuery.browser.safari && event.target.nodeType == 3)
230 event.target = originalEvent.target.parentNode;
232 // Add relatedTarget, if necessary
233 if ( !event.relatedTarget && event.fromElement )
234 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
236 // Calculate pageX/Y if missing and clientX/Y available
237 if ( event.pageX == null && event.clientX != null ) {
238 var e = document.documentElement, b = document.body;
239 event.pageX = event.clientX + (e && e.scrollLeft || b.scrollLeft || 0);
240 event.pageY = event.clientY + (e && e.scrollTop || b.scrollTop || 0);
243 // Add which for key events
244 if ( !event.which && (event.charCode || event.keyCode) )
245 event.which = event.charCode || event.keyCode;
247 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
248 if ( !event.metaKey && event.ctrlKey )
249 event.metaKey = event.ctrlKey;
251 // Add which for click: 1 == left; 2 == middle; 3 == right
252 // Note: button is not normalized, so don't use it
253 if ( !event.which && event.button )
254 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
263 * Binds a handler to a particular event (like click) for each matched element.
264 * The event handler is passed an event object that you can use to prevent
265 * default behaviour. To stop both default action and event bubbling, your handler
266 * has to return false.
268 * In most cases, you can define your event handlers as anonymous functions
269 * (see first example). In cases where that is not possible, you can pass additional
270 * data as the second parameter (and the handler function as the third), see
273 * Calling bind with an event type of "unload" will automatically
274 * use the one method instead of bind to prevent memory leaks.
276 * @example $("p").bind("click", function(){
277 * alert( $(this).text() );
279 * @before <p>Hello</p>
280 * @result alert("Hello")
282 * @example function handler(event) {
283 * alert(event.data.foo);
285 * $("p").bind("click", {foo: "bar"}, handler)
286 * @result alert("bar")
287 * @desc Pass some additional data to the event handler.
289 * @example $("form").bind("submit", function() { return false; })
290 * @desc Cancel a default action and prevent it from bubbling by returning false
291 * from your function.
293 * @example $("form").bind("submit", function(event){
294 * event.preventDefault();
296 * @desc Cancel only the default action by using the preventDefault method.
299 * @example $("form").bind("submit", function(event){
300 * event.stopPropagation();
302 * @desc Stop only an event from bubbling by using the stopPropagation method.
306 * @param String type An event type
307 * @param Object data (optional) Additional data passed to the event handler as event.data
308 * @param Function fn A function to bind to the event on each of the set of matched elements
311 bind: function( type, data, fn ) {
312 return type == "unload" ? this.one(type, data, fn) : this.each(function(){
313 jQuery.event.add( this, type, fn || data, fn && data );
318 * Binds a handler to a particular event (like click) for each matched element.
319 * The handler is executed only once for each element. Otherwise, the same rules
320 * as described in bind() apply.
321 * The event handler is passed an event object that you can use to prevent
322 * default behaviour. To stop both default action and event bubbling, your handler
323 * has to return false.
325 * In most cases, you can define your event handlers as anonymous functions
326 * (see first example). In cases where that is not possible, you can pass additional
327 * data as the second paramter (and the handler function as the third), see
330 * @example $("p").one("click", function(){
331 * alert( $(this).text() );
333 * @before <p>Hello</p>
334 * @result alert("Hello")
338 * @param String type An event type
339 * @param Object data (optional) Additional data passed to the event handler as event.data
340 * @param Function fn A function to bind to the event on each of the set of matched elements
343 one: function( type, data, fn ) {
344 return this.each(function(){
345 jQuery.event.add( this, type, function(event) {
346 jQuery(this).unbind(event);
347 return (fn || data).apply( this, arguments);
353 * The opposite of bind, removes a bound event from each of the matched
356 * Without any arguments, all bound events are removed.
358 * If the type is provided, all bound events of that type are removed.
360 * If the function that was passed to bind is provided as the second argument,
361 * only that specific event handler is removed.
363 * @example $("p").unbind()
364 * @before <p onclick="alert('Hello');">Hello</p>
365 * @result [ <p>Hello</p> ]
367 * @example $("p").unbind( "click" )
368 * @before <p onclick="alert('Hello');">Hello</p>
369 * @result [ <p>Hello</p> ]
371 * @example $("p").unbind( "click", function() { alert("Hello"); } )
372 * @before <p onclick="alert('Hello');">Hello</p>
373 * @result [ <p>Hello</p> ]
377 * @param String type (optional) An event type
378 * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
381 unbind: function( type, fn ) {
382 return this.each(function(){
383 jQuery.event.remove( this, type, fn );
388 * Trigger a type of event on every matched element. This will also cause
389 * the default action of the browser with the same name (if one exists)
390 * to be executed. For example, passing 'submit' to the trigger()
391 * function will also cause the browser to submit the form. This
392 * default action can be prevented by returning false from one of
393 * the functions bound to the event.
395 * You can also trigger custom events registered with bind.
397 * @example $("p").trigger("click")
398 * @before <p click="alert('hello')">Hello</p>
399 * @result alert('hello')
401 * @example $("p").click(function(event, a, b) {
402 * // when a normal click fires, a and b are undefined
403 * // for a trigger like below a refers too "foo" and b refers to "bar"
404 * }).trigger("click", ["foo", "bar"]);
405 * @desc Example of how to pass arbitrary data to an event
407 * @example $("p").bind("myEvent",function(event,message1,message2) {
408 * alert(message1 + ' ' + message2);
410 * $("p").trigger("myEvent",["Hello","World"]);
411 * @result alert('Hello World') // One for each paragraph
415 * @param String type An event type to trigger.
416 * @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler
419 trigger: function( type, data, fn ) {
420 return this.each(function(){
421 jQuery.event.trigger( type, data, this, true, fn );
425 triggerHandler: function( type, data, fn ) {
427 return jQuery.event.trigger( type, data, this[0], false, fn );
431 * Toggle between two function calls every other click.
432 * Whenever a matched element is clicked, the first specified function
433 * is fired, when clicked again, the second is fired. All subsequent
434 * clicks continue to rotate through the two functions.
436 * Use unbind("click") to remove.
438 * @example $("p").toggle(function(){
439 * $(this).addClass("selected");
441 * $(this).removeClass("selected");
446 * @param Function even The function to execute on every even click.
447 * @param Function odd The function to execute on every odd click.
451 // Save reference to arguments for access in closure
454 return this.click(function(e) {
455 // Figure out which function to execute
456 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
458 // Make sure that clicks stop
461 // and execute the function
462 return a[this.lastToggle].apply( this, [e] ) || false;
467 * A method for simulating hovering (moving the mouse on, and off,
468 * an object). This is a custom method which provides an 'in' to a
471 * Whenever the mouse cursor is moved over a matched
472 * element, the first specified function is fired. Whenever the mouse
473 * moves off of the element, the second specified function fires.
474 * Additionally, checks are in place to see if the mouse is still within
475 * the specified element itself (for example, an image inside of a div),
476 * and if it is, it will continue to 'hover', and not move out
477 * (a common error in using a mouseout event handler).
479 * @example $("p").hover(function(){
480 * $(this).addClass("hover");
482 * $(this).removeClass("hover");
487 * @param Function over The function to fire whenever the mouse is moved over a matched element.
488 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
491 hover: function(f,g) {
493 // A private function for handling mouse 'hovering'
494 function handleHover(e) {
495 // Check if mouse(over|out) are still within the same parent element
496 var p = e.relatedTarget;
498 // Traverse up the tree
499 while ( p && p != this ) try { p = p.parentNode; } catch(e) { p = this; };
501 // If we actually just moused on to a sub-element, ignore it
502 if ( p == this ) return false;
504 // Execute the right function
505 return (e.type == "mouseover" ? f : g).apply(this, [e]);
508 // Bind the function to the two event listeners
509 return this.mouseover(handleHover).mouseout(handleHover);
513 * Bind a function to be executed whenever the DOM is ready to be
514 * traversed and manipulated. This is probably the most important
515 * function included in the event module, as it can greatly improve
516 * the response times of your web applications.
518 * In a nutshell, this is a solid replacement for using window.onload,
519 * and attaching a function to that. By using this method, your bound function
520 * will be called the instant the DOM is ready to be read and manipulated,
521 * which is when what 99.99% of all JavaScript code needs to run.
523 * There is one argument passed to the ready event handler: A reference to
524 * the jQuery function. You can name that argument whatever you like, and
525 * can therefore stick with the $ alias without risk of naming collisions.
527 * Please ensure you have no code in your <body> onload event handler,
528 * otherwise $(document).ready() may not fire.
530 * You can have as many $(document).ready events on your page as you like.
531 * The functions are then executed in the order they were added.
533 * @example $(document).ready(function(){ Your code here... });
535 * @example jQuery(function($) {
536 * // Your code using failsafe $ alias here...
538 * @desc Uses both the [[Core#.24.28_fn_.29|shortcut]] for $(document).ready() and the argument
539 * to write failsafe jQuery code using the $ alias, without relying on the
544 * @param Function fn The function to be executed when the DOM is ready.
546 * @see $.noConflict()
550 // Attach the listeners
553 // If the DOM is already ready
554 if ( jQuery.isReady )
555 // Execute the function immediately
556 f.apply( document, [jQuery] );
558 // Otherwise, remember the function for later
560 // Add the function to the wait list
561 jQuery.readyList.push( function() { return f.apply(this, [jQuery]); } );
569 * All the code that makes DOM Ready work nicely.
574 // Handle when the DOM is ready
576 // Make sure that the DOM is not already loaded
577 if ( !jQuery.isReady ) {
578 // Remember that the DOM is ready
579 jQuery.isReady = true;
581 // If there are functions bound, to execute
582 if ( jQuery.readyList ) {
583 // Execute all of them
584 jQuery.each( jQuery.readyList, function(){
585 this.apply( document );
588 // Reset the list of functions
589 jQuery.readyList = null;
591 // Remove event listener to avoid memory leak
592 if ( jQuery.browser.mozilla || jQuery.browser.opera )
593 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
595 // Remove script element used by IE hack
596 if( !window.frames.length ) // don't remove if frames are present (#1187)
597 jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
603 * Bind a function to the scroll event of each matched element.
605 * @example $("p").scroll( function() { alert("Hello"); } );
606 * @before <p>Hello</p>
607 * @result <p onscroll="alert('Hello');">Hello</p>
611 * @param Function fn A function to bind to the scroll event on each of the matched elements.
616 * Bind a function to the submit event of each matched element.
618 * @example $("#myform").submit( function() {
619 * return $("input", this).val().length > 0;
621 * @before <form id="myform"><input /></form>
622 * @desc Prevents the form submission when the input has no value entered.
626 * @param Function fn A function to bind to the submit event on each of the matched elements.
631 * Trigger the submit event of each matched element. This causes all of the functions
632 * that have been bound to that submit event to be executed, and calls the browser's
633 * default submit action on the matching element(s). This default action can be prevented
634 * by returning false from one of the functions bound to the submit event.
636 * Note: This does not execute the submit method of the form element! If you need to
637 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
639 * @example $("form").submit();
640 * @desc Triggers all submit events registered to the matched form(s), and submits them.
648 * Bind a function to the focus event of each matched element.
650 * @example $("p").focus( function() { alert("Hello"); } );
651 * @before <p>Hello</p>
652 * @result <p onfocus="alert('Hello');">Hello</p>
656 * @param Function fn A function to bind to the focus event on each of the matched elements.
661 * Trigger the focus event of each matched element. This causes all of the functions
662 * that have been bound to thet focus event to be executed.
664 * Note: This does not execute the focus method of the underlying elements! If you need to
665 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
667 * @example $("p").focus();
668 * @before <p onfocus="alert('Hello');">Hello</p>
669 * @result alert('Hello');
677 * Bind a function to the keydown event of each matched element.
679 * @example $("p").keydown( function() { alert("Hello"); } );
680 * @before <p>Hello</p>
681 * @result <p onkeydown="alert('Hello');">Hello</p>
685 * @param Function fn A function to bind to the keydown event on each of the matched elements.
690 * Bind a function to the dblclick event of each matched element.
692 * @example $("p").dblclick( function() { alert("Hello"); } );
693 * @before <p>Hello</p>
694 * @result <p ondblclick="alert('Hello');">Hello</p>
698 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
703 * Bind a function to the keypress event of each matched element.
705 * @example $("p").keypress( function() { alert("Hello"); } );
706 * @before <p>Hello</p>
707 * @result <p onkeypress="alert('Hello');">Hello</p>
711 * @param Function fn A function to bind to the keypress event on each of the matched elements.
716 * Bind a function to the error event of each matched element.
718 * @example $("p").error( function() { alert("Hello"); } );
719 * @before <p>Hello</p>
720 * @result <p onerror="alert('Hello');">Hello</p>
724 * @param Function fn A function to bind to the error event on each of the matched elements.
729 * Bind a function to the blur event of each matched element.
731 * @example $("p").blur( function() { alert("Hello"); } );
732 * @before <p>Hello</p>
733 * @result <p onblur="alert('Hello');">Hello</p>
737 * @param Function fn A function to bind to the blur event on each of the matched elements.
742 * Trigger the blur event of each matched element. This causes all of the functions
743 * that have been bound to that blur event to be executed, and calls the browser's
744 * default blur action on the matching element(s). This default action can be prevented
745 * by returning false from one of the functions bound to the blur event.
747 * Note: This does not execute the blur method of the underlying elements! If you need to
748 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
750 * @example $("p").blur();
751 * @before <p onblur="alert('Hello');">Hello</p>
752 * @result alert('Hello');
760 * Bind a function to the load event of each matched element.
762 * @example $("p").load( function() { alert("Hello"); } );
763 * @before <p>Hello</p>
764 * @result <p onload="alert('Hello');">Hello</p>
768 * @param Function fn A function to bind to the load event on each of the matched elements.
773 * Bind a function to the select event of each matched element.
775 * @example $("p").select( function() { alert("Hello"); } );
776 * @before <p>Hello</p>
777 * @result <p onselect="alert('Hello');">Hello</p>
781 * @param Function fn A function to bind to the select event on each of the matched elements.
786 * Trigger the select event of each matched element. This causes all of the functions
787 * that have been bound to that select event to be executed, and calls the browser's
788 * default select action on the matching element(s). This default action can be prevented
789 * by returning false from one of the functions bound to the select event.
791 * @example $("p").select();
792 * @before <p onselect="alert('Hello');">Hello</p>
793 * @result alert('Hello');
801 * Bind a function to the mouseup event of each matched element.
803 * @example $("p").mouseup( function() { alert("Hello"); } );
804 * @before <p>Hello</p>
805 * @result <p onmouseup="alert('Hello');">Hello</p>
809 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
814 * Bind a function to the unload event of each matched element.
816 * @example $("p").unload( function() { alert("Hello"); } );
817 * @before <p>Hello</p>
818 * @result <p onunload="alert('Hello');">Hello</p>
822 * @param Function fn A function to bind to the unload event on each of the matched elements.
827 * Bind a function to the change event of each matched element.
829 * @example $("p").change( function() { alert("Hello"); } );
830 * @before <p>Hello</p>
831 * @result <p onchange="alert('Hello');">Hello</p>
835 * @param Function fn A function to bind to the change event on each of the matched elements.
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 * Bind a function to the keyup event of each matched element.
855 * @example $("p").keyup( function() { alert("Hello"); } );
856 * @before <p>Hello</p>
857 * @result <p onkeyup="alert('Hello');">Hello</p>
861 * @param Function fn A function to bind to the keyup event on each of the matched elements.
866 * Bind a function to the click event of each matched element.
868 * @example $("p").click( function() { alert("Hello"); } );
869 * @before <p>Hello</p>
870 * @result <p onclick="alert('Hello');">Hello</p>
874 * @param Function fn A function to bind to the click event on each of the matched elements.
879 * Trigger the click event of each matched element. This causes all of the functions
880 * that have been bound to thet click event to be executed.
882 * @example $("p").click();
883 * @before <p onclick="alert('Hello');">Hello</p>
884 * @result alert('Hello');
892 * Bind a function to the resize event of each matched element.
894 * @example $("p").resize( function() { alert("Hello"); } );
895 * @before <p>Hello</p>
896 * @result <p onresize="alert('Hello');">Hello</p>
900 * @param Function fn A function to bind to the resize event on each of the matched elements.
905 * Bind a function to the mousemove event of each matched element.
907 * @example $("p").mousemove( function() { alert("Hello"); } );
908 * @before <p>Hello</p>
909 * @result <p onmousemove="alert('Hello');">Hello</p>
913 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
918 * Bind a function to the mousedown event of each matched element.
920 * @example $("p").mousedown( function() { alert("Hello"); } );
921 * @before <p>Hello</p>
922 * @result <p onmousedown="alert('Hello');">Hello</p>
926 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
931 * Bind a function to the mouseover event of each matched element.
933 * @example $("p").mouseover( function() { alert("Hello"); } );
934 * @before <p>Hello</p>
935 * @result <p onmouseover="alert('Hello');">Hello</p>
939 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
942 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
943 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
944 "submit,keydown,keypress,keyup,error").split(","), function(i,o){
946 // Handle event binding
947 jQuery.fn[o] = function(f){
948 return f ? this.bind(o, f) : this.trigger(o);
953 var readyBound = false;
955 function bindReady(){
956 if ( readyBound ) return;
959 // If Mozilla is used
960 if ( jQuery.browser.mozilla || jQuery.browser.opera )
961 // Use the handy event callback
962 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
964 // If IE is used, use the excellent hack by Matthias Miller
965 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
966 else if ( jQuery.browser.msie ) {
968 // Only works if you document.write() it
969 document.write("<scr" + "ipt id=__ie_init defer=true " +
970 "src=//:><\/script>");
972 // Use the defer script hack
973 var script = document.getElementById("__ie_init");
975 // script does not exist if jQuery is loaded dynamically
977 script.onreadystatechange = function() {
978 if ( document.readyState != "complete" ) return;
986 } else if ( jQuery.browser.safari )
987 // Continually check to see if the document.readyState is valid
988 jQuery.safariTimer = setInterval(function(){
989 // loaded and complete are both valid states
990 if ( document.readyState == "loaded" ||
991 document.readyState == "complete" ) {
993 // If either one are found, remove the timer
994 clearInterval( jQuery.safariTimer );
995 jQuery.safariTimer = null;
997 // and execute any waiting functions
1002 // A fallback to window.onload, that will always work
1003 jQuery.event.add( window, "load", jQuery.ready );