Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Toggle trends using link.

  • Loading branch information...
commit 8aa9035acbf2ada3f7cd52c61ac90ef438bc269b 1 parent 0086070
Miki Leskinen authored
23 application/public/js/application.js
View
@@ -1,13 +1,20 @@
$(document).ready(function() {
- $.ajax({
- url: 'http://api.twitter.com/1/trends/current.json',
- type: 'GET',
- dataType: 'jsonp',
- success: function(data) {
- var trends = _(data.trends).chain().map(function(v, k){ return v }).first().flatten().value()
- _.forEach(trends, function(t) {
- $('.trends').append('<li class="trend">' + t.name + '</li>')
+ $('.actions .showTrends').live('click', function(event) {
+ event.preventDefault()
+ if ($('.trends .trend').length === 0) {
+ $.ajax({
+ url: 'http://api.twitter.com/1/trends/current.json',
+ type: 'GET',
+ dataType: 'jsonp',
+ success: function(data) {
+ var trends = _(data.trends).chain().map(function(v, k){ return v }).first().flatten().value()
+ _.forEach(trends, function(t) {
+ $('.trends').append('<li class="trend">' + t.name + '</li>')
+ })
+ }
})
+ } else {
+ $('.trends').empty()
}
})
})
2  application/views/index.jade
View
@@ -10,6 +10,6 @@ html(lang="en")
div.main
h3 Foo Twitter Client
div.actions
- a.showTrends
+ a.showTrends(href: '#') Trends
div.trendsScrollContainer
ol.trends
20 spec/js/acceptance/foo-twitter-client-spec.js
View
@@ -11,12 +11,28 @@ describe('twitter client', function() {
asyncSpecWait()
})
- it('shows latest trends', function() {
+ it('has trends link', function() {
browser.visit('http://localhost:8003/', function(error, browser) {
- expect(browser.querySelectorAll('.trends .trend').length).toEqual(10)
+ expect(browser.text('.actions .showTrends')).toEqual('Trends')
asyncSpecDone()
})
asyncSpecWait()
})
})
+
+ describe('when toggling trends link', function() {
+ it('shows and hides latest trends', function() {
+ expect(browser.querySelectorAll('.trends .trend').length).toEqual(0)
+ browser.visit('http://localhost:8003/', function(error, browser) {
+ browser.clickLink('.showTrends', function(error, browser) {
+ expect(browser.querySelectorAll('.trends .trend').length).toEqual(10)
+ browser.clickLink('.showTrends', function(error, browser) {
+ expect(browser.querySelectorAll('.trends .trend').length).toEqual(0)
+ asyncSpecDone()
+ })
+ })
+ })
+ asyncSpecWait()
+ })
+ })
})
Please sign in to comment.
Something went wrong with that request. Please try again.