X-Git-Url: https://git.auder.net/js/rpsls.js?a=blobdiff_plain;f=base_rules.js;h=ad30c0a04cd97d376d252adb1a6f0428b0fd3a34;hb=5abaabb3061f9c2927e2204a33a58c309f3a0082;hp=5eb4d773c008f390cb5e7f1b6aa600ef20827ae8;hpb=e7b64798015851c120b9e8b4872297cfbaa0cb15;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 5eb4d77..ad30c0a 100644 --- a/base_rules.js +++ b/base_rules.js @@ -415,6 +415,7 @@ export default class ChessRules { // Graphical (can use variables defined above) this.containerId = o.element; + this.isDiagram = o.diagram; this.graphicalInit(); } @@ -559,10 +560,22 @@ 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(); + if (!this.isDiagram) + 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() { @@ -644,6 +657,7 @@ export default class ChessRules { } setupPieces(r) { + // TODO: d_pieces : only markers (for diagrams) / also in rescale() if (this.g_pieces) { // Refreshing: delete old pieces first for (let i=0; i { document.removeEventListener(ml.type, ml.listener);