Skip to content

This is a simple MooTools Plugin for Event Delegation, now I would suggest the MooTools More 1.3 Delegation though

Notifications You must be signed in to change notification settings

arian/Element.Delegation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simpler Element.Delegation

This extension is a another fresh look at event delegation. No addEvent('relay(a)',fn) kind of things, but a more simple API

Screenshot

How to use

This is the most simple example how you can use this Element.Delegation

#JS
document.body.addDelegate('click','a',function(){
	// do it!
});

More advanced Selector example

#JS
document.id('myElement').addDelegate('click','a[href^=mailto:]',function(){
	// so you want to mail someone ?
});

More delegates

#JS
document.id('myElement').addDelegates({
	'click': {
		'a[href^=mailto:]': function(){
			// so you want to mail someone ?
		},
		'a[a.email]': function(){
			// Do something else
		}
		
	},
	'mouseover': {
		'p': function(){
			// You hovered a paragraph
		}
	}
});

Remove delegates

#JS
var fn = function(){};
document.id('myElement').addDelegate('click','a',fn);	
document.id('myElement').removeDelegate('click','a',fn);

Remove more than one at the time

#JS
var fn = function(){};
document.id('myElement').addDelegate('click','a',fn);	
document.id('myElement').removeDelegate({
	'click': {
		'a': fn
	}
});

Add delegates to a new Element

#JS
new Element('div',{
	delegates: {
		'click': {
			'input:checked': function(e){
				// Your code
			}
		}
	}
});

About

This is a simple MooTools Plugin for Event Delegation, now I would suggest the MooTools More 1.3 Delegation though

Resources

Stars

Watchers

Forks

Packages