Changeset 1386
- Timestamp:
- 06/12/08 06:16:51 (4 months ago)
- Files:
-
- mochikit/trunk/MochiKit/Signal.js (modified) (6 diffs)
- mochikit/trunk/doc/html/MochiKit/Signal.html (modified) (2 diffs)
- mochikit/trunk/doc/rst/MochiKit/Signal.rst (modified) (2 diffs)
- mochikit/trunk/examples/mouse_events (added)
- mochikit/trunk/examples/mouse_events/index.html (added)
- mochikit/trunk/examples/mouse_events/mouse_events.css (added)
- mochikit/trunk/examples/mouse_events/mouse_events.js (added)
- mochikit/trunk/packed/MochiKit/MochiKit.js (modified) (6 diffs)
- mochikit/trunk/tests/test_Signal.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/trunk/MochiKit/Signal.js
r1378 r1386 56 56 ', client: ' + repr(this.mouse().client); 57 57 58 if (this.type() != 'mousemove' ) {58 if (this.type() != 'mousemove' && this.type() != 'mousewheel') { 59 59 str += ', button: {left: ' + repr(this.mouse().button.left) + 60 60 ', middle: ' + repr(this.mouse().button.middle) + 61 ', right: ' + repr(this.mouse().button.right) + '}}'; 62 } else { 63 str += '}'; 64 } 61 ', right: ' + repr(this.mouse().button.right) + '}'; 62 } 63 if (this.type() == 'mousewheel') { 64 str += ', wheel: ' + repr(this.mouse().wheel); 65 } 66 str += '}'; 65 67 } 66 68 if (this.type() == 'mouseover' || this.type() == 'mouseout' || … … 89 91 /** @id MochiKit.Signal.Event.prototype.type */ 90 92 type: function () { 91 return this._event.type || undefined; 93 if (this._event.type === "DOMMouseScroll") { 94 return "mousewheel"; 95 } else { 96 return this._event.type || undefined; 97 } 92 98 }, 93 99 … … 293 299 294 300 } 295 if (this.type() != 'mousemove' ) {301 if (this.type() != 'mousemove' && this.type() != 'mousewheel') { 296 302 m.button = {}; 297 303 m.button.left = false; … … 327 333 m.button.middle = !!(e.button & 4); 328 334 } 335 } 336 if (this.type() == 'mousewheel') { 337 m.wheel = e.detail ? e.detail : -e.wheelDelta / 40; 329 338 } 330 339 this._mouse = m; … … 550 559 }, 551 560 561 _browserHasMouseWheelEvent: function () { 562 return /MSIE/.test(navigator.userAgent) || /Opera/.test(navigator.userAgent); 563 }, 564 552 565 _mouseEnterListener: function (src, sig, func, obj) { 553 566 var E = MochiKit.Signal.Event; … … 623 636 sig = "onmouseout"; 624 637 } 638 } else if (isDOM && sig == "onmousewheel" && !self._browserHasMouseWheelEvent()) { 639 var listener = self._listener(src, sig, func, obj, isDOM); 640 sig = "onDOMMouseScroll"; 625 641 } else { 626 642 var listener = self._listener(src, sig, func, obj, isDOM); mochikit/trunk/doc/html/MochiKit/Signal.html
r1378 r1386 152 152 </dl> 153 153 </blockquote> 154 <p><tt class="docutils literal"><span class="pre">onmousewheel</span></tt></p> 155 <blockquote> 156 <p>Not strictly synthesized, but named <tt class="docutils literal"><span class="pre">'DOMMouseScroll'</span></tt> in Firefox 157 and Safari browsers. MochiKit translates <tt class="docutils literal"><span class="pre">'onmousewheel'</span></tt> to the 158 correct event in these browsers.</p> 159 <dl class="docutils"> 160 <dt><em>Availability:</em></dt> 161 <dd>Available in MochiKit 1.4+</dd> 162 </dl> 163 </blockquote> 154 164 </div> 155 165 <div class="section"> … … 411 421 each property is <tt class="docutils literal"><span class="pre">true</span></tt> if the mouse button was pressed, 412 422 <tt class="docutils literal"><span class="pre">false</span></tt> otherwise.</li> 423 </ul> 424 </blockquote> 425 <p>Properties for <tt class="docutils literal"><span class="pre">'onmousewheel'</span></tt>:</p> 426 <blockquote> 427 <ul class="simple"> 428 <li><tt class="docutils literal"><span class="pre">mouse().wheel</span></tt> returns a number for the scroll wheel 429 offset. The number will normally be +3 when scrolling down, 430 and -3 when scrolling up.</li> 413 431 </ul> 414 432 </blockquote> mochikit/trunk/doc/rst/MochiKit/Signal.rst
r1378 r1386 168 168 Available in MochiKit 1.4+ 169 169 170 ``onmousewheel`` 171 172 Not strictly synthesized, but named ``'DOMMouseScroll'`` in Firefox 173 and Safari browsers. MochiKit translates ``'onmousewheel'`` to the 174 correct event in these browsers. 175 176 *Availability:* 177 Available in MochiKit 1.4+ 178 170 179 171 180 Using Signal for non-DOM objects … … 416 425 ``false`` otherwise. 417 426 427 Properties for ``'onmousewheel'``: 428 429 - ``mouse().wheel`` returns a number for the scroll wheel 430 offset. The number will normally be +3 when scrolling down, 431 and -3 when scrolling up. 432 418 433 Known browser bugs: 419 434 mochikit/trunk/packed/MochiKit/MochiKit.js
r1385 r1386 4912 4912 if(this.type()&&(this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu")){ 4913 4913 str+=", mouse(): {page: "+repr(this.mouse().page)+", client: "+repr(this.mouse().client); 4914 if(this.type()!="mousemove"){ 4915 str+=", button: {left: "+repr(this.mouse().button.left)+", middle: "+repr(this.mouse().button.middle)+", right: "+repr(this.mouse().button.right)+"}}"; 4916 }else{ 4914 if(this.type()!="mousemove"&&this.type()!="mousewheel"){ 4915 str+=", button: {left: "+repr(this.mouse().button.left)+", middle: "+repr(this.mouse().button.middle)+", right: "+repr(this.mouse().button.right)+"}"; 4916 } 4917 if(this.type()=="mousewheel"){ 4918 str+=", wheel: "+repr(this.mouse().wheel); 4919 } 4917 4920 str+="}"; 4918 }4919 4921 } 4920 4922 if(this.type()=="mouseover"||this.type()=="mouseout"||this.type()=="mouseenter"||this.type()=="mouseleave"){ … … 4930 4932 return this._event; 4931 4933 },type:function(){ 4934 if(this._event.type==="DOMMouseScroll"){ 4935 return "mousewheel"; 4936 }else{ 4932 4937 return this._event.type||undefined; 4938 } 4933 4939 },target:function(){ 4934 4940 return this._event.target||this._event.srcElement; … … 5014 5020 m.page.y=e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); 5015 5021 } 5016 if(this.type()!="mousemove" ){5022 if(this.type()!="mousemove"&&this.type()!="mousewheel"){ 5017 5023 m.button={}; 5018 5024 m.button.left=false; … … 5028 5034 m.button.middle=!!(e.button&4); 5029 5035 } 5036 } 5037 if(this.type()=="mousewheel"){ 5038 m.wheel=e.detail?e.detail:-e.wheelDelta/40; 5030 5039 } 5031 5040 this._mouse=m; … … 5139 5148 },_browserAlreadyHasMouseEnterAndLeave:function(){ 5140 5149 return /MSIE/.test(navigator.userAgent); 5150 },_browserHasMouseWheelEvent:function(){ 5151 return /MSIE/.test(navigator.userAgent)||/Opera/.test(navigator.userAgent); 5141 5152 },_mouseEnterListener:function(src,sig,func,obj){ 5142 5153 var E=MochiKit.Signal.Event; … … 5206 5217 } 5207 5218 }else{ 5219 if(_565&&sig=="onmousewheel"&&!self._browserHasMouseWheelEvent()){ 5208 5220 var _566=self._listener(src,sig,func,obj,_565); 5221 sig="onDOMMouseScroll"; 5222 }else{ 5223 var _566=self._listener(src,sig,func,obj,_565); 5224 } 5209 5225 } 5210 5226 if(src.addEventListener){ mochikit/trunk/tests/test_Signal.js
r1378 r1386 60 60 newEvt.clientY = 1; 61 61 newEvt.button = 1; 62 newEvt.detail = 3; 62 63 element.fireEvent('on' + eventType, newEvt); 63 64 } else if (document.createEvent && (typeof(document.createEvent('MouseEvents').initMouseEvent) == 'function')) { 64 65 var evt = document.createEvent('MouseEvents'); 65 66 evt.initMouseEvent(eventType, canBubble, true, // event, bubbles, cancelable 66 document.defaultView, 1, // view, # of clicks67 document.defaultView, 3, // view, detail (either scroll or # of clicks) 67 68 1, 0, 0, 0, // screenX, screenY, clientX, clientY 68 69 false, false, false, false, // ctrlKey, altKey, shiftKey, metaKey … … 97 98 t.ok((typeof(e.relatedTarget()) === 'undefined'), 'checking that relatedTarget() is undefined'); 98 99 t.ok((typeof(e.key()) === 'undefined'), 'checking that key() is undefined'); 100 t.ok((typeof(e.mouse().wheel) === 'undefined'), 'checking that mouse().wheel is undefined'); 99 101 }; 100 102 … … 108 110 t.is(i, 3, 'Disconnecting an event to an HTML object and firing a synthetic event'); 109 111 110 111 112 } 112 ident = connect('submit', 'onmousewheel', function(e) { 113 i++; 114 t.ok((typeof(e.mouse()) === 'object'), 'checking that mouse() is an object'); 115 t.ok((typeof(e.mouse().wheel) === 'number'), 'checking that mouse().wheel is a number'); 116 }); 117 var nativeSignal = 'mousewheel'; 118 if (!/MSIE/.test(navigator.userAgent) && !/Opera/.test(navigator.userAgent)) { 119 nativeSignal = 'DOMMouseScroll'; 120 } 121 triggerMouseEvent('submit', nativeSignal, false); 122 t.is(i, 4, 'Connecting a mousewheel event to an HTML object and firing a synthetic event'); 123 disconnect(ident); 124 triggerMouseEvent('submit', nativeSignal, false); 125 t.is(i, 4, 'Disconnecting a mousewheel event to an HTML object and firing a synthetic event'); 126 } 113 127 114 128 // non-DOM tests
