Skip to content

Commit

Permalink
Add routing to full article url when clicking headline
Browse files Browse the repository at this point in the history
  • Loading branch information
lezhangxyz committed Oct 10, 2012
1 parent 07e6113 commit d91e21e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/js/AppRouter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ define ['libs/backbone', 'libs/backbone.layoutmanager'], ->

# Use Tim Branyen's excellent Backbone layout manager
# enabling us to easily chain view rendering and also
# automate the loading of module templates and css
# automate the loading of module templates
Backbone.LayoutManager.configure
# Enables layoutmanager when extending Backbone.View
manage: true
Expand All @@ -39,9 +39,9 @@ define ['libs/backbone', 'libs/backbone.layoutmanager'], ->

routes:
'uidevtest/src/html/index.html': 'home'
'uidevtest/src/html/index.html?story=sto:storyNum': 'home'
'*404': '404' # The asterisk catches all missed routes
home: ->
console.log 'Home!'
404: ->
console.log '404'
Backbone.history.navigate 'uidevtest/src/html/index.html', true
Expand Down
6 changes: 5 additions & 1 deletion src/js/modules/StoryCollection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ StoryCollection = (Backbone) ->
parse: (response) ->
# News story models are under 'objects' in the JSON data
stories = response.objects
for story in stories
for story, i in stories
# Add some render-specific fields
story.formatted_categories = "#{story.categories_name[0]} / #{story.categories_name[1]}"
story.formatted_pub_date = @parseDate story.pub_date
story.formatted_updated = @parseDate story.updated
storyNum = i + 1
if storyNum < 10 then storyNum = "0#{storyNum}"
story.story_url = "?story=sto#{storyNum}"
return stories

parseDate: (unixDate) ->
Expand Down
2 changes: 1 addition & 1 deletion src/js/modules/StoryList/StoryListTemplate.hogan
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#stories}}
<li class="headline">
<img class="picture" src="{{lead_photo_image_url}}">
<h1 class="title">{{title}}</h1>
<h2 class="title"><a href="{{story_url}}">{{title}}</a></h2>
<p class="categories">{{formatted_categories}}</p>
<p class="postedDate">{{formatted_pub_date}}</p>
<p class="updatedDate">{{formatted_updated}}</p>
Expand Down
5 changes: 5 additions & 0 deletions src/js/modules/StoryList/StoryListView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ define [
@.stories.fetch()
serialize: ->
return stories: @.stories.toJSON()
events:
"click .headline .title a": "viewStory"
viewStory: (event) ->
event.preventDefault()
Backbone.history.navigate window.location.pathname + event.target.getAttribute "href"
return StoryListView

0 comments on commit d91e21e

Please sign in to comment.