From a55a55156638efd574b7d78f57da0955f355ba40 Mon Sep 17 00:00:00 2001 From: B Mathis Date: Thu, 12 Nov 2009 11:57:01 -0600 Subject: added ability to collapse layout --- source/javascripts/octopress.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'source/javascripts') diff --git a/source/javascripts/octopress.js b/source/javascripts/octopress.js index a91d30e8..23716351 100644 --- a/source/javascripts/octopress.js +++ b/source/javascripts/octopress.js @@ -1,14 +1,13 @@ window.addEvent('domready', function() { - $$('div.highlight').each(addExpander); + codeblocks = $$('div.highlight'); + codeblocks.each(addExpander); + enableCompressedLayout(codeblocks); }); function addExpander(div){ new Element('span',{ html: 'expand »', 'class': 'pre_expander', - 'styles': { - 'display': 'block' - }, 'events': { 'click': function(){ toggleExpander(); @@ -18,12 +17,26 @@ function addExpander(div){ } function toggleExpander(){ var html = ''; - if($('main').toggleClass('expanded').hasClass('expanded')){ + if($('main').toggleClass('expanded').hasClass('expanded')) html = '« contract'; - } else { + else html = 'expand »'; - } $$('div.highlight span.pre_expander').each(function(span){ span.set('html',html); }); +} +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'); } \ No newline at end of file -- cgit v1.2.1