Sha256: 5dfc0686d396d006338519189c165aada7ff37302f8c413af97dc03cf2c6d877

Contents?: true

Size: 1.41 KB

Versions: 21

Compression:

Stored size: 1.41 KB

Contents

Luca.Router = Backbone.Router.extend
  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() )

  #### 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

21 entries across 21 versions & 1 rubygems

Version Path
luca-0.8.599 src/components/router.coffee
luca-0.8.59 src/components/router.coffee
luca-0.8.3 src/components/router.coffee
luca-0.8.2 src/components/router.coffee
luca-0.8.06 src/components/router.coffee
luca-0.8 src/components/router.coffee
luca-0.7.92 src/components/router.coffee
luca-0.7.91 src/components/router.coffee
luca-0.7.9 src/components/router.coffee
luca-0.7.8 src/components/router.coffee
luca-0.7.7 src/components/router.coffee
luca-0.7.6 src/components/router.coffee
luca-0.7.5 src/components/router.coffee
luca-0.7.4 src/components/router.coffee
luca-0.7.3 src/components/router.coffee
luca-0.7.2 src/components/router.coffee
luca-0.7.0 src/components/router.coffee
luca-0.6.9 src/components/router.coffee
luca-0.6.8 src/components/router.coffee
luca-0.6.7 src/components/router.coffee