AngularJS sample : last tweets
by tchatel
HTML
<script src="http://code.angularjs.org/1.0.0rc2/angular-1.0.0rc2.js"></script>
<div ng-app ng-controller="TweetsCntl">
<h1>Last tweets about AngularJS</h1>
<div id="filter">
<p>
Full text filter (instant.): <input ng-model="fullTextSearch" ng-model-instant/>
<button ng-click="fullTextSearch=''">Clear</button>
</p>
<p>
User only : <input ng-model="structuredSearch.from_user_name"/>
Message only : <input ng-model="structuredSearch.text"/>
<button>Search</button>
<button ng-click="structuredSearch={}">Clear</button>
</p>
</div>
<div id="tweets">
<div class="tweet" ng-repeat="tweet in tweets | filter:fullTextSearch | filter:structuredSearch">
<img class="avatar" ng-src="{{tweet.profile_image_url}}"/>
<p class="date">{{tweet.date | date:'dd/MM/yyyy - hh:mm'}}</p>
<p class="user">{{tweet.from_user_name}}
<span class="userid">@{{tweet.from_user}}</span></p>
<p class="text" ng-bind-html="tweet.text | linky" />
</div>
</div>
</div>
CSS
body {
background-color: #dadaff;
padding: 15px;
}
h1 {
text-align: center;
}
#filter {
background-color: white;
margin: 1em auto 1em auto;
padding: 1em;
border: solid #aaa 1px;
border-radius: 6px;
}
#tweets {
background-color: white;
margin: 1em auto 1em auto;
padding: 0;
border: solid #aaa 1px;
border-radius: 6px;
}
#tweets div.tweet {
border-bottom: solid #aaa 1px;
padding: 0.7em;
font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
#tweets div.tweet:last-child {
border-bottom: none;
}
#tweets div.tweet img.avatar {
float: left;
width: 48px;
height: 48px;
margin-right: 10px;
padding: 4px;
}
#tweets div.tweet p {
margin: 0.3em;
padding: 0;
}
#tweets div.tweet p.user {
font-weight: bold;
}
#tweets div.tweet p.user span.userid {
font-weight: normal;
color: grey;
padding-left: 0.5em;
}
#tweets div.tweet p.date {
float: right;
font-size: 0.8em;
color: grey;
}
JavaScript
function TweetsCntl($scope, $http) {
$http.jsonp('http://search.twitter.com/search.json'
+ '?q=angularjs&rpp=100&include_entities=true&result_type=mixed'
+ '&callback=JSON_CALLBACK')
.success(function(data, status) {
$scope.tweets = data.results;
for (var i = 0 ; i < $scope.tweets.length ; i ++) {
$scope.tweets[i].date = Date.parse($scope.tweets[i].created_at);
}
});
}