Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/120057
Change subject: Fix 'original dimensions' async call in MediaEdit dialog ...................................................................... Fix 'original dimensions' async call in MediaEdit dialog The request for originalDimensions is taken from the API, which can be rather slow. There is a future (soon) fix that refactors the entire way we read the originalDimensions asynchronously and load it into the dialog but until that is available, this fix introduces a couple of basic fallbacks in case originalDimensions are not yet available in the size widget. Bug: 62024 Change-Id: I8d00cea6f1d667359a44a6c185c16340bc6e81c9 --- M modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js 1 file changed, 16 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/57/120057/1 diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js index 09f6825..926c9d7 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js @@ -385,9 +385,11 @@ * @param {OO.ui.ButtonOptionWidget} item Selected item */ ve.ui.MWMediaEditDialog.prototype.onTypeChange = function ( item ) { - var originalDimensions = this.sizeWidget.getOriginalDimensions(), + var originalDimensions, selectedType = item ? item.getData() : '', thumbOrFrameless = selectedType === 'thumb' || selectedType === 'frameless'; + + originalDimensions = this.sizeWidget.getOriginalDimensions() || {}; // As per wikitext docs, both 'thumb' and 'frameless' have // explicitly limited size, as opposed to the similar case @@ -395,14 +397,14 @@ if ( thumbOrFrameless ) { // Set the placeholders to be wiki default, but only if the image // is not smaller. Limit on width only (according to wikitext default) - if ( originalDimensions.width > this.defaultThumbSize ) { - this.sizeWidget.setPlaceholderDimensions( { - 'width': this.defaultThumbSize, - } ); - } else { + if ( originalDimensions && originalDimensions.width < this.defaultThumbSize ) { // The image is smaller than wiki default. Make the default dimensions // the image max size this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } else { + this.sizeWidget.setPlaceholderDimensions( { + 'width': this.defaultThumbSize, + } ); } // Enable the size select widget 'default' option @@ -414,8 +416,10 @@ // Set placeholders to be image original dimensions // Technically, this is the 'default' of non thumb/frameless // images, as that is the size that they render in when - // no size is specified. - this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + // no size is specified. Only do that if original dimensions exist + if ( originalDimensions.width && originalDimensions.height ) { + this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } // Don't allow for 'default' choice this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( true ); @@ -518,6 +522,7 @@ } else if ( currentItem === 'full' ) { if ( this.typeInput.getSelectedItem() && + this.sizeWidget.getPlaceholderDimensions() && ( this.typeInput.getSelectedItem().getData() === 'frame' || this.typeInput.getSelectedItem().getData() === 'none' @@ -607,7 +612,7 @@ dialog.sizeWidget.setOriginalDimensions( mediaNodeView.getOriginalDimensions() ); dialog.sizeWidget.setEnforcedMax( false ); // Original dimensions available, enable the button - this.sizeSelectWidget.getItemFromData( 'full' ).setDisabled( false ); + dialog.sizeSelectWidget.getItemFromData( 'full' ).setDisabled( false ); if ( mediaNodeView.getMaxDimensions() ) { dialog.sizeWidget.setMaxDimensions( mediaNodeView.getMaxDimensions() ); if ( dialog.mediaNode.getAttribute( 'type' ) === 'thumb' ) { @@ -633,6 +638,8 @@ // If there are original dimensions, enable that choice if ( this.sizeWidget.getOriginalDimensions() ) { this.sizeSelectWidget.getItemFromData( 'full' ).setDisabled( false ); + } else { + this.sizeSelectWidget.getItemFromData( 'full' ).setDisabled( true ); } } -- To view, visit https://gerrit.wikimedia.org/r/120057 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8d00cea6f1d667359a44a6c185c16340bc6e81c9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits