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 // Namespaced event handlers
39 var parts = type.split(".");
41 handler.type = parts[1];
43 // Init the element's event structure
48 element.$handle = function() {
49 // returned undefined or false
52 // Handle the second event of a trigger and when
53 // an event is called after a page has unloaded
54 if ( typeof jQuery == "undefined" || jQuery.event.triggered )
57 val = jQuery.event.handle.apply(element, arguments);
62 // Get the current list of functions bound to this event
63 var handlers = element.$events[type];
65 // Init the event handler queue
67 handlers = element.$events[type] = {};
69 // And bind the global event handler to the element
70 if (element.addEventListener)
71 element.addEventListener(type, element.$handle, false);
73 element.attachEvent("on" + type, element.$handle);
76 // Add the function to the element's handler list
77 handlers[handler.guid] = handler;
79 // Keep track of which events have been used, for global triggering
80 this.global[type] = true;
86 // Detach an event or set of events from an element
87 remove: function(element, type, handler) {
88 var events = element.$events, ret, index;
90 // Namespaced event handlers
91 if ( typeof type == "string" ) {
92 var parts = type.split(".");
97 // type is actually an event object here
98 if ( type && type.type ) {
99 handler = type.handler;
104 for ( type in events )
105 this.remove( element, type );
107 } else if ( events[type] ) {
108 // remove the given handler for the given type
110 delete events[type][handler.guid];
112 // remove all handlers for the given type
114 for ( handler in element.$events[type] )
115 // Handle the removal of namespaced events
116 if ( !parts[1] || events[type][handler].type == parts[1] )
117 delete events[type][handler];
119 // remove generic event handler if no more handlers exist
120 for ( ret in events[type] ) break;
122 if (element.removeEventListener)
123 element.removeEventListener(type, element.$handle, false);
125 element.detachEvent("on" + type, element.$handle);
131 // Remove the expando if it's no longer used
132 for ( ret in events ) break;
134 element.$handle = element.$events = null;
138 trigger: function(type, data, element, native, extra) {
139 // Clone the incoming data, if any
140 data = jQuery.makeArray(data || []);
142 // Handle a global trigger
144 // Only trigger if we've ever bound an event for it
145 if ( this.global[type] )
146 jQuery("*").add([window, document]).trigger(type, data);
148 // Handle triggering a single element
150 var val, ret, fn = jQuery.isFunction( element[ type ] || null ),
151 // Check to see if we need to provide a fake event, or not
152 evt = !data[0] || !data[0].preventDefault;
154 // Pass along a fake event
156 data.unshift( this.fix({ type: type, target: element }) );
159 if ( jQuery.isFunction( element.$handle ) )
160 val = element.$handle.apply( element, data );
162 // Handle triggering native .onfoo handlers
163 if ( !fn && element["on"+type] && element["on"+type].apply( element, data ) === false )
166 // Extra functions don't get the custom event object
170 // Handle triggering of extra function
171 if ( extra && extra.apply( element, data ) === false )
174 // Trigger the native events (except for clicks on links)
175 if ( fn && native !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) {
176 this.triggered = true;
180 this.triggered = false;
186 handle: function(event) {
187 // returned undefined or false
190 // Empty object is for triggered events with no data
191 event = jQuery.event.fix( event || window.event || {} );
193 // Namespaced event handlers
194 var parts = event.type.split(".");
195 event.type = parts[0];
197 var c = this.$events && this.$events[event.type], args = Array.prototype.slice.call( arguments, 1 );
198 args.unshift( event );
201 // Pass in a reference to the handler function itself
202 // So that we can later remove it
203 args[0].handler = c[j];
204 args[0].data = c[j].data;
206 // Filter the functions by class
207 if ( !parts[1] || c[j].type == parts[1] ) {
208 var tmp = c[j].apply( this, args );
213 if ( tmp === false ) {
214 event.preventDefault();
215 event.stopPropagation();
220 // Clean up added properties in IE to prevent memory leak
221 if (jQuery.browser.msie)
222 event.target = event.preventDefault = event.stopPropagation =
223 event.handler = event.data = null;
228 fix: function(event) {
229 // store a copy of the original event object
230 // and clone to set read-only properties
231 var originalEvent = event;
232 event = jQuery.extend({}, originalEvent);
234 // add preventDefault and stopPropagation since
235 // they will not work on the clone
236 event.preventDefault = function() {
237 // if preventDefault exists run it on the original event
238 if (originalEvent.preventDefault)
239 originalEvent.preventDefault();
240 // otherwise set the returnValue property of the original event to false (IE)
241 originalEvent.returnValue = false;
243 event.stopPropagation = function() {
244 // if stopPropagation exists run it on the original event
245 if (originalEvent.stopPropagation)
246 originalEvent.stopPropagation();
247 // otherwise set the cancelBubble property of the original event to true (IE)
248 originalEvent.cancelBubble = true;
251 // Fix target property, if necessary
252 if ( !event.target && event.srcElement )
253 event.target = event.srcElement;
255 // check if target is a textnode (safari)
256 if (jQuery.browser.safari && event.target.nodeType == 3)
257 event.target = originalEvent.target.parentNode;
259 // Add relatedTarget, if necessary
260 if ( !event.relatedTarget && event.fromElement )
261 event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
263 // Calculate pageX/Y if missing and clientX/Y available
264 if ( event.pageX == null && event.clientX != null ) {
265 var e = document.documentElement, b = document.body;
266 event.pageX = event.clientX + (e && e.scrollLeft || b.scrollLeft || 0);
267 event.pageY = event.clientY + (e && e.scrollTop || b.scrollTop || 0);
270 // Add which for key events
271 if ( !event.which && (event.charCode || event.keyCode) )
272 event.which = event.charCode || event.keyCode;
274 // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
275 if ( !event.metaKey && event.ctrlKey )
276 event.metaKey = event.ctrlKey;
278 // Add which for click: 1 == left; 2 == middle; 3 == right
279 // Note: button is not normalized, so don't use it
280 if ( !event.which && event.button )
281 event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
290 * Binds a handler to a particular event (like click) for each matched element.
291 * The event handler is passed an event object that you can use to prevent
292 * default behaviour. To stop both default action and event bubbling, your handler
293 * has to return false.
295 * In most cases, you can define your event handlers as anonymous functions
296 * (see first example). In cases where that is not possible, you can pass additional
297 * data as the second parameter (and the handler function as the third), see
300 * Calling bind with an event type of "unload" will automatically
301 * use the one method instead of bind to prevent memory leaks.
303 * @example $("p").bind("click", function(){
304 * alert( $(this).text() );
306 * @before <p>Hello</p>
307 * @result alert("Hello")
309 * @example function handler(event) {
310 * alert(event.data.foo);
312 * $("p").bind("click", {foo: "bar"}, handler)
313 * @result alert("bar")
314 * @desc Pass some additional data to the event handler.
316 * @example $("form").bind("submit", function() { return false; })
317 * @desc Cancel a default action and prevent it from bubbling by returning false
318 * from your function.
320 * @example $("form").bind("submit", function(event){
321 * event.preventDefault();
323 * @desc Cancel only the default action by using the preventDefault method.
326 * @example $("form").bind("submit", function(event){
327 * event.stopPropagation();
329 * @desc Stop only an event from bubbling by using the stopPropagation method.
333 * @param String type An event type
334 * @param Object data (optional) Additional data passed to the event handler as event.data
335 * @param Function fn A function to bind to the event on each of the set of matched elements
338 bind: function( type, data, fn ) {
339 return type == "unload" ? this.one(type, data, fn) : this.each(function(){
340 jQuery.event.add( this, type, fn || data, fn && data );
345 * Binds a handler to a particular event (like click) for each matched element.
346 * The handler is executed only once for each element. Otherwise, the same rules
347 * as described in bind() apply.
348 * The event handler is passed an event object that you can use to prevent
349 * default behaviour. To stop both default action and event bubbling, your handler
350 * has to return false.
352 * In most cases, you can define your event handlers as anonymous functions
353 * (see first example). In cases where that is not possible, you can pass additional
354 * data as the second paramter (and the handler function as the third), see
357 * @example $("p").one("click", function(){
358 * alert( $(this).text() );
360 * @before <p>Hello</p>
361 * @result alert("Hello")
365 * @param String type An event type
366 * @param Object data (optional) Additional data passed to the event handler as event.data
367 * @param Function fn A function to bind to the event on each of the set of matched elements
370 one: function( type, data, fn ) {
371 return this.each(function(){
372 jQuery.event.add( this, type, function(event) {
373 jQuery(this).unbind(event);
374 return (fn || data).apply( this, arguments);
380 * The opposite of bind, removes a bound event from each of the matched
383 * Without any arguments, all bound events are removed.
385 * If the type is provided, all bound events of that type are removed.
387 * If the function that was passed to bind is provided as the second argument,
388 * only that specific event handler is removed.
390 * @example $("p").unbind()
391 * @before <p onclick="alert('Hello');">Hello</p>
392 * @result [ <p>Hello</p> ]
394 * @example $("p").unbind( "click" )
395 * @before <p onclick="alert('Hello');">Hello</p>
396 * @result [ <p>Hello</p> ]
398 * @example $("p").unbind( "click", function() { alert("Hello"); } )
399 * @before <p onclick="alert('Hello');">Hello</p>
400 * @result [ <p>Hello</p> ]
404 * @param String type (optional) An event type
405 * @param Function fn (optional) A function to unbind from the event on each of the set of matched elements
408 unbind: function( type, fn ) {
409 return this.each(function(){
410 jQuery.event.remove( this, type, fn );
415 * Trigger a type of event on every matched element. This will also cause
416 * the default action of the browser with the same name (if one exists)
417 * to be executed. For example, passing 'submit' to the trigger()
418 * function will also cause the browser to submit the form. This
419 * default action can be prevented by returning false from one of
420 * the functions bound to the event.
422 * You can also trigger custom events registered with bind.
424 * @example $("p").trigger("click")
425 * @before <p click="alert('hello')">Hello</p>
426 * @result alert('hello')
428 * @example $("p").click(function(event, a, b) {
429 * // when a normal click fires, a and b are undefined
430 * // for a trigger like below a refers too "foo" and b refers to "bar"
431 * }).trigger("click", ["foo", "bar"]);
432 * @desc Example of how to pass arbitrary data to an event
434 * @example $("p").bind("myEvent",function(event,message1,message2) {
435 * alert(message1 + ' ' + message2);
437 * $("p").trigger("myEvent",["Hello","World"]);
438 * @result alert('Hello World') // One for each paragraph
442 * @param String type An event type to trigger.
443 * @param Array data (optional) Additional data to pass as arguments (after the event object) to the event handler
446 trigger: function( type, data, fn ) {
447 return this.each(function(){
448 jQuery.event.trigger( type, data, this, true, fn );
452 triggerHandler: function( type, data, fn ) {
454 return jQuery.event.trigger( type, data, this[0], false, fn );
458 * Toggle between two function calls every other click.
459 * Whenever a matched element is clicked, the first specified function
460 * is fired, when clicked again, the second is fired. All subsequent
461 * clicks continue to rotate through the two functions.
463 * Use unbind("click") to remove.
465 * @example $("p").toggle(function(){
466 * $(this).addClass("selected");
468 * $(this).removeClass("selected");
473 * @param Function even The function to execute on every even click.
474 * @param Function odd The function to execute on every odd click.
478 // Save reference to arguments for access in closure
481 return this.click(function(e) {
482 // Figure out which function to execute
483 this.lastToggle = 0 == this.lastToggle ? 1 : 0;
485 // Make sure that clicks stop
488 // and execute the function
489 return a[this.lastToggle].apply( this, [e] ) || false;
494 * A method for simulating hovering (moving the mouse on, and off,
495 * an object). This is a custom method which provides an 'in' to a
498 * Whenever the mouse cursor is moved over a matched
499 * element, the first specified function is fired. Whenever the mouse
500 * moves off of the element, the second specified function fires.
501 * Additionally, checks are in place to see if the mouse is still within
502 * the specified element itself (for example, an image inside of a div),
503 * and if it is, it will continue to 'hover', and not move out
504 * (a common error in using a mouseout event handler).
506 * @example $("p").hover(function(){
507 * $(this).addClass("hover");
509 * $(this).removeClass("hover");
514 * @param Function over The function to fire whenever the mouse is moved over a matched element.
515 * @param Function out The function to fire whenever the mouse is moved off of a matched element.
518 hover: function(f,g) {
520 // A private function for handling mouse 'hovering'
521 function handleHover(e) {
522 // Check if mouse(over|out) are still within the same parent element
523 var p = e.relatedTarget;
525 // Traverse up the tree
526 while ( p && p != this ) try { p = p.parentNode; } catch(e) { p = this; };
528 // If we actually just moused on to a sub-element, ignore it
529 if ( p == this ) return false;
531 // Execute the right function
532 return (e.type == "mouseover" ? f : g).apply(this, [e]);
535 // Bind the function to the two event listeners
536 return this.mouseover(handleHover).mouseout(handleHover);
540 * Bind a function to be executed whenever the DOM is ready to be
541 * traversed and manipulated. This is probably the most important
542 * function included in the event module, as it can greatly improve
543 * the response times of your web applications.
545 * In a nutshell, this is a solid replacement for using window.onload,
546 * and attaching a function to that. By using this method, your bound function
547 * will be called the instant the DOM is ready to be read and manipulated,
548 * which is when what 99.99% of all JavaScript code needs to run.
550 * There is one argument passed to the ready event handler: A reference to
551 * the jQuery function. You can name that argument whatever you like, and
552 * can therefore stick with the $ alias without risk of naming collisions.
554 * Please ensure you have no code in your <body> onload event handler,
555 * otherwise $(document).ready() may not fire.
557 * You can have as many $(document).ready events on your page as you like.
558 * The functions are then executed in the order they were added.
560 * @example $(document).ready(function(){ Your code here... });
562 * @example jQuery(function($) {
563 * // Your code using failsafe $ alias here...
565 * @desc Uses both the [[Core#.24.28_fn_.29|shortcut]] for $(document).ready() and the argument
566 * to write failsafe jQuery code using the $ alias, without relying on the
571 * @param Function fn The function to be executed when the DOM is ready.
573 * @see $.noConflict()
577 // Attach the listeners
580 // If the DOM is already ready
581 if ( jQuery.isReady )
582 // Execute the function immediately
583 f.apply( document, [jQuery] );
585 // Otherwise, remember the function for later
587 // Add the function to the wait list
588 jQuery.readyList.push( function() { return f.apply(this, [jQuery]); } );
596 * All the code that makes DOM Ready work nicely.
601 // Handle when the DOM is ready
603 // Make sure that the DOM is not already loaded
604 if ( !jQuery.isReady ) {
605 // Remember that the DOM is ready
606 jQuery.isReady = true;
608 // If there are functions bound, to execute
609 if ( jQuery.readyList ) {
610 // Execute all of them
611 jQuery.each( jQuery.readyList, function(){
612 this.apply( document );
615 // Reset the list of functions
616 jQuery.readyList = null;
618 // Remove event listener to avoid memory leak
619 if ( jQuery.browser.mozilla || jQuery.browser.opera )
620 document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
622 // Remove script element used by IE hack
623 if( !window.frames.length ) // don't remove if frames are present (#1187)
624 jQuery(window).load(function(){ jQuery("#__ie_init").remove(); });
630 * Bind a function to the scroll event of each matched element.
632 * @example $("p").scroll( function() { alert("Hello"); } );
633 * @before <p>Hello</p>
634 * @result <p onscroll="alert('Hello');">Hello</p>
638 * @param Function fn A function to bind to the scroll event on each of the matched elements.
643 * Bind a function to the submit event of each matched element.
645 * @example $("#myform").submit( function() {
646 * return $("input", this).val().length > 0;
648 * @before <form id="myform"><input /></form>
649 * @desc Prevents the form submission when the input has no value entered.
653 * @param Function fn A function to bind to the submit event on each of the matched elements.
658 * Trigger the submit event of each matched element. This causes all of the functions
659 * that have been bound to that submit event to be executed, and calls the browser's
660 * default submit action on the matching element(s). This default action can be prevented
661 * by returning false from one of the functions bound to the submit event.
663 * Note: This does not execute the submit method of the form element! If you need to
664 * submit the form via code, you have to use the DOM method, eg. $("form")[0].submit();
666 * @example $("form").submit();
667 * @desc Triggers all submit events registered to the matched form(s), and submits them.
675 * Bind a function to the focus event of each matched element.
677 * @example $("p").focus( function() { alert("Hello"); } );
678 * @before <p>Hello</p>
679 * @result <p onfocus="alert('Hello');">Hello</p>
683 * @param Function fn A function to bind to the focus event on each of the matched elements.
688 * Trigger the focus event of each matched element. This causes all of the functions
689 * that have been bound to thet focus event to be executed.
691 * Note: This does not execute the focus method of the underlying elements! If you need to
692 * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
694 * @example $("p").focus();
695 * @before <p onfocus="alert('Hello');">Hello</p>
696 * @result alert('Hello');
704 * Bind a function to the keydown event of each matched element.
706 * @example $("p").keydown( function() { alert("Hello"); } );
707 * @before <p>Hello</p>
708 * @result <p onkeydown="alert('Hello');">Hello</p>
712 * @param Function fn A function to bind to the keydown event on each of the matched elements.
717 * Bind a function to the dblclick event of each matched element.
719 * @example $("p").dblclick( function() { alert("Hello"); } );
720 * @before <p>Hello</p>
721 * @result <p ondblclick="alert('Hello');">Hello</p>
725 * @param Function fn A function to bind to the dblclick event on each of the matched elements.
730 * Bind a function to the keypress event of each matched element.
732 * @example $("p").keypress( function() { alert("Hello"); } );
733 * @before <p>Hello</p>
734 * @result <p onkeypress="alert('Hello');">Hello</p>
738 * @param Function fn A function to bind to the keypress event on each of the matched elements.
743 * Bind a function to the error event of each matched element.
745 * @example $("p").error( function() { alert("Hello"); } );
746 * @before <p>Hello</p>
747 * @result <p onerror="alert('Hello');">Hello</p>
751 * @param Function fn A function to bind to the error event on each of the matched elements.
756 * Bind a function to the blur event of each matched element.
758 * @example $("p").blur( function() { alert("Hello"); } );
759 * @before <p>Hello</p>
760 * @result <p onblur="alert('Hello');">Hello</p>
764 * @param Function fn A function to bind to the blur event on each of the matched elements.
769 * Trigger the blur event of each matched element. This causes all of the functions
770 * that have been bound to that blur event to be executed, and calls the browser's
771 * default blur action on the matching element(s). This default action can be prevented
772 * by returning false from one of the functions bound to the blur event.
774 * Note: This does not execute the blur method of the underlying elements! If you need to
775 * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
777 * @example $("p").blur();
778 * @before <p onblur="alert('Hello');">Hello</p>
779 * @result alert('Hello');
787 * Bind a function to the load event of each matched element.
789 * @example $("p").load( function() { alert("Hello"); } );
790 * @before <p>Hello</p>
791 * @result <p onload="alert('Hello');">Hello</p>
795 * @param Function fn A function to bind to the load event on each of the matched elements.
800 * Bind a function to the select event of each matched element.
802 * @example $("p").select( function() { alert("Hello"); } );
803 * @before <p>Hello</p>
804 * @result <p onselect="alert('Hello');">Hello</p>
808 * @param Function fn A function to bind to the select event on each of the matched elements.
813 * Trigger the select event of each matched element. This causes all of the functions
814 * that have been bound to that select event to be executed, and calls the browser's
815 * default select action on the matching element(s). This default action can be prevented
816 * by returning false from one of the functions bound to the select event.
818 * @example $("p").select();
819 * @before <p onselect="alert('Hello');">Hello</p>
820 * @result alert('Hello');
828 * Bind a function to the mouseup event of each matched element.
830 * @example $("p").mouseup( function() { alert("Hello"); } );
831 * @before <p>Hello</p>
832 * @result <p onmouseup="alert('Hello');">Hello</p>
836 * @param Function fn A function to bind to the mouseup event on each of the matched elements.
841 * Bind a function to the unload event of each matched element.
843 * @example $("p").unload( function() { alert("Hello"); } );
844 * @before <p>Hello</p>
845 * @result <p onunload="alert('Hello');">Hello</p>
849 * @param Function fn A function to bind to the unload event on each of the matched elements.
854 * Bind a function to the change event of each matched element.
856 * @example $("p").change( function() { alert("Hello"); } );
857 * @before <p>Hello</p>
858 * @result <p onchange="alert('Hello');">Hello</p>
862 * @param Function fn A function to bind to the change event on each of the matched elements.
867 * Bind a function to the mouseout event of each matched element.
869 * @example $("p").mouseout( function() { alert("Hello"); } );
870 * @before <p>Hello</p>
871 * @result <p onmouseout="alert('Hello');">Hello</p>
875 * @param Function fn A function to bind to the mouseout event on each of the matched elements.
880 * Bind a function to the keyup event of each matched element.
882 * @example $("p").keyup( function() { alert("Hello"); } );
883 * @before <p>Hello</p>
884 * @result <p onkeyup="alert('Hello');">Hello</p>
888 * @param Function fn A function to bind to the keyup event on each of the matched elements.
893 * Bind a function to the click event of each matched element.
895 * @example $("p").click( function() { alert("Hello"); } );
896 * @before <p>Hello</p>
897 * @result <p onclick="alert('Hello');">Hello</p>
901 * @param Function fn A function to bind to the click event on each of the matched elements.
906 * Trigger the click event of each matched element. This causes all of the functions
907 * that have been bound to thet click event to be executed.
909 * @example $("p").click();
910 * @before <p onclick="alert('Hello');">Hello</p>
911 * @result alert('Hello');
919 * Bind a function to the resize event of each matched element.
921 * @example $("p").resize( function() { alert("Hello"); } );
922 * @before <p>Hello</p>
923 * @result <p onresize="alert('Hello');">Hello</p>
927 * @param Function fn A function to bind to the resize event on each of the matched elements.
932 * Bind a function to the mousemove event of each matched element.
934 * @example $("p").mousemove( function() { alert("Hello"); } );
935 * @before <p>Hello</p>
936 * @result <p onmousemove="alert('Hello');">Hello</p>
940 * @param Function fn A function to bind to the mousemove event on each of the matched elements.
945 * Bind a function to the mousedown event of each matched element.
947 * @example $("p").mousedown( function() { alert("Hello"); } );
948 * @before <p>Hello</p>
949 * @result <p onmousedown="alert('Hello');">Hello</p>
953 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
958 * Bind a function to the mouseover event of each matched element.
960 * @example $("p").mouseover( function() { alert("Hello"); } );
961 * @before <p>Hello</p>
962 * @result <p onmouseover="alert('Hello');">Hello</p>
966 * @param Function fn A function to bind to the mousedown event on each of the matched elements.
969 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
970 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
971 "submit,keydown,keypress,keyup,error").split(","), function(i,o){
973 // Handle event binding
974 jQuery.fn[o] = function(f){
975 return f ? this.bind(o, f) : this.trigger(o);
980 var readyBound = false;
982 function bindReady(){
983 if ( readyBound ) return;
986 // If Mozilla is used
987 if ( jQuery.browser.mozilla || jQuery.browser.opera )
988 // Use the handy event callback
989 document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
991 // If IE is used, use the excellent hack by Matthias Miller
992 // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
993 else if ( jQuery.browser.msie ) {
995 // Only works if you document.write() it
996 document.write("<scr" + "ipt id=__ie_init defer=true " +
997 "src=//:><\/script>");
999 // Use the defer script hack
1000 var script = document.getElementById("__ie_init");
1002 // script does not exist if jQuery is loaded dynamically
1004 script.onreadystatechange = function() {
1005 if ( this.readyState != "complete" ) return;
1009 // Clear from memory
1012 // If Safari is used
1013 } else if ( jQuery.browser.safari )
1014 // Continually check to see if the document.readyState is valid
1015 jQuery.safariTimer = setInterval(function(){
1016 // loaded and complete are both valid states
1017 if ( document.readyState == "loaded" ||
1018 document.readyState == "complete" ) {
1020 // If either one are found, remove the timer
1021 clearInterval( jQuery.safariTimer );
1022 jQuery.safariTimer = null;
1024 // and execute any waiting functions
1029 // A fallback to window.onload, that will always work
1030 jQuery.event.add( window, "load", jQuery.ready );