Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Event listener similar to jQuery.delegate
JavaScript
Branch: master
Pull request Compare This branch is 1 commit ahead, 3 commits behind termi:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
__COMPILE
__SRC
README.md
package.json

README.md

DelegateListener

Dependencies

Element.prototype.matchesSelector shim. It coudth be found in https://gist.github.com/2369850

Example

//Filtering by class
document.addEventListener("click", new DelegateListener(".player", callback))
//Filtering by attribute value
document.addEventListener("click", DelegateListener({"data-event" : "click"}, callback))
//Filtering by attribute exists
document.addEventListener("click", DelegateListener({"data-is-menu" : void 0}, callback))
//Filtering by custom filter
document.addEventListener("click", DelegateListener(
    function(node) {
        return node.contains(someOtherNode);
    },
    callback)
)

//Using filter instead of callback
var editorController = {
    copy : function() {},
    paste : function() {},
    handler : function(node) {
        var operation = node.getAttrubute("data-menu-event"),//"copy" or "paste" or null
            function = operation && this[operation];

        if(function) {
            function.call(this, node);
            return true;
        }
    }
}

document.addEventListener("click", DelegateListener(
    editorController.handler.bind(editorController),
    function(){return false}
));

Licence

MIT

Something went wrong with that request. Please try again.