[MediaWiki-commits] [Gerrit] Fix 'original dimensions' async call in MediaEdit dialog - change (mediawiki...VisualEditor)
Catrope has submitted this change and it was merged. 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, 26 insertions(+), 15 deletions(-) Approvals: Catrope: Verified; Looks good to me, approved diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js index 09f6825..123d0ac 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 && originalDimensions.width && originalDimensions.height ) { + this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } // Don't allow for 'default' choice this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( true ); @@ -451,10 +455,10 @@ // Sanity check just in case before the comparison this.sizeWidget.getCurrentDimensions() && // Make sure there are original dimensions set up - this.sizeWidget.getOriginalDimensions() && + originalDimensions && OO.compare( this.sizeWidget.getCurrentDimensions(), - this.sizeWidget.getOriginalDimensions() + originalDimensions ) ) { this.sizeSelectWidget.selectItem( @@ -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' @@ -529,10 +534,14 @@ 'height': 0 } ); } else { - // Fill in the values of the original dimensions - this.sizeWidget.setCurrentDimensions( -
[MediaWiki-commits] [Gerrit] Fix 'original dimensions' async call in MediaEdit dialog - change (mediawiki...VisualEditor)
Catrope has submitted this change and it was merged. 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, 26 insertions(+), 15 deletions(-) Approvals: Catrope: Verified; Looks good to me, approved diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js index 1d20a0d..3322cff 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js @@ -382,9 +382,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 @@ -392,14 +394,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 @@ -411,8 +413,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 && originalDimensions.width && originalDimensions.height ) { + this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } // Don't allow for 'default' choice this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( true ); @@ -448,10 +452,10 @@ // Sanity check just in case before the comparison this.sizeWidget.getCurrentDimensions() && // Make sure there are original dimensions set up - this.sizeWidget.getOriginalDimensions() && + originalDimensions && OO.compare( this.sizeWidget.getCurrentDimensions(), - this.sizeWidget.getOriginalDimensions() + originalDimensions ) ) { this.sizeSelectWidget.selectItem( @@ -515,6 +519,7 @@ } else if ( currentItem === 'full' ) { if ( this.typeInput.getSelectedItem() && + this.sizeWidget.getPlaceholderDimensions() && ( this.typeInput.getSelectedItem().getData() === 'frame' || this.typeInput.getSelectedItem().getData() === 'none' @@ -526,10 +531,14 @@ 'height': 0 } ); } else { - // Fill in the values of the original dimensions - this.sizeWidget.setCurrentDimensions( -
[MediaWiki-commits] [Gerrit] Fix 'original dimensions' async call in MediaEdit dialog - change (mediawiki...VisualEditor)
jenkins-bot has submitted this change and it was merged. 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, 26 insertions(+), 15 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js index 09f6825..123d0ac 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 && originalDimensions.width && originalDimensions.height ) { + this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } // Don't allow for 'default' choice this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( true ); @@ -451,10 +455,10 @@ // Sanity check just in case before the comparison this.sizeWidget.getCurrentDimensions() && // Make sure there are original dimensions set up - this.sizeWidget.getOriginalDimensions() && + originalDimensions && OO.compare( this.sizeWidget.getCurrentDimensions(), - this.sizeWidget.getOriginalDimensions() + originalDimensions ) ) { this.sizeSelectWidget.selectItem( @@ -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' @@ -529,10 +534,14 @@ 'height': 0 } ); } else { - // Fill in the values of the original dimensions - this.sizeWidget.setCurrentDimens
[MediaWiki-commits] [Gerrit] Fix 'original dimensions' async call in MediaEdit dialog - change (mediawiki...VisualEditor)
Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/120691 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, 26 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/91/120691/1 diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js index 1d20a0d..3322cff 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaEditDialog.js @@ -382,9 +382,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 @@ -392,14 +394,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 @@ -411,8 +413,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 && originalDimensions.width && originalDimensions.height ) { + this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } // Don't allow for 'default' choice this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( true ); @@ -448,10 +452,10 @@ // Sanity check just in case before the comparison this.sizeWidget.getCurrentDimensions() && // Make sure there are original dimensions set up - this.sizeWidget.getOriginalDimensions() && + originalDimensions && OO.compare( this.sizeWidget.getCurrentDimensions(), - this.sizeWidget.getOriginalDimensions() + originalDimensions ) ) { this.sizeSelectWidget.selectItem( @@ -515,6 +519,7 @@ } else if ( currentItem === 'full' ) { if ( this.typeInput.getSelectedItem() && + this.sizeWidget.getPlaceholderDimensions() && ( this.typeInput.getSelectedItem().getData() === 'frame' || this.typeInput.getSelectedItem().getData() === 'none' @@ -526,10 +531,14 @@ 'height': 0 } ); } else { - // Fill in the values of the original dimensio
[MediaWiki-commits] [Gerrit] Fix 'original dimensions' async call in MediaEdit dialog - change (mediawiki...VisualEditor)
Catrope has uploaded a new change for review. https://gerrit.wikimedia.org/r/120690 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, 26 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/90/120690/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..123d0ac 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 && originalDimensions.width && originalDimensions.height ) { + this.sizeWidget.setPlaceholderDimensions( originalDimensions ); + } // Don't allow for 'default' choice this.sizeSelectWidget.getItemFromData( 'default' ).setDisabled( true ); @@ -451,10 +455,10 @@ // Sanity check just in case before the comparison this.sizeWidget.getCurrentDimensions() && // Make sure there are original dimensions set up - this.sizeWidget.getOriginalDimensions() && + originalDimensions && OO.compare( this.sizeWidget.getCurrentDimensions(), - this.sizeWidget.getOriginalDimensions() + originalDimensions ) ) { this.sizeSelectWidget.selectItem( @@ -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' @@ -529,10 +534,14 @@ 'height': 0 } ); } else { - // Fill in the values of the original dimensio
[MediaWiki-commits] [Gerrit] Fix 'original dimensions' async call in MediaEdit dialog - change (mediawiki...VisualEditor)
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