aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/octopress.js
diff options
context:
space:
mode:
authorBrandon Mathis <brandon@imathis.com>2011-04-17 22:49:30 -0500
committerBrandon Mathis <brandon@imathis.com>2011-04-17 22:49:30 -0500
commite4c2d5790bac6a74037638fde049c374fc44cc7b (patch)
tree83f5e5b7324fcb5951d755442e2e601a3eaed35a /public/javascripts/octopress.js
parent4db81a9e51e452495a06ad8c57ac4ac689a9ff34 (diff)
downloadmy_new_personal_website-e4c2d5790bac6a74037638fde049c374fc44cc7b.tar.xz
my_new_personal_website-e4c2d5790bac6a74037638fde049c374fc44cc7b.zip
irrisponsibly massive commit
Diffstat (limited to 'public/javascripts/octopress.js')
-rw-r--r--public/javascripts/octopress.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/public/javascripts/octopress.js b/public/javascripts/octopress.js
new file mode 100644
index 00000000..bf94ebe4
--- /dev/null
+++ b/public/javascripts/octopress.js
@@ -0,0 +1,76 @@
+window.addEvent('domready', function() {
+ codeblocks = $$('div.highlight');
+ codeblocks.each(addExpander);
+});
+
+window.addEvents({
+ domready: function(){
+ if(twitter_user){
+ new Request.Twitter(twitter_user, {
+ include_replies: false,
+ data: { count: 3 },
+ onSuccess: function(tweets){
+ $('tweets').empty();
+ for (var i = tweets.length; i--; ){
+ new Element('li', {
+ 'class': 'tweet'
+ }).adopt(
+ new Element('p', { 'html': tweets[i].text+' ' }).adopt(
+ new Element('a', {
+ 'href': 'http://twitter.com/'+twitter_user+'/status/'+tweets[i].id_str,
+ 'text': new Date(tweets[i].created_at).timeDiffInWords()
+ }))
+ ).inject('tweets', 'top');
+ }
+ }
+ }).send();
+ }
+ $$('#recent_posts time').each(function(date){
+ date.set('text', new Date(date.get('text')).timeDiffInWords());
+ });
+ },
+});
+
+
+function addExpander(div){
+ new Element('span',{
+ html: 'expand &raquo;',
+ '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 = '&laquo; contract';
+ else
+ html = 'expand &raquo;';
+ $$('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');
+}