Skip to content

Instantly share code, notes, and snippets.

@luiscronicl
Created February 14, 2013 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luiscronicl/4953670 to your computer and use it in GitHub Desktop.
Save luiscronicl/4953670 to your computer and use it in GitHub Desktop.
class window.HomeView extends Backbone.View
template: _.template($('#home').html())
render: (eventName) ->
$(@el).html(@template())
return @
class window.Page1View extends Backbone.View
template: _.template($('#page1').html())
render: (eventName) ->
$(@el).html(@template())
return @
class window.Page2View extends Backbone.View
template: _.template($('#page2').html())
render: (eventName) ->
$(@el).html(@template())
return @
class window.AppRouter extends Backbone.Router
routes:
"":"home",
"page1":"page1",
"page2":"page2"
initialize: ->
_.bindAll @
$('.back').on 'click', (event) ->
window.history.back()
false
@firstPage = true
return
home: ->
console.log '#home'
@changePage new HomeView
page1: ->
console.log '#page1'
@changePage new Page1View
page2: ->
console.log '#page2'
@changePage new Page2View
changePage: (page) ->
$(page.el).attr('data-role', 'page')
page.render()
$('body').append($(page.el))
transition = $.mobile.defaultPageTransition
#We don't want to slide the first page
if @firstPage
transition = 'none'
@firstPage = false
$.mobile.changePage $(page.el), {changeHash: false, transition: transition }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment