[WIP] JS refactoring

https://tracker.phpbb.com/browse/PHPBB3-12982