Sha256: c367dab2a334c3e54bb672c99b593c7888930749c4376d071bb014b4d736123e

Contents?: true

Size: 1.57 KB

Versions: 5

Compression:

Stored size: 1.57 KB

Contents

#_.def("Luca.Router").extends("Backbone.Router").with
router = Luca.register  "Luca.Router"
router.extends          "Backbone.Router"
router.defines
  routes:
    "" : "default"

  initialize: (@options)->
    _.extend @, @options

    @routeHandlers = _( @routes ).values()

    # when a route handler is fired, the route:route_name event is triggered by the router
    # unfortunately this doesn't apply to calls to @navigate() so we override Backbone.Router.navigate
    # and trigger an event separately.
    _( @routeHandlers ).each (route_id) =>
      @bind "route:#{ route_id }", ()=>
        @trigger.apply @, ["change:navigation", route_id  ].concat( _( arguments ).flatten() )

    Backbone.Router.initialize?.apply(@, arguments)

  #### Router Functions

  # Intercept calls to Backbone.Router.navigate so that we can at least
  # build a path from the route, even if we don't trigger the route handler
  navigate: (route, triggerRoute=false)->
    Backbone.Router.prototype.navigate.apply @, arguments
    @buildPathFrom( Backbone.history.getFragment() )

  # given a url fragment, construct an argument chain similar to what would be
  # emitted from a normal route:#{ name } event that gets triggered
  # when a route is actually fired.  This is used to trap route changes that happen
  # through calls to @navigate()
  buildPathFrom: (matchedRoute)->
    _(@routes).each (route_id, route)=>
      regex = @_routeToRegExp(route)
      if regex.test(matchedRoute)
        args = @_extractParameters(regex, matchedRoute)
        @trigger.apply @, ["change:navigation", route_id].concat( args )

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
luca-0.9.91 app/assets/javascripts/luca/components/router.coffee
luca-0.9.9 app/assets/javascripts/luca/components/router.coffee
luca-0.9.899 app/assets/javascripts/luca/components/router.coffee
luca-0.9.89 app/assets/javascripts/luca/components/router.coffee
luca-0.9.8 app/assets/javascripts/luca/components/router.coffee