Created
January 19, 2011 10:10
-
-
Save assertchris/785949 to your computer and use it in GitHub Desktop.
Delegation-powered expand/collapse
This file contains hidden or 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
window.addEvent('domready', function() { | |
// expand/collapse (with delegation) | |
var accordion = document.getElement('.zoopy-content-left-accordion'), | |
groups = accordion.getElements('.zoopy-content-left-accordion-group'); | |
function toggle() { | |
var content = this.getElement('.zoopy-content-left-accordion-group-content'); | |
if (content && content.offsetHeight > 0) { | |
content.tween('height', 0); | |
} else if (content && content.offsetHeight == 0) { | |
content.tween('height', content.retrieve('offsetHeight')); | |
} | |
} | |
function dispatch() { | |
var parent = this.getParent('.zoopy-content-left-accordion-group'); | |
toggle.apply(parent); | |
} | |
accordion.delegateEvent('click', { | |
'.zoopy-content-left-accordion-group-heading': dispatch, | |
'.zoopy-content-left-accordion-group-tagline': dispatch | |
}); | |
Array.each(groups, function(group) { | |
var content = group.getElement('.zoopy-content-left-accordion-group-content'); | |
if (content) { | |
content.set('tween', {'duration': 'short'}); | |
content.store('offsetHeight', content.offsetHeight); | |
content.setStyle('height', 0); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment