Bartosz Dziewoński has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277437
Change subject: InputWidget: Actually reuse parts of the DOM when infusing
......................................................................
InputWidget: Actually reuse parts of the DOM when infusing
It is expected that almost any subclass of InputWidget will override
the #getInputElement method to display its own input. Therefore, if I
rely on the InputWidget implementation of it, it won't work. What the
hell was I thinking.
Moved checking for config.$input into the constructor, before
#getInputElement is called. For subclasses that need to tweak the
original $input, moved that code to constructor also.
Bug: T114408
Change-Id: I3a464fe730dc9382b9cb5936edc21f9bf9b3ed2e
---
M src/widgets/ButtonInputWidget.js
M src/widgets/DropdownInputWidget.js
M src/widgets/InputWidget.js
3 files changed, 15 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/37/277437/1
diff --git a/src/widgets/ButtonInputWidget.js b/src/widgets/ButtonInputWidget.js
index a1228f1..79ffcdc 100644
--- a/src/widgets/ButtonInputWidget.js
+++ b/src/widgets/ButtonInputWidget.js
@@ -36,6 +36,11 @@
// Configuration initialization
config = $.extend( { type: 'button', useInputTag: false }, config );
+ // See InputWidget#reusePreInfuseDOM about config.$input
+ if ( config.$input ) {
+ config.$input.empty();
+ }
+
// Properties (must be set before parent constructor, which calls
#setValue)
this.useInputTag = config.useInputTag;
@@ -81,10 +86,6 @@
*/
OO.ui.ButtonInputWidget.prototype.getInputElement = function ( config ) {
var type;
- // See InputWidget#reusePreInfuseDOM about config.$input
- if ( config.$input ) {
- return config.$input.empty();
- }
type = [ 'button', 'submit', 'reset' ].indexOf( config.type ) !== -1 ?
config.type : 'button';
return $( '<' + ( config.useInputTag ? 'input' : 'button' ) + ' type="'
+ type + '">' );
};
diff --git a/src/widgets/DropdownInputWidget.js
b/src/widgets/DropdownInputWidget.js
index c3a5f83..636767c 100644
--- a/src/widgets/DropdownInputWidget.js
+++ b/src/widgets/DropdownInputWidget.js
@@ -36,6 +36,11 @@
// Configuration initialization
config = config || {};
+ // See InputWidget#reusePreInfuseDOM about config.$input
+ if ( config.$input ) {
+ config.$input.addClass( 'oo-ui-element-hidden' );
+ }
+
// Properties (must be done before parent constructor which calls
#setDisabled)
this.dropdownWidget = new OO.ui.DropdownWidget( config.dropdown );
@@ -66,11 +71,7 @@
* @inheritdoc
* @protected
*/
-OO.ui.DropdownInputWidget.prototype.getInputElement = function ( config ) {
- // See InputWidget#reusePreInfuseDOM about config.$input
- if ( config.$input ) {
- return config.$input.addClass( 'oo-ui-element-hidden' );
- }
+OO.ui.DropdownInputWidget.prototype.getInputElement = function () {
return $( '<input>' ).attr( 'type', 'hidden' );
};
diff --git a/src/widgets/InputWidget.js b/src/widgets/InputWidget.js
index e70b6fa..1726c66 100644
--- a/src/widgets/InputWidget.js
+++ b/src/widgets/InputWidget.js
@@ -30,7 +30,8 @@
OO.ui.InputWidget.parent.call( this, config );
// Properties
- this.$input = this.getInputElement( config );
+ // See #reusePreInfuseDOM about config.$input
+ this.$input = config.$input || this.getInputElement( config );
this.value = '';
this.inputFilter = config.inputFilter;
@@ -114,9 +115,8 @@
* @param {Object} config Configuration options
* @return {jQuery} Input element
*/
-OO.ui.InputWidget.prototype.getInputElement = function ( config ) {
- // See #reusePreInfuseDOM about config.$input
- return config.$input || $( '<input>' );
+OO.ui.InputWidget.prototype.getInputElement = function () {
+ return $( '<input>' );
};
/**
--
To view, visit https://gerrit.wikimedia.org/r/277437
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3a464fe730dc9382b9cb5936edc21f9bf9b3ed2e
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