JezK
Edit File: http_request.js
// Generated by CoffeeScript 2.7.0 (function() { Turbolinks.HttpRequest = (function() { class HttpRequest { constructor(delegate, location, referrer) { // XMLHttpRequest events this.requestProgressed = this.requestProgressed.bind(this); this.requestLoaded = this.requestLoaded.bind(this); this.requestFailed = this.requestFailed.bind(this); this.requestTimedOut = this.requestTimedOut.bind(this); this.requestCanceled = this.requestCanceled.bind(this); this.delegate = delegate; this.url = Turbolinks.Location.wrap(location).requestURL; this.referrer = Turbolinks.Location.wrap(referrer).absoluteURL; this.createXHR(); } send() { var base; if (this.xhr && !this.sent) { this.notifyApplicationBeforeRequestStart(); this.setProgress(0); this.xhr.send(); this.sent = true; return typeof (base = this.delegate).requestStarted === "function" ? base.requestStarted() : void 0; } } cancel() { if (this.xhr && this.sent) { return this.xhr.abort(); } } requestProgressed(event) { if (event.lengthComputable) { return this.setProgress(event.loaded / event.total); } } requestLoaded() { return this.endRequest(() => { var ref; if ((200 <= (ref = this.xhr.status) && ref < 300)) { return this.delegate.requestCompletedWithResponse(this.xhr.responseText, this.xhr.getResponseHeader("Turbolinks-Location")); } else { this.failed = true; return this.delegate.requestFailedWithStatusCode(this.xhr.status, this.xhr.responseText); } }); } requestFailed() { return this.endRequest(() => { this.failed = true; return this.delegate.requestFailedWithStatusCode(this.constructor.NETWORK_FAILURE); }); } requestTimedOut() { return this.endRequest(() => { this.failed = true; return this.delegate.requestFailedWithStatusCode(this.constructor.TIMEOUT_FAILURE); }); } requestCanceled() { return this.endRequest(); } // Application events notifyApplicationBeforeRequestStart() { return Turbolinks.dispatch("turbolinks:request-start", { data: { url: this.url, xhr: this.xhr } }); } notifyApplicationAfterRequestEnd() { return Turbolinks.dispatch("turbolinks:request-end", { data: { url: this.url, xhr: this.xhr } }); } // Private createXHR() { this.xhr = new XMLHttpRequest(); this.xhr.open("GET", this.url, true); this.xhr.timeout = this.constructor.timeout * 1000; this.xhr.setRequestHeader("Accept", "text/html, application/xhtml+xml"); this.xhr.setRequestHeader("Turbolinks-Referrer", this.referrer); this.xhr.onprogress = this.requestProgressed; this.xhr.onload = this.requestLoaded; this.xhr.onerror = this.requestFailed; this.xhr.ontimeout = this.requestTimedOut; return this.xhr.onabort = this.requestCanceled; } endRequest(callback) { if (this.xhr) { this.notifyApplicationAfterRequestEnd(); if (callback != null) { callback.call(this); } return this.destroy(); } } setProgress(progress) { var base; this.progress = progress; return typeof (base = this.delegate).requestProgressed === "function" ? base.requestProgressed(this.progress) : void 0; } destroy() { var base; this.setProgress(1); if (typeof (base = this.delegate).requestFinished === "function") { base.requestFinished(); } this.delegate = null; return this.xhr = null; } }; HttpRequest.NETWORK_FAILURE = 0; HttpRequest.TIMEOUT_FAILURE = -1; HttpRequest.timeout = 60; return HttpRequest; }).call(this); }).call(this);