X-Git-Url: https://git.auder.net/?p=xogo.git;a=blobdiff_plain;f=base_rules.js;h=ea34a3d806d1c26b2a645d88c1a6bdf730f86f9f;hp=5eb4d773c008f390cb5e7f1b6aa600ef20827ae8;hb=65c770d1d8b4b1d6fe3beae9f0ada4bf8f8856cb;hpb=e7b64798015851c120b9e8b4872297cfbaa0cb15 diff --git a/base_rules.js b/base_rules.js index 5eb4d77..ea34a3d 100644 --- a/base_rules.js +++ b/base_rules.js @@ -559,10 +559,21 @@ export default class ChessRules { graphicalInit() { // NOTE: not window.onresize = this.re_drawBoardElts because scope (this) window.onresize = () => this.re_drawBoardElements(); - this.re_drawBoardElements(); - this.initMouseEvents(); - const chessboard = - document.getElementById(this.containerId).querySelector(".chessboard"); + const g_init = () => { + this.re_drawBoardElements(); + this.initMouseEvents(); + }; + let container = document.getElementById(this.containerId); + if (container.getBoundingClientRect().width == 0) { + // Element not ready yet + let ro = new ResizeObserver(() => { + ro.unobserve(container); + g_init(); + }); + ro.observe(container); + } + else + g_init(); } re_drawBoardElements() {