Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Tweets to sidebar powered by a cool new Request.Twitter Class.

  • Loading branch information...
commit c5b6e1be08b51994a701e2ca4e373504f2f50baa 1 parent fd6fb2f
@appden authored
View
1  _config.yml
@@ -14,6 +14,7 @@ comment: Jekyll is awesome
author:
name: Scott Kyle
email: scott@appden.com
+ twitter: appden
about: >
Hi, I'm Scott Kyle, a JavaScript and Apple enthusiast.
View
17 _includes/sidebar.html
@@ -1,8 +1,10 @@
-<div class="widget">
- <h3><a href="/about/">About Me</a></h3>
- <p>{{ site.about }}</p>
-</div>
+{% if site.about %}
+ <div class="widget">
+ <h3><a href="/about/">About Me</a></h3>
+ <p>{{ site.about }}</p>
+ </div>
+{% endif %}
{% if page.title %}
<div class="widget">
@@ -15,6 +17,13 @@
</div>
{% endif %}
+{% if site.author.twitter %}
+ <div class="widget">
+ <h3><a href="http://twitter.com/{{ site.author.twitter }}">Tweets</a></h3>
+ <div id="tweets"></div>
+ </div>
+{% endif %}
+
{% if site.bookmarks %}
<div class="widget">
<h3>Good Reads</h3>
View
4 lib/appden.css
@@ -513,6 +513,10 @@ h3 {
color: #4d6c70;
}
+#tweets .tweet {
+ padding-bottom: 10px;
+}
+
#search {
margin-left: -24px;
width: 320px;
View
53 lib/appden.js
@@ -10,6 +10,17 @@ window.addEvents({
new Footnotes('#alpha a');
$$('a[href^=mailto:]').unmaskEmail();
+
+ new Request.Twitter('appden', {
+ data: { count: 3 },
+ onSuccess: function(tweets){
+ for (var i = tweets.length; i--; )
+ new Element('div', {
+ 'class': 'tweet',
+ 'html': tweets[i].text
+ }).inject('tweets', 'top');
+ }
+ }).send();
},
load: function(){
@@ -144,6 +155,44 @@ var Analytics = new Class({
});
+// Twitter
+
+Request.Twitter = new Class({
+
+ Extends: Request.JSONP,
+
+ options: {
+ linkify: true,
+ data: {
+ count: 5
+ }
+ },
+
+ initialize: function(username, options){
+ this.parent(options);
+ this.options.url = 'http://twitter.com/statuses/user_timeline/' + username + '.json';
+ },
+
+ success: function(data, script){
+ 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(data, script);
+ },
+
+ 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>');
+ }
+
+});
+
// Utility Functions
@@ -189,10 +238,6 @@ Element.implement({
return this;
},
- addRules: function(){
- return this.addClass("validate['" + Array.flatten(arguments).join("','") + "']");
- },
-
// I like my morph and fade more...
morph: function(props, duration, callback){
var fx = this.retrieve('morph');
Please sign in to comment.
Something went wrong with that request. Please try again.