Skip to content

Commit 1b7e0d5

Browse files
committed
Add restart on Backbone route change
1 parent 1b9940d commit 1b7e0d5

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

pace.coffee

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ defaultOptions =
2727
# means ajax navigation has occured)
2828
restartOnPushState: true
2929

30+
# Should pace automatically restart when a Backbone route change occurs? Can also be an
31+
# array of route names. Ignored if Backbone.js is not included on the page.
32+
restartOnBackboneRoute: true
33+
3034
elements:
3135
# How frequently in ms should we check for the elements being tested for
3236
# using the element monitor?
@@ -411,6 +415,24 @@ if window.history.replaceState?
411415

412416
_replaceState.apply window.history, arguments
413417

418+
if options.restartOnBackboneRoute
419+
# Bind in a timeout, as it's possible Backbone hasen't been
420+
# included yet
421+
setTimeout ->
422+
return unless window.Backbone?
423+
424+
Backbone.History.on 'route', (router, name) ->
425+
return unless rule = options.restartOnBackboneRoute
426+
427+
if typeof rule is 'object'
428+
# It's an array of route names
429+
for routeName in rule when routeName is name
430+
Pace.restart()
431+
break
432+
else
433+
Pace.restart()
434+
, 0
435+
414436
SOURCE_KEYS =
415437
ajax: AjaxMonitor
416438
elements: ElementMonitor

pace.js

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pace.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)