irrisponsibly massive commit

This commit is contained in:
Brandon Mathis 2011-04-17 22:49:30 -05:00
parent 4db81a9e51
commit e4c2d5790b
119 changed files with 16689 additions and 2442 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,35 @@ window.addEvent('domready', function() {
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 »',
@ -44,4 +73,4 @@ function enableCompressedLayout(codeblocks){
}
}
}).inject($('main'), 'top');
}
}

View file

@ -0,0 +1,52 @@
var count = pinboard_count;
var linkroll = 'pinboard_linkroll';
function pinboardNS_fetch_script(url) {
document.writeln('<s'+'cript type="text/javascript" src="' + url + '"></s'+'cript>');
}
function pinboardNS_show_bmarks(r) {
var lr = new Pinboard_Linkroll();
lr.set_items(r);
lr.show_bmarks();
}
var json_URL = "http://feeds.pinboard.in/json/v1/u:"+pinboard_user+"/?cb=pinboardNS_show_bmarks\&count=" + count;
pinboardNS_fetch_script(json_URL);
function Pinboard_Linkroll() {
var items;
this.set_items = function(i) {
this.items = i;
}
this.show_bmarks = function() {
var lines = [];
for (var i = 0; i < this.items.length; i++) {
var item = this.items[i];
var str = this.format_item(item);
lines.push(str);
}
$(linkroll).set('html', lines.join("\n"));
}
this.cook = function(v) {
return v.replace('<', '&lt;').replace('>', '&gt>');
}
this.format_item = function(it) {
var str = "<li class=\"pin-item\">";
if (!it.d) { return; }
str += "<p><a class=\"pin-title\" href=\"" + this.cook(it.u) + "\">" + this.cook(it.d) + "</a>";
if (it.n) {
str += "<span class=\"pin-description\">" + this.cook(it.n) + "</span>\n";
}
if (it.t.length > 0) {
for (var i = 0; i < it.t.length; i++) {
var tag = it.t[i];
str += " <a class=\"pin-tag\" href=\"http://pinboard.in/u:"+ this.cook(it.a) + "/t:" + this.cook(tag) + "\">" + this.cook(tag) + "</a> ";
}
}
str += "</p></li>\n";
return str;
}
}
Pinboard_Linkroll.prototype = new Pinboard_Linkroll();

View file

