Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/230106
Change subject: If ProcessDialog#fitLabel is called before dialog is open, defer
......................................................................
If ProcessDialog#fitLabel is called before dialog is open, defer
Also, when the width is not a number, use the computed width of
the header, as '100%' - 20 is NaN.
Bug: T108326
Change-Id: I251b63e0b9d077ec9143b88a37f48f8b249c9813
---
M src/Window.js
M src/WindowManager.js
M src/dialogs/ProcessDialog.js
3 files changed, 58 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/06/230106/1
diff --git a/src/Window.js b/src/Window.js
index 928162b..4cff430 100644
--- a/src/Window.js
+++ b/src/Window.js
@@ -185,7 +185,27 @@
* @return {string} Symbolic name of the size: `small`, `medium`, `large`,
`larger`, `full`
*/
OO.ui.Window.prototype.getSize = function () {
- return this.size;
+ var viewport = OO.ui.Element.static.getDimensions(
this.getElementWindow() ),
+ sizes = this.manager.constructor.static.sizes,
+ size = this.size;
+
+ if ( !sizes[ size ] ) {
+ size = this.manager.constructor.static.defaultSize;
+ }
+ if ( size !== 'full' && viewport.rect.right - viewport.rect.left <
sizes[ size ].width ) {
+ size = 'full';
+ }
+
+ return size;
+};
+
+/**
+ * Get the size properties associated with the current window size
+ *
+ * @return {Object} Size properties
+ */
+OO.ui.Window.prototype.getSizeProperties = function () {
+ return this.manager.constructor.static.sizes[ this.getSize() ];
};
/**
diff --git a/src/WindowManager.js b/src/WindowManager.js
index 01f22cb..b2336d6 100644
--- a/src/WindowManager.js
+++ b/src/WindowManager.js
@@ -561,20 +561,11 @@
return;
}
- var viewport = OO.ui.Element.static.getDimensions(
win.getElementWindow() ),
- sizes = this.constructor.static.sizes,
- size = win.getSize();
+ var isFullscreen = win.getSize() === 'full';
- if ( !sizes[ size ] ) {
- size = this.constructor.static.defaultSize;
- }
- if ( size !== 'full' && viewport.rect.right - viewport.rect.left <
sizes[ size ].width ) {
- size = 'full';
- }
-
- this.$element.toggleClass( 'oo-ui-windowManager-fullscreen', size ===
'full' );
- this.$element.toggleClass( 'oo-ui-windowManager-floating', size !==
'full' );
- win.setDimensions( sizes[ size ] );
+ this.$element.toggleClass( 'oo-ui-windowManager-fullscreen',
isFullscreen );
+ this.$element.toggleClass( 'oo-ui-windowManager-floating',
!isFullscreen );
+ win.setDimensions( win.getSizeProperties() );
this.emit( 'resize', win );
diff --git a/src/dialogs/ProcessDialog.js b/src/dialogs/ProcessDialog.js
index d1daab2..039ee78 100644
--- a/src/dialogs/ProcessDialog.js
+++ b/src/dialogs/ProcessDialog.js
@@ -62,6 +62,9 @@
// Parent constructor
OO.ui.ProcessDialog.parent.call( this, config );
+ // Properties
+ this.fitOnOpen = false;
+
// Initialization
this.$element.addClass( 'oo-ui-processDialog' );
};
@@ -204,21 +207,47 @@
};
/**
+ * @inheritdoc
+ */
+OO.ui.ProcessDialog.prototype.setDimensions = function () {
+ // Parent method
+ OO.ui.ProcessDialog.parent.prototype.setDimensions.apply( this,
arguments );
+
+ this.fitLabel();
+};
+
+/**
* Fit label between actions.
*
* @private
* @chainable
*/
OO.ui.ProcessDialog.prototype.fitLabel = function () {
- var safeWidth, primaryWidth, biggerWidth, labelWidth, navigationWidth,
leftWidth, rightWidth;
+ var safeWidth, primaryWidth, biggerWidth, labelWidth, navigationWidth,
leftWidth, rightWidth,
+ size = this.getSizeProperties();
+
+ if ( typeof size.width !== 'number' ) {
+ if ( this.isOpened() ) {
+ navigationWidth = this.$head.width() - 20;
+ } else if ( this.isOpening() ) {
+ if ( !this.fitOnOpen ) {
+ // Size is relative and the dialog isn't open
yet, so wait.
+ this.manager.opening.done( this.fitLabel.bind(
this ) );
+ this.fitOnOpen = true;
+ }
+ return;
+ } else {
+ return;
+ }
+ } else {
+ navigationWidth = size.width - 20;
+ }
safeWidth = this.$safeActions.is( ':visible' ) ?
this.$safeActions.width() : 0;
primaryWidth = this.$primaryActions.is( ':visible' ) ?
this.$primaryActions.width() : 0;
biggerWidth = Math.max( safeWidth, primaryWidth );
labelWidth = this.title.$element.width();
- // Is there a better way to calculate this?
- navigationWidth = OO.ui.WindowManager.static.sizes[ this.getSize()
].width - 20;
if ( 2 * biggerWidth + labelWidth < navigationWidth ) {
// We have enough space to center the label
@@ -312,5 +341,6 @@
.first( function () {
// Make sure to hide errors
this.hideErrors();
+ this.fitOnOpen = false;
}, this );
};
--
To view, visit https://gerrit.wikimedia.org/r/230106
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I251b63e0b9d077ec9143b88a37f48f8b249c9813
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits