JezK
Edit File: progress_bar.js
// Generated by CoffeeScript 2.7.0 (function() { Turbolinks.ProgressBar = (function() { var ANIMATION_DURATION; class ProgressBar { constructor() { this.trickle = this.trickle.bind(this); this.stylesheetElement = this.createStylesheetElement(); this.progressElement = this.createProgressElement(); } show() { if (!this.visible) { this.visible = true; this.installStylesheetElement(); this.installProgressElement(); return this.startTrickling(); } } hide() { if (this.visible && !this.hiding) { this.hiding = true; return this.fadeProgressElement(() => { this.uninstallProgressElement(); this.stopTrickling(); this.visible = false; return this.hiding = false; }); } } setValue(value) { this.value = value; return this.refresh(); } // Private installStylesheetElement() { return document.head.insertBefore(this.stylesheetElement, document.head.firstChild); } installProgressElement() { this.progressElement.style.width = 0; this.progressElement.style.opacity = 1; document.documentElement.insertBefore(this.progressElement, document.body); return this.refresh(); } fadeProgressElement(callback) { this.progressElement.style.opacity = 0; return setTimeout(callback, ANIMATION_DURATION * 1.5); } uninstallProgressElement() { if (this.progressElement.parentNode) { return document.documentElement.removeChild(this.progressElement); } } startTrickling() { return this.trickleInterval != null ? this.trickleInterval : this.trickleInterval = setInterval(this.trickle, ANIMATION_DURATION); } stopTrickling() { clearInterval(this.trickleInterval); return this.trickleInterval = null; } trickle() { return this.setValue(this.value + Math.random() / 100); } refresh() { return requestAnimationFrame(() => { return this.progressElement.style.width = `${10 + (this.value * 90)}%`; }); } createStylesheetElement() { var element; element = document.createElement("style"); element.type = "text/css"; element.textContent = this.constructor.defaultCSS; return element; } createProgressElement() { var element; element = document.createElement("div"); element.className = "turbolinks-progress-bar"; return element; } }; ANIMATION_DURATION = 300; ProgressBar.defaultCSS = `.turbolinks-progress-bar { position: fixed; display: block; top: 0; left: 0; height: 3px; background: #0076ff; z-index: 9999; transition: width ${ANIMATION_DURATION}ms ease-out, opacity ${ANIMATION_DURATION / 2}ms ${ANIMATION_DURATION / 2}ms ease-in; transform: translate3d(0, 0, 0); }`; return ProgressBar; }).call(this); }).call(this);