JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://github.com/arieh/Event-once/raw/master/Source/Event.once.js"></script>
<div id='for-element'>Click Me - as many times as you wish!</div>
<div id='for-class'>Click Me Too!</div>
<ul id='res'></ul>
CSS
ul{list-style-type:disc; padding:10px;}
JavaScript
/*
* Just some example class that fires the foo event
* whenever it's element is clicked
*/
var FireWhenClicked = new Class({
Implements:[Events]
, initialize: function(el){
var $this = this;
el.addEvent('click',function(){$this.fireEvent('foo');});
}
});
var instance = new FireWhenClicked($('for-class'));
//Adding the events:
//for an element:
$('for-element').addEvent('click:once',function(){
new Element('li').appendText('element clicked!').inject($('res'));
});
//for a class:
instance.addEvent('foo:once',function(){
new Element('li').appendText('Class-element clicked!').inject($('res'));
});