@@ -35,6 +35,9 @@ defaultOptions =
3535 # array of route names. Ignored if Backbone.js is not included on the page.
3636 restartOnBackboneRoute : true
3737
38+ # What element should the pace element be appended to on the page?
39+ target : ' body'
40+
3841 elements :
3942 # How frequently in ms should we check for the elements being tested for
4043 # using the element monitor?
@@ -49,8 +52,12 @@ defaultOptions =
4952 # how many samples we need before we consider a low number to mean completion.
5053 minSamples : 10
5154
52- # What element should the pace element be appended to on the page?
53- target : ' body'
55+ ajax :
56+ # Which HTTP methods should we track?
57+ trackMethods : [' GET' ]
58+
59+ # Should we track web socket connections?
60+ trackWebSockets : true
5461
5562now = ->
5663 performance ? .now ? () ? + new Date
@@ -207,7 +214,8 @@ class RequestIntercept extends Events
207214 monitorXHR = (req ) =>
208215 _open = req .open
209216 req .open = (type , url , async ) =>
210- @ trigger ' request' , {type, url, request : req}
217+ if (type ? ' GET' ).toUpperCase () in options .ajax .trackMethods
218+ @ trigger ' request' , {type, url, request : req}
211219
212220 _open .apply req, arguments
213221
@@ -230,7 +238,7 @@ class RequestIntercept extends Events
230238
231239 extendNative window .XDomainRequest , _XDomainRequest
232240
233- if _WebSocket?
241+ if _WebSocket? and options . ajax . trackWebSockets
234242 window .WebSocket = (url , protocols ) =>
235243 req = new _WebSocket (url, protocols)
236244
@@ -260,12 +268,11 @@ class XHRRequestTracker
260268 constructor : (request ) ->
261269 @progress = 0
262270
263- if request . onprogress isnt undefined
264- # It will be null, not undefined, on browsers which don't support it
265-
271+ if window . ProgressEvent ?
272+ # We're dealing with a modern browser with progress event support
273+
266274 size = null
267- _onprogress = request .onprogress
268- request .onprogress = =>
275+ request .addEventListener ' progress' , =>
269276 try
270277 headers = request .getAllResponseHeaders ()
271278
@@ -287,15 +294,9 @@ class XHRRequestTracker
287294 # never hit 100% until it's done.
288295 @progress = @progress + (100 - @progress ) / 2
289296
290- _onprogress? (arguments ... )
291-
292- for handler in [' onload' , ' onabort' , ' ontimeout' , ' onerror' ]
293- do (handler ) =>
294- fn = request[handler]
295- request[handler] = =>
296- @progress = 100
297-
298- fn? (arguments ... )
297+ for event in [' load' , ' abort' , ' timeout' , ' error' ]
298+ request .addEventListener event, =>
299+ @progress = 100
299300
300301 else
301302 _onreadystatechange = request .onreadystatechange
@@ -480,7 +481,7 @@ SOURCE_KEYS =
480481 eventLag : EventLagMonitor
481482
482483do init = ->
483- sources = []
484+ Pace . sources = sources = []
484485
485486 for type in [' ajax' , ' elements' , ' document' , ' eventLag' ]
486487 if options[type] isnt false
@@ -489,7 +490,7 @@ do init = ->
489490 for source in options .extraSources ? []
490491 sources .push new source (options)
491492
492- bar = new Bar
493+ Pace . bar = bar = new Bar
493494
494495 # Each source of progress data has it's own scaler to smooth its output
495496 scalers = []
0 commit comments