diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-11-15 22:04:02 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2022-11-15 23:01:36 +0000 |
| commit | 1b3a6bd2044d074c506cbd22327b3314e43d055a (patch) | |
| tree | f673f2fc354a9e9655af85d442a1b054055cd643 | |
| parent | 298615408b87df453a1bf106049a080f99758704 (diff) | |
| download | puzzles-1b3a6bd2044d074c506cbd22327b3314e43d055a.zip puzzles-1b3a6bd2044d074c506cbd22327b3314e43d055a.tar.gz puzzles-1b3a6bd2044d074c506cbd22327b3314e43d055a.tar.bz2 puzzles-1b3a6bd2044d074c506cbd22327b3314e43d055a.tar.xz | |
js: Create the puzzle resize handle only if the puzzle is resizable
If there's no resizable div to attach it to, there's not much point in
creating the handle and the doing nothing with it.
| -rw-r--r-- | emccpre.js | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -447,11 +447,13 @@ function initPuzzle() { permalink_desc = document.getElementById("permalink-desc"); permalink_seed = document.getElementById("permalink-seed"); - // Create the resize handle. - var resize_handle = document.createElement("canvas"); - resize_handle.width = 10; - resize_handle.height = 10; - { + resizable_div = document.getElementById("resizable"); + if (resizable_div !== null) { + // Create the resize handle. + var resize_handle = document.createElement("canvas"); + resize_handle.width = 10; + resize_handle.height = 10; + var ctx = resize_handle.getContext("2d"); ctx.beginPath(); for (var i = 1; i <= 7; i += 3) { @@ -463,9 +465,7 @@ function initPuzzle() { ctx.lineJoin = 'round'; ctx.strokeStyle = '#000000'; ctx.stroke(); - } - resizable_div = document.getElementById("resizable"); - if (resizable_div !== null) { + resizable_div.appendChild(resize_handle); resize_handle.id = "resizehandle"; resize_handle.title = "Drag to resize the puzzle. Right-click to restore the default size."; |