Skip to content

Move setSelect into the Jcrop init callback - #9270

Open
c-tonneslan wants to merge 1 commit into
mysociety:developfrom
c-tonneslan:fix-profile-photo-jcrop-init
Open

Move setSelect into the Jcrop init callback#9270
c-tonneslan wants to merge 1 commit into
mysociety:developfrom
c-tonneslan:fix-profile-photo-jcrop-init

Conversation

@c-tonneslan

Copy link
Copy Markdown

Relevant issue(s)

Closes #9196.

What does this do?

Moves the jcrop_api.setSelect(...) call into the Jcrop init callback so the initial centred crop box appears again on the profile photo crop page.

Why was this needed?

Jcrop's init is async, so on a fresh load jcrop_api was still undefined when setSelect ran on the next line, throwing Uncaught TypeError: Cannot read properties of undefined (reading 'setSelect'). Drag-select still worked, which is why the bug was minor in practice, but the default selection was missing.

Implementation notes

Just moved the single line inside the callback that already assigns jcrop_api = this.

Screenshots

n/a, console-only

Notes to reviewer

Added a CHANGES.md entry under develop. Happy to drop the author attribution if you prefer a different format.

Jcrop's init is async: the second argument is a callback that runs
once the plugin has wired itself up and the api object becomes 'this'.
The setSelect call sat outside that callback, so on a fresh page load
jcrop_api was still undefined and the browser threw

    Uncaught TypeError: Cannot read properties of undefined (reading 'setSelect')

which left the page without the initial centred crop box. Drag-select
still worked, which is why this slipped through, but the default
selection was gone.

Closes mysociety#9196

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript error on profile photo crop page

1 participant