git.asbjorn.biz
/
jquery.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Made sure that $.event.handle() always has some form of an event object.
[jquery.git]
/
jquery
/
jquery.js
diff --git
a/jquery/jquery.js
b/jquery/jquery.js
index
e9db33d
..
fe12bf7
100644
(file)
--- a/
jquery/jquery.js
+++ b/
jquery/jquery.js
@@
-9,6
+9,9
@@
* $Rev$
*/
* $Rev$
*/
+/* For JSLint (jslint.com): */
+/*extern ActiveXObject Prototype setTimeout setInterval clearInterval document window XMLHttpRequest navigator*/
+
function $(a,c) {
var $a = a || $.context || document;
var $c = c && c.$jquery && c.get(0) || c;
function $(a,c) {
var $a = a || $.context || document;
var $c = c && c.$jquery && c.get(0) || c;
@@
-214,13
+217,13
@@
function $(a,c) {
},
bind: function(t,f) {
},
bind: function(t,f) {
- return this.each(function(){addEvent(this,t,f);});
+ return this.each(function(){$.event.add(this,t,f);});
},
unbind: function(t,f) {
},
unbind: function(t,f) {
- return this.each(function(){removeEvent(this,t,f);});
+ return this.each(function(){$.event.remove(this,t,f);});
},
trigger: function(t) {
},
trigger: function(t) {
- return this.each(function(){triggerEvent(this,t);});
+ return this.each(function(){$.event.trigger(this,t);});
},
find: function(t) {
},
find: function(t) {
@@
-315,6
+318,8
@@
function $(a,c) {
return self;
}
return self;
}
+$.eval = eval;
+
$.apply = function(o,f,a) {
a = a || [];
if ( f.apply ) {
$.apply = function(o,f,a) {
a = a || [];
if ( f.apply ) {
@@
-325,7
+330,7
@@
$.apply = function(o,f,a) {
p[i] = 'a['+i+']';
}
o.$$exec = this;
p[i] = 'a['+i+']';
}
o.$$exec = this;
- var r = eval('o.$$exec(' + p.join(',') + ')');
+ var r = $.eval('o.$$exec(' + p.join(',') + ')');
o.$$exec = null;
return r;
}
o.$$exec = null;
return r;
}
@@
-568,7
+573,7
@@
$.attr = function(o,a,v){
a = (fix[a] && fix[a].replace && fix[a]) || a;
var r = new RegExp("-([a-z])","ig");
a = a.replace(r,function(z,b){return b.toUpperCase();});
a = (fix[a] && fix[a].replace && fix[a]) || a;
var r = new RegExp("-([a-z])","ig");
a = a.replace(r,function(z,b){return b.toUpperCase();});
- if ( v !== null ) {
+ if ( typeof v != 'undefined' ) {
o[a] = v;
if ( o.setAttribute ) {
o.setAttribute(a,v);
o[a] = v;
if ( o.setAttribute ) {
o.setAttribute(a,v);
@@
-620,7
+625,7
@@
$.filter = function(t,r,not) {
}
if ( f !== null ) {
}
if ( f !== null ) {
- eval('f = function(a,i){return ' + f + '}');
+ $.eval('f = function(a,i){return ' + f + '}');
r = g( r, f );
}
}
r = g( r, f );
}
}
@@
-728,11
+733,13
@@
$.map = function(a,f) {
return r;
};
return r;
};
+$.event = {};
+
// Bind an event to an element
// Original by Dean Edwards
// Bind an event to an element
// Original by Dean Edwards
-function addEvent(element, type, handler) {
+$.event.add = function(element, type, handler) {
if ( element.location ) { element = window; } // Ughhhhh....
if ( element.location ) { element = window; } // Ughhhhh....
- if (!handler.$$guid) { handler.$$guid = addEvent.guid++; }
+ if (!handler.$$guid) { handler.$$guid = $.event.add.guid++; }
if (!element.events) { element.events = {}; }
var handlers = element.events[type];
if (!handlers) {
if (!element.events) { element.events = {}; }
var handlers = element.events[type];
if (!handlers) {
@@
-742,13
+749,13
@@
function addEvent(element, type, handler) {
}
}
handlers[handler.$$guid] = handler;
}
}
handlers[handler.$$guid] = handler;
- element["on" + type] = handleEvent;
-}
+ element["on" + type] = $.event.handle;
+};
-addEvent.guid = 1;
+$.event.add.guid = 1;
// Detach an event or set of events from an element
// Detach an event or set of events from an element
-function removeEvent(element, type, handler) {
+$.event.remove = function(element, type, handler) {
if (element.events) {
if (type && element.events[type]) {
if ( handler ) {
if (element.events) {
if (type && element.events[type]) {
if ( handler ) {
@@
-760,26
+767,29
@@
function removeEvent(element, type, handler) {
}
} else {
for ( var j in element.events ) {
}
} else {
for ( var j in element.events ) {
- removeEvent( element, j );
+ $.event.remove( element, j );
}
}
}
}
}
}
-}
+};
-function triggerEvent(element,type,data) {
+$.event.trigger = function(element,type,data) {
data = data || [{ type: type }];
if ( element && element["on" + type] ) {
$.apply( element, element["on" + type], data );
}
data = data || [{ type: type }];
if ( element && element["on" + type] ) {
$.apply( element, element["on" + type], data );
}
-}
+};
+
+$.event.handle = function(event) {
+ if ( !event && !window.event ) { return null; }
+
+ var returnValue = true, handlers = [];
+ event = event || $.event.fix(window.event);
-function handleEvent(event) {
- var returnValue = true;
- event = event || fixEvent(window.event);
- var handlers = [];
for ( var j in this.events[event.type] ) {
handlers[handlers.length] = this.events[event.type][j];
}
for ( var j in this.events[event.type] ) {
handlers[handlers.length] = this.events[event.type][j];
}
+
for ( var i = 0; i < handlers.length; i++ ) {
try {
if ( handlers[i].constructor == Function ) {
for ( var i = 0; i < handlers.length; i++ ) {
try {
if ( handlers[i].constructor == Function ) {
@@
-793,19
+803,19
@@
function handleEvent(event) {
} catch(e){}
}
return returnValue;
} catch(e){}
}
return returnValue;
-}
+};
-function fixEvent(event) {
- event.preventDefault = fixEvent.preventDefault;
- event.stopPropagation = fixEvent.stopPropagation;
+$.event.fix = function(event) {
+ event.preventDefault = $.event.fix.preventDefault;
+ event.stopPropagation = $.event.fix.stopPropagation;
return event;
return event;
-}
+};
-fixEvent.preventDefault = function() {
+$.event.fix.preventDefault = function() {
this.returnValue = false;
};
this.returnValue = false;
};
-fixEvent.stopPropagation = function() {
+$.event.fix.stopPropagation = function() {
this.cancelBubble = true;
};
this.cancelBubble = true;
};