mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-15 02:24:04 +00:00
96171236d7
Check commit and GitHub actions for more details
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
const config = require( './config.json' );
|
|
const htmlHelper = require( './htmlHelper.js' )();
|
|
const searchHistory = require( './searchHistory.js' )( config );
|
|
|
|
function searchPresults() {
|
|
return {
|
|
elements: undefined,
|
|
addSearchHistory: function ( fragment ) {
|
|
const historyData = searchHistory.get();
|
|
if ( !historyData?.length > 0 ) {
|
|
return fragment;
|
|
}
|
|
|
|
const itemGroupData = {
|
|
id: 'history',
|
|
items: []
|
|
};
|
|
|
|
historyData.forEach( ( result ) => {
|
|
const data = {
|
|
icon: 'history',
|
|
// TODO: Add option to prepend the result to input field
|
|
link: `${ config.wgScriptPath }/index.php?title=Special:Search&search=${ result }`,
|
|
type: 'history',
|
|
size: 'sm',
|
|
title: result
|
|
};
|
|
itemGroupData.items.push( data );
|
|
} );
|
|
|
|
fragment.append( htmlHelper.getItemGroupElement( itemGroupData ) );
|
|
return fragment;
|
|
},
|
|
render: function ( typeaheadEl ) {
|
|
const fragment = document.createDocumentFragment();
|
|
this.addSearchHistory( fragment );
|
|
|
|
if ( fragment.childNodes.length === 0 ) {
|
|
const data = {
|
|
icon: 'articlesSearch',
|
|
type: 'placeholder',
|
|
size: 'lg',
|
|
title: mw.message( 'searchsuggest-search' ).text(),
|
|
desc: mw.message( 'citizen-search-empty-desc' ).text()
|
|
};
|
|
fragment.append( htmlHelper.getItemElement( data ) );
|
|
}
|
|
|
|
typeaheadEl.querySelector( '.citizen-typeahead__item-placeholder' )?.remove();
|
|
typeaheadEl.append( fragment );
|
|
this.set( typeaheadEl );
|
|
},
|
|
set: function ( typeaheadEl ) {
|
|
// FIXME: Clean this up when we add top pages
|
|
this.elements = typeaheadEl.querySelectorAll( '.citizen-typeahead-item-group[data-group="history"]' );
|
|
},
|
|
clear: function ( typeaheadEl ) {
|
|
htmlHelper.removeItemGroup( typeaheadEl, 'history' );
|
|
this.elements = undefined;
|
|
}
|
|
};
|
|
}
|
|
|
|
/** @module searchPresults */
|
|
module.exports = searchPresults;
|