[ticket/12982] JS refactoring

https://tracker.phpbb.com/browse/PHPBB3-12982

I'm trying to keep opinions out of this PR (I'm not going to be that guy).

I've converted a load of code to the correct coding standards, and basically fixed most JSHint and IDE errors in the JS.

It also contains a few potential bug fixes such as undeclared variables, and in one case, a typo'd variable name—please don't delay this until 3.2 (that would cause horrible merge conflicts, too).
Yes