oakmac / chessboardjs

JavaScript chessboard
https://chessboardjs.com
MIT License
2.01k stars 408 forks source link

Use ResizeObserverAPI instead of the old widget.resize function. #251

Closed pakdad-mousavi closed 1 month ago

pakdad-mousavi commented 1 month ago

Main change

By replacing the widget.resize function (later referred to by board.resize in usage of the board) with the ResizeObserverAPI, the board is automatically resized when the window is resized.

Another important reason for this change is that by following the documentation provided with an event listener on the window, the board is not always resized properly:

window.addEventListener('resize', => {
  board.resize()
});

When closing the window too fast, the board isn't resized respectively and overflows out of the body. By using a resize observer, this issue is resolved.

Quick Note

I've also formatted the code so that there are semicolons at the end of each line of code respectively (hence the large number of changes!)