JezK
Edit File: visit.js
// Generated by CoffeeScript 2.7.0 (function() { require('./http_request'); Turbolinks.Visit = (function() { var getHistoryMethodForAction; class Visit { constructor(controller, location, action1) { // Scrolling this.performScroll = this.performScroll.bind(this); this.controller = controller; this.action = action1; this.identifier = Turbolinks.uuid(); this.location = Turbolinks.Location.wrap(location); this.adapter = this.controller.adapter; this.state = "initialized"; this.timingMetrics = {}; } start() { if (this.state === "initialized") { this.recordTimingMetric("visitStart"); this.state = "started"; return this.adapter.visitStarted(this); } } cancel() { var ref; if (this.state === "started") { if ((ref = this.request) != null) { ref.cancel(); } this.cancelRender(); return this.state = "canceled"; } } complete() { var base; if (this.state === "started") { this.recordTimingMetric("visitEnd"); this.state = "completed"; if (typeof (base = this.adapter).visitCompleted === "function") { base.visitCompleted(this); } return this.controller.visitCompleted(this); } } fail() { var base; if (this.state === "started") { this.state = "failed"; return typeof (base = this.adapter).visitFailed === "function" ? base.visitFailed(this) : void 0; } } changeHistory() { var actionForHistory, method; if (!this.historyChanged) { actionForHistory = this.location.isEqualTo(this.referrer) ? "replace" : this.action; method = getHistoryMethodForAction(actionForHistory); this.controller[method](this.location, this.restorationIdentifier); return this.historyChanged = true; } } issueRequest() { if (this.shouldIssueRequest() && (this.request == null)) { this.progress = 0; this.request = new Turbolinks.HttpRequest(this, this.location, this.referrer); return this.request.send(); } } getCachedSnapshot() { var snapshot; if (snapshot = this.controller.getCachedSnapshotForLocation(this.location)) { if ((this.location.anchor == null) || snapshot.hasAnchor(this.location.anchor)) { if (this.action === "restore" || snapshot.isPreviewable()) { return snapshot; } } } } hasCachedSnapshot() { return this.getCachedSnapshot() != null; } loadCachedSnapshot() { var isPreview, snapshot; if (snapshot = this.getCachedSnapshot()) { isPreview = this.shouldIssueRequest(); return this.render(function() { var base; this.cacheSnapshot(); this.controller.render({snapshot, isPreview}, this.performScroll); if (typeof (base = this.adapter).visitRendered === "function") { base.visitRendered(this); } if (!isPreview) { return this.complete(); } }); } } loadResponse() { if (this.response != null) { return this.render(function() { var base, base1; this.cacheSnapshot(); if (this.request.failed) { this.controller.render({ error: this.response }, this.performScroll); if (typeof (base = this.adapter).visitRendered === "function") { base.visitRendered(this); } return this.fail(); } else { this.controller.render({ snapshot: this.response }, this.performScroll); if (typeof (base1 = this.adapter).visitRendered === "function") { base1.visitRendered(this); } return this.complete(); } }); } } followRedirect() { if (this.redirectedToLocation && !this.followedRedirect) { this.location = this.redirectedToLocation; this.controller.replaceHistoryWithLocationAndRestorationIdentifier(this.redirectedToLocation, this.restorationIdentifier); return this.followedRedirect = true; } } // HTTP Request delegate requestStarted() { var base; this.recordTimingMetric("requestStart"); return typeof (base = this.adapter).visitRequestStarted === "function" ? base.visitRequestStarted(this) : void 0; } requestProgressed(progress) { var base; this.progress = progress; return typeof (base = this.adapter).visitRequestProgressed === "function" ? base.visitRequestProgressed(this) : void 0; } requestCompletedWithResponse(response, redirectedToLocation) { this.response = response; if (redirectedToLocation != null) { this.redirectedToLocation = Turbolinks.Location.wrap(redirectedToLocation); } return this.adapter.visitRequestCompleted(this); } requestFailedWithStatusCode(statusCode, response) { this.response = response; return this.adapter.visitRequestFailedWithStatusCode(this, statusCode); } requestFinished() { var base; this.recordTimingMetric("requestEnd"); return typeof (base = this.adapter).visitRequestFinished === "function" ? base.visitRequestFinished(this) : void 0; } performScroll() { if (!this.scrolled) { if (this.action === "restore") { this.scrollToRestoredPosition() || this.scrollToTop(); } else { this.scrollToAnchor() || this.scrollToTop(); } return this.scrolled = true; } } scrollToRestoredPosition() { var position, ref; position = (ref = this.restorationData) != null ? ref.scrollPosition : void 0; if (position != null) { this.controller.scrollToPosition(position); return true; } } scrollToAnchor() { if (this.location.anchor != null) { this.controller.scrollToAnchor(this.location.anchor); return true; } } scrollToTop() { return this.controller.scrollToPosition({ x: 0, y: 0 }); } // Instrumentation recordTimingMetric(name) { var base; return (base = this.timingMetrics)[name] != null ? base[name] : base[name] = new Date().getTime(); } getTimingMetrics() { return Turbolinks.copyObject(this.timingMetrics); } shouldIssueRequest() { if (this.action === "restore") { return !this.hasCachedSnapshot(); } else { return true; } } cacheSnapshot() { if (!this.snapshotCached) { this.controller.cacheSnapshot(); return this.snapshotCached = true; } } render(callback) { this.cancelRender(); return this.frame = requestAnimationFrame(() => { this.frame = null; return callback.call(this); }); } cancelRender() { if (this.frame) { return cancelAnimationFrame(this.frame); } } }; // Private getHistoryMethodForAction = function(action) { switch (action) { case "replace": return "replaceHistoryWithLocationAndRestorationIdentifier"; case "advance": case "restore": return "pushHistoryWithLocationAndRestorationIdentifier"; } }; return Visit; }).call(this); }).call(this);