Worth to separate out the js part into an individual javascript file and define all the event listeners there.

See mods/_core/editor/js/edit.js