Offcanvas js refractor

Repeated event handler calls removed
Code was repeating a lot, so moved them to functions
Hoping that this is OK