Step 1 in converting to a Backbone-based website

This commit is contained in:
Andrew Miner
2014-12-22 16:36:04 -08:00
parent dc9fd0de07
commit 16832e02dd
95 changed files with 41866 additions and 17 deletions
+57
View File
@@ -0,0 +1,57 @@
###
# Crafting Guide - router.coffee
#
# Copyright (c) 2014 by Redwood Labs
# All rights reserved.
###
{Duration} = require './constants'
LandingPageController = require './controllers/landing_page_controller'
{Opacity} = require './constants'
########################################################################################################################
module.exports = class CraftingGuideRouter extends Backbone.Router
constructor: (options={})->
@_page = null
@_pageControllers = {}
super options
# Backbone.Router Overrides ####################################################################
routes:
'': 'landing'
# Route Methods ################################################################################
landing: ->
@_pageControllers.landing ?= new LandingPageController
@_setPage 'landing'
# Private Methods ##############################################################################
_setPage: (controllerName)->
controller = @_pageControllers[controllerName]
if not controller? then throw new Error "cannot find controller named: #{controllerName}"
return if @_page is controller
logger.info "changing to #{controllerName} page"
showDuration = Duration.normal
show = =>
@_page = controller
controller.render()
# controller.$el.css 'opacity', Opacity.hidden
$pageContent = $('.page')
$pageContent.empty()
$pageContent.append controller.$el
controller.$el.fadeIn showDuration
if @_mainController?
showDuration = Duration.fast
@_page.$el.fadeOut Duration.fast, show
else
show()