Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Winton Welsh http://stu.dicio.us

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

Execute Event

// executes an event using the DOM element and event name (take out the throw $break to execute all of them)

execEvent: function(el, type) {
  Event.observers.each(function(item,index) {
    if (item[0] == el && item[1] == type) { item[2](); throw $break; }
  });
}

Attach Events

// takes this.events with format 'element:event': function(e) { } and attaches it

attachEvent: function(selector) {
  var sel = selector.split(':');
  var el =  this.el[sel[0]];
  var ev =  sel[1];
  if (!el)      return;
  if (!el.each) Event.observe(el, ev, this.events[selector]);
  else el.each( function(item, index) {
    Event.observe(item, ev, this.events[selector]);
  }.bind(this));
},
attachEvents: function() {
  for (property in this.events) this.attachEvent(property);
},
removeEvent: function(selector) {
  var sel = selector.split(':');
  var el = this.el[sel[0]];
  var ev = sel[1];
  if (!el) return;
  if (!el.each) Event.stopObserving(el, ev, this.events[selector]);
  else el.each(function(item, index) {
    Event.stopObserving(item, ev, this.events[selector]);
  }.bind(this));
},
removeEvents: function() {
  for (x in this.events) this.removeEvent(x);
}
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed