Created
June 17, 2010 16:19
-
-
Save mollifier/442344 to your computer and use it in GitHub Desktop.
jQuery Text Change Event plugin demo
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
// twitter incremental search | |
// jQuery Text Change Event plugin demo | |
// | |
// requires | |
// jQuery 1.4.2 | |
// http://jquery.com/ | |
// jQuery Text Change Event plugin | |
// http://www.zurb.com/playground/jquery-text-change-custom-event | |
$(function() { | |
function searchTwitter(query) { | |
var url = "http://search.twitter.com/search.json"; | |
$.ajax({ | |
url : url, | |
data : { | |
lang : "ja", | |
locale : "ja", | |
rpp : "15", | |
q : query | |
}, | |
dataType : "jsonp", | |
timeout : 700, | |
success : function(data, dataType) { | |
if (data !== null && data.results !== null) { | |
showData(data.results); | |
} | |
} | |
}); | |
} | |
function showData(results) { | |
var container = $("#search-result"); | |
container.html(""); | |
for (var i = 0; i < results.length; i++) { | |
var userUrl = "http://twitter.com/" + results[i].from_user; | |
var li = $("<li></li>"). | |
append( | |
"<span>" + | |
"<a href='" + userUrl + "'>" + | |
"<img alt='profile_image' src='" + results[i].profile_image_url + "' />" + | |
"</a>" + | |
"</span>"). | |
append( | |
"<span>" + | |
"<a href='" + userUrl + "'>" + results[i].from_user + "</a>" + | |
"</span>"). | |
append("<span>" + results[i].text + "</span>"); | |
container.append(li); | |
} | |
} | |
var timeout = null; | |
$("#query-area").bind("textchange", function() { | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
var query = $.trim($(this).val()); | |
if (query === "") { | |
return; | |
} | |
timeout = setTimeout(function() { | |
searchTwitter(query); | |
}, 900); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment