Development #287

Merged
bones7242 merged 58 commits from development into master 2017-12-11 20:53:02 +01:00
Showing only changes of commit 0d5bec7ebd - Show all commits

View file

@ -1,46 +1,43 @@
const ProgressBar = function() {
this.state = {
this.data = {
x: 0,
adder: 1,
bars: [],
};
this.setState = function (key, value) {
this.state[key] = value;
};
this.barHolder = document.getElementById('bar-holder');
this.createProgressBar = function (size) {
this.setState('size', size);
this.data['size'] = size;
for (var i = 0; i < size; i++) {
const bar = document.createElement('span');
bar.innerText = '| ';
bar.setAttribute('class', 'progress-bar progress-bar--inactive');
this.barHolder.appendChild(bar);
this.state.bars.push(bar);
this.data.bars.push(bar);
}
};
this.startProgressBar = function () {
this.updateInterval = setInterval(this.updateProgressBar.bind(this), 300);
};
this.updateProgressBar = function () {
const x = this.state.x;
const adder = this.state.adder;
const size = this.state.size;
const x = this.data.x;
const adder = this.data.adder;
const size = this.data.size;
// update the appropriate bar
if (x > -1 && x < size){
if (adder === 1){
this.state.bars[x].setAttribute('class', 'progress-bar progress-bar--active');
this.data.bars[x].setAttribute('class', 'progress-bar progress-bar--active');
} else {
this.state.bars[x].setAttribute('class', 'progress-bar progress-bar--inactive');
this.data.bars[x].setAttribute('class', 'progress-bar progress-bar--inactive');
}
}
// update adder
if (x === size){
this.setState('adder', -1);
this.data['adder'] = -1;
} else if ( x === -1){
this.setState('adder', 1);
this.data['adder'] = 1;
}
// update x
this.setState('x', x + adder);
this.data['x'] = x + adder;
};
this.stopProgressBar = function () {
clearInterval(this.updateInterval);