kamrify commited on
Commit
97eb6a7
·
1 Parent(s): 0b84e47

Fix - Canvas elements keep adding

Browse files
Files changed (1) hide show
  1. assets/scripts/src/overlay.js +9 -2
assets/scripts/src/overlay.js CHANGED
@@ -33,19 +33,26 @@ export default class Overlay {
33
  this.window = window;
34
  this.document = document;
35
 
36
- this.prepareContext();
37
  this.setSize();
38
  }
39
 
40
  /**
41
  * Prepares the overlay
42
  */
43
- prepareContext() {
 
 
 
 
 
 
44
  const overlay = this.document.createElement('canvas');
45
 
46
  this.overlay = overlay;
47
  this.context = overlay.getContext('2d');
48
 
 
49
  this.overlay.style.pointerEvents = 'none';
50
  this.overlay.style.background = 'transparent';
51
  this.overlay.style.position = 'fixed';
 
33
  this.window = window;
34
  this.document = document;
35
 
36
+ this.resetOverlay();
37
  this.setSize();
38
  }
39
 
40
  /**
41
  * Prepares the overlay
42
  */
43
+ resetOverlay() {
44
+ // Check and remove the canvas if it already exists
45
+ const canvasOverlay = this.document.getElementById('sholo-canvas-overlay');
46
+ if (canvasOverlay && canvasOverlay.parentNode) {
47
+ canvasOverlay.parentNode.removeChild(canvasOverlay);
48
+ }
49
+
50
  const overlay = this.document.createElement('canvas');
51
 
52
  this.overlay = overlay;
53
  this.context = overlay.getContext('2d');
54
 
55
+ this.overlay.id = 'sholo-canvas-overlay';
56
  this.overlay.style.pointerEvents = 'none';
57
  this.overlay.style.background = 'transparent';
58
  this.overlay.style.position = 'fixed';