2006-06-19 02:12:14 +02:00
|
|
|
// We're overriding the old toggle function, so
|
|
|
|
// remember it for later
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype._toggle = jQuery.prototype.toggle;
|
2006-04-08 08:28:40 +02:00
|
|
|
|
2006-06-19 02:12:14 +02:00
|
|
|
/**
|
|
|
|
* Toggle between two function calls every other click.
|
|
|
|
*/
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype.toggle = function(a,b) {
|
2006-06-19 02:12:14 +02:00
|
|
|
// If two functions are passed in, we're
|
|
|
|
// toggling on a click
|
|
|
|
return a && b ? this.click(function(e){
|
|
|
|
// Figure out which function to execute
|
|
|
|
this.last = this.last == a ? b : a;
|
2006-03-22 04:33:07 +01:00
|
|
|
|
2006-06-19 02:12:14 +02:00
|
|
|
// Make sure that clicks don't pass through
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// and execute the function
|
2006-06-23 16:11:39 +02:00
|
|
|
return this.last.apply( this, [e] ) || false;
|
2006-06-19 02:12:14 +02:00
|
|
|
}) :
|
|
|
|
|
|
|
|
// Otherwise, execute the old toggle function
|
|
|
|
this._toggle();
|
2006-03-22 04:33:07 +01:00
|
|
|
};
|
|
|
|
|
2006-06-19 02:12:14 +02:00
|
|
|
/**
|
|
|
|
* Toggle between two function calls on mouse over/out.
|
|
|
|
*/
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype.hover = function(f,g) {
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// A private function for haandling mouse 'hovering'
|
|
|
|
function handleHover(e) {
|
|
|
|
// Check if mouse(over|out) are still within the same parent element
|
|
|
|
var p = e.fromElement || e.toElement || e.relatedTarget;
|
|
|
|
while ( p && p != this ) p = p.parentNode;
|
|
|
|
|
|
|
|
// If we actually just moused on to a sub-element, ignore it
|
|
|
|
if ( p == this ) return false;
|
|
|
|
|
|
|
|
// Execute the right function
|
2006-06-23 16:11:39 +02:00
|
|
|
return (e.type == "mouseover" ? f : g).apply(this, [e]);
|
2006-05-17 00:15:05 +02:00
|
|
|
}
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Bind the function to the two event listeners
|
|
|
|
return this.mouseover(handleHover).mouseout(handleHover);
|
2006-04-08 08:28:40 +02:00
|
|
|
};
|
|
|
|
|
2006-06-11 20:59:45 +02:00
|
|
|
/**
|
|
|
|
* Bind a function to fire when the DOM is ready.
|
|
|
|
*/
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype.ready = function(f) {
|
2006-06-19 02:12:14 +02:00
|
|
|
// If the DOM is already ready
|
2006-06-22 22:14:41 +02:00
|
|
|
if ( jQuery.isReady )
|
2006-06-19 02:12:14 +02:00
|
|
|
// Execute the function immediately
|
2006-06-23 16:11:39 +02:00
|
|
|
f.apply( document );
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Otherwise, remember the function for later
|
|
|
|
else {
|
|
|
|
// Add the function to the wait list
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.readyList.push( f );
|
2006-06-14 22:05:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2006-03-22 04:33:07 +01:00
|
|
|
};
|
|
|
|
|
2006-06-19 02:12:14 +02:00
|
|
|
(function(){
|
|
|
|
/*
|
|
|
|
* Bind a number of event-handling functions, dynamically
|
|
|
|
*/
|
2006-06-22 23:37:18 +02:00
|
|
|
var e = ("blur,focus,contextmenu,load,resize,scroll,unload,click,dblclick," +
|
2006-06-22 07:23:38 +02:00
|
|
|
"mousedown,mouseup,mouseenter,mouseleave,mousemove,mouseover,mouseout," +
|
2006-06-22 23:37:18 +02:00
|
|
|
"change,reset,select,submit,keydown,keypress,keyup").split(",");
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Go through all the event names, but make sure that
|
|
|
|
// it is enclosed properly
|
|
|
|
for ( var i = 0; i < e.length; i++ ) {(function(){
|
|
|
|
|
|
|
|
var o = e[i];
|
|
|
|
|
|
|
|
// Handle event binding
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype[o] = function(f){ return this.bind(o, f); };
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Handle event unbinding
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype["un"+o] = function(f){ return this.unbind(o, f); };
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Handle event triggering
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype["do"+o] = function(){ return this.trigger(o); };
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Finally, handle events that only fire once
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.prototype["one"+o] = function(f){
|
2006-06-19 02:12:14 +02:00
|
|
|
// Attach the event listener
|
|
|
|
return this.bind(o, function(e){
|
|
|
|
// TODO: Remove the event listener, instead of this hack
|
|
|
|
|
|
|
|
// If this function has already been executed, stop
|
|
|
|
if ( this[o+f] !== null )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Otherwise, mark as having been executed
|
|
|
|
this[o+f]++;
|
|
|
|
|
|
|
|
// And execute the bound function
|
2006-06-23 16:11:39 +02:00
|
|
|
return f.apply(this, [e]);
|
2006-06-19 02:12:14 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
})();}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All the code that makes DOM Ready work nicely.
|
|
|
|
*/
|
|
|
|
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.isReady = false;
|
|
|
|
jQuery.readyList = [];
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Handle when the DOM is ready
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.ready = function() {
|
2006-06-19 02:12:14 +02:00
|
|
|
// Make sure that the DOM hasn't already loaded
|
2006-06-22 22:14:41 +02:00
|
|
|
if ( !jQuery.isReady ) {
|
2006-06-19 02:12:14 +02:00
|
|
|
// Remember that the DOM is ready
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.isReady = true;
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// If there are functions bound, to execute
|
2006-06-22 22:14:41 +02:00
|
|
|
if ( jQuery.readyList ) {
|
2006-06-19 02:12:14 +02:00
|
|
|
// Execute all of them
|
2006-06-22 22:14:41 +02:00
|
|
|
for ( var i = 0; i < jQuery.readyList.length; i++ )
|
2006-06-23 16:11:39 +02:00
|
|
|
jQuery.readyList[i].apply( document );
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Reset the list of functions
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.readyList = null;
|
2006-06-19 02:12:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// If Mozilla is used
|
2006-06-22 22:14:41 +02:00
|
|
|
if ( jQuery.browser == "mozilla" || jQuery.browser == "opera" ) {
|
2006-06-19 02:12:14 +02:00
|
|
|
// Use the handy event callback
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.event.add( document, "DOMContentLoaded", jQuery.ready );
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// If IE is used, use the excellent hack by Matthias Miller
|
|
|
|
// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
|
2006-06-22 22:14:41 +02:00
|
|
|
} else if ( jQuery.browser == "msie" ) {
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Only works if you document.write() it
|
2006-06-22 07:23:38 +02:00
|
|
|
document.write("<scr" + "ipt id=__ie_init defer=true " +
|
|
|
|
"src=javascript:void(0)><\/script>");
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// Use the defer script hack
|
2006-06-22 07:23:38 +02:00
|
|
|
var script = document.getElementById("__ie_init");
|
2006-06-19 02:12:14 +02:00
|
|
|
script.onreadystatechange = function() {
|
2006-06-22 07:23:38 +02:00
|
|
|
if ( this.readyState == "complete" )
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.ready();
|
2006-06-19 02:12:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Clear from memory
|
|
|
|
script = null;
|
|
|
|
|
|
|
|
// If Safari is used
|
2006-06-22 22:14:41 +02:00
|
|
|
} else if ( jQuery.browser == "safari" ) {
|
2006-06-19 02:12:14 +02:00
|
|
|
// Continually check to see if the document.readyState is valid
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.safariTimer = setInterval(function(){
|
2006-06-19 02:12:14 +02:00
|
|
|
// loaded and complete are both valid states
|
|
|
|
if ( document.readyState == "loaded" ||
|
|
|
|
document.readyState == "complete" ) {
|
|
|
|
|
|
|
|
// If either one are found, remove the timer
|
2006-06-22 22:14:41 +02:00
|
|
|
clearInterval( jQuery.safariTimer );
|
|
|
|
jQuery.safariTimer = null;
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
// and execute any waiting functions
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.ready();
|
2006-06-19 02:12:14 +02:00
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
// A fallback to window.onload, that will always work
|
2006-06-22 22:14:41 +02:00
|
|
|
jQuery.event.add( window, "load", jQuery.ready );
|
2006-06-19 02:12:14 +02:00
|
|
|
|
|
|
|
})();
|