aboutsummaryrefslogtreecommitdiff
path: root/source/javascripts/octopress.js
blob: d5173a47517dd2b2f1a3dfcd5956237adb80f9f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
window.addEvent('domready', function() {
  codeblocks = $$('div.highlight');
  codeblocks.each(addExpander);
});

function addExpander(div){
  new Element('span',{
		html: 'expand »',
		'class': 'pre_expander',
    'events': {
      'click': function(){
        toggleExpander(this);
      }
    }
	}).inject(div, 'top');
}
function toggleExpander(expander){
  var html = '';
  var expanderPos = expander.getPosition().y;
  if($('page').toggleClass('expanded').hasClass('expanded'))
    html = '« contract';
  else
    html = 'expand »';
  $$('div.highlight span.pre_expander').each(function(span){
      span.set('html',html);
  });
  fixScroll(expander, expanderPos);
}
function fixScroll(el, position){
  pos = el.getPosition().y - position;
  window.scrollTo(window.getScroll().x ,window.getScroll().y + pos);
}
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');
}