Skip to content

Instantly share code, notes, and snippets.

@imathis
Created January 30, 2010 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imathis/290613 to your computer and use it in GitHub Desktop.
Save imathis/290613 to your computer and use it in GitHub Desktop.
document.observe('dom:loaded', function() {
$$('a[rel^=toggle]').each(toggleLinkBehavior)
});
function parseRel(key, rel){
var keypos = rel.indexOf(key)+key.length+1; //find occurance of key
var keys = rel.slice(keypos).split(']')[0].strip(); //split at end of key segment and trip whitespace
return keys.split(','); //return keys as an array
}
function toggleLinkBehavior(el){
el.toggle_ids = parseRel('toggle', el.readAttribute('rel'));
el.toggle_ids.each(wrapElement)
el.observe('click', function(event){
if(el.match('a')) event.stop();
el.toggle_ids.each(function(id){
effectToggle($('toggle_wrapper_' + id))
});
});
}
function wrapElement(element){
var element = $(element)
var parent = $(element.parentNode);
if (parent.hasClassName('toggle_wrapper_'+element.id)) {
return parent;
} else {
return element.wrap(new Element('div', {'id': 'toggle_wrapper_'+element.id, 'style': 'display: none;'}));
}
}
function effectToggle(el){
if(!el.visible()){
Effect.BlindDown(el.id, { duration: 0.3, transition: Effect.Transitions.SwingTo });
}else{
Effect.BlindUp(el.id, { duration: 0.3, transition: Effect.Transitions.SwingTo });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment