Fix bugs in intra-site linking

* Refactor event handling in controllers to use a method to define
  the hash (and thereby allow inheritance)
* Refactor link handling so that links which should be handled by the
  router can be handled by the base class
* Change the router to throw out controllers for pages which aren't
  on-screen (and thereby avoid a lot of weirdness)
This commit is contained in:
Andrew Miner
2015-01-29 13:59:12 -08:00
parent d5140f963d
commit 841af15d5e
13 changed files with 63 additions and 66 deletions
+13 -14
View File
@@ -65,14 +65,14 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
@item params.recipeName, params.count
item: (name, quantity=1)->
@_pageControllers.item ?= new ItemPageController @_defaultOptions
@_pageControllers.item.model.params = name:name, quantity:quantity
@_setPage 'item'
controller = new ItemPageController @_defaultOptions
controller.model.params = name:name, quantity:quantity
@_setPage 'item', controller
mod: (slug)->
@_pageControllers.mod ?= new ModPageController @_defaultOptions
@_pageControllers.mod.model = @modPack.getMod slug
@_setPage 'mod'
controller = new ModPageController @_defaultOptions
controller.model = @modPack.getMod slug
@_setPage 'mod', controller
# Private Methods ##############################################################################
@@ -85,15 +85,14 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
else
logger.info "Suppressing GA page view: #{pathname}"
_setPage: (controllerName)->
controller = @_pageControllers[controllerName]
if not controller? then throw new Error "cannot find controller named: #{controllerName}"
return if @_page is controller
_setPage: (page, controller)->
return if @_page is page
logger.info "changing to #{controllerName} page"
logger.info "changing to #{page} page"
showDuration = Duration.normal
show = =>
@_page = controller
@_page = page
@_controller = controller
controller.onWillShow()
controller.render()
@@ -105,8 +104,8 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
controller.$el.fadeIn showDuration, ->
controller.onDidShow()
if @_mainController?
if @_controller?
showDuration = Duration.fast
@_page.$el.fadeOut Duration.fast, show
@_controller.$el.fadeOut showDuration, show
else
show()