Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243082
Change subject: Preserve DOM node of InputWidget's $input when infusing
......................................................................
Preserve DOM node of InputWidget's $input when infusing
Ideally we would preserve all the DOM (T114408), this just solves
a single case (in a hacky way).
Bug: T114134
Change-Id: I3c21b3710d16dbb4dbcbdd3871a70fdfd0e7b536
---
M src/Element.js
M src/widgets/DropdownInputWidget.js
M src/widgets/InputWidget.js
3 files changed, 24 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/82/243082/1
diff --git a/src/Element.js b/src/Element.js
index fe10f98..0109f09 100644
--- a/src/Element.js
+++ b/src/Element.js
@@ -204,6 +204,25 @@
obj = new cls( data ); // rebuild widget
// pick up dynamic state, like focus, value of form inputs, scroll
position, etc.
state = obj.gatherPreInfuseState( $elem );
+ // Hack to let browsers preserve inputted values across page reloads
(T114134)
+ // Ideally we would be just reusing all of the DOM, not a single node.
+ if ( $elem.hasClass( 'oo-ui-inputWidget' ) ) {
+ data.$input = $elem.find( '.oo-ui-inputWidget-input' );
+ obj = null; // needs rebuild with new data
+ }
+ // HACK until this is generalized...
+ if ( $elem.hasClass( 'mw-widget-complexTitleInputWidget' ) ) {
+ data.namespace.$input = $elem.find(
'.mw-widget-namespaceInputWidget .oo-ui-inputWidget-input' );
+ data.title.$input = $elem.find( '.mw-widget-titleInputWidget
.oo-ui-inputWidget-input' );
+ obj = null; // needs rebuild with new data
+ }
+ if ( !obj ) {
+ // rebuild widget... again, with $input this time.
gatherPreInfuseState() really should've been a
+ // static method, so that we wouldn't need to instantiate it
above.
+ obj = new cls( data );
+ // $input is no longer present in its original location in the
DOM now, which is why we had to
+ // gatherPreInfuseState() earlier.
+ }
// now replace old DOM with this new DOM.
if ( top ) {
$elem.replaceWith( obj.$element );
diff --git a/src/widgets/DropdownInputWidget.js
b/src/widgets/DropdownInputWidget.js
index 29c39f1..1bc41f0 100644
--- a/src/widgets/DropdownInputWidget.js
+++ b/src/widgets/DropdownInputWidget.js
@@ -49,6 +49,8 @@
this.dropdownWidget.getMenu().connect( this, { select: 'onMenuSelect' }
);
// Initialization
+ // In case this.$input was provided via config.$input when infusing a
widget (see OO.ui.infuse)
+ this.$input.addClass( 'oo-ui-element-hidden' );
this.setOptions( config.options || [] );
this.$element
.addClass( 'oo-ui-dropdownInputWidget' )
diff --git a/src/widgets/InputWidget.js b/src/widgets/InputWidget.js
index 3fd5fa5..68fd58d 100644
--- a/src/widgets/InputWidget.js
+++ b/src/widgets/InputWidget.js
@@ -30,7 +30,9 @@
OO.ui.InputWidget.parent.call( this, config );
// Properties
- this.$input = this.getInputElement( config );
+ // Hack to let browsers preserve typed content across page reloads
(T106313)
+ // config.$input is internal and may only be provided when infusing a
widget (see OO.ui.infuse)
+ this.$input = config.$input || this.getInputElement( config );
this.value = '';
this.inputFilter = config.inputFilter;
--
To view, visit https://gerrit.wikimedia.org/r/243082
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3c21b3710d16dbb4dbcbdd3871a70fdfd0e7b536
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits