3 namespace MediaWiki\Widget
;
8 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
11 class SearchInputWidget
extends TitleInputWidget
{
13 protected $performSearchOnClick = true;
14 protected $validateTitle = false;
15 protected $highlightFirst = false;
16 protected $dataLocation = 'header';
19 * @param array $config Configuration options
20 * - bool|null $config['performSearchOnClick'] If true, the script will start a search
21 * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into
22 * the text field only (default: true)
23 * - string $config['dataLocation'] Where the search input field will be
24 * used (header or content, default: header)
26 public function __construct( array $config = [] ) {
27 $config = array_merge( [
32 parent
::__construct( $config );
34 // Properties, which are ignored in PHP and just shipped back to JS
35 if ( isset( $config['performSearchOnClick'] ) ) {
36 $this->performSearchOnClick
= $config['performSearchOnClick'];
39 if ( isset( $config['dataLocation'] ) ) {
40 // identifies the location of the search bar for tracking purposes
41 $this->dataLocation
= $config['dataLocation'];
45 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
48 protected function getInputElement( $config ) {
49 return ( new \OOUI\
Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
52 protected function getJavaScriptClassName() {
53 return 'mw.widgets.SearchInputWidget';
56 public function getConfig( &$config ) {
57 $config['performSearchOnClick'] = $this->performSearchOnClick
;
58 if ( $this->dataLocation
) {
59 $config['dataLocation'] = $this->dataLocation
;
61 $config['$overlay'] = true;
62 return parent
::getConfig( $config );