Created
February 29, 2012 08:50
-
-
Save eliaskg/1939262 to your computer and use it in GitHub Desktop.
Refresh members loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --- This little script loads the users of the @refreshmunich lists and sorts them by name. | |
var members = []; | |
// --- Fire the Twitter API request | |
JSONP.get('https://api.twitter.com/1/lists/members.json', { | |
slug:'members', | |
owner_screen_name:'refreshmunich' | |
}, function(data) { | |
members = data.users; | |
// --- We want the members sorted alphabetically | |
members = members.sort(sortMembers); | |
// --- Finished! your code comes here! | |
console.log(members); | |
alert('Loaded ALL the members!'); | |
}); | |
// --- Custom sort function for sorting the members | |
function sortMembers(a, b, key) { | |
// --- Members are sorted by Name. They can be also sorted by | |
// --- twitter @handle by changing a.name to a.screen_name | |
var nameA = a.name.toLowerCase(); | |
var nameB = b.name.toLowerCase(); | |
if (nameA < nameB) | |
return -1; | |
else if (nameA > nameB) | |
return 1; | |
return 0; | |
} | |
//Lightweight JSONP fetcher - www.nonobtrusive.com | |
var JSONP=(function(){var a=0,c,f,b,d=this;function e(j){var i=document.createElement('script'),h=false;i.src=j;i.async=true;i.onload=i.onreadystatechange=function(){if(!h&&(!this.readyState||this.readyState==='loaded'||this.readyState==='complete')){h=true;i.onload=i.onreadystatechange=null;if(i&&i.parentNode){i.parentNode.removeChild(i)}}};if(!c){c=document.getElementsByTagName('head')[0]}c.appendChild(i)}function g(h,j,k){f='?';j=j||{};for(b in j){if(j.hasOwnProperty(b)){f+=encodeURIComponent(b)+'='+encodeURIComponent(j[b])+'&'}}var i='json'+(++a);d[i]=function(l){k(l);try{delete d[i]}catch(m){}d[i]=null;};e(h+f+'callback='+i);return i}return{get:g}}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment