ProgressIndicator.js 1.2 KB

1234567891011
  1. export default class ProgressIndicator{constructor(){this.element=createElementWithClass('div','progress-indicator');this._shadowRoot=UI.createShadowRootWithCoreStyles(this.element,'ui/progressIndicator.css');this._contentElement=this._shadowRoot.createChild('div','progress-indicator-shadow-container');this._labelElement=this._contentElement.createChild('div','title');this._progressElement=this._contentElement.createChild('progress');this._progressElement.value=0;this._stopButton=this._contentElement.createChild('button','progress-indicator-shadow-stop-button');this._stopButton.addEventListener('click',this.cancel.bind(this));this._isCanceled=false;this._worked=0;}
  2. show(parent){parent.appendChild(this.element);}
  3. done(){if(this._isDone){return;}
  4. this._isDone=true;this.element.remove();}
  5. cancel(){this._isCanceled=true;}
  6. isCanceled(){return this._isCanceled;}
  7. setTitle(title){this._labelElement.textContent=title;}
  8. setTotalWork(totalWork){this._progressElement.max=totalWork;}
  9. setWorked(worked,title){this._worked=worked;this._progressElement.value=worked;if(title){this.setTitle(title);}}
  10. worked(worked){this.setWorked(this._worked+(worked||1));}}
  11. self.UI=self.UI||{};UI=UI||{};UI.ProgressIndicator=ProgressIndicator;