Skip to content

Commit

Permalink
Fixes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Sep 30, 2013
1 parent 4007a29 commit db58761
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 37 deletions.
12 changes: 10 additions & 2 deletions pace.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,19 @@ window.Pace ?= {}

options = Pace.options = extend defaultOptions, window.paceOptions, getFromDOM()

class NoTargetError extends Error

class Bar
constructor: ->
@progress = 0

getElement: ->
if not @el?
targetElement = document.querySelector options.target

if not targetElement
throw new NoTargetError

@el = document.createElement 'div'
@el.className = "pace pace-active"

Expand All @@ -133,7 +140,6 @@ class Bar
</div>
<div class="pace-activity"></div>
'''
targetElement = document.querySelector options.target
if targetElement.firstChild?
targetElement.insertBefore @el, targetElement.firstChild
else
Expand Down Expand Up @@ -561,7 +567,9 @@ Pace.go = ->
Pace.start = (_options) ->
extend options, _options

bar.render()
try
bar.render()
catch NoTargetError

# It's usually possible to render a bit before the document declares itself ready
if not document.querySelector('.pace')
Expand Down
87 changes: 53 additions & 34 deletions pace.js

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

Loading

0 comments on commit db58761

Please sign in to comment.