mediawiki.page.image.pagination: Clean up, optimise and fix various bugs
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 17 Jun 2014 19:16:46 +0000 (21:16 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 19 Jun 2014 14:12:01 +0000 (14:12 +0000)
commitc955ffce294d9e68a3b76ba07ffc6536c3a97583
treeecf25627a9347ba25e535af09e0bdab11d1ed7b5
parenta41cd4d6c478092ba77c3db582b23cbfd738f155
mediawiki.page.image.pagination: Clean up, optimise and fix various bugs

Follows-up 427b0e15e77f39.

* Remove comment stating the obvious (initialize variable).

* Unset 'xhr' variable in the success handler. This allows it to
  be freed from memory, and prevents us from uselessly trying to
  abort an already finished request.

* Rename 'xhr' to 'jqXhr' as it is not an xhr.

* Use the Promise of jQuery.ajax instead of the long-deprecated
  callback option 'success'.

* Rephrase comment stating that jQuery.load is used (which is
  not true).

* Don't re-query 'table.multipageimage' multiple times. Instead
  query it from the document once and cache it.

* Remove useless 'window.history' check. This is not a new global
  in HTML5. The 'history' global, infamous from history.go() and
  history.back(), has been a part of the web for a very long time.
  We can safely depend on them, just as we depend on 'location',
  'navigator' and 'document'.

* Add an identifier to the history pop-state to prevent an
  exception when dealing with the state object of another
  application. Lots of gadgets use the History API these days
  (as well as extensions like VisualEditor and MultimediaViewer).

* Don't store the location.href inside the pop state data. This
  is not needed because it is already stored by the browser
  natively. A history event contains a url, page title and
  custom data stored as JSON. There is no need to store the url
  again in the custom data.

* Despite the width/height transferring from the old content
  to the spinner container, the scroll position still jumped
  because it wasn't accounting for margin, padding and border.
  Use outerHeight() instead of height().

* Avoid using the DOM to store and retrieve information. Use
  application state instead of a DOM query to know whether we
  have a spinner already. This increases performance but also
  avoids false positives where (unlikely) other similar elements
  and/or spinners from a different script are on the page.

* Properly replace the entire table contents() instead of just
  dropping the <tr> straight into the emptied <table>. This way
  the script makes no assumptions about whether there is a
  caption/thead/tbody or multiple rows etc. Plus it saves another
  recursive DOM query (the one for "tr"). And fixes a potential
  bug if there are nested tables (since it was doing a recursive
  query).

Change-Id: I8b64a0860b73a5dcd8051b5e7a1fcb65107228a6
resources/src/mediawiki.page/mediawiki.page.image.pagination.js