summaryrefslogtreecommitdiff
path: root/extensions/Vector/modules/ext.vector.simpleSearch.js
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/Vector/modules/ext.vector.simpleSearch.js')
-rw-r--r--extensions/Vector/modules/ext.vector.simpleSearch.js88
1 files changed, 46 insertions, 42 deletions
diff --git a/extensions/Vector/modules/ext.vector.simpleSearch.js b/extensions/Vector/modules/ext.vector.simpleSearch.js
index 8af1f9a1..4dbdd705 100644
--- a/extensions/Vector/modules/ext.vector.simpleSearch.js
+++ b/extensions/Vector/modules/ext.vector.simpleSearch.js
@@ -1,9 +1,11 @@
-/* JavaScript for SimpleSearch extension */
+/**
+ * JavaScript for SimpleSearch
+ */
-jQuery( document ).ready( function( $ ) {
+jQuery( document ).ready( function ( $ ) {
// Ensure that the thing is actually present!
- if ($('#simpleSearch').length == 0) {
+ if ( $( '#simpleSearch' ).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).
@@ -12,23 +14,23 @@ jQuery( document ).ready( function( $ ) {
// Compatibility map
var map = {
- 'browsers': {
+ browsers: {
// Left-to-right languages
- 'ltr': {
+ ltr: {
// SimpleSearch is broken in Opera < 9.6
- 'opera': [['>=', 9.6]],
- 'docomo': false,
- 'blackberry': false,
- 'ipod': false,
- 'iphone': false
+ 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
+ rtl: {
+ opera: [['>=', 9.6]],
+ docomo: false,
+ blackberry: false,
+ ipod: false,
+ iphone: false
}
}
};
@@ -49,38 +51,39 @@ jQuery( document ).ready( function( $ ) {
// General suggestions functionality for all search boxes
$( '#searchInput, #searchInput2, #powerSearchText, #searchText' )
.suggestions( {
- fetch: function( query ) {
- var $this = $(this);
+ fetch: function ( query ) {
+ var $el = $(this);
if ( query.length !== 0 ) {
- var request = $.ajax( {
+ var 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 ) && 1 in data ) {
- $this.suggestions( 'suggestions', data[1] );
+ success: function ( data ) {
+ if ( $.isArray( data ) && data.length ) {
+ $el.suggestions( 'suggestions', data[1] );
}
}
});
- $this.data( 'request', request );
+ $el.data( 'request', jqXhr );
}
},
- cancel: function() {
- var request = $(this).data( 'request' );
- // If the delay setting has caused the fetch to have not even happend yet, the request object will
- // have never been set
- if ( request && $.isFunction( request.abort ) ) {
- request.abort();
+ cancel: function () {
+ var jqXhr = $(this).data( 'request' );
+ // If the delay setting has caused the fetch to have not even happend yet,
+ // the jqXHR object will have never been set.
+ if ( jqXhr && $.isFunction ( jqXhr.abort ) ) {
+ jqXhr.abort();
$(this).removeData( 'request' );
}
},
result: {
- select: function( $input ) {
+ select: function ( $input ) {
$input.closest( 'form' ).submit();
}
},
@@ -88,7 +91,7 @@ jQuery( document ).ready( function( $ ) {
positionFromLeft: $( 'body' ).hasClass( 'rtl' ),
highlightInput: true
} )
- .bind( 'paste cut drop', function( e ) {
+ .bind( 'paste cut drop', function ( e ) {
// 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' );
@@ -96,33 +99,34 @@ jQuery( document ).ready( function( $ ) {
// Special suggestions functionality for skin-provided search box
$( '#searchInput' ).suggestions( {
result: {
- select: function( $input ) {
+ select: function ( $input ) {
$input.closest( 'form' ).submit();
}
},
special: {
- render: function( query ) {
- if ( $(this).children().length === 0 ) {
- $(this).show();
- var $label = $( '<div></div>', {
+ render: function ( query ) {
+ var $el = $(this);
+ if ( $el.children().length === 0 ) {
+ $el.show();
+ $( '<div>', {
'class': 'special-label',
text: mw.msg( 'vector-simplesearch-containing' )
})
- .appendTo( $(this) );
- var $query = $( '<div></div>', {
+ .appendTo( $el );
+ $( '<div>', {
'class': 'special-query',
text: query
})
- .appendTo( $(this) );
- $query.autoEllipsis();
+ .appendTo( $el )
+ .autoEllipsis();
} else {
- $(this).find( '.special-query' )
+ $el.find( '.special-query' )
.empty()
.text( query )
.autoEllipsis();
}
},
- select: function( $input ) {
+ select: function ( $input ) {
$input.closest( 'form' ).append(
$( '<input>', {
type: 'hidden',