houdini/javascripts/app/loading_indicator.ts

53 lines
980 B
TypeScript
Raw Normal View History

2018-05-24 15:06:44 +00:00
// License: LGPL-3.0-or-later
class PageProgressBar {
template: HTMLTemplateElement
constructor() {
this.template = document.createElement('template')
this.template.innerHTML = `<div class='progressBar--app' id="pageProgressBar"><div class='progressBar-fill--striped'></div></div>`
}
beginPageLoad(): void {
let element = this.getElem()
if (!element) {
let firstChild = document.body.firstChild
let clone = document.importNode(this.template.content, true)
if (firstChild) {
document.body.insertBefore(clone, firstChild)
}
else {
document.body.appendChild(clone)
}
}
return
}
finishPageLoad() {
let element = this.getElem()
if (element) {
element.remove()
}
}
private getElem(): Element {
return document.getElementById("pageProgressBar")
}
}
const pp: PageProgressBar = new PageProgressBar();
(window as any).pageProgress = pp
pp.beginPageLoad()