in static/js/script.js [258:349]
function CollapseBox(container){
container.children('.item').each(function(){
// build the TOC DOM
// the animated open/close is enabled by having each item's content exist in the flow, at its natural height,
// enclosed in a wrapper with height = 0 when closed, and height = contentHeight when open.
var item = this;
// only add content wrappers to containers, not to links
var isContainer = item.tagName === 'DIV';
var titleText = item.getAttribute('data-title');
var title = newDOMElement('div', 'title');
title.innerHTML = titleText;
var wrapper, content;
if (isContainer) {
wrapper = newDOMElement('div', 'wrapper');
content = newDOMElement('div', 'content');
content.innerHTML = item.innerHTML;
wrapper.appendChild(content);
}
item.innerHTML = '';
item.appendChild(title);
if (wrapper) {
item.appendChild(wrapper);
$(wrapper).css({height: 0});
}
$(title).click(function(){
if (!yah) {
if (moving) return;
moving = true;
}
if (container[0].getAttribute('data-single')) {
var openSiblings = item.siblings().filter(function(sib){return sib.hasClass('on');});
openSiblings.forEach(function(sibling){
toggleItem(sibling);
});
}
setTimeout(function(){
if (!isContainer) {
moving = false;
return;
}
toggleItem(item);
}, CSS_BROWSER_HACK_DELAY);
});
function toggleItem(thisItem){
var thisWrapper = $(thisItem).find('.wrapper').eq(0);
if (!thisWrapper) return;
var contentHeight = thisWrapper.find('.content').eq(0).innerHeight() + 'px';
if ($(thisItem).hasClass('on')) {
thisWrapper.css({height: contentHeight});
$(thisItem).removeClass('on');
setTimeout(function(){
thisWrapper.css({height: 0});
moving = false;
}, CSS_BROWSER_HACK_DELAY);
} else {
$(item).addClass('on');
thisWrapper.css({height: contentHeight});
var duration = parseFloat(getComputedStyle(thisWrapper[0]).transitionDuration) * 1000;
setTimeout(function(){
thisWrapper.css({height: ''});
moving = false;
}, duration);
}
}
if (content) {
var innerContainers = $(content).children('.container');
if (innerContainers.length > 0) {
innerContainers.each(function(){
CollapseBox($(this));
});
}
}
});
}