Skip to content

Instantly share code, notes, and snippets.

@melchoy
Created November 18, 2009 11:08
Show Gist options
  • Save melchoy/237748 to your computer and use it in GitHub Desktop.
Save melchoy/237748 to your computer and use it in GitHub Desktop.
Clickable blocks for link target
/************************************
* Clickables (big block targets)
***********************************/
var Clickables = Class.create({
initialize: function(options) {
selector = $$(options.selector) || $$(".clickables");
this.clickable = options.clickable || "li";
this.hoverclass = options.hoverclass || "over";
selector.each(function(e) { $(e).setStyle({ cursor: 'pointer' }) });
selector.invoke('observe', 'click', this.clicked.bind(this));
selector.invoke('observe', 'mouseover', this.activate.bind(this));
selector.invoke('observe', 'mouseout', this.deactivate.bind(this));
},
activate: function(event) {
event.stop();
element = Event.findElement(event, this.clickable);
element.addClassName(this.hoverclass);
},
deactivate: function(event) {
event.stop();
element = Event.findElement(event, this.clickable);
element.removeClassName(this.hoverclass);
},
clicked: function(event) {
event.stop();
element = Event.findElement(event, this.clickable);
window.location = element.select("a").first().href;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment