Skip to content

Commit

Permalink
Support monitoring XDomainRequests
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Sep 19, 2013
1 parent 1105faa commit 322ac80
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/themes/pace-theme-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
</div>
<div class="pace-activity"></div>
</div>
</body>
</body>
24 changes: 17 additions & 7 deletions pace.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ getFromDOM = (key='options', json=true) ->
try
return JSON.parse data
catch e
console.error "Error parsing inline pace options", e
console?.error "Error parsing inline pace options", e

window.Pace ?= {}

Expand Down Expand Up @@ -184,23 +184,33 @@ class Events

# We should only ever instantiate one of these
_XMLHttpRequest = window.XMLHttpRequest
_XDomainRequest = window.XDomainRequest
class RequestIntercept extends Events
constructor: ->
super

_intercept = @
monitor = (req) =>
_open = req.open
req.open = (type, url, async) =>
@trigger 'request', {type, url, request: req}

_open.apply req, arguments

window.XMLHttpRequest = ->
req = new _XMLHttpRequest

_open = req.open
req.open = (type, url, async) ->
_intercept.trigger 'request', {type, url, request: req}

_open.apply req, arguments
monitor req

req

if _XDomainRequest?
window.XDomainRequest = ->
req = new _XDomainRequest

monitor req

req

intercept = new RequestIntercept

class AjaxMonitor
Expand Down
32 changes: 23 additions & 9 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 322ac80

Please sign in to comment.