Need to detect Editor mode with js

I have a custom image gallery on a page, and it gets broken while Editor Mode is on.
I wish to detect that Editor Mode is on and turn off the gallery. I tried to check that (".w-editor") is present on (document).ready, but it doesn’t work.
Any ideas?