Changeset 1387

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

Corrected MochiKit.Signal mouse wheel handling for Safari.
Also added support for detecting horizontal wheel movement.

Files:

Legend:

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

    r1386 r1387  
    335335            } 
    336336            if (this.type() == 'mousewheel') { 
    337                 m.wheel = e.detail ? e.detail : -e.wheelDelta / 40; 
     337                m.wheel = new MochiKit.Style.Coordinates(0, 0); 
     338                if (e.wheelDeltaX || e.wheelDeltaY) { 
     339                    m.wheel.x = e.wheelDeltaX / -40 || 0; 
     340                    m.wheel.y = e.wheelDeltaY / -40 || 0; 
     341                } else if (e.wheelDelta) { 
     342                    m.wheel.y = e.wheelDelta / -40; 
     343                } else { 
     344                    m.wheel.y = e.detail || 0; 
     345                } 
    338346            } 
    339347            this._mouse = m; 
     
    559567    }, 
    560568 
    561     _browserHasMouseWheelEvent: function () { 
    562         return /MSIE/.test(navigator.userAgent) || /Opera/.test(navigator.userAgent); 
     569    _browserLacksMouseWheelEvent: function () { 
     570        return /Gecko\//.test(navigator.userAgent); 
    563571    }, 
    564572 
     
    636644                sig = "onmouseout"; 
    637645            } 
    638         } else if (isDOM && sig == "onmousewheel" && !self._browserHasMouseWheelEvent()) { 
     646        } else if (isDOM && sig == "onmousewheel" && self._browserLacksMouseWheelEvent()) { 
    639647            var listener = self._listener(src, sig, func, obj, isDOM); 
    640648            sig = "onDOMMouseScroll"; 
  • mochikit/trunk/doc/html/MochiKit/Signal.html

    r1386 r1387  
    55<head> 
    66<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    7 <meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" /> 
     7<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" /> 
    88<title>MochiKit.Signal - Simple universal event handling</title> 
    99 
     
    154154<p><tt class="docutils literal"><span class="pre">onmousewheel</span></tt></p> 
    155155<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> 
     156<p>Not strictly synthesized, but named <tt class="docutils literal"><span class="pre">'DOMMouseScroll'</span></tt> in 
     157Gecko-based browsers. MochiKit translates <tt class="docutils literal"><span class="pre">'onmousewheel'</span></tt> to 
     158the corresponding event in these browsers.</p> 
    159159<dl class="docutils"> 
    160160<dt><em>Availability:</em></dt> 
     
    426426<blockquote> 
    427427<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> 
     428<li><tt class="docutils literal"><span class="pre">mouse().wheel</span></tt> is a <a class="mochiref reference" href="Style.html#fn-coordinates">MochiKit.Style.Coordinates</a> 
     429object containing the scroll wheel offset. The number will be 
     430positive when scrolling down (or to the right) and negative 
     431when scrolling up (or to the left). Note that only Safari 3 
     432currently supports horizontal scrolling. In other browsers, 
     433the <tt class="docutils literal"><span class="pre">'y'</span></tt> component will contain the scroll offset for 
     434both directions.</li> 
    431435</ul> 
    432436</blockquote> 
  • mochikit/trunk/doc/rst/MochiKit/Signal.rst

    r1386 r1387  
    170170``onmousewheel`` 
    171171 
    172     Not strictly synthesized, but named ``'DOMMouseScroll'`` in Firefox 
    173     and Safari browsers. MochiKit translates ``'onmousewheel'`` to the 
    174     correct event in these browsers. 
     172    Not strictly synthesized, but named ``'DOMMouseScroll'`` in 
     173    Gecko-based browsers. MochiKit translates ``'onmousewheel'`` to 
     174    the corresponding event in these browsers. 
    175175 
    176176    *Availability:* 
     
    427427    Properties for ``'onmousewheel'``: 
    428428 
    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. 
     429        -   ``mouse().wheel`` is a :mochiref:`MochiKit.Style.Coordinates` 
     430            object containing the scroll wheel offset. The number will be 
     431            positive when scrolling down (or to the right) and negative 
     432            when scrolling up (or to the left). Note that only Safari 3 
     433            currently supports horizontal scrolling. In other browsers, 
     434            the ``'y'`` component will contain the scroll offset for 
     435            both directions. 
    432436 
    433437    Known browser bugs: 
  • mochikit/trunk/examples/mouse_events/mouse_events.js

    r1386 r1387  
    2121 
    2222  // scrolling up 
    23   if (event.mouse().wheel < 0) { 
     23  if (event.mouse().wheel.y < 0) { 
    2424    // Following test should probably be "if (scrollTop == 0)" which 
    2525    // works in FF but not IE. 
  • mochikit/trunk/packed/MochiKit/MochiKit.js

    r1386 r1387  
    50365036} 
    50375037if(this.type()=="mousewheel"){ 
    5038 m.wheel=e.detail?e.detail:-e.wheelDelta/40; 
     5038m.wheel=new MochiKit.Style.Coordinates(0,0); 
     5039if(e.wheelDeltaX||e.wheelDeltaY){ 
     5040m.wheel.x=e.wheelDeltaX/-40||0; 
     5041m.wheel.y=e.wheelDeltaY/-40||0; 
     5042}else{ 
     5043if(e.wheelDelta){ 
     5044m.wheel.y=e.wheelDelta/-40; 
     5045}else{ 
     5046m.wheel.y=e.detail||0; 
     5047
     5048
    50395049} 
    50405050this._mouse=m; 
     
    51485158},_browserAlreadyHasMouseEnterAndLeave:function(){ 
    51495159return /MSIE/.test(navigator.userAgent); 
    5150 },_browserHasMouseWheelEvent:function(){ 
    5151 return /MSIE/.test(navigator.userAgent)||/Opera/.test(navigator.userAgent); 
     5160},_browserLacksMouseWheelEvent:function(){ 
     5161return /Gecko\//.test(navigator.userAgent); 
    51525162},_mouseEnterListener:function(src,sig,func,obj){ 
    51535163var E=MochiKit.Signal.Event; 
     
    52175227} 
    52185228}else{ 
    5219 if(_565&&sig=="onmousewheel"&&!self._browserHasMouseWheelEvent()){ 
     5229if(_565&&sig=="onmousewheel"&&self._browserLacksMouseWheelEvent()){ 
    52205230var _566=self._listener(src,sig,func,obj,_565); 
    52215231sig="onDOMMouseScroll"; 
  • mochikit/trunk/tests/test_Signal.js

    r1386 r1387  
    113113            i++; 
    114114            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'); 
     115            t.ok((typeof(e.mouse().wheel) === 'object'), 'checking that mouse().wheel is an object'); 
     116            t.ok((typeof(e.mouse().wheel.x) === 'number'), 'checking that mouse().wheel.x is a number'); 
     117            t.ok((typeof(e.mouse().wheel.y) === 'number'), 'checking that mouse().wheel.y is a number'); 
    116118        }); 
    117119        var nativeSignal = 'mousewheel'; 
    118         if (!/MSIE/.test(navigator.userAgent) && !/Opera/.test(navigator.userAgent)) { 
     120        if (MochiKit.Signal._browserLacksMouseWheelEvent()) { 
    119121            nativeSignal = 'DOMMouseScroll'; 
    120122        }