List events of an element wired up with addEventListener

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mebemikeyc@gmail.com

    List events of an element wired up with addEventListener

    With Element.addEven tListener, you can easily wire-up several
    different event handlers on the fly. This works great, but debugging
    can be difficult if I don't know what exactly is reacting to an event.

    Is there a way to list event listeners that have been wired-up to an
    element's event?
  • Thomas 'PointedEars' Lahn

    #2
    Re: List events of an element wired up with addEventListene r

    mebemikeyc@gmai l.com wrote:
    With Element.addEven tListener, you can easily wire-up several
    different event handlers on the fly. This works great, but debugging
    can be difficult if I don't know what exactly is reacting to an event.
    >
    Is there a way to list event listeners that have been wired-up to an
    element's event?
    AFAIK only if you use a wrapper object, and use only its event
    listener-registering methods to add event listeners to the wrapped
    target object. For example:

    function _EventListener( fListener, bCapture)
    {
    this.listener = fListener || null;
    this.capture = !!bCapture;
    }

    function _EventRegistry( )
    {
    this.data = {};
    }

    _EventRegistry. prototype.add = function(sEvent , fListener, bCapture) {
    var d = this.data;

    if (typeof d[sEvent] == "undefined" )
    {
    d[sEvent] = [];
    }

    d[sEvent].push(new _EventListener( fListener, bCapture));
    };

    _EventRegistry. prototype.get = function(sEvent ) {
    return this.data[sEvent];
    };

    function _Element(oTarge t)
    {
    this.target = oTarget;
    this.events = new _EventRegistry( );
    }

    _Element.protot ype.addEventLis tener =
    function(sEvent , fListener, bCapture) {
    // add feature test here

    this.target.add EventListener(s Event, fListener, bCapture);
    this.events.add (sEvent, fListener, bCapture);
    };

    // add feature test here

    var o = new _Element(docume nt.getElementBy Id("foo"));
    o.addEventListe ner("click", function() { window.alert(42 ); }, false);
    window.alert(o. events.get("cli ck")[0].listener);

    BTW: `Element::addEv entListener' is more like it. We are talking
    *interfaces* here.


    HTH

    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann

    Comment

    Working...