(bug 40448) Replace legacy mwsuggest with mediawiki.searchSuggest
The module has been broken for a while now, but nobody noticed
because in plain core it is disabled by default, and in the
bundle we ship with Extension:Vector (and its SimpleSearch).
This commit removed the mediawiki.legacy.mwsuggest module (and
related components that become obsolete with its deletion) and
replaces it with the new mediawiki.searchSuggest module, which is
based on SimpleSearch from Extension:Vector (where it will be
removed soon).
The following and all references to it in core have been removed,
I also made sure that they weren't used in any of extensions/*.
Only matches in extensions/Settings and some file that dumped the startup module, and in extensions/Vector which are addressed in
I1d5bf81a8a0266c51c99d41eefacc0f4b3ae4b76.
Had to make a few updates to jquery.suggestions to make it work
in other skins. So far it was only used in Vector, but now that
it is used in mediawiki.searchSuggest, I noticed several issues
in other skins. Most importantly the fact that it assumed the
default offset was from the right corner, which isn't the case in
Monobook where the search bar is on the left (in the sidebar).
It now detects the appropiate origin corner automatically, and
also takes directionality of the page into account.
It also uses the correct font-size automatically. Previously it
used font-size: 0.8; but that only works in Vector. Every skin
seems to have its own way of making a sane font-size. In Monobook
the <body> has an extra small font-size which is then fixed in
div#globalWrapper, and in Vector it is extra large, which is then
fixed as well deeper in the document. Either way, the size on
<body> can't be used, and since this suggestions box is appended
to the <body> (it is a generic jQuery plugin without knowledge of
the document, and even if we could give it knowledge inside
the configuration, it'd have to be per-skin). So I removed the
Vector specific font-size and let it handle it automatically.
This was needed because it is now used in all skins.
Removed modules:
* mediawiki.legacy.mwsuggest:
> Replaced with mediawiki.searchSuggest.
Removed messages:
* search-mwsuggest-enabled
* search-mwsuggest-disabled
> No longer used.
Removed mw.config.values:
* wgMWSuggestTemplate
> Obsolete.
* wgSearchNamespaces
> Obsolete.
Removed server-side settings:
* $wgEnableMWSuggest
> Suggestions are now enabled by default and can be disabled
through the user preference `disablesuggest` still.
They can be disabled by default site-wide or hidden from
prefs through the standard mechanisms for that.
* $wgMWSuggestTemplate
> Obsolete.
Removed methods
* SearchEngine::getMWSuggestTemplate()
> Obsolete.
Filters:
$ ack mwsuggest -i -Q --ignore-dir=languages/messages
$ ack wgSearchNamespaces -Q
Message changes:
* vector-simplesearch-preference
> It was wrong, it didn't activate search suggestions, that
was handled by the Vector extension. This preference in
MediaWiki core controls whether the SimpleSearch bar HTML
and CSS will be used (e.g. the rectangle search box with
the magnifying class instead of the browser-default input
field with the plain submit buttons).
* searchsuggest-search
* searchsuggest-containing
These come from Extension:Vector message and should be imported
by translatewiki:
- vector-simplesearch-search
- vector-simplesearch-containing
Change-Id: Icd721011b40bb8d2c20aefa8b359a3e45413a07f
This commit is contained in:
parent
bf219783ef
commit
1f987fb5ee
14 changed files with 298 additions and 1152 deletions
|
|
@ -149,6 +149,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
|
|||
* (bug 40072) Add CSS classes to items in output of ChangesList pages.
|
||||
* Added $wgCopyUploadProxy global to define which proxy to use for copy
|
||||
uploads.
|
||||
* (bug 40448) mediawiki.legacy.mwsuggest has been replaced with a new module,
|
||||
mediawiki.searchSuggest, based on SimpleSeach from Extension:Vector.
|
||||
|
||||
=== Bug fixes in 1.20 ===
|
||||
* (bug 30245) Use the correct way to construct a log page title.
|
||||
|
|
@ -323,6 +325,11 @@ changes to languages because of Bugzilla reports.
|
|||
* Use of __DIR__ instead of dirname( __FILE__ ).
|
||||
* OutputPage::wrapWikiMsg() no longer supports the 'options' parameter. It was
|
||||
not used and complicated migration to Message class.
|
||||
* (bug 40448) Removed mediawiki.legacy.mwsuggest module, and removed the
|
||||
following that has become obsolete:
|
||||
- globals $wgEnableMWSuggest and $wgMWSuggestTemplate.
|
||||
- mw.config.values wgMWSuggestTemplate and wgSearchNamespaces.
|
||||
- method SearchEngine::getMWSuggestTemplate().
|
||||
|
||||
== Compatibility ==
|
||||
|
||||
|
|
|
|||
|
|
@ -2720,7 +2720,7 @@ $wgFooterIcons = array(
|
|||
$wgUseCombinedLoginLink = false;
|
||||
|
||||
/**
|
||||
* Search form behavior for Vector skin only.
|
||||
* Search form look for Vector skin only.
|
||||
* - true = use an icon search button
|
||||
* - false = use Go & Search buttons
|
||||
*/
|
||||
|
|
@ -4694,17 +4694,11 @@ $wgCountTotalSearchHits = false;
|
|||
*/
|
||||
$wgOpenSearchTemplate = false;
|
||||
|
||||
/**
|
||||
* Enable suggestions while typing in search boxes
|
||||
* (results are passed around in OpenSearch format)
|
||||
* Requires $wgEnableOpenSearchSuggest = true;
|
||||
*/
|
||||
$wgEnableMWSuggest = false;
|
||||
|
||||
/**
|
||||
* Enable OpenSearch suggestions requested by MediaWiki. Set this to
|
||||
* false if you've disabled MWSuggest or another suggestion script and
|
||||
* want reduce load caused by cached scripts pulling suggestions.
|
||||
* false if you've disabled scripts that use api?action=opensearch and
|
||||
* want reduce load caused by cached scripts still pulling suggestions.
|
||||
* It will let the API fallback by responding with an empty array.
|
||||
*/
|
||||
$wgEnableOpenSearchSuggest = true;
|
||||
|
||||
|
|
@ -4713,14 +4707,6 @@ $wgEnableOpenSearchSuggest = true;
|
|||
*/
|
||||
$wgSearchSuggestCacheExpiry = 1200;
|
||||
|
||||
/**
|
||||
* Template for internal MediaWiki suggestion engine, defaults to API action=opensearch
|
||||
*
|
||||
* Placeholders: {searchTerms}, {namespaces}, {dbname}
|
||||
*
|
||||
*/
|
||||
$wgMWSuggestTemplate = false;
|
||||
|
||||
/**
|
||||
* If you've disabled search semi-permanently, this also disables updates to the
|
||||
* table. If you ever re-enable, be sure to rebuild the search table.
|
||||
|
|
|
|||
|
|
@ -2459,7 +2459,7 @@ $templates
|
|||
*/
|
||||
private function addDefaultModules() {
|
||||
global $wgIncludeLegacyJavaScript, $wgPreloadJavaScriptMwUtil, $wgUseAjax,
|
||||
$wgAjaxWatch, $wgEnableMWSuggest;
|
||||
$wgAjaxWatch;
|
||||
|
||||
// Add base resources
|
||||
$this->addModules( array(
|
||||
|
|
@ -2487,8 +2487,8 @@ $templates
|
|||
$this->addModules( 'mediawiki.page.watch.ajax' );
|
||||
}
|
||||
|
||||
if ( $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
|
||||
$this->addModules( 'mediawiki.legacy.mwsuggest' );
|
||||
if ( !$this->getUser()->getOption( 'disablesuggest', false ) ) {
|
||||
$this->addModules( 'mediawiki.searchSuggest' );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2912,7 +2912,7 @@ $templates
|
|||
* @return array
|
||||
*/
|
||||
public function getJSVars() {
|
||||
global $wgUseAjax, $wgEnableMWSuggest, $wgContLang;
|
||||
global $wgUseAjax, $wgContLang;
|
||||
|
||||
$latestRevID = 0;
|
||||
$pageID = 0;
|
||||
|
|
@ -2978,9 +2978,6 @@ $templates
|
|||
foreach ( $title->getRestrictionTypes() as $type ) {
|
||||
$vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
|
||||
}
|
||||
if ( $wgUseAjax && $wgEnableMWSuggest && !$this->getUser()->getOption( 'disablesuggest', false ) ) {
|
||||
$vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $this->getUser() );
|
||||
}
|
||||
if ( $title->isMainPage() ) {
|
||||
$vars['wgIsMainPage'] = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -978,7 +978,7 @@ class Preferences {
|
|||
* @param $defaultPreferences Array
|
||||
*/
|
||||
static function searchPreferences( $user, IContextSource $context, &$defaultPreferences ) {
|
||||
global $wgContLang, $wgEnableMWSuggest, $wgVectorUseSimpleSearch;
|
||||
global $wgContLang, $wgVectorUseSimpleSearch;
|
||||
|
||||
## Search #####################################
|
||||
$defaultPreferences['searchlimit'] = array(
|
||||
|
|
@ -988,22 +988,21 @@ class Preferences {
|
|||
'min' => 0,
|
||||
);
|
||||
|
||||
if ( $wgEnableMWSuggest ) {
|
||||
$defaultPreferences['disablesuggest'] = array(
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'mwsuggest-disable',
|
||||
'section' => 'searchoptions/displaysearchoptions',
|
||||
);
|
||||
}
|
||||
|
||||
if ( $wgVectorUseSimpleSearch ) {
|
||||
$defaultPreferences['vector-simplesearch'] = array(
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'vector-simplesearch-preference',
|
||||
'section' => 'searchoptions/displaysearchoptions'
|
||||
'section' => 'searchoptions/displaysearchoptions',
|
||||
);
|
||||
}
|
||||
|
||||
$defaultPreferences['disablesuggest'] = array(
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'mwsuggest-disable',
|
||||
'section' => 'searchoptions/displaysearchoptions',
|
||||
);
|
||||
|
||||
$defaultPreferences['searcheverything'] = array(
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'searcheverything-enable',
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class ApiOpenSearch extends ApiBase {
|
|||
$namespaces = $params['namespace'];
|
||||
$suggest = $params['suggest'];
|
||||
|
||||
// MWSuggest or similar hit
|
||||
// Some script that was loaded regardless of wgEnableOpenSearchSuggest, likely cached.
|
||||
if ( $suggest && !$wgEnableOpenSearchSuggest ) {
|
||||
$searches = array();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
|||
protected function getConfig( $context ) {
|
||||
global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension,
|
||||
$wgArticlePath, $wgScriptPath, $wgServer, $wgContLang,
|
||||
$wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion,
|
||||
$wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest,
|
||||
$wgVariantArticlePath, $wgActionPaths, $wgVersion,
|
||||
$wgEnableAPI, $wgEnableWriteAPI, $wgDBname,
|
||||
$wgSitename, $wgFileExtensions, $wgExtensionAssetsPath,
|
||||
$wgCookiePrefix, $wgResourceLoaderMaxQueryLength;
|
||||
|
||||
|
|
@ -95,9 +95,6 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule {
|
|||
'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength,
|
||||
'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces,
|
||||
);
|
||||
if ( $wgUseAjax && $wgEnableMWSuggest ) {
|
||||
$vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
|
||||
}
|
||||
|
||||
wfRunHooks( 'ResourceLoaderGetConfigVars', array( &$vars ) );
|
||||
|
||||
|
|
|
|||
|
|
@ -505,19 +505,6 @@ class SearchEngine {
|
|||
return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get internal MediaWiki Suggest template
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static function getMWSuggestTemplate() {
|
||||
global $wgMWSuggestTemplate, $wgServer;
|
||||
if ( $wgMWSuggestTemplate )
|
||||
return $wgMWSuggestTemplate;
|
||||
else
|
||||
return $wgServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace={namespaces}&suggest';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -799,7 +799,7 @@ XHTML id names.
|
|||
'vector-action-protect' => 'Protect',
|
||||
'vector-action-undelete' => 'Undelete',
|
||||
'vector-action-unprotect' => 'Change protection',
|
||||
'vector-simplesearch-preference' => 'Enable enhanced search suggestions (Vector skin only)',
|
||||
'vector-simplesearch-preference' => 'Enable simplified search bar (Vector skin only)',
|
||||
'vector-view-create' => 'Create',
|
||||
'vector-view-edit' => 'Edit',
|
||||
'vector-view-history' => 'View history',
|
||||
|
|
@ -1752,8 +1752,6 @@ Details can be found in the [{{fullurl:{{#Special:Log}}/delete|page={{FULLPAGENA
|
|||
'search-interwiki-default' => '$1 results:',
|
||||
'search-interwiki-custom' => '', # do not translate or duplicate this message to other languages
|
||||
'search-interwiki-more' => '(more)',
|
||||
'search-mwsuggest-enabled' => 'with suggestions',
|
||||
'search-mwsuggest-disabled' => 'no suggestions',
|
||||
'search-relatedarticle' => 'Related',
|
||||
'mwsuggest-disable' => 'Disable AJAX suggestions',
|
||||
'searcheverything-enable' => 'Search in all namespaces',
|
||||
|
|
@ -4889,6 +4887,10 @@ Otherwise, you can use the easy form below. Your comment will be added to the pa
|
|||
'feedback-bugcheck' => 'Great! Just check that it is not already one of the [$1 known bugs].',
|
||||
'feedback-bugnew' => 'I checked. Report a new bug',
|
||||
|
||||
# Search suggestions
|
||||
'searchsuggest-search' => 'Search',
|
||||
'searchsuggest-containing' => 'containing...',
|
||||
|
||||
# API errors
|
||||
'api-error-badaccess-groups' => 'You are not permitted to upload files to this wiki.',
|
||||
'api-error-badtoken' => 'Internal error: Bad token.',
|
||||
|
|
|
|||
|
|
@ -4837,6 +4837,12 @@ $4 is the gender of the target user.',
|
|||
'feedback-bugcheck' => 'Message that appears before the user submits a bug, reminding them to check for known bugs.',
|
||||
'feedback-bugnew' => 'Button label - asserts that the user has checked for existing bugs. When clicked will launch a bugzilla form to add a new bug in a new tab or window',
|
||||
|
||||
# SimpleSearch
|
||||
'simplesearch-search' => 'Greyed out default text in the simple search box (it disappears and lets the user enter the requested search terms when the search box receives focus.)
|
||||
|
||||
{{Identical|Search}}',
|
||||
'simplesearch-containing' => 'Label used in the special item of the search suggestions list which gives the user an option to perform a full text search for the term.',
|
||||
|
||||
# API errors
|
||||
'api-error-badaccess-groups' => 'API error message that can be used for client side localisation of API errors.',
|
||||
'api-error-badtoken' => 'API error message that can be used for client side localisation of API errors.',
|
||||
|
|
|
|||
|
|
@ -614,6 +614,19 @@ return array(
|
|||
'mediawiki.notify' => array(
|
||||
'scripts' => 'resources/mediawiki/mediawiki.notify.js',
|
||||
),
|
||||
'mediawiki.searchSuggest' => array(
|
||||
'scripts' => 'resources/mediawiki/mediawiki.searchSuggest.js',
|
||||
'messages' => array(
|
||||
'searchsuggest-search',
|
||||
'searchsuggest-containing',
|
||||
),
|
||||
'dependencies' => array(
|
||||
'jquery.autoEllipsis',
|
||||
'jquery.client',
|
||||
'jquery.placeholder',
|
||||
'jquery.suggestions',
|
||||
),
|
||||
),
|
||||
'mediawiki.Title' => array(
|
||||
'scripts' => 'resources/mediawiki/mediawiki.Title.js',
|
||||
'dependencies' => 'mediawiki.util',
|
||||
|
|
@ -901,13 +914,6 @@ return array(
|
|||
'localBasePath' => $GLOBALS['wgStyleDirectory'],
|
||||
'dependencies' => 'mediawiki.legacy.wikibits',
|
||||
),
|
||||
'mediawiki.legacy.mwsuggest' => array(
|
||||
'scripts' => 'common/mwsuggest.js',
|
||||
'remoteBasePath' => $GLOBALS['wgStylePath'],
|
||||
'localBasePath' => $GLOBALS['wgStyleDirectory'],
|
||||
'dependencies' => 'mediawiki.legacy.wikibits',
|
||||
'messages' => array( 'search-mwsuggest-enabled', 'search-mwsuggest-disabled' ),
|
||||
),
|
||||
'mediawiki.legacy.protect' => array(
|
||||
'scripts' => 'common/protect.js',
|
||||
'remoteBasePath' => $GLOBALS['wgStylePath'],
|
||||
|
|
|
|||
|
|
@ -11,14 +11,15 @@
|
|||
padding: 0;
|
||||
margin: -1px -1px 0 0;
|
||||
}
|
||||
|
||||
/* IGNORED BY IE6 */
|
||||
html > body .suggestions {
|
||||
margin: -1px 0 0 0;
|
||||
}
|
||||
|
||||
.suggestions-special {
|
||||
position: relative;
|
||||
background-color: white;
|
||||
font-size: 0.8em;
|
||||
cursor: pointer;
|
||||
border: solid 1px #aaaaaa;
|
||||
padding: 0;
|
||||
|
|
@ -28,14 +29,15 @@ html > body .suggestions {
|
|||
padding: 0.25em 0.25em;
|
||||
line-height: 1.25em;
|
||||
}
|
||||
|
||||
.suggestions-results {
|
||||
background-color: white;
|
||||
font-size: 0.8em;
|
||||
cursor: pointer;
|
||||
border: solid 1px #aaaaaa;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.suggestions-result {
|
||||
color: black;
|
||||
margin: 0;
|
||||
|
|
@ -43,28 +45,33 @@ html > body .suggestions {
|
|||
padding: 0.01em 0.25em;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.suggestions-result-current {
|
||||
background-color: #4C59A6;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.suggestions-special .special-label {
|
||||
font-size: 0.8em;
|
||||
color: gray;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.suggestions-special .special-query {
|
||||
color: black;
|
||||
font-style: italic;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.suggestions-special .special-hover {
|
||||
background-color: silver;
|
||||
}
|
||||
|
||||
.suggestions-result-current .special-label,
|
||||
.suggestions-result-current .special-query {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.autoellipsis-matched,
|
||||
.highlight {
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,11 @@
|
|||
* maxExpandFactor: Maximum suggestions box width relative to the textbox width. If set to e.g. 2, the suggestions box
|
||||
* will never be grown beyond 2 times the width of the textbox.
|
||||
* Type: Number, Range: 1 - infinity, Default: 3
|
||||
* positionFromLeft: Whether to position the suggestion box with the left attribute or the right
|
||||
* expandFrom: Which direction to offset the suggestion box from.
|
||||
* Values 'start' and 'end' translate to left and right respectively depending on the directionality
|
||||
* of the current document, according to $( 'html' ).css( 'direction' ).
|
||||
* Type: String, default: 'auto', options: 'left', 'right', 'start', 'end', 'auto'.
|
||||
* positionFromLeft: Sets expandFrom=left, for backwards compatibility
|
||||
* Type: Boolean, Default: true
|
||||
* highlightInput: Whether to hightlight matched portions of the input or not
|
||||
* Type: Boolean, Default: false
|
||||
|
|
@ -114,6 +118,7 @@ $.suggestions = {
|
|||
* @param value Mixed Value to set property with
|
||||
*/
|
||||
configure: function ( context, property, value ) {
|
||||
var newCSS;
|
||||
// Validate creation using fallback values
|
||||
switch( property ) {
|
||||
case 'fetch':
|
||||
|
|
@ -121,6 +126,7 @@ $.suggestions = {
|
|||
case 'special':
|
||||
case 'result':
|
||||
case '$region':
|
||||
case 'expandFrom':
|
||||
context.config[property] = value;
|
||||
break;
|
||||
case 'suggestions':
|
||||
|
|
@ -134,19 +140,77 @@ $.suggestions = {
|
|||
// Rebuild the suggestions list
|
||||
context.data.$container.show();
|
||||
// Update the size and position of the list
|
||||
var newCSS = {
|
||||
newCSS = {
|
||||
top: context.config.$region.offset().top + context.config.$region.outerHeight(),
|
||||
bottom: 'auto',
|
||||
width: context.config.$region.outerWidth(),
|
||||
height: 'auto'
|
||||
};
|
||||
if ( context.config.positionFromLeft ) {
|
||||
|
||||
// Process expandFrom, after this it is set to left or right.
|
||||
context.config.expandFrom = ( function ( expandFrom ) {
|
||||
var regionWidth, docWidth, regionCenter, docCenter,
|
||||
docDir = $( document.documentElement ).css( 'direction' ),
|
||||
$region = context.config.$region;
|
||||
|
||||
// Backwards compatible
|
||||
if ( context.config.positionFromLeft ) {
|
||||
expandFrom = 'left';
|
||||
|
||||
// Catch invalid values, default to 'auto'
|
||||
} else if ( $.inArray( expandFrom, ['left', 'right', 'start', 'end', 'auto'] ) === -1 ) {
|
||||
expandFrom = 'auto';
|
||||
}
|
||||
|
||||
if ( expandFrom === 'auto' ) {
|
||||
if ( $region.data( 'searchsuggest-expand-dir' ) ) {
|
||||
// If the markup explicitly contains a direction, use it.
|
||||
expandFrom = $region.data( 'searchsuggest-expand-dir' );
|
||||
} else {
|
||||
regionWidth = $region.outerWidth();
|
||||
docWidth = $( document ).width();
|
||||
if ( ( regionWidth / docWidth ) > 0.85 ) {
|
||||
// If the input size takes up more than 85% of the document horizontally
|
||||
// expand the suggestions to the writing direction's native end.
|
||||
expandFrom = 'start';
|
||||
} else {
|
||||
// Calculate the center points of the input and document
|
||||
regionCenter = $region.offset().left + regionWidth / 2;
|
||||
docCenter = docWidth / 2;
|
||||
if ( Math.abs( regionCenter - docCenter ) / docCenter < 0.10 ) {
|
||||
// If the input's center is within 10% of the document center
|
||||
// use the writing direction's native end.
|
||||
expandFrom = 'start';
|
||||
} else {
|
||||
// Otherwise expand the input from the closest side of the page,
|
||||
// towards the side of the page with the most free open space
|
||||
expandFrom = regionCenter > docCenter ? 'right' : 'left';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( expandFrom === 'start' ) {
|
||||
expandFrom = docDir === 'rtl' ? 'right': 'left';
|
||||
|
||||
} else if ( expandFrom === 'end' ) {
|
||||
expandFrom = docDir === 'rtl' ? 'left': 'right';
|
||||
}
|
||||
|
||||
return expandFrom;
|
||||
|
||||
}( context.config.expandFrom ) );
|
||||
|
||||
if ( context.config.expandFrom === 'left' ) {
|
||||
// Expand from left
|
||||
newCSS.left = context.config.$region.offset().left;
|
||||
newCSS.right = 'auto';
|
||||
} else {
|
||||
// Expand from right
|
||||
newCSS.left = 'auto';
|
||||
newCSS.right = $( 'body' ).width() - ( context.config.$region.offset().left + context.config.$region.outerWidth() );
|
||||
}
|
||||
|
||||
context.data.$container.css( newCSS );
|
||||
var $results = context.data.$container.children( '.suggestions-results' );
|
||||
$results.empty();
|
||||
|
|
@ -344,14 +408,15 @@ $.suggestions = {
|
|||
$.fn.suggestions = function () {
|
||||
|
||||
// Multi-context fields
|
||||
var returnValue;
|
||||
var args = arguments;
|
||||
var returnValue,
|
||||
args = arguments;
|
||||
|
||||
$(this).each( function () {
|
||||
var context, key;
|
||||
|
||||
/* Construction / Loading */
|
||||
|
||||
var context = $(this).data( 'suggestions-context' );
|
||||
context = $(this).data( 'suggestions-context' );
|
||||
if ( context === undefined || context === null ) {
|
||||
context = {
|
||||
config: {
|
||||
|
|
@ -365,7 +430,7 @@ $.fn.suggestions = function () {
|
|||
'delay': 120,
|
||||
'submitOnClick': false,
|
||||
'maxExpandFactor': 3,
|
||||
'positionFromLeft': true,
|
||||
'expandFrom': 'auto',
|
||||
'highlightInput': false
|
||||
}
|
||||
};
|
||||
|
|
@ -377,7 +442,7 @@ $.fn.suggestions = function () {
|
|||
if ( args.length > 0 ) {
|
||||
if ( typeof args[0] === 'object' ) {
|
||||
// Apply set of properties
|
||||
for ( var key in args[0] ) {
|
||||
for ( key in args[0] ) {
|
||||
$.suggestions.configure( context, key, args[0][key] );
|
||||
}
|
||||
} else if ( typeof args[0] === 'string' ) {
|
||||
|
|
@ -409,22 +474,9 @@ $.fn.suggestions = function () {
|
|||
$textbox: $(this),
|
||||
selectedWithMouse: false
|
||||
};
|
||||
// Setup the css for positioning the results box
|
||||
var newCSS = {
|
||||
top: Math.round( context.data.$textbox.offset().top + context.data.$textbox.outerHeight() ),
|
||||
width: context.data.$textbox.outerWidth(),
|
||||
display: 'none'
|
||||
};
|
||||
if ( context.config.positionFromLeft ) {
|
||||
newCSS.left = context.config.$region.offset().left;
|
||||
newCSS.right = 'auto';
|
||||
} else {
|
||||
newCSS.left = 'auto';
|
||||
newCSS.right = $( 'body' ).width() - ( context.config.$region.offset().left + context.config.$region.outerWidth() );
|
||||
}
|
||||
|
||||
context.data.$container = $( '<div>' )
|
||||
.css( newCSS )
|
||||
.css( 'display', 'none' )
|
||||
.addClass( 'suggestions' )
|
||||
.append(
|
||||
$( '<div>' ).addClass( 'suggestions-results' )
|
||||
|
|
@ -476,6 +528,7 @@ $.fn.suggestions = function () {
|
|||
} )
|
||||
)
|
||||
.appendTo( $( 'body' ) );
|
||||
|
||||
$(this)
|
||||
// Stop browser autocomplete from interfering
|
||||
.attr( 'autocomplete', 'off')
|
||||
|
|
@ -521,6 +574,7 @@ $.fn.suggestions = function () {
|
|||
$.suggestions.cancel( context );
|
||||
} );
|
||||
}
|
||||
|
||||
// Store the context for next time
|
||||
$(this).data( 'suggestions-context', context );
|
||||
} );
|
||||
|
|
|
|||
161
resources/mediawiki/mediawiki.searchSuggest.js
Normal file
161
resources/mediawiki/mediawiki.searchSuggest.js
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
/**
|
||||
* Add search suggestions to the search form.
|
||||
*/
|
||||
( function ( mw, $ ) {
|
||||
$( document ).ready( function ( $ ) {
|
||||
var map,
|
||||
// Region where the suggestions box will appear directly below
|
||||
// (using the same width). Can be a container element or the input
|
||||
// itself, depending on what suits best in the environment.
|
||||
// For Vector the suggestion box should align with the simpleSearch
|
||||
// container's borders, in other skins it should align with the input
|
||||
// element (not the search form, as that would leave the buttons
|
||||
// vertically between the input and the suggestions).
|
||||
$searchRegion = $( '#simpleSearch, #searchInput' ).first(),
|
||||
$searchInput = $( '#searchInput' );
|
||||
|
||||
// Ensure that the thing is actually present!
|
||||
if ( $searchRegion.length === 0 ) {
|
||||
// Don't try to set anything up if simpleSearch is disabled sitewide.
|
||||
// The loader code loads us if the option is present, even if we're
|
||||
// not actually enabled (anymore).
|
||||
return;
|
||||
}
|
||||
|
||||
// Compatibility map
|
||||
map = {
|
||||
browsers: {
|
||||
// Left-to-right languages
|
||||
ltr: {
|
||||
// SimpleSearch is broken in Opera < 9.6
|
||||
opera: [['>=', 9.6]],
|
||||
docomo: false,
|
||||
blackberry: false,
|
||||
ipod: false,
|
||||
iphone: false
|
||||
},
|
||||
// Right-to-left languages
|
||||
rtl: {
|
||||
opera: [['>=', 9.6]],
|
||||
docomo: false,
|
||||
blackberry: false,
|
||||
ipod: false,
|
||||
iphone: false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if ( !$.client.test( map ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Placeholder text for search box
|
||||
$searchInput
|
||||
.attr( 'placeholder', mw.msg( 'searchsuggest-search' ) )
|
||||
.placeholder();
|
||||
|
||||
// General suggestions functionality for all search boxes
|
||||
$( '#searchInput, #searchInput2, #powerSearchText, #searchText' )
|
||||
.suggestions( {
|
||||
fetch: function ( query ) {
|
||||
var $el, jqXhr;
|
||||
|
||||
if ( query.length !== 0 ) {
|
||||
$el = $(this);
|
||||
jqXhr = $.ajax( {
|
||||
url: mw.util.wikiScript( 'api' ),
|
||||
data: {
|
||||
format: 'json',
|
||||
action: 'opensearch',
|
||||
search: query,
|
||||
namespace: 0,
|
||||
suggest: ''
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function ( data ) {
|
||||
if ( $.isArray( data ) && data.length ) {
|
||||
$el.suggestions( 'suggestions', data[1] );
|
||||
}
|
||||
}
|
||||
});
|
||||
$el.data( 'request', jqXhr );
|
||||
}
|
||||
},
|
||||
cancel: function () {
|
||||
var jqXhr = $(this).data( 'request' );
|
||||
// If the delay setting has caused the fetch to have not even happened
|
||||
// yet, the jqXHR object will have never been set.
|
||||
if ( jqXhr && $.isFunction ( jqXhr.abort ) ) {
|
||||
jqXhr.abort();
|
||||
$(this).removeData( 'request' );
|
||||
}
|
||||
},
|
||||
result: {
|
||||
select: function ( $input ) {
|
||||
$input.closest( 'form' ).submit();
|
||||
}
|
||||
},
|
||||
delay: 120,
|
||||
highlightInput: true
|
||||
} )
|
||||
.bind( 'paste cut drop', function () {
|
||||
// make sure paste and cut events from the mouse and drag&drop events
|
||||
// trigger the keypress handler and cause the suggestions to update
|
||||
$( this ).trigger( 'keypress' );
|
||||
} );
|
||||
|
||||
// Special suggestions functionality for skin-provided search box
|
||||
$searchInput.suggestions( {
|
||||
result: {
|
||||
select: function ( $input ) {
|
||||
$input.closest( 'form' ).submit();
|
||||
}
|
||||
},
|
||||
special: {
|
||||
render: function ( query ) {
|
||||
var $el = this;
|
||||
if ( $el.children().length === 0 ) {
|
||||
$el
|
||||
.append(
|
||||
$( '<div>' )
|
||||
.addClass( 'special-label' )
|
||||
.text( mw.msg( 'searchsuggest-containing' ) )
|
||||
)
|
||||
.append(
|
||||
$( '<div>' )
|
||||
.addClass( 'special-query' )
|
||||
.text( query )
|
||||
.autoEllipsis()
|
||||
)
|
||||
.show();
|
||||
} else {
|
||||
$el.find( '.special-query' )
|
||||
.empty()
|
||||
.text( query )
|
||||
.autoEllipsis();
|
||||
}
|
||||
},
|
||||
select: function ( $input ) {
|
||||
$input.closest( 'form' ).append(
|
||||
$( '<input type="hidden"/>', {
|
||||
name: 'fulltext',
|
||||
val: '1'
|
||||
})
|
||||
);
|
||||
$input.closest( 'form' ).submit();
|
||||
}
|
||||
},
|
||||
$region: $searchRegion
|
||||
} );
|
||||
|
||||
// In most skins (at least Monobook and Vector), the font-size is messed up in <body>.
|
||||
// (they use 2 elements to get a sane font-height). So, instead of making exceptions for
|
||||
// each skin or adding more stylesheets, just copy it from the active element so auto-fit.
|
||||
$searchInput
|
||||
.data( 'suggestions-context' )
|
||||
.data.$container
|
||||
.css( 'fontSize', $searchInput.css( 'fontSize' ) );
|
||||
|
||||
} );
|
||||
|
||||
}( mediaWiki, jQuery ) );
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue