Skip to content

Commit

Permalink
Add restart on Backbone route change
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Sep 23, 2013
1 parent 1b9940d commit 1b7e0d5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
22 changes: 22 additions & 0 deletions pace.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ defaultOptions =
# means ajax navigation has occured)
restartOnPushState: true

# Should pace automatically restart when a Backbone route change occurs? Can also be an
# array of route names. Ignored if Backbone.js is not included on the page.
restartOnBackboneRoute: true

elements:
# How frequently in ms should we check for the elements being tested for
# using the element monitor?
Expand Down Expand Up @@ -411,6 +415,24 @@ if window.history.replaceState?

_replaceState.apply window.history, arguments

if options.restartOnBackboneRoute
# Bind in a timeout, as it's possible Backbone hasen't been
# included yet
setTimeout ->
return unless window.Backbone?

Backbone.History.on 'route', (router, name) ->
return unless rule = options.restartOnBackboneRoute

if typeof rule is 'object'
# It's an array of route names
for routeName in rule when routeName is name
Pace.restart()
break
else
Pace.restart()
, 0

SOURCE_KEYS =
ajax: AjaxMonitor
elements: ElementMonitor
Expand Down
29 changes: 29 additions & 0 deletions pace.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pace.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1b7e0d5

Please sign in to comment.