W3C home > Mailing lists > Public > public-html@w3.org > May 2013

[new Feature] QueryEventListeners

From: Michaël Rouges <michael.rouges@gmail.com>
Date: Sat, 18 May 2013 12:03:53 +0200
Message-ID: <CAMNVKQFF0Jarp1+2_yR4oXToNSq_83N5_S=xdgenBwDtFQuMng@mail.gmail.com>
To: public-html@w3.org
Hello everyone,

Faced with the need to extend a DOM builder for one of my scripts, I
thought about a feature that would be very useful, as more and more sites are
going through dynamic content systems.

The idea is being able to add events to a collection of nodes, existing and
future, for a given selector.

This would avoid costly solutions like this:

(function () {
    var catchClickOnAnchors;
    catchClickOnAnchors = function(event){
        var anchors, iterator, length;
        anchors = document.getElementsByTagName('a');
        for (; iterator < length; iterator += 1) {
            anchors[iterator].addEventListener('click', function (event) {
                console.log('Caught click');
                event.preventDefault();
                event.returnValue = false;
                return false;
            }, false);
        }
    };
    catchClickOnAnchors();
    document.addEventListener('DOMSubtreeModified', catchClickOnAnchors,
false);
}());

Suggested design :

window.addQueryEventListener = function (querySelector, event, listener,
useCapture) {};

window.removeQueryEventListener = function (querySelector, event, listener,
useCapture) {};



Well, that's all for now, if you have any questions, do not hesitate to
contact me, I will answer with pleasure.

Cordially,

Michaël Rouges
Received on Saturday, 18 May 2013 10:04:20 UTC

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:46:02 UTC