Last active
October 9, 2016 22:14
-
-
Save englishextra/6a8c79c9efbf1f2f50523d46a918b785 to your computer and use it in GitHub Desktop.
modified for babel ToProgress v0.1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* modified for babel ToProgress v0.1.1 | |
* http://github.com/djyde/ToProgress | |
* gist.github.com/englishextra/6a8c79c9efbf1f2f50523d46a918b785 | |
* jsfiddle.net/englishextra/z5xhjde8/ | |
* arguments.callee changed to TP, a local wrapper function, | |
* so that public function name is now customizable; | |
* wrapped in curly brackets: | |
* else{document.body.appendChild(this.progressBar);}; | |
* removed AMD, CommonJS support | |
* changed this or window to self as argument; | |
* added if("undefined"==typeof window||!("document"in window)) | |
* {return console.log("window is undefined or document is not in window"),!1;} | |
*/ | |
var ToProgress = (function () { | |
var TP = function () { | |
if ("undefined" == typeof window || !("document" in window)) { | |
return console.log("window is undefined or document is not in window"), | |
!1; | |
} | |
function t() { | |
var t, | |
s = document.createElement("fakeelement"), | |
i = { | |
transition : "transitionend", | |
OTransition : "oTransitionEnd", | |
MozTransition : "transitionend", | |
WebkitTransition : "webkitTransitionEnd" | |
}; | |
for (t in i) | |
if (void 0 !== s.style[t]) | |
return i[t] | |
} | |
function s(t, s) { | |
if (this.progress = 0, this.options = { | |
id : "top-progress-bar", | |
color : "#F44336", | |
height : "2px", | |
duration : .2 | |
}, t && "object" == typeof t) | |
for (var i in t) | |
this.options[i] = t[i]; | |
if (this.options.opacityDuration = 3 * this.options.duration, this.progressBar = document.createElement("div"), this.progressBar.id = this.options.id, this.progressBar.setCSS = function (t) { | |
for (var s in t) | |
this.style[s] = t[s] | |
}, this.progressBar.setCSS({ | |
position : s ? "relative" : "fixed", | |
top : "0", | |
left : "0", | |
right : "0", | |
"background-color" : this.options.color, | |
height : this.options.height, | |
width : "0%", | |
transition : "width " + this.options.duration + "s, opacity " + this.options.opacityDuration + "s", | |
"-moz-transition" : "width " + this.options.duration + "s, opacity " + this.options.opacityDuration + "s", | |
"-webkit-transition" : "width " + this.options.duration + "s, opacity " + this.options.opacityDuration + "s" | |
}), s) { | |
var o = document.querySelector(s); | |
o && (o.hasChildNodes() ? o.insertBefore(this.progressBar, o.firstChild) : o.appendChild(this.progressBar)) | |
} else { | |
document.body.appendChild(this.progressBar) | |
} | |
} | |
var i = t(); | |
return s.prototype.transit = function () { | |
this.progressBar.style.width = this.progress + "%" | |
}, | |
s.prototype.getProgress = function () { | |
return this.progress | |
}, | |
s.prototype.setProgress = function (t, s) { | |
this.show(), | |
this.progress = t > 100 ? 100 : 0 > t ? 0 : t, | |
this.transit(), | |
s && s() | |
}, | |
s.prototype.increase = function (t, s) { | |
this.show(), | |
this.setProgress(this.progress + t, s) | |
}, | |
s.prototype.decrease = function (t, s) { | |
this.show(), | |
this.setProgress(this.progress - t, s) | |
}, | |
s.prototype.finish = function (t) { | |
var s = this; | |
this.setProgress(100, t), | |
this.hide(), | |
i && this.progressBar.addEventListener(i, function (t) { | |
s.reset(), | |
s.progressBar.removeEventListener(t.type, TP) | |
}) | |
}, | |
s.prototype.reset = function (t) { | |
this.progress = 0, | |
this.transit(), | |
t && t() | |
}, | |
s.prototype.hide = function () { | |
this.progressBar.style.opacity = "0" | |
}, | |
s.prototype.show = function () { | |
this.progressBar.style.opacity = "1" | |
}, | |
s; | |
}; | |
return TP(); | |
} | |
()); | |
/*! | |
* init ToProgress and extend methods | |
*/ | |
var progressBar = new ToProgress({ | |
id : "top-progress-bar", | |
color : "#FE5F55", | |
height : "3px", | |
duration : .2 | |
}); | |
/*! | |
* @memberof progressBar | |
* @param {Int} [n] a whole positive number | |
* progressBar.init(n) | |
*/ | |
progressBar.init = function (n) { | |
n = n || 20; | |
return this.increase(n); | |
}; | |
/*! | |
* @memberof progressBar | |
* progressBar.complete() | |
*/ | |
progressBar.complete = function () { | |
return this.finish(), | |
this.hide(); | |
}; | |
progressBar.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment