Pd canvas cleanup
This moves some global functions into the canvas_events closure.
It also creates an "init" method for the shared event listeners. Previously these were set when the page was loaded. This sometimes would cause a race between the nw.js "move" event (which can fire upon window load for some reason) and the patch registration routine which sets the canvas id. This meant that the "move" callback could send Pd a message with an undefined canvas id and cause an error.