3 * MediaWiki Widgets – SearchInputWidget class.
5 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
6 * @license The MIT License (MIT); see LICENSE.txt
8 namespace MediaWiki\Widget
;
11 * Search input widget.
13 class SearchInputWidget
extends TitleInputWidget
{
15 protected $pushPending = false;
16 protected $performSearchOnClick = true;
17 protected $validateTitle = false;
18 protected $highlightFirst = false;
19 protected $dataLocation = 'header';
22 * @param array $config Configuration options
23 * @param int|null $config['pushPending'] Whether the input should be visually marked as
24 * "pending", while requesting suggestions (default: false)
25 * @param bool|null $config['performSearchOnClick'] If true, the script will start a search
26 * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into the
27 * text field only (default: true)
28 * @param string $config['dataLocation'] Where the search input field will be
29 * used (header or content, default: header)
31 public function __construct( array $config = [] ) {
32 $config = array_merge( [
37 parent
::__construct( $config );
39 // Properties, which are ignored in PHP and just shipped back to JS
40 if ( isset( $config['pushPending'] ) ) {
41 $this->pushPending
= $config['pushPending'];
44 if ( isset( $config['performSearchOnClick'] ) ) {
45 $this->performSearchOnClick
= $config['performSearchOnClick'];
48 if ( isset( $config['dataLocation'] ) ) {
49 // identifies the location of the search bar for tracking purposes
50 $this->dataLocation
= $config['dataLocation'];
54 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
57 protected function getInputElement( $config ) {
58 return ( new \OOUI\
Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
61 protected function getJavaScriptClassName() {
62 return 'mw.widgets.SearchInputWidget';
65 public function getConfig( &$config ) {
66 $config['pushPending'] = $this->pushPending
;
67 $config['performSearchOnClick'] = $this->performSearchOnClick
;
68 if ( $this->dataLocation
) {
69 $config['dataLocation'] = $this->dataLocation
;
71 $config['$overlay'] = true;
72 return parent
::getConfig( $config );