git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bug fix with how global event triggers are handled.
[jquery.git]
/
event
/
event.js
diff --git
a/event/event.js
b/event/event.js
index
485dc4e
..
fe6e621
100644
(file)
--- a/
event/event.js
+++ b/
event/event.js
@@
-1,22
+1,22
@@
// We're overriding the old toggle function, so
// remember it for later
// We're overriding the old toggle function, so
// remember it for later
-$.fn._toggle = $.fn.toggle;
+jQuery.prototype._toggle = jQuery.prototype.toggle;
/**
* Toggle between two function calls every other click.
*/
/**
* Toggle between two function calls every other click.
*/
-$.fn.toggle = function(a,b) {
+jQuery.prototype.toggle = function(a,b) {
// 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;
// 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;
- // Make sure that clicks don't pass through
+ // Make sure that clicks stop
e.preventDefault();
// and execute the function
e.preventDefault();
// and execute the function
- return $.apply( this, this.last, [e] ) || false;
+ return this.last.apply( this, [e] ) || false;
}) :
// Otherwise, execute the old toggle function
}) :
// Otherwise, execute the old toggle function
@@
-26,19
+26,21
@@
$.fn.toggle = function(a,b) {
/**
* Toggle between two function calls on mouse over/out.
*/
/**
* Toggle between two function calls on mouse over/out.
*/
-$.fn.hover = function(f,g) {
+jQuery.prototype.hover = function(f,g) {
// A private function for haandling mouse 'hovering'
function handleHover(e) {
// Check if mouse(over|out) are still within the same parent element
// 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;
+ var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
+
+ // Traverse up the tree
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
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
- return (e.type == "mouseover" ? f : g).apply(this,[e]);
+ return (e.type == "mouseover" ? f : g).apply(this, [e]);
}
// Bind the function to the two event listeners
}
// Bind the function to the two event listeners
@@
-48,16
+50,16
@@
$.fn.hover = function(f,g) {
/**
* Bind a function to fire when the DOM is ready.
*/
/**
* Bind a function to fire when the DOM is ready.
*/
-$.fn.ready = function(f) {
+jQuery.prototype.ready = function(f) {
// If the DOM is already ready
// If the DOM is already ready
- if ( $.isReady )
+ if ( jQuery.isReady )
// Execute the function immediately
// Execute the function immediately
- $.apply( document, f );
+ f.apply( document );
// Otherwise, remember the function for later
else {
// Add the function to the wait list
// Otherwise, remember the function for later
else {
// Add the function to the wait list
- $.readyList.push( f );
+ jQuery.readyList.push( f );
}
return this;
}
return this;
@@
-67,9
+69,9
@@
$.fn.ready = function(f) {
/*
* Bind a number of event-handling functions, dynamically
*/
/*
* Bind a number of event-handling functions, dynamically
*/
- var e = "blur,focus,contextmenu,load,resize,scroll,unload,click,dblclick," +
+ var e = ("blur,focus,contextmenu,load,resize,scroll,unload,click,dblclick," +
"mousedown,mouseup,mouseenter,mouseleave,mousemove,mouseover,mouseout," +
"mousedown,mouseup,mouseenter,mouseleave,mousemove,mouseover,mouseout," +
- "change,reset,select,submit,keydown,keypress,keyup,abort,error,ready".split(",");
+ "change,reset,select,submit,keydown,keypress,keyup").split(",");
// Go through all the event names, but make sure that
// it is enclosed properly
// Go through all the event names, but make sure that
// it is enclosed properly
@@
-78,16
+80,16
@@
$.fn.ready = function(f) {
var o = e[i];
// Handle event binding
var o = e[i];
// Handle event binding
- $.fn[o] = function(f){ return this.bind(o, f); };
+ jQuery.prototype[o] = function(f){ return this.bind(o, f); };
// Handle event unbinding
// Handle event unbinding
- $.fn["un"+o] = function(f){ return this.unbind(o, f); };
+ jQuery.prototype["un"+o] = function(f){ return this.unbind(o, f); };
// Handle event triggering
// Handle event triggering
- $.fn["do"+o] = function(){ return this.trigger(o); };
+ jQuery.prototype["do"+o] = function(){ return this.trigger(o); };
// Finally, handle events that only fire once
// Finally, handle events that only fire once
- $.fn["one"+o] = function(f){
+ jQuery.prototype["one"+o] = function(f){
// Attach the event listener
return this.bind(o, function(e){
// TODO: Remove the event listener, instead of this hack
// Attach the event listener
return this.bind(o, function(e){
// TODO: Remove the event listener, instead of this hack
@@
-100,7
+102,7
@@
$.fn.ready = function(f) {
this[o+f]++;
// And execute the bound function
this[o+f]++;
// And execute the bound function
- return $.apply(this,f,[e]);
+ return f.apply(this, [e]);
});
};
});
};
@@
-110,70
+112,70
@@
$.fn.ready = function(f) {
* All the code that makes DOM Ready work nicely.
*/
* All the code that makes DOM Ready work nicely.
*/
- $.isReady = false;
- $.readyList = [];
+ jQuery.isReady = false;
+ jQuery.readyList = [];
// Handle when the DOM is ready
// Handle when the DOM is ready
- $.ready = function() {
- // Make sure that the DOM hasn't already loaded
- if ( !$.isReady ) {
+ jQuery.ready = function() {
+ // Make sure that the DOM is not already loaded
+ if ( !jQuery.isReady ) {
// Remember that the DOM is ready
// Remember that the DOM is ready
- $.isReady = true;
+ jQuery.isReady = true;
// If there are functions bound, to execute
// If there are functions bound, to execute
- if ( $.readyList ) {
+ if ( jQuery.readyList ) {
// Execute all of them
// Execute all of them
- for ( var i = 0; i < $.readyList.length; i++ )
- $.apply( document, $.readyList[i] );
+ for ( var i = 0; i < jQuery.readyList.length; i++ )
+ jQuery.readyList[i].apply( document );
// Reset the list of functions
// Reset the list of functions
- $.readyList = null;
+ jQuery.readyList = null;
}
}
};
// If Mozilla is used
}
}
};
// If Mozilla is used
- if ( $.browser == "mozilla" || $.browser == "opera" ) {
+ if ( jQuery.browser == "mozilla" || jQuery.browser == "opera" ) {
// Use the handy event callback
// Use the handy event callback
- $.event.add( document, "DOMContentLoaded", $.ready );
+ document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
// If IE is used, use the excellent hack by Matthias Miller
// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
// If IE is used, use the excellent hack by Matthias Miller
// http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
- } else if ( $.browser == "msie" ) {
+ } else if ( jQuery.browser == "msie" ) {
// Only works if you document.write() it
document.write("<scr" + "ipt id=__ie_init defer=true " +
// Only works if you document.write() it
document.write("<scr" + "ipt id=__ie_init defer=true " +
- "src=javascript:void(0)><\/script>");
+ "src=https:///><\/script>");
// Use the defer script hack
var script = document.getElementById("__ie_init");
script.onreadystatechange = function() {
if ( this.readyState == "complete" )
// Use the defer script hack
var script = document.getElementById("__ie_init");
script.onreadystatechange = function() {
if ( this.readyState == "complete" )
- $.ready();
+ jQuery.ready();
};
// Clear from memory
script = null;
// If Safari is used
};
// Clear from memory
script = null;
// If Safari is used
- } else if ( $.browser == "safari" ) {
+ } else if ( jQuery.browser == "safari" ) {
// Continually check to see if the document.readyState is valid
// Continually check to see if the document.readyState is valid
- $.safariTimer = setInterval(function(){
+ jQuery.safariTimer = setInterval(function(){
// loaded and complete are both valid states
if ( document.readyState == "loaded" ||
document.readyState == "complete" ) {
// If either one are found, remove the timer
// loaded and complete are both valid states
if ( document.readyState == "loaded" ||
document.readyState == "complete" ) {
// If either one are found, remove the timer
- clearInterval( $.safariTimer );
- $.safariTimer = null;
+ clearInterval( jQuery.safariTimer );
+ jQuery.safariTimer = null;
// and execute any waiting functions
// and execute any waiting functions
- $.ready();
+ jQuery.ready();
}
}, 10);
}
// A fallback to window.onload, that will always work
}
}, 10);
}
// A fallback to window.onload, that will always work
- $.event.add( window, "load", $.ready );
+ jQuery.event.add( window, "load", jQuery.ready );
})();
})();