summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/MixedNamespaceSearchSuggestions/resources
first commit
Diffstat (limited to 'www/wiki/extensions/MixedNamespaceSearchSuggestions/resources')
-rw-r--r--www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.js78
-rw-r--r--www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.less14
2 files changed, 92 insertions, 0 deletions
diff --git a/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.js b/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.js
new file mode 100644
index 00000000..0a3e666b
--- /dev/null
+++ b/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.js
@@ -0,0 +1,78 @@
+/**
+ * @author Niklas Laxström
+ * @license MIT
+ */
+
+( function ( mw, $ ) {
+
+ // Compute form data for search suggestions functionality.
+ function computeResultRenderCache( context ) {
+ var $form, baseHref, linkParams;
+
+ // Compute common parameters for links' hrefs
+ $form = context.config.$region.closest( 'form' );
+
+ baseHref = $form.attr( 'action' );
+ baseHref += baseHref.indexOf( '?' ) > -1 ? '&' : '?';
+
+ linkParams = {};
+ $.each( $form.serializeArray(), function ( idx, obj ) {
+ linkParams[ obj.name ] = obj.value;
+ } );
+
+ return {
+ textParam: context.data.$textbox.attr( 'name' ),
+ linkParams: linkParams,
+ baseHref: baseHref
+ };
+ }
+
+ // The function used to render the suggestions.
+ function customRenderFunction( text, context ) {
+ var page, namespace,
+ title = mw.Title.newFromText( text ),
+ info = computeResultRenderCache( context );
+
+ info.linkParams[ info.textParam ] = text;
+
+ page = title.getMainText();
+ namespace = $( '<span>' )
+ .text( mw.config.get( 'wgFormattedNamespaces' )[ title.namespace ] )
+ .addClass( 'mw-mnss-srcc' );
+
+ // 'this' is the container <div>, jQueryfied
+ this
+ .append( page, namespace )
+ .wrap(
+ $( '<a>' )
+ .attr( 'href', info.baseHref + $.param( info.linkParams ) )
+ .addClass( 'mw-searchSuggest-link' )
+ );
+ }
+
+ $( document ).ready( function () {
+ var $searchInput = $( '#searchInput' );
+
+ $searchInput.suggestions( {
+ fetch: function ( query ) {
+ var $el;
+
+ if ( query.length !== 0 ) {
+ $el = $( this );
+ $el.data( 'request', ( new mw.Api() ).get( {
+ action: 'opensearch',
+ search: query,
+ namespace: mw.config.get( 'wgContentNamespaces' ).join( '|' ),
+ suggest: ''
+ } ).done( function ( data ) {
+ $el.suggestions( 'suggestions', data[1] );
+ } ) );
+ }
+ },
+ result: {
+ render: customRenderFunction
+ }
+ } );
+ } );
+
+}( mediaWiki, jQuery ) );
diff --git a/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.less b/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.less
new file mode 100644
index 00000000..43472e60
--- /dev/null
+++ b/www/wiki/extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.less
@@ -0,0 +1,14 @@
+/**
+ * @author Niklas Laxström
+ * @license MIT
+ */
+
+/* This is used in the search field autocompletion */
+.mw-mnss-srcc {
+ float: right;
+ font-style: italic;
+}
+
+.suggestions-result {
+ white-space: inherit;
+}