.
*
* @file
* @ingroup Skins
*/
namespace Skins\Chameleon\Components;
use \Linker;
use Skins\Chameleon\IdRegistry;
/**
* The SearchBar class.
*
* The search form wrapped in a div:
*
* @author Stephan Gambke
* @since 1.0
* @ingroup Skins
*/
class SearchBar extends Component {
/**
* Builds the HTML code for this component
*
* @return string
*/
public function getHtml() {
$ret = $this->indent() . '' .
$this->indent() . '
IdRegistry::getRegistry()->getId( 'p-search' ),
'class' => 'p-search ' . $this->getClassString(),
'role' => 'search',
)
) . Linker::tooltip( 'p-search' ) . '>' .
$this->indent( 1 ) . '
' .
$this->indent( -1 ) . '
' . "\n";
return $ret;
}
/**
* @return string
*/
private function getGoButton() {
$valueAttr = 'searcharticle';
$idAttr = 'searchGoButton';
$nameAttr = 'go';
$glyphicon = ( $this->getAttribute( 'buttons' ) === 'go' ? 'search' : 'share-alt' );
return $this->getButton( 'go', $valueAttr, $idAttr, $nameAttr, $glyphicon );
}
/**
* @return string
*/
private function getSearchButton() {
$valueAttr = 'searchbutton';
$idAttr = 'mw-searchButton';
$nameAttr = 'fulltext';
$glyphicon = 'search';
return $this->getButton( 'search', $valueAttr, $idAttr, $nameAttr, $glyphicon );
}
/**
* @param $valueAttr
* @param $idAttr
* @param $nameAttr
* @param $glyphicon
* @return string
*/
private function getButton( $button, $valueAttr, $idAttr, $nameAttr, $glyphicon ) {
if ( $this->shouldShowButton( $button ) ) {
$buttonAttrs = array(
'value' => $this->getSkinTemplate()->getSkin()->msg( $valueAttr ),
'id' => IdRegistry::getRegistry()->getId( $idAttr ),
'name' => $nameAttr,
'type' => 'submit',
'class' => $idAttr . ' btn btn-default'
);
$buttonAttrs = array_merge(
$buttonAttrs,
Linker::tooltipAndAccesskeyAttribs( "search-$nameAttr" )
);
return $this->indent() . \Html::rawElement( 'button', $buttonAttrs, '
' );
}
return '';
}
private function shouldShowButton( $button ) {
$buttonsAttribute = $this->getAttribute( 'buttons' );
return $button === 'go' && $buttonsAttribute !== 'search' ||
$button === 'search' && $buttonsAttribute !== 'go';
}
}