Skip to content

Instantly share code, notes, and snippets.

@mollifier
Created December 17, 2009 12:29
Show Gist options
  • Save mollifier/258711 to your computer and use it in GitHub Desktop.
Save mollifier/258711 to your computer and use it in GitHub Desktop.
Jetpack Feature to search tweet in slidebar
// twitterlist.js
// Jetpack Feature to search tweet in slidebar
jetpack.future.import("slideBar");
jetpack.slideBar.append({
icon: "http://a1.twimg.com/a/1260817727/images/favicon.ico",
html: "<h1>Twitter List</h1>" +
"<form>" +
"keyword : <input type='text' id='keyword' value=''></input>" +
"<input type='submit' value='search' id='searchbutton'></input>" +
"</form>" +
"<ul id='userlist'></ul>",
width: 320,
onSelect: function(s) {
s.slide(320, {persist: true});
},
onReady: function(s) {
var submitFunction = function() {
var keyword = $(s.contentDocument).find("#keyword").val();
var searchSuccess = function(data, status) {
$(s.contentDocument).find("#userlist").empty();
for (var i = 0; i < data.results.length; i++) {
var username = data.results[i].from_user;
var id = data.results[i].id;
var tweetParmalink = "http://twitter.com/" + username + "/status/" + id;
var a = $("<a>", s.contentDocument).
attr({href: encodeURI(tweetParmalink), target: "_blank"}).text(username);
var elem = $("<li>", s.contentDocument).append(a);
$(s.contentDocument).find("#userlist").append(elem);
}
};
var searchError = function(xhr, errMsg, errObj) {
console.error("twitterlist.js: search error: " + xhr.responseText);
};
jetpack.lib.twitter.search({
q: keyword,
lang: "ja",
locale: "ja",
rpp: 25,
success: searchSuccess,
error: searchError
});
// デフォルトの動作を行わない
return false;
};
$(s.contentDocument).find("form").submit(submitFunction);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment