// Generated by CoffeeScript 1.12.8 (function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; require('./http_request'); require('./progress_bar'); Turbolinks.BrowserAdapter = (function() { var NETWORK_FAILURE, TIMEOUT_FAILURE, ref; ref = Turbolinks.HttpRequest, NETWORK_FAILURE = ref.NETWORK_FAILURE, TIMEOUT_FAILURE = ref.TIMEOUT_FAILURE; function BrowserAdapter(controller) { this.controller = controller; this.showProgressBar = bind(this.showProgressBar, this); this.progressBar = new Turbolinks.ProgressBar; } BrowserAdapter.prototype.visitProposedToLocationWithAction = function(location, action) { return this.controller.startVisitToLocationWithAction(location, action); }; BrowserAdapter.prototype.visitStarted = function(visit) { visit.issueRequest(); visit.changeHistory(); return visit.loadCachedSnapshot(); }; BrowserAdapter.prototype.visitRequestStarted = function(visit) { this.progressBar.setValue(0); if (visit.hasCachedSnapshot() || visit.action !== "restore") { return this.showProgressBarAfterDelay(); } else { return this.showProgressBar(); } }; BrowserAdapter.prototype.visitRequestProgressed = function(visit) { return this.progressBar.setValue(visit.progress); }; BrowserAdapter.prototype.visitRequestCompleted = function(visit) { return visit.loadResponse(); }; BrowserAdapter.prototype.visitRequestFailedWithStatusCode = function(visit, statusCode) { switch (statusCode) { case NETWORK_FAILURE: case TIMEOUT_FAILURE: return this.reload(); default: return visit.loadResponse(); } }; BrowserAdapter.prototype.visitRequestFinished = function(visit) { return this.hideProgressBar(); }; BrowserAdapter.prototype.visitCompleted = function(visit) { return visit.followRedirect(); }; BrowserAdapter.prototype.pageInvalidated = function() { return this.reload(); }; BrowserAdapter.prototype.showProgressBarAfterDelay = function() { return this.progressBarTimeout = setTimeout(this.showProgressBar, this.controller.progressBarDelay); }; BrowserAdapter.prototype.showProgressBar = function() { return this.progressBar.show(); }; BrowserAdapter.prototype.hideProgressBar = function() { this.progressBar.hide(); return clearTimeout(this.progressBarTimeout); }; BrowserAdapter.prototype.reload = function() { return window.location.reload(); }; return BrowserAdapter; })(); }).call(this);