X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=jquery%2Fjquery.js;h=179cd29a70e88152fc01af28561d4dafefceeb10;hb=956529c7beddf7fed3f9d92aec10ecaa3289ad1b;hp=e9db33d1f777b0962e4b816c4e7ba418fc07bdba;hpb=2a6b0ee7c846d5bdd535dcc9a399d528f65460ac;p=jquery.git diff --git a/jquery/jquery.js b/jquery/jquery.js index e9db33d..179cd29 100644 --- a/jquery/jquery.js +++ b/jquery/jquery.js @@ -9,6 +9,9 @@ * $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; @@ -214,13 +217,13 @@ function $(a,c) { }, 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) { - return this.each(function(){removeEvent(this,t,f);}); + return this.each(function(){$.event.remove(this,t,f);}); }, trigger: function(t) { - return this.each(function(){triggerEvent(this,t);}); + return this.each(function(){$.event.trigger(this,t);}); }, find: function(t) { @@ -315,6 +318,8 @@ function $(a,c) { return self; } +$.eval = eval; + $.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; - var r = eval('o.$$exec(' + p.join(',') + ')'); + var r = $.eval('o.$$exec(' + p.join(',') + ')'); o.$$exec = null; return r; } @@ -620,7 +625,7 @@ $.filter = function(t,r,not) { } if ( f !== null ) { - eval('f = function(a,i){return ' + f + '}'); + $.eval('f = function(a,i){return ' + f + '}'); r = g( r, f ); } } @@ -728,11 +733,13 @@ $.map = function(a,f) { return r; }; +$.event = {}; + // 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 (!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) { @@ -742,13 +749,13 @@ function addEvent(element, type, 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 -function removeEvent(element, type, handler) { +$.event.remove = function(element, type, handler) { if (element.events) { if (type && element.events[type]) { if ( handler ) { @@ -760,22 +767,22 @@ function removeEvent(element, type, handler) { } } 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 ); } -} +}; -function handleEvent(event) { +$.event.handle = function(event) { var returnValue = true; - event = event || fixEvent(window.event); + event = event || $.event.fix(window.event); var handlers = []; for ( var j in this.events[event.type] ) { handlers[handlers.length] = this.events[event.type][j]; @@ -793,19 +800,19 @@ function handleEvent(event) { } 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; -} +}; -fixEvent.preventDefault = function() { +$.event.fix.preventDefault = function() { this.returnValue = false; }; -fixEvent.stopPropagation = function() { +$.event.fix.stopPropagation = function() { this.cancelBubble = true; };