Changeset 7056
- Timestamp:
- 06/18/07 17:00:15 (1 year ago)
- Files:
-
- spinoffs/prototype/branches/event/src/event.js (modified) (5 diffs)
- spinoffs/prototype/branches/event/test/functional/event.html (modified) (2 diffs)
- spinoffs/prototype/branches/event/TODO (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/branches/event/src/event.js
r7045 r7056 64 64 Object.extend(Observer.prototype, { 65 65 initialize: function(element, type, callback, useCapture) { 66 this.element = $(element); 66 // underscored properties are for overriding 67 this.element = this._element = $(element); 67 68 this.type = this._type = type; 68 69 this.callback = this._callback = callback; … … 73 74 if (B.IE || B.WebKit) this._type = 'keydown'; 74 75 break; 75 case 'mouseenter': case 'mouseleave': 76 case 'mouseenter': 77 case 'mouseleave': 76 78 if (B.IE) break; 77 79 this._type = type == 'mouseenter' ? 'mouseover' : 'mouseout'; 78 80 this._callback = function(event) { 79 81 var rel = event.relatedTarget, cur = event.currentTarget; 80 rel = (rel.nodeType == Node.TEXT_NODE) ? rel.parentNode : rel;81 if (rel && rel != =cur && !rel.descendantOf(cur))82 if (rel.nodeType == Node.TEXT_NODE) rel = rel.parentNode; 83 if (rel && rel != cur && !rel.descendantOf(cur)) 82 84 return callback.call(this, event); 83 85 }; 84 86 break; 85 87 case 'mousewheel': 88 case 'DOMMouseScroll': 89 if (B.IE || B.Opera) this._type = 'mousewheel'; 90 else this._type = 'DOMMouseScroll'; 91 86 92 if (B.IE) { 87 // this.element == window ? document : this.element93 if (this.element == window) this._element = document; 88 94 this._callback = function(event) { 89 95 callback.call(this, event, event.wheelDelta/120); 90 96 } 91 97 } else { 92 this._type = 'DOMMouseScroll'; 98 if (this.element == document && (B.Opera || B.Safari)) this._element = window; 99 // Opera handler is similar to IE's 93 100 this._callback = B.Opera ? function(event) { 94 101 callback.call(this, event, -event.wheelDelta/120); … … 102 109 add: function() { 103 110 if (this.type == 'DOMContentLoaded' && this.element == document) { 104 Event.onReady(this.callback); return; 111 Event.onReady(this.callback); 112 return; 105 113 } 106 114 this._add(); … … 155 163 Object.extend(Observer.prototype, { 156 164 _add: function() { 157 this.element.addEventListener(this._type, this._callback, this.useCapture); 165 if (this._type == 'mousewheel') 166 this._element['on' + this._type] = this._callback; 167 else 168 this._element.addEventListener(this._type, this._callback, this.useCapture); 158 169 }, 159 170 _remove: function() { 160 this.element.removeEventListener(this._type, this._callback, this.useCapture); 171 if (this._type == 'mousewheel') 172 this._element['on' + this._type] = null; 173 else 174 this._element.removeEventListener(this._type, this._callback, this.useCapture); 161 175 } 162 176 }); 163 177 178 // extend Event.prototype with our neat instance methods 164 179 Event.prototype = Event.prototype || document.createEvent("UIEvents").__proto__; 165 180 Object.extend(Event.prototype, instanceMethods); … … 168 183 _add: function() { 169 184 // create a wrapper for scope correction and event object normalization 170 var ob = this._callback, el = this. element, klass = this.constructor;185 var ob = this._callback, el = this._element, klass = this.constructor; 171 186 this.wrapper = function(e) { return ob.call(el, klass.extendEvent(e, el)) }; 172 187 // attach it 173 if (this._type == 'mousewheel') this. element['on' + this._type] = this.wrapper;174 else this. element.attachEvent('on' + this._type, this.wrapper);188 if (this._type == 'mousewheel') this._element['on' + this._type] = this.wrapper; 189 else this._element.attachEvent('on' + this._type, this.wrapper); 175 190 this.constructor.globalCache.push(this); 176 191 }, 177 192 _remove: function() { 178 if (this._type == 'mousewheel') this. element['on' + this._type] = null;193 if (this._type == 'mousewheel') this._element['on' + this._type] = null; 179 194 else { 180 195 if (!this.wrapper) 181 this.wrapper = this. element._observers[this.type][this.callback.$$guid].wrapper;182 this. element.detachEvent('on' + this._type, this.wrapper);196 this.wrapper = this._element._observers[this.type][this.callback.$$guid].wrapper; 197 this._element.detachEvent('on' + this._type, this.wrapper); 183 198 } 184 199 } spinoffs/prototype/branches/event/test/functional/event.html
r7045 r7056 180 180 msg.update('<i>DETACHED</i>').setStyle({ color:'gray' }); 181 181 }, 182 scope: $('wheel')182 scope: document 183 183 } 184 184 </script> … … 342 342 </script> 343 343 344 <p id="custom_events">Custom events test </p>344 <p id="custom_events">Custom events test <b>(incomplete)</b></p> 345 345 346 346 <p id="custom_events_target">Lorem ipsum dolor sit amet.</p> spinoffs/prototype/branches/event/TODO
r7045 r7056 1 * [done] Event handling (IE) fixes and enhancements, see r6194 2 * [done] Remove all event listeners on any element 3 * [done] event.stop() instead of Event.stop(event) 4 * [done] Node constants as per DOM/ECMAScript bindings (r6205) 5 * [done] isLeft/Middle/RightClick 6 * [done] support for "DOMContentLoaded" 7 * [done] Event.findElement should extend the result 1 * try to prevent wrapper functions from messing with the scope: 2 - IE scope correction hack 3 - mouseenter/leave 4 - mousewheel 8 5 * resolve special cases for mousewheel handling: 9 6 - window in IE 10 7 - document in Opera 8 - Opera & Safari won't fire the event on objects other than document 11 9 * stopImmediatePropagation 12 10 http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-Event-stopImmediatePropagation … … 14 12 https://prototype.campfirenow.com/room/73745/transcript/message/23651995#message_23651995 15 13 * Custom events for adding/removing class names, updating elements, etc. 14 15 16 Useful resources 17 ---------------- 18 19 http://www.quirksmode.org/dom/w3c_events.html 20 http://del.icio.us/mislav/events 21 http://dev.opera.com/articles/javascript/