3 namespace MediaWiki\Widget
;
10 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
13 class SearchInputWidget
extends TitleInputWidget
{
16 protected $performSearchOnClick = true;
18 protected $validateTitle = false;
20 protected $highlightFirst = false;
22 protected $dataLocation = 'header';
24 protected $showDescriptions = false;
27 * @param array $config Configuration options
28 * - bool|null $config['performSearchOnClick'] If true, the script will start a search
29 * whenever a user hits a suggestion. If false, the text of the suggestion is inserted into
30 * the text field only (default: true)
31 * - string $config['dataLocation'] Where the search input field will be
32 * used (header or content, default: header)
34 public function __construct( array $config = [] ) {
35 $config = array_merge( [
39 '@phan-var array $config';
41 parent
::__construct( $config );
43 // Properties, which are ignored in PHP and just shipped back to JS
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'];
53 if ( !empty( $config['showDescriptions'] ) ) {
54 $this->showDescriptions
= true;
57 // Perhaps should be upstreamed to TextInputWidget?
58 if ( isset( $config['autocapitalize'] ) ) {
59 $this->input
->setAttributes( [ 'autocapitalize' => $config['autocapitalize'] ] );
63 $this->addClasses( [ 'mw-widget-searchInputWidget' ] );
66 protected function getInputElement( $config ) {
67 return ( new Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] );
70 protected function getJavaScriptClassName() {
71 return 'mw.widgets.SearchInputWidget';
74 public function getConfig( &$config ) {
75 $config['performSearchOnClick'] = $this->performSearchOnClick
;
76 if ( $this->dataLocation
) {
77 $config['dataLocation'] = $this->dataLocation
;
79 if ( $this->showDescriptions
) {
80 $config['showDescriptions'] = true;
82 $config['$overlay'] = true;
83 return parent
::getConfig( $config );