|
@@ -33,15 +33,30 @@ export abstract class VexFlowBackend {
|
|
|
return this.renderer;
|
|
|
}
|
|
|
|
|
|
+ public removeAllChildrenFromContainer(container: HTMLElement): void {
|
|
|
+ while (container.children.length !== 0) {
|
|
|
+ container.removeChild(container.children.item(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // note: removing single children to remove all is error-prone, because sometimes a random SVG-child remains.
|
|
|
public removeFromContainer(container: HTMLElement): void {
|
|
|
//console.log("backend type: " + this.getVexflowBackendType());
|
|
|
- if (this.getVexflowBackendType() === Vex.Flow.Renderer.Backends.SVG) {
|
|
|
- container.removeChild(this.canvas);
|
|
|
- } else if (this.getVexflowBackendType() === Vex.Flow.Renderer.Backends.CANVAS) {
|
|
|
- container.removeChild(this.inner);
|
|
|
+ let htmlElementToRemove: HTMLElement = this.canvas; // for SVGBackend
|
|
|
+ if (this.getVexflowBackendType() === Vex.Flow.Renderer.Backends.CANVAS) {
|
|
|
+ htmlElementToRemove = this.inner;
|
|
|
// for SVG, this.canvas === this.inner, but for Canvas, removing this.canvas causes an error because it's not a child of container,
|
|
|
// so we have to remove this.inner instead.
|
|
|
}
|
|
|
+
|
|
|
+ // only remove child if the container has this child, otherwise it will throw an error.
|
|
|
+ for (let i: number = 0; i < container.children.length; i++) {
|
|
|
+ if (container.children.item(i) === htmlElementToRemove) {
|
|
|
+ container.removeChild(htmlElementToRemove);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // there is unfortunately no built-in container.hasChild(child) method.
|
|
|
}
|
|
|
|
|
|
public abstract getContext(): Vex.IRenderContext;
|