SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    X Library Question (Mike Foster's X Lib)

    Suppose I enable drag for an item like this:

    xEnableDrag('thing',startDrag,doDrag,endDrag);

    In my startDrag function, how do I get the current event without
    using window.event? That is, in the following:

    function startDrag() {
    // how do I tell if the shiftKey was pressed when this function
    // was called?
    }

    - eric juvet

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Eric, Welcome to SPF!

    and thanks for your interest in X

    There have been a few times where I've noticed the need for this too - but currently there is no way to get the event. So I'll make a change so that the event object is also passed to the callback functions. The question is... do I pass the xEvent object, or the native event object? My idea for now is to pass the xEvent object.

    I'll try to get this done soon, but tbh my to-do list for X is quite long . You can go ahead and make the change in your copy, and I'll try to get the change into the next X release. In the following snippets (from xEnableDrag) I've added 'ev' as the last argument in the calls to the callback functions, that is the only change you'll have to make:
    Code:
    function _xOMD(e) // drag start
    {
    ...
        if (t.xODS) { t.xODS(t, ev.pageX, ev.pageY, ev); } // added ev as last argument
      }
    }
    function _xOMM(e) // drag
    {
    ...
        if (el.xOD) { el.xOD(el, dx, dy, b, ev); } // added ev as last argument
        else if (b) { xMoveTo(el, xLeft(el) + dx, xTop(el) + dy); }
      }
    }
    function _xOMU(e) // drag end
    {
    ...
          _xDrgMgr.ele.xODE(_xDrgMgr.ele, ev.pageX, ev.pageY, ev); // added ev as last argument
        }
        _xDrgMgr.ele = null;
      }
    }
    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •