2009-11-12 11:19:36 -05:00
|
|
|
window.addEvent('domready', function() {
|
2009-11-12 12:57:01 -05:00
|
|
|
codeblocks = $$('div.highlight');
|
|
|
|
codeblocks.each(addExpander);
|
2009-11-12 11:19:36 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
function addExpander(div){
|
|
|
|
new Element('span',{
|
|
|
|
html: 'expand »',
|
|
|
|
'class': 'pre_expander',
|
|
|
|
'events': {
|
|
|
|
'click': function(){
|
2009-11-12 14:23:01 -05:00
|
|
|
toggleExpander(this);
|
2009-11-12 11:19:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).inject(div, 'top');
|
|
|
|
}
|
2009-11-12 14:23:01 -05:00
|
|
|
function toggleExpander(expander){
|
2009-11-12 11:19:36 -05:00
|
|
|
var html = '';
|
2009-11-12 14:23:01 -05:00
|
|
|
var expanderPos = expander.getPosition().y;
|
2010-03-10 14:59:18 -05:00
|
|
|
if($('page').toggleClass('expanded').hasClass('expanded'))
|
2009-11-12 11:19:36 -05:00
|
|
|
html = '« contract';
|
2009-11-12 12:57:01 -05:00
|
|
|
else
|
2009-11-12 11:19:36 -05:00
|
|
|
html = 'expand »';
|
|
|
|
$$('div.highlight span.pre_expander').each(function(span){
|
2009-11-12 11:28:30 -05:00
|
|
|
span.set('html',html);
|
2009-11-12 11:19:36 -05:00
|
|
|
});
|
2009-11-12 14:23:01 -05:00
|
|
|
fixScroll(expander, expanderPos);
|
|
|
|
}
|
|
|
|
function fixScroll(el, position){
|
|
|
|
pos = el.getPosition().y - position;
|
|
|
|
window.scrollTo(window.getScroll().x ,window.getScroll().y + pos);
|
2009-11-12 12:57:01 -05:00
|
|
|
}
|
|
|
|
function enableCompressedLayout(codeblocks){
|
|
|
|
if(!codeblocks.length) return;
|
|
|
|
new Element('span',{
|
|
|
|
html: 'Collapse layout',
|
|
|
|
'id': 'collapser',
|
|
|
|
'events': {
|
|
|
|
'click': function(){
|
|
|
|
if($('page').toggleClass('collapsed').hasClass('collapsed'))
|
|
|
|
this.set('html','Expand layout');
|
|
|
|
else
|
|
|
|
this.set('html','Collapse layout');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).inject($('main'), 'top');
|
2009-11-12 11:19:36 -05:00
|
|
|
}
|