@@ -240,6 +240,32 @@ extendNative = (to, from) ->
240240 to[key] = val
241241 catch e
242242
243+ ignoreStack = []
244+
245+ Pace .ignore = (fn , args ... ) ->
246+ ignoreStack .unshift ' ignore'
247+ ret = fn (args... )
248+ ignoreStack .shift ()
249+ ret
250+
251+ Pace .track = (fn , args ... ) ->
252+ ignoreStack .unshift ' track'
253+ ret = fn (args... )
254+ ignoreStack .shift ()
255+ ret
256+
257+ shouldTrack = (method = ' GET' ) ->
258+ if ignoreStack[0 ] is ' track'
259+ return ' force'
260+
261+ if not ignoreStack .length and options .ajax
262+ if method is ' socket' and options .ajax .trackWebSockets
263+ return true
264+ else if method .toUpperCase () in options .ajax .trackMethods
265+ return true
266+
267+ return false
268+
243269# We should only ever instantiate one of these
244270class RequestIntercept extends Events
245271 constructor : ->
@@ -248,7 +274,7 @@ class RequestIntercept extends Events
248274 monitorXHR = (req ) =>
249275 _open = req .open
250276 req .open = (type , url , async ) =>
251- if (type ? ' GET ' ). toUpperCase () in options . ajax . trackMethods
277+ if shouldTrack (type)
252278 @ trigger ' request' , {type, url, request : req}
253279
254280 _open .apply req, arguments
@@ -276,7 +302,8 @@ class RequestIntercept extends Events
276302 window .WebSocket = (url , protocols ) =>
277303 req = new _WebSocket (url, protocols)
278304
279- @ trigger ' request' , {type : ' socket' , url, protocols, request : req}
305+ if shouldTrack (' socket' )
306+ @ trigger ' request' , {type : ' socket' , url, protocols, request : req}
280307
281308 req
282309
@@ -288,30 +315,33 @@ getIntercept = ->
288315 _intercept = new RequestIntercept
289316 _intercept
290317
291- if options .restartOnRequestAfter isnt false
292- # If we want to start the progress bar
293- # on every request, we need to hear the request
294- # and then inject it into the new ajax monitor
295- # start will have created.
318+ # If we want to start the progress bar
319+ # on every request, we need to hear the request
320+ # and then inject it into the new ajax monitor
321+ # start will have created.
296322
297- getIntercept ().on ' request' , ({type, request}) ->
298- if not Pace .running
299- args = arguments
323+ getIntercept ().on ' request' , ({type, request}) ->
324+ if not Pace .running and ( options . restartOnRequestAfter isnt false or shouldTrack (type) is ' force ' )
325+ args = arguments
300326
301- setTimeout ->
302- if type is ' socket'
303- stillActive = request .readyState < 2
304- else
305- stillActive = 0 < request .readyState < 4
327+ after = options .restartOnRequestAfter or 0
328+ if typeof after is ' boolean'
329+ after = 0
330+
331+ setTimeout ->
332+ if type is ' socket'
333+ stillActive = request .readyState < 2
334+ else
335+ stillActive = 0 < request .readyState < 4
306336
307- if stillActive
308- Pace .restart ()
337+ if stillActive
338+ Pace .restart ()
309339
310- for source in Pace .sources
311- if source instanceof AjaxMonitor
312- source .watch args...
313- break
314- , options . restartOnRequestAfter
340+ for source in Pace .sources
341+ if source instanceof AjaxMonitor
342+ source .watch args...
343+ break
344+ , after
315345
316346class AjaxMonitor
317347 constructor : ->
0 commit comments