jenkins-bot has submitted this change and it was merged.
Change subject: Implement HTMLTitleTextField with suggestions for non-OOUI
forms, too
......................................................................
Implement HTMLTitleTextField with suggestions for non-OOUI forms, too
Also implement a way to use mediawiki.searchSuggests without wrapping
a link around the suggestions.
Bug: T117033
Change-Id: I2c7fc71d19cefaa16a6cc4526af05be9cd32366e
---
M includes/htmlform/HTMLTextField.php
M includes/htmlform/HTMLTitleTextField.php
M resources/src/mediawiki/mediawiki.searchSuggest.js
3 files changed, 35 insertions(+), 5 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/htmlform/HTMLTextField.php
b/includes/htmlform/HTMLTextField.php
index c2606c2..fb7584b 100644
--- a/includes/htmlform/HTMLTextField.php
+++ b/includes/htmlform/HTMLTextField.php
@@ -22,7 +22,7 @@
'value' => $value,
'dir' => $this->mDir,
'spellcheck' => $this->getSpellCheck(),
- ] + $this->getTooltipAndAccessKey();
+ ] + $this->getTooltipAndAccessKey() +
$this->getDataAttribs();
if ( $this->mClass !== '' ) {
$attribs['class'] = $this->mClass;
@@ -126,4 +126,13 @@
protected function getInputWidget( $params ) {
return new OOUI\TextInputWidget( $params );
}
+
+ /**
+ * Returns an array of data-* attributes to add to the field.
+ *
+ * @return array
+ */
+ protected function getDataAttribs() {
+ return [];
+ }
}
diff --git a/includes/htmlform/HTMLTitleTextField.php
b/includes/htmlform/HTMLTitleTextField.php
index 09fbaa7..410d15d 100644
--- a/includes/htmlform/HTMLTitleTextField.php
+++ b/includes/htmlform/HTMLTitleTextField.php
@@ -80,4 +80,20 @@
$params['relative'] = $this->mParams['relative'];
return new TitleInputWidget( $params );
}
+
+ public function getInputHtml( $value ) {
+ // add mw-searchInput class to enable search suggestions for
non-OOUI, too
+ $this->mClass .= 'mw-searchInput';
+
+ // return the HTMLTextField html
+ return parent::getInputHtml( $value );
+ }
+
+ protected function getDataAttribs() {
+ return [
+ 'data-mw-searchsuggest' => FormatJson::encode( [
+ 'wrapAsLink' => false,
+ ] ),
+ ];
+ }
}
diff --git a/resources/src/mediawiki/mediawiki.searchSuggest.js
b/resources/src/mediawiki/mediawiki.searchSuggest.js
index 0fcd22c..782501a 100644
--- a/resources/src/mediawiki/mediawiki.searchSuggest.js
+++ b/resources/src/mediawiki/mediawiki.searchSuggest.js
@@ -108,19 +108,24 @@
// The function used to render the suggestions.
function renderFunction( text, context ) {
- var formData = getFormData( context );
+ var formData = getFormData( context ),
+ textboxConfig = context.data.$textbox.data(
'mw-searchsuggest' ) || {};
// linkParams object is modified and reused
formData.linkParams[ formData.textParam ] = text;
- // this is the container <div>, jQueryfied
- this.text( text )
- .wrap(
+ // this is the container <div>, jQueryfield
+ this.text( text );
+
+ // wrap only as link, if the config doesn't disallow it
+ if ( textboxConfig.wrapAsLink !== false ) {
+ this.wrap(
$( '<a>' )
.attr( 'href',
formData.baseHref + $.param( formData.linkParams ) )
.attr( 'title', text )
.addClass(
'mw-searchSuggest-link' )
);
+ }
}
// The function used when the user makes a selection
--
To view, visit https://gerrit.wikimedia.org/r/249790
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2c7fc71d19cefaa16a6cc4526af05be9cd32366e
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Glaisher <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits