Switched out ender.js in favor of jQuery. Some small improvements to sidebar feed scripts

This commit is contained in:
Brandon Mathis 2012-05-24 23:03:59 -05:00
parent b69e876828
commit d40eaab07c
12 changed files with 144 additions and 1686 deletions

View File

@ -8,23 +8,23 @@
<a href="https://github.com/{{site.github_user}}">@{{site.github_user}}</a> on GitHub
{% endif %}
<script type="text/javascript">
$.domReady(function(){
$(document).ready(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '{{ root_url}}/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '{{ root_url}}/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: '{{site.github_user}}',
count: {{site.github_repo_count}},
skip_forks: {{site.github_skip_forks}},
target: '#gh_repos'
user: '{{site.github_user}}'
, count: {{site.github_repo_count}}
, skip_forks: {{site.github_skip_forks}}
, target: '#gh_repos'
});
});
</script>
<script src="{{ root_url }}/javascripts/github.js" type="text/javascript"> </script>
<script src="{{ root_url }}/javascripts/github.js" type="text/javascript"></script>
</section>
{% endif %}

View File

@ -5,15 +5,13 @@
<p><a href="http://pinboard.in/u:{{ site.pinboard_user }}">My Pinboard Bookmarks &raquo;</a></p>
</section>
<script type="text/javascript">
var linkroll = 'pinboard_linkroll'; //id target for pinboard list
var pinboard_user = "{{ site.pinboard_user }}"; //id target for pinboard list
var pinboard_count = {{ site.pinboard_count }}; //id target for pinboard list
(function(){
var pinboardInit = document.createElement('script');
pinboardInit.type = 'text/javascript';
pinboardInit.async = true;
pinboardInit.src = '{{ root_url }}/javascripts/pinboard.js';
document.getElementsByTagName('head')[0].appendChild(pinboardInit);
})();
$(document).ready(function(){
pinboard.getFeed({
target: 'pinboard_linkroll' //id target for pinboard list
, user: "{{ site.pinboard_user }}"
, count: {{ site.pinboard_count }}
});
});
</script>
<script src="{{ root_url }}/javascripts/pinboard.js" type="text/javascript"></script>
{% endif %}

View File

@ -5,8 +5,12 @@
<li class="loading">Status updating...</li>
</ul>
<script type="text/javascript">
$.domReady(function(){
getTwitterFeed("{{site.twitter_user}}", {{site.twitter_tweet_count}}, {{site.twitter_show_replies}});
$(document).ready(function(){
twitter.getFeed({
user: "{{site.twitter_user}}"
, count: {{site.twitter_tweet_count}}
, replies: {{site.twitter_show_replies}}
});
});
</script>
<script src="{{ root_url }}/javascripts/twitter.js" type="text/javascript"> </script>

View File

@ -22,7 +22,7 @@
<link href="{{ root_url }}/favicon.png" rel="icon">
<link href="{{ root_url }}/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="{{ root_url }}/javascripts/modernizr-2.0.js"></script>
<script src="{{ root_url }}/javascripts/ender.js"></script>
<script src="{{ root_url }}/javascripts/jquery.min.js"></script>
<script src="{{ root_url }}/javascripts/octopress.js" type="text/javascript"></script>
<link href="{{ site.subscribe_rss }}" rel="alternate" title="{{site.title}}" type="application/atom+xml">
{% include custom/head.html %}

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@ var github = (function(){
showRepos: function(options){
$.ajax({
url: "https://api.github.com/users/"+options.user+"/repos?callback=?"
, type: 'jsonp'
, dataType: 'jsonp'
, error: function (err) { $(options.target + ' li.loading').addClass('error').text("Error loading feed"); }
, success: function(data) {
var repos = [];

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,14 @@
function getNav() {
var mobileNav = $('nav[role=navigation] ul.main-navigation').before('<fieldset class="mobile-nav"></fieldset>').next().append('<select></select>');
mobileNav.children('select').append('<option value="">Navigate&hellip;</option>');
$('ul[role=main-navigation]').addClass('main-navigation');
$('ul.main-navigation a').each(function(link) {
mobileNav.children('select').append('<option value="'+link.href+'">&raquo; '+link.text+'</option>');
var mainNav = $('ul.main-navigation, ul[role=main-navigation]').before('<fieldset class="mobile-nav">')
var mobileNav = $('fieldset.mobile-nav').append('<select>');
mobileNav.find('select').append('<option value="">Navigate&hellip;</option>');
mainNav.find('a').each(function() {
mobileNav.find('select').append('<option value="'+this.href+'">&raquo; '+this.text+'</option>');
});
$('ul.subscription a').each(function(link) {
mobileNav.children('select').append('<option value="'+link.href+'">&raquo; '+link.text+'</option>');
$('ul.subscription a').each(function() {
mobileNav.find('select').append('<option value="'+this.href+'">&raquo; '+this.text+'</option>');
});
mobileNav.children('select').bind('change', function(event) {
mobileNav.find('select').bind('change', function(event) {
if (event.target.value) { window.location.href = event.target.value; }
});
}
@ -25,35 +25,19 @@ function addSidebarToggler() {
}
});
}
var sections = $('aside.sidebar > section');
var sections = $('.sidebar section');
if (sections.length > 1) {
sections.each(function(section, index){
sections.each(function(index){
if ((sections.length >= 3) && index % 3 === 0) {
$(section).addClass("first");
$(this).addClass("first");
}
var count = ((index +1) % 2) ? "odd" : "even";
$(section).addClass(count);
$(this).addClass(count);
});
}
if (sections.length >= 3){ $('aside.sidebar').addClass('thirds'); }
}
function testFeatures() {
var features = ['maskImage'];
$(features).map(function(feature) {
if (Modernizr.testAllProps(feature)) {
$('html').addClass(feature);
} else {
$('html').addClass('no-'+feature);
}
});
if ("placeholder" in document.createElement("input")) {
$('html').addClass('placeholder');
} else {
$('html').addClass('no-placeholder');
}
}
function addCodeLineNumbers() {
if (navigator.appName === 'Microsoft Internet Explorer') { return; }
$('div.gist-highlight').each(function(code) {
@ -116,8 +100,7 @@ function renderDeliciousLinks(items) {
$('#delicious').html(output);
}
$.domReady(function() {
testFeatures();
$(document).ready(function() {
wrapFlashVideos();
flashVideoFallback();
addCodeLineNumbers();

View File

@ -1,56 +1,62 @@
function pinboardNS_fetch_script(url) {
//document.writeln('<s'+'cript type="text/javascript" src="' + url + '"></s'+'cript>');
(function(){
var pinboardLinkroll = document.createElement('script');
pinboardLinkroll.type = 'text/javascript';
pinboardLinkroll.async = true;
pinboardLinkroll.src = url;
document.getElementsByTagName('head')[0].appendChild(pinboardLinkroll);
})();
}
function pinboardNS_show_bmarks(r) {
var lr = new Pinboard_Linkroll();
lr.set_items(r);
lr.show_bmarks();
}
function Pinboard_Linkroll() {
var items;
this.set_items = function(i) {
this.items = i;
var pinboard = (function(){
function fetch(url) {
(function(){
var pinboardLinkroll = document.createElement('script');
pinboardLinkroll.type = 'text/javascript';
pinboardLinkroll.async = true;
pinboardLinkroll.src = url;
document.getElementsByTagName('head')[0].appendChild(pinboardLinkroll);
})();
}
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);
function linkroll(element) {
var items;
this.set_items = function(i) {
this.items = i;
}
document.getElementById(linkroll).innerHTML = 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).replace(/^\s+|\s+$/g, '') + "</a> ";
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);
}
document.getElementById(element).innerHTML = lines.join("\n");
}
this.cook = function(v) {
return v.replace('<', '&lt;').replace('>', '&gt>');
}
str += "</p></li>\n";
return str;
}
}
Pinboard_Linkroll.prototype = new Pinboard_Linkroll();
pinboardNS_fetch_script("http://feeds.pinboard.in/json/v1/u:"+pinboard_user+"/?cb=pinboardNS_show_bmarks\&count="+pinboard_count);
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).replace(/^\s+|\s+$/g, '') + "</a> ";
}
}
str += "</p></li>\n";
return str;
}
}
return {
getFeed: function(options) {
this.element = options.target;
fetch("http://feeds.pinboard.in/json/v1/u:"+options.user+"/?cb=pinboard.render\&count="+options.count);
},
render: function(data) {
var lr = new linkroll(this.element);
lr.set_items(data);
lr.show_bmarks();
}
}
})();

View File

@ -2,6 +2,7 @@
// (c) Brandon Mathis // MIT License
/* Sky Slavin, Ludopoli. MIT license. * based on JavaScript Pretty Date * Copyright (c) 2008 John Resig (jquery.com) * Licensed under the MIT license. */
/* Updated considerably by Brandon Mathis */
function prettyDate(time) {
if (navigator.appName === 'Microsoft Internet Explorer') {
return "<span>&infin;</span>"; // because IE date parsing isn't fun.
@ -39,40 +40,45 @@ function prettyDate(time) {
day_diff > 7 && Math.ceil(day_diff / 7) + say.weeks_ago;
}
function linkifyTweet(text, url) {
// Linkify urls, usernames, hashtags
text = text.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi, '<a href="$1$2">$2</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>');
var twitter = (function(){
// Use twitter's api to replace t.co shortened urls with expanded ones.
for (var u in url) {
if(url[u].expanded_url != null){
var shortUrl = new RegExp(url[u].url, 'g');
text = text.replace(shortUrl, url[u].expanded_url);
var shortUrl = new RegExp(">"+(url[u].url.replace(/https?:\/\//, '')), 'g');
text = text.replace(shortUrl, ">"+url[u].display_url);
function linkifyTweet(text, url) {
// Linkify urls, usernames, hashtags
text = text.replace(/(https?:\/\/)([\w\-:;?&=+.%#\/]+)/gi, '<a href="$1$2">$2</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>');
// Use twitter's api to replace t.co shortened urls with expanded ones.
for (var u in url) {
if(url[u].expanded_url != null){
var shortUrl = new RegExp(url[u].url, 'g');
text = text.replace(shortUrl, url[u].expanded_url);
var shortUrl = new RegExp(">"+(url[u].url.replace(/https?:\/\//, '')), 'g');
text = text.replace(shortUrl, ">"+url[u].display_url);
}
}
return text
}
function render(tweets, twitter_user) {
var timeline = document.getElementById('tweets'),
content = '';
for (var t in tweets) {
content += '<li>'+'<p>'+'<a href="http://twitter.com/'+twitter_user+'/status/'+tweets[t].id_str+'">'+prettyDate(tweets[t].created_at)+'</a>'+linkifyTweet(tweets[t].text.replace(/\n/g, '<br>'), tweets[t].entities.urls)+'</p>'+'</li>';
}
timeline.innerHTML = content;
}
return {
getFeed: function(options){
count = parseInt(options.count, 10);
$.ajax({
url: "http://api.twitter.com/1/statuses/user_timeline/" + options.user + ".json?trim_user=true&count=" + (count + 20) + "&include_entities=1&exclude_replies=" + (options.replies ? "0" : "1") + "&callback=?"
, dataType: 'jsonp'
, error: function (err) { $('#tweets li.loading').addClass('error').text("Twitter's busted"); }
, success: function(data) { render(data.slice(0, count), options.user); }
});
}
}
return text
}
function showTwitterFeed(tweets, twitter_user) {
var timeline = document.getElementById('tweets'),
content = '';
for (var t in tweets) {
content += '<li>'+'<p>'+'<a href="http://twitter.com/'+twitter_user+'/status/'+tweets[t].id_str+'">'+prettyDate(tweets[t].created_at)+'</a>'+linkifyTweet(tweets[t].text.replace(/\n/g, '<br>'), tweets[t].entities.urls)+'</p>'+'</li>';
}
timeline.innerHTML = content;
}
function getTwitterFeed(user, count, replies) {
count = parseInt(count, 10);
$.ajax({
url: "http://api.twitter.com/1/statuses/user_timeline/" + user + ".json?trim_user=true&count=" + (count + 20) + "&include_entities=1&exclude_replies=" + (replies ? "0" : "1") + "&callback=?"
, type: 'jsonp'
, error: function (err) { $('#tweets li.loading').addClass('error').text("Twitter's busted"); }
, success: function(data) { showTwitterFeed(data.slice(0, count), user); }
})
}
})();