Event listener similar to jQuery.delegate
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
__COMPILE
__SRC
.travis.yml
README.md
package.json

README.md

build status

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