Created
January 30, 2010 16:29
-
-
Save imathis/290613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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