Permalink
Browse files

Built a little twitter search using ICanHaz js

  • Loading branch information...
1 parent 3fab6cf commit 74a9106d140480fd2f56df529c0eb0daccda8f8d Samuel Higginbotham committed Apr 1, 2013
Showing with 54 additions and 21 deletions.
  1. BIN .DS_Store
  2. +11 −0 ICanHaz.min.js
  3. +23 −5 index.html
  4. +20 −16 twitter-search.js
View
BIN .DS_Store
Binary file not shown.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,5 +1,23 @@
-<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
-<script src="twitter-search.js" type="text/javascript"></script>
-<input type='text' id='query'></input>
-<button id='btn'>Search</button>
-<div id="results"></div>
+<html>
+ <head>
+ <title>Twitter Search</title>
+ </head>
+ <body>
+ <h1>Twitter Search</h1>
+ <input id="query">
+ <button id="btn">Search</button>
+ <ul id="results"></ul>
+ <script id="tweets" type="text/html">
+ <li>
+ <img src="{{profile_image_url}}" />
+ <p class="name"><a href="http://www.twitter.com/{{from_user}}">{{from_user}}</a></p>
+ <p>{{text}}</p>
+ </li>
+ </script>
+
+ <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
+ <script src="twitter-search.js" type="text/javascript"></script>
+ <script src="ICanHaz.min.js" type="text/javascript"></script>
+ </body>
+</html>
+
View
@@ -1,19 +1,23 @@
function search(){
- var query = $('#query').val();
- $('#results').html('');
- $.ajax({
- url: "http://search.twitter.com/search.json?q=" + query,
- dataType: 'jsonp',
- success: function(data){
- $.each(data.results, function(i, result){
- var name = $("<p>").text(result.from_user);
- var tweet = $("<p>").text(result.text);
- $('#results').append(name);
- $('#results').append(tweet);
- });
- console.log(data);
- }
- });
+ var query = $('#query').val();
+ $('#results').html('');
+ $.ajax({
+ url: 'http://search.twitter.com/search.json?q=' + query,
+ dataType: 'jsonp'
+ })
+ .done(function(data){
+ $.each(data.results, function(i, result){
+ var tweets = ich.tweet(result)
+ $("#results").append(tweets);
+ })
+ })
+ .fail(function(data){
+ var error = "Sorry, there is something wrong. Please try again in a bit. Thanks for your patience!"
+ $('#error').append(error);
+ })
}
-$('#btn').on('click', search);
+$(function(){
+ $('#query').focus();
+ $('#btn').on('click', search);
+})

0 comments on commit 74a9106

Please sign in to comment.