Tidy up JS

Code style, docs fixes

Change-Id: I0d6bca748e1035489f39b963063028ac9b941f25
More misc JS fixes

* Remove some variables used only once
* Use mw.util.getUrl
* Check .length to see whether jQuery matched any elements

Change-Id: I14d104fd696a8f41b885a1fe1101f62b381e4f9f