| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Widget; |
| 4 |
|
| 5 |
use OOUI\Tag; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class SearchInputWidget extends TitleInputWidget { |
| 14 |
|
| 15 |
|
| 16 |
protected $performSearchOnClick = true; |
| 17 |
|
| 18 |
protected $validateTitle = false; |
| 19 |
|
| 20 |
protected $highlightFirst = false; |
| 21 |
|
| 22 |
protected $dataLocation = 'header'; |
| 23 |
|
| 24 |
protected $showDescriptions = false; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public function __construct( array $config = [] ) { |
| 35 |
$config = array_merge( [ |
| 36 |
'maxLength' => null, |
| 37 |
'icon' => 'search', |
| 38 |
], $config ); |
| 39 |
'@phan-var array $config'; |
| 40 |
|
| 41 |
parent::__construct( $config ); |
| 42 |
|
| 43 |
|
| 44 |
if ( isset( $config['performSearchOnClick'] ) ) { |
| 45 |
$this->performSearchOnClick = $config['performSearchOnClick']; |
| 46 |
} |
| 47 |
|
| 48 |
if ( isset( $config['dataLocation'] ) ) { |
| 49 |
|
| 50 |
$this->dataLocation = $config['dataLocation']; |
| 51 |
} |
| 52 |
|
| 53 |
if ( !empty( $config['showDescriptions'] ) ) { |
| 54 |
$this->showDescriptions = true; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
if ( isset( $config['autocapitalize'] ) ) { |
| 59 |
$this->input->setAttributes( [ 'autocapitalize' => $config['autocapitalize'] ] ); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
$this->addClasses( [ 'mw-widget-searchInputWidget' ] ); |
| 64 |
} |
| 65 |
|
| 66 |
protected function getInputElement( $config ) { |
| 67 |
return ( new Tag( 'input' ) )->setAttributes( [ 'type' => 'search' ] ); |
| 68 |
} |
| 69 |
|
| 70 |
protected function getJavaScriptClassName() { |
| 71 |
return 'mw.widgets.SearchInputWidget'; |
| 72 |
} |
| 73 |
|
| 74 |
public function getConfig( &$config ) { |
| 75 |
$config['performSearchOnClick'] = $this->performSearchOnClick; |
| 76 |
if ( $this->dataLocation ) { |
| 77 |
$config['dataLocation'] = $this->dataLocation; |
| 78 |
} |
| 79 |
if ( $this->showDescriptions ) { |
| 80 |
$config['showDescriptions'] = true; |
| 81 |
} |
| 82 |
$config['$overlay'] = true; |
| 83 |
return parent::getConfig( $config ); |
| 84 |
} |
| 85 |
} |