Skip to content

Instantly share code, notes, and snippets.

@mech
Created December 6, 2011 09:36
Show Gist options
  • Select an option

  • Save mech/1437554 to your computer and use it in GitHub Desktop.

Select an option

Save mech/1437554 to your computer and use it in GitHub Desktop.
Mobile application inspired by Spine Mobile, SproutCore, Backbone.js and iOS
class Jobline extends UI.Application
constructor: ->
new NavigationController()
@start
start: ->
class UI.NavigationController
headerLeftButton: nil
headerRightButton: nil
_stack: nil
constructor: (el, header, rootView)->
_stack = [rootView]
@el = el || "#content" # <div id="container"></div> - The main DOM element this navigation will add on
@header = header || "header" # <header></header>
# Setup event listener for headerLeftButton which is a back button
currentView: ->
@stack.last
rootView: ->
@stack.first
pushView: (view) ->
@stack.push view
view.viewDidPush(@) # a callback for the BBV, which in turn can transition/render itself
# Most likely to happen when user press the "Back" button
popView: ->
return if currentView == @rootView
poppedView = @stack.pop
poppedView.viewDidPop(@) # remove this view, clean up...
@currentView.viewDidAppear(@) # and display the top view
poppedView # ??
class UI.ActionSheetView extends Backbone.View
class UI.View extends Backbone.View
subviews: [@] # UI.View can have many BBVs
initialize: (url_fragment, subviews...) ->
@url_fragment = url_fragment
@subviews.append subviews # append additional BBVs if there is any
# controller is the main UI.NavigationController which basically oversee all
# hierarchy of panels
viewDidPush: (controller) ->
# 1. Change header title
controller.header.title = @title
# 2. render it
# we will access the router here via `controller.router`
controller.router.navigate(@url_fragment, true)
# or we dun care about routing and directly replace the controller's main screen
# render all subviews
@render
# 3. Animate it
render: ->
subview.render for subview in @subviews
class UI.Application
config: {} # Some configuration
# Kick start the application
new Jobline();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment