X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=jquery%2Fjquery.js;h=4592c1bf3bea6a0fda5a854681f07c95350637e4;hb=c75701a0152a589c21c4862c33b691902a8b8f7b;hp=bd25ed2055a7401bebe16b8165167130e292ff6f;hpb=d71a85001b0562ed05925e0c5635c3c0a1d52068;p=jquery.git diff --git a/jquery/jquery.js b/jquery/jquery.js index bd25ed2..4592c1b 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; @@ -43,7 +46,7 @@ function $(a,c) { // The only two getters size: function() {return this.get().length;}, get: function(i) { - return i === null ? this.cur : this.cur[i]; + return typeof i == 'undefined' ? this.cur : this.cur[i]; }, each: function(f) { @@ -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; } @@ -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();}); - if ( v !== null ) { + if ( typeof v != 'undefined' ) { o[a] = v; if ( o.setAttribute ) { o.setAttribute(a,v); @@ -620,7 +625,7 @@ $.filter = function(t,r,not) { } if ( f !== null ) { - f = new 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; };