(bug 17808) (bug 21167) use real links for search suggestions
authorMatmaRex <matma.rex@gmail.com>
Thu, 1 Nov 2012 13:16:41 +0000 (14:16 +0100)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 18 Jan 2013 20:46:48 +0000 (20:46 +0000)
commit0ee84eedfa4abbe1621a27ea046afef35161e97c
treeb293ad36331915e83c73ad1e956c32e78582793a
parent297a110e6d32c6540aaa1317d69f9bc903a50d08
(bug 17808) (bug 21167) use real links for search suggestions

Use real links for search suggestions. This allows the viewer to, for
example, open the search results in a new tab or right-click them
to copy link's address.

We hook up the result.render callback and wrap the entire container
element (.suggestions-results <div>) in an <a>. This is permitted in HTML5
and appears to work even on IE 6. (It has some quirks related to e.g.
backgrounds handling, but thankfully none of them apply here, as we just
need it to be properly clickable - see http://jsbin.com/ejurub/2 for
a minimal test.)

We do the same for the special.render callback, although it has to be
handled slightly differently due to inconsistencies in $.suggestions that
would require a rewrite to fix.

We have to do some pretty ugly mangling to determine the links' hrefs,
but well, that's life.

This required some changes to $.suggestions:
* pass the necessary data to the render callback
* do not interfere with clicks with a mouse button other than left
  or with modifier keys active, to allow for the standard link behavior
  described above
* adjusting the width of suggestions container and applying autoellipsis
  should be done regardless of the render callback being used or not
* add some flexibility to $.suggestions.highlight, so it doesn't break
  down when DOM is modified

Also did some good-to-have changes to $.suggestions:
* detect suggestions elements in various places by their classes, not by
  them being <div>s

Change-Id: I87940ca86a2b3776969cbcee8cdf93e3c66b0cd9
resources/Resources.php
resources/jquery/jquery.suggestions.js
resources/mediawiki/mediawiki.searchSuggest.css [new file with mode: 0644]
resources/mediawiki/mediawiki.searchSuggest.js