@ -1,151 +1,52 @@
//
// The Octopress Twitter Feed is based on the following work:
// Valerio's javascript framework Mootools: Mootools.net
// David Walsh's Twitter Gitter plugin: http://davidwalsh.name/mootools-twitter-plugin
// Aaron Newtons JSONP plugin: http://clientcide.com/js
// PrettyDate by John Resig at http://ejohn.org/files/pretty.js
//
Request.Twitter = new Class({
/*
Plugin: Octopress Twitter Feed
Author: Brandon Mathis
Website: http://brandonmathis.com
Date: 11/07/2009
*/
Extends: Request.JSONP,
var tweet_container = 'li';
var twitter_container = 'twitter_status';
var key = '-!-!-';
var show_source = false;
options: {
linkify: true,
url: 'http://twitter.com/statuses/user_timeline/{term}.json',
include_replies: true,
data: {
count: 5,
trim_user: true
}
},
window.addEvent('domready',function() {
getTwitterStatus(twitter_user);
});
initialize: function(term, options){
this.parent(options);
if(this.options.include_replies == false){
this.options.count = this.options.data.count
this.options.data.count += 30; // adds 30 tweets to request for filtering
}
this.options.url = this.options.url.substitute({term: term});
console.log(this.options.url);
},
function showTweets(the_tweets, from_cookie){
if(from_cookie){
the_tweets = the_tweets.split('^!^!^');
success: function(args, index){
if(!this.options.include_replies){
args[0] = args[0].filter(function(item, index, array){
return item.in_reply_to_screen_name == null;
});
if(args[0].length > this.options.count){ args[0].length = this.options.count; }
}
var data = args[0];
if (this.options.linkify) data.each(function(tweet){
tweet.text = this.linkify(tweet.text);
}, this);
if (data[0]) this.options.data.since_id = data[0].id; // keep subsequent calls newer
this.parent(args, index);
},
linkify: function(text){
// modified from TwitterGitter by David Walsh (davidwalsh.name)
// courtesy of Jeremy Parrish (rrish.org)
return text.replace(/(https?:\/\/[\w\-:;?&=+.%#\/]+)/gi, '<a href="$1">$1</a>')
.replace(/(^|\W)@(\w+)/g, '$1<a href="http://twitter.com/$2">@$2</a>')
.replace(/(^|\W)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2">$2</a>');
}
$(twitter_container).set('html', '');
the_tweets.each(function(tweet){
tweet = parseTweetMeta(tweet)
tweet = '<p>' + tweet.replace(/\n\n/gi,'</p><p>') + '</p>';
new Element(tweet_container,{
html: tweet
}).inject(twitter_container);
});
}
function parseTweetMeta(tweet_data){
var tweet_data = tweet_data.split(key);
var tweet = tweet_data[0];
var date = tweet_data[1];
var tweet_id = tweet_data[2];
var source = tweet_data[3];
date = prettyDate(new Date().parse(date));
return tweet + '<span class="meta"><a href="http://twitter.com/'+twitter_user + '/status/' + tweet_id + '">' + date + '</a>' + (show_source ? ' from '+source : '') + '</span>';
}
function prettyDate(time){
var date = time;
var diff = (((new Date()).getTime() - date.getTime()) / 1000)
var day_diff = Math.floor(diff / 86400);
if ( isNaN(day_diff) || day_diff < 0)
return;
return day_diff == 0 && (
diff < 60 && "just now" ||
diff < 120 && "1 minute ago" ||
diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
diff < 7200 && "1 hour ago" ||
diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
day_diff == 1 && "1 day ago" ||
day_diff < 7 && day_diff + " days ago" ||
day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
true && Math.ceil( day_diff / 30 ) + " months ago";
}
function getTwitterStatus(twitter_name){
var container = $(twitter_container);
if(!container) return;
var tweet_cookie = 'tweets_by_' + twitter_name + tweet_count;
container.set('html', 'Fetching tweets...');
if(!Cookie.read(tweet_cookie)) {
var myTwitterGitter = new TwitterGitter(twitter_name,{
count: ((show_replies) ? tweet_count : 15 + tweet_count),
onComplete: function(tweets,user) {
the_tweets = Array();
tweets.each(function(tweet,i) {
if((tweet.in_reply_to_status_id && show_replies) || !tweet.in_reply_to_status_id){
if(the_tweets.length == tweet_count) return;
the_tweets.push(tweet.text + key + tweet.created_at + key + tweet.id + key + tweet.source);
}
});
Cookie.write(tweet_cookie,the_tweets.join('^!^!^'), { duration: 0.02 });
showTweets(the_tweets);
}
}).retrieve();
} else {
showTweets(Cookie.read(tweet_cookie),true);
}
}
/*
Plugin: TwitterGitter
Author: David Walsh
Website: http://davidwalsh.name
Date: 2/21/2009
*/
var TwitterGitter = new Class({
//implements
Implements: [Options,Events],
//options
options: {
count: 2,
sinceID: 1,
link: true,
onRequest: $empty,
onComplete: $empty
},
//initialization
initialize: function(username,options) {
//set options
this.setOptions(options);
this.info = {};
this.username = username;
},
//get it!
retrieve: function() {
new JsonP('http://twitter.com/statuses/user_timeline/' + this.username + '.json',{
data: {
count: this.options.count,
since_id: this.options.sinceID
},
onRequest: this.fireEvent('request'),
onComplete: function(data) {
//linkify?
if(this.options.link) {
data.each(function(tweet) { tweet.text = this.linkify(tweet.text); },this);
}
//complete!
this.fireEvent('complete',[data,data[0].user]);
}.bind(this)
}).request();
return this;
},
//format
linkify: function(text) {
//courtesy of Jeremy Parrish (rrish.org)
return text.replace(/(https?:\/\/[\w\-:;?&=+.%#\/]+)/gi,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1<a class="user" href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\w+)/g,'$1<a class="topic" href="http://search.twitter.com/search?q=%23$2">#$2</a>');
}
});
//Compact Jsonp from http://clientcide.com/js
MooTools.More={'version':'1.2.3.1'};var Log=new Class({log:function(){Log.logger.call(this,arguments)}});Log.logged=[];Log.logger=function(){if(window.console&&console.log)console.log.apply(console,arguments);else Log.logged.push(arguments)};Class.refactor=function(original,refactors){$each(refactors,function(item,name){var origin=original.prototype[name];if(origin&&(origin=origin._origin)&&typeof item=='function')original.implement(name,function(){var old=this.previous;this.previous=origin;var value=item.apply(this,arguments);this.previous=old;return value});else original.implement(name,item)});return original};Request.JSONP=new Class({Implements:[Chain,Events,Options,Log],options:{url:'',data:{},retries:0,timeout:0,link:'ignore',callbackKey:'callback',injectScript:document.head},initialize:function(options){this.setOptions(options);this.running=false;this.requests=0;this.triesRemaining=[]},check:function(){if(!this.running)return true;switch(this.options.link){case'cancel':this.cancel();return true;case'chain':this.chain(this.caller.bind(this,arguments));return false}return false},send:function(options){if(!$chk(arguments[1])&&!this.check(options))return this;var type=$type(options),old=this.options,index=$chk(arguments[1])?arguments[1]:this.requests++;if(type=='string'||type=='element')options={data:options};options=$extend({data:old.data,url:old.url},options);if(!$chk(this.triesRemaining[index]))this.triesRemaining[index]=this.options.retries;var remaining=this.triesRemaining[index];(function(){var script=this.getScript(options);this.log('JSONP retrieving script with url: '+script.get('src'));this.fireEvent('request',script);this.running=true;(function(){if(remaining){this.triesRemaining[index]=remaining-1;if(script){script.destroy();this.send(options,index);this.fireEvent('retry',this.triesRemaining[index])}}else if(script&&this.options.timeout){script.destroy();this.cancel();this.fireEvent('failure')}}).delay(this.options.timeout,this)}).delay(Browser.Engine.trident?50:0,this);return this},cancel:function(){if(!this.running)return this;this.running=false;this.fireEvent('cancel');return this},getScript:function(options){var index=Request.JSONP.counter,data;Request.JSONP.counter++;switch($type(options.data)){case'element':data=document.id(options.data).toQueryString();break;case'object':case'hash':data=Hash.toQueryString(options.data)}var src=options.url+(options.url.test('\\?')?'&':'?')+(options.callbackKey||this.options.callbackKey)+'=Request.JSONP.request_map.request_'+index+(data?'&'+data:'');if(src.length>2083)this.log('JSONP '+src+' will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs');var script=new Element('script',{type:'text/javascript',src:src});Request.JSONP.request_map['request_'+index]=function(data){this.success(data,script)}.bind(this);return script.inject(this.options.injectScript)},success:function(data,script){if(script)script.destroy();this.running=false;this.log('JSONP successfully retrieved: ',data);this.fireEvent('complete',[data]).fireEvent('success',[data]).callChain()}});Request.JSONP.counter=0;Request.JSONP.request_map={};var JsonP=Class.refactor(Request.JSONP,{initialize:function(){var params=Array.link(arguments,{url:String.type,options:Object.type});options=(params.options||{});options.url=options.url||params.url;if(options.callBackKey)options.callbackKey=options.callBackKey;this.previous(options)},getScript:function(options){var queryString=options.queryString||this.options.queryString;if(options.url&&queryString)options.url+=(options.url.indexOf("?")>=0?"&":"?")+queryString;var script=this.previous(options);if($chk(options.globalFunction)){window[options.globalFunction]=function(r){JsonP.requestors[index].handleResults(r)}}return script},request:function(url){this.send({url:url||this.options.url})}});