Split JavaScript code between the toolbar itself and each panel

Fix #304