Changeset 1386

Show
Ignore:
Timestamp:
06/12/08 06:16:51 (4 months ago)
Author:
cederberg@gmail.com
Message:

Added initial support for 'onmousewheel' event in MochiKit.Signal. Based on patch submitted by Simon Cusack. Fixes trac ticket #156.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/trunk/MochiKit/Signal.js

    r1378 r1386  
    5656                ', client: ' + repr(this.mouse().client); 
    5757 
    58             if (this.type() != 'mousemove') { 
     58            if (this.type() != 'mousemove' && this.type() != 'mousewheel') { 
    5959                str += ', button: {left: ' + repr(this.mouse().button.left) + 
    6060                    ', 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 += '}'; 
    6567        } 
    6668        if (this.type() == 'mouseover' || this.type() == 'mouseout' ||  
     
    8991    /** @id MochiKit.Signal.Event.prototype.type */ 
    9092    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        } 
    9298    }, 
    9399 
     
    293299 
    294300            } 
    295             if (this.type() != 'mousemove') { 
     301            if (this.type() != 'mousemove' && this.type() != 'mousewheel') { 
    296302                m.button = {}; 
    297303                m.button.left = false; 
     
    327333                    m.button.middle = !!(e.button & 4); 
    328334                } 
     335            } 
     336            if (this.type() == 'mousewheel') { 
     337                m.wheel = e.detail ? e.detail : -e.wheelDelta / 40; 
    329338            } 
    330339            this._mouse = m; 
     
    550559    }, 
    551560 
     561    _browserHasMouseWheelEvent: function () { 
     562        return /MSIE/.test(navigator.userAgent) || /Opera/.test(navigator.userAgent); 
     563    }, 
     564 
    552565    _mouseEnterListener: function (src, sig, func, obj) { 
    553566        var E = MochiKit.Signal.Event; 
     
    623636                sig = "onmouseout"; 
    624637            } 
     638        } else if (isDOM && sig == "onmousewheel" && !self._browserHasMouseWheelEvent()) { 
     639            var listener = self._listener(src, sig, func, obj, isDOM); 
     640            sig = "onDOMMouseScroll"; 
    625641        } else { 
    626642            var listener = self._listener(src, sig, func, obj, isDOM); 
  • mochikit/trunk/doc/html/MochiKit/Signal.html

    r1378 r1386  
    152152</dl> 
    153153</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 
     157and Safari browsers. MochiKit translates <tt class="docutils literal"><span class="pre">'onmousewheel'</span></tt> to the 
     158correct 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> 
    154164</div> 
    155165<div class="section"> 
     
    411421each property is <tt class="docutils literal"><span class="pre">true</span></tt> if the mouse button was pressed, 
    412422<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 
     429offset. The number will normally be +3 when scrolling down, 
     430and -3 when scrolling up.</li> 
    413431</ul> 
    414432</blockquote> 
  • mochikit/trunk/doc/rst/MochiKit/Signal.rst

    r1378 r1386  
    168168        Available in MochiKit 1.4+ 
    169169 
     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 
    170179 
    171180Using Signal for non-DOM objects 
     
    416425            ``false`` otherwise. 
    417426 
     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 
    418433    Known browser bugs: 
    419434 
  • mochikit/trunk/packed/MochiKit/MochiKit.js

    r1385 r1386  
    49124912if(this.type()&&(this.type().indexOf("mouse")===0||this.type().indexOf("click")!=-1||this.type()=="contextmenu")){ 
    49134913str+=", 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{ 
     4914if(this.type()!="mousemove"&&this.type()!="mousewheel"){ 
     4915str+=", button: {left: "+repr(this.mouse().button.left)+", middle: "+repr(this.mouse().button.middle)+", right: "+repr(this.mouse().button.right)+"}"; 
     4916
     4917if(this.type()=="mousewheel"){ 
     4918str+=", wheel: "+repr(this.mouse().wheel); 
     4919
    49174920str+="}"; 
    4918 } 
    49194921} 
    49204922if(this.type()=="mouseover"||this.type()=="mouseout"||this.type()=="mouseenter"||this.type()=="mouseleave"){ 
     
    49304932return this._event; 
    49314933},type:function(){ 
     4934if(this._event.type==="DOMMouseScroll"){ 
     4935return "mousewheel"; 
     4936}else{ 
    49324937return this._event.type||undefined; 
     4938} 
    49334939},target:function(){ 
    49344940return this._event.target||this._event.srcElement; 
     
    50145020m.page.y=e.clientY+(de.scrollTop||b.scrollTop)-(de.clientTop||0); 
    50155021} 
    5016 if(this.type()!="mousemove"){ 
     5022if(this.type()!="mousemove"&&this.type()!="mousewheel"){ 
    50175023m.button={}; 
    50185024m.button.left=false; 
     
    50285034m.button.middle=!!(e.button&4); 
    50295035} 
     5036} 
     5037if(this.type()=="mousewheel"){ 
     5038m.wheel=e.detail?e.detail:-e.wheelDelta/40; 
    50305039} 
    50315040this._mouse=m; 
     
    51395148},_browserAlreadyHasMouseEnterAndLeave:function(){ 
    51405149return /MSIE/.test(navigator.userAgent); 
     5150},_browserHasMouseWheelEvent:function(){ 
     5151return /MSIE/.test(navigator.userAgent)||/Opera/.test(navigator.userAgent); 
    51415152},_mouseEnterListener:function(src,sig,func,obj){ 
    51425153var E=MochiKit.Signal.Event; 
     
    52065217} 
    52075218}else{ 
     5219if(_565&&sig=="onmousewheel"&&!self._browserHasMouseWheelEvent()){ 
    52085220var _566=self._listener(src,sig,func,obj,_565); 
     5221sig="onDOMMouseScroll"; 
     5222}else{ 
     5223var _566=self._listener(src,sig,func,obj,_565); 
     5224} 
    52095225} 
    52105226if(src.addEventListener){ 
  • mochikit/trunk/tests/test_Signal.js

    r1378 r1386  
    6060                newEvt.clientY = 1; 
    6161                newEvt.button = 1; 
     62                newEvt.detail = 3; 
    6263                element.fireEvent('on' + eventType, newEvt); 
    6364            } else if (document.createEvent && (typeof(document.createEvent('MouseEvents').initMouseEvent) == 'function')) { 
    6465                var evt = document.createEvent('MouseEvents'); 
    6566                evt.initMouseEvent(eventType, canBubble, true, // event, bubbles, cancelable 
    66                     document.defaultView, 1, // view, # of clicks 
     67                    document.defaultView, 3, // view, detail (either scroll or # of clicks) 
    6768                    1, 0, 0, 0, // screenX, screenY, clientX, clientY 
    6869                    false, false, false, false, // ctrlKey, altKey, shiftKey, metaKey 
     
    9798            t.ok((typeof(e.relatedTarget()) === 'undefined'), 'checking that relatedTarget() is undefined'); 
    9899            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'); 
    99101        }; 
    100102 
     
    108110        t.is(i, 3, 'Disconnecting an event to an HTML object and firing a synthetic event'); 
    109111 
    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    } 
    113127 
    114128    // non-DOM tests