Adding progress indicator
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
import Q from 'q';
|
||||
|
||||
var renderCounter = 0,
|
||||
maxCounter = 0;
|
||||
|
||||
export default {
|
||||
setContainer(container) {
|
||||
this.container = container;
|
||||
@@ -85,17 +88,40 @@ export default {
|
||||
console.log(box, anchorLine.node);
|
||||
},
|
||||
|
||||
startRender() {
|
||||
renderCounter++;
|
||||
},
|
||||
|
||||
doneRender() {
|
||||
if (maxCounter === 0) {
|
||||
maxCounter = renderCounter;
|
||||
}
|
||||
|
||||
renderCounter--;
|
||||
document.body.dispatchEvent(new CustomEvent('updateStatus', {
|
||||
detail: {
|
||||
percentage: (maxCounter - renderCounter) / maxCounter
|
||||
}
|
||||
}));
|
||||
|
||||
if (renderCounter === 0) {
|
||||
maxCounter = 0;
|
||||
}
|
||||
},
|
||||
|
||||
render(container) {
|
||||
if (container) {
|
||||
this.setContainer(container);
|
||||
}
|
||||
|
||||
this.startRender();
|
||||
return this._render()
|
||||
.then((() => {
|
||||
if (this.anchorDebug) {
|
||||
this.renderAnchor();
|
||||
}
|
||||
}).bind(this))
|
||||
.then(this.doneRender.bind(this))
|
||||
.then(_.constant(this));
|
||||
},
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ export default class Regexper {
|
||||
this.error = root.querySelector('#error');
|
||||
this.permalink = root.querySelector('a[data-glyph="link-intact"]');
|
||||
this.download = root.querySelector('a[data-glyph="data-transfer-download"]');
|
||||
this.percentage = root.querySelector('#progress div');
|
||||
this.svg = root.querySelector('#regexp-render svg');
|
||||
|
||||
this.padding = 10;
|
||||
@@ -46,12 +47,18 @@ export default class Regexper {
|
||||
}
|
||||
}
|
||||
|
||||
updatePercentage(event) {
|
||||
this.percentage.style.width = event.detail.percentage * 100 + '%';
|
||||
}
|
||||
|
||||
bindListeners() {
|
||||
this.field.addEventListener('keypress', this.keypressListener.bind(this));
|
||||
|
||||
this.form.addEventListener('submit', this.submitListener.bind(this));
|
||||
|
||||
window.addEventListener('hashchange', this.hashchangeListener.bind(this));
|
||||
|
||||
this.root.addEventListener('updateStatus', this.updatePercentage.bind(this));
|
||||
}
|
||||
|
||||
setState(state) {
|
||||
|
||||
Reference in New Issue
Block a user