Changeset 6287
- Timestamp:
- 03/02/07 14:01:24 (1 year ago)
- Files:
-
- spinoffs/prototype/branches/event/src/event.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/branches/event/src/event.js
r6237 r6287 114 114 Object.extend(Observer.prototype, { 115 115 _add: function() { 116 // TODO: create wrapper for Safari?117 116 this.element.addEventListener(this.type, this.observer, this.useCapture); 118 117 }, … … 126 125 // create a wrapper for scope correction and event object normalization 127 126 var ob = this.observer, el = this.element, klass = this.constructor; 128 this.wrapper = function(e) { 129 return ob.call(el, klass.extendEvent(e)) 130 }; 127 this.wrapper = function(e) { return ob.call(el, klass.extendEvent(e)) }; 131 128 this.element.attachEvent('on' + this.type, this.wrapper); 132 129 this.constructor.globalCache.push(this); … … 141 138 globalCache: [], 142 139 unloadCache: function() { 143 for (var i=0, length = this.globalCache.length; i < length; i++)140 for (var i = 0, length = this.globalCache.length; i < length; i++) 144 141 this.globalCache[i].remove(); 145 142 }, … … 157 154 }, 158 155 eventMethods: { 159 stopPropagation: function() { this.cancelBubble = true ;},160 preventDefault: function() { this.returnValue = false ;},161 inspect: function() { return '[object Event]' ;}156 stopPropagation: function() { this.cancelBubble = true }, 157 preventDefault: function() { this.returnValue = false }, 158 inspect: function() { return '[object Event]' } 162 159 } 163 160 }); … … 168 165 169 166 // applies the calling method to an array of elements 170 function applyTo List(args) {167 function applyToCollection(args) { 171 168 if (args[0].constructor != Array) return false; 172 169 var method = args.callee; 173 170 args = $A(args); 174 args.shift().each(function(el){ 175 method.apply(null, [el].concat(args)); 176 }); 171 args.shift().each(function(el){ method.apply(null, [el].concat(args)) }); 177 172 return true; // the calling method can end 178 } ,173 }; 179 174 180 175 return { 181 176 observe: function(element, type, observer, useCapture) { 182 if (applyTo List(arguments)) return;177 if (applyToCollection(arguments)) return; 183 178 new Observer(element, type, observer, useCapture).add(); 184 179 }, 185 180 stopObserving: function(element, type, observer, useCapture) { 186 if (applyTo List(arguments)) return;181 if (applyToCollection(arguments)) return; 187 182 new Observer(element, type, observer, useCapture).remove(); 188 183 }