Widget:Hide ISBN search box/doc

< Widget:Hide ISBN search box

This widget emits JavaScript code to hide the ISBN 'Search' form displayed by Special:BookSources. It has no use cases outside of Bogleheads:Book sources (invoked by Special:BookSources).

Rationale
The ISBN 'Search' form displayed by Special:BookSources has multiple UI and UX issues:
 * It is mislabelled. It does not search, but instead reloads Special:BookSources with the ISBN entered.
 * Its default value is the ISBN of the book currently being shown. This strongly suggests that users need to click 'Search' to activate this page. They do not.
 * Clicking "Search" without changing the form field content does nothing. (More specifically, it navigates to the same page but adds a pointless entry to the browser history.)
 * The form uses a lot of valuable screen space, especially on mobile.
 * Even when operated correctly, use-cases are rare (possibly non-existent).

Hiding the 'Search' form when Special:BookSources is showing details for a valid ISBN resolves these issues.

Implementation notes
This widget operates by placing a small self-executing JavaScript function on the page. This function runs on page load, and does the following:
 * Retrieves all the HTML elements found in the page. Special:BookSources has two; the main Wiki search, and the ISBN 'search'.
 * Finds the element whose action is to load a Special:BookSources with the form's URL. This uniquely identifies the ISBN 'Search' form to hide. This form is inside a  container with a border.
 * Verifies that this form's parent element is a in class mw-htmlform-ooui-wrapper. This ensures that it has properly identified the right element to hide.
 * Sets the CSS display attribute of the form's parent to none.

Any form on the page that is not the ISBN 'Search' form is unaffected and remains visible. If any of the checks above fail, the function does nothing; that is, it is fail-safe against changes in the way MediaWiki generates the HTML for the ISBN 'Search'.

Because browsers can start to render pages before JavaScript has completed, it is best to place this small JavaScript as close to the ISBN 'Search' form's definition as possible. This minimises the chance of seeing the form briefly flash up onto the screen before then disappearing.

To use correctly, Bogleheads:Book sources should include this widget only when showing information for a valid ISBN. This leaves the ISBN 'Search' form visible for cases where Special:BookSources is invoked with either no ISBN, or with an invalid ISBN.

Code listings
The listings below show an abbreviated example of the HTML that this widget modifies (single line when generated by MediaWiki, but formatted with newlines for readability), and the widget source code.