Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
JsSelectToInput.php
1<?php
2declare( strict_types = 1 );
3
5
6use MediaWiki\Context\RequestContext;
7use MediaWiki\Xml\Xml;
8use MediaWiki\Xml\XmlSelect;
9use RuntimeException;
10
16final class JsSelectToInput {
18 private string $targetId;
19 private XmlSelect $select;
20
21 public function __construct( XmlSelect $select ) {
22 $this->select = $select;
23 }
24
25 public function setTargetId( string $id ) {
26 $this->targetId = $id;
27 }
28
33 public function getHtmlAndPrepareJS(): string {
34 $sourceId = $this->select->getAttribute( 'id' );
35
36 if ( !is_string( $sourceId ) ) {
37 throw new RuntimeException( 'ID needs to be specified for the selector' );
38 }
39
40 RequestContext::getMain()->getOutput()->addModules( 'ext.translate.selecttoinput' );
41 $html = $this->select->getHTML();
42 $html .= Xml::element( 'input', [
43 'type' => 'button',
44 'value' => wfMessage( 'translate-jssti-add' )->text(),
45 'class' => 'mw-translate-jssti',
46 'data-translate-jssti-sourceid' => $sourceId,
47 'data-translate-jssti-targetid' => $this->targetId
48 ] );
49
50 return $html;
51 }
52}
Code for JavaScript enhanced <option> selectors.
getHtmlAndPrepareJS()
Returns the whole input element and injects needed JavaScript.
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:29