Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/115306
Change subject: Allow dynamic limit to maxDimensions ...................................................................... Allow dynamic limit to maxDimensions Make sure that the ability to limit to maximum dimensions is dyamic and can change. This is beneficial for when the image type changes to thumbnail (which requires a limit) or to anything else (that can allow for any size without limit.) Also, allow for a forced revalidation of the current size widget dimensions in case limits were applied or removed. Change-Id: I362c7c378c5ccd7a83495b03e4429c9b93c1e9ee --- M modules/ve/ui/widgets/ve.ui.MediaSizeWidget.js M modules/ve/ve.Scalable.js 2 files changed, 35 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/06/115306/1 diff --git a/modules/ve/ui/widgets/ve.ui.MediaSizeWidget.js b/modules/ve/ui/widgets/ve.ui.MediaSizeWidget.js index c36ea65..0820e0a 100644 --- a/modules/ve/ui/widgets/ve.ui.MediaSizeWidget.js +++ b/modules/ve/ui/widgets/ve.ui.MediaSizeWidget.js @@ -137,12 +137,29 @@ this.widthInput.setValue( this.getCurrentDimensions().width ); this.heightInput.setValue( this.getCurrentDimensions().height ); - this.errorLabel.$element.toggle( !this.isCurrentDimensionsValid() ); - this.$element.toggleClass( 've-ui-mediaSizeWidget-input-hasError', !this.isCurrentDimensionsValid() ); + this.validateDimensions( false ); this.preventChangeRecursion = false; }; +/** + * Explicitly call for validating the current dimensions. This is especially + * useful if we've changed conditions for the widget, like limiting image + * dimensions for thumbnails when the image type changes. Triggers the error + * class if needed. + * + * @param {boolean} isForced Force a re-evaluation even if this.valid is + * already set. + * @returns {boolean} Current dimensions are valid + */ +ve.ui.MediaSizeWidget.prototype.validateDimensions = function ( isForced ) { + var isValid = this.isCurrentDimensionsValid( isForced ); + this.errorLabel.$element.toggle( !isValid ); + this.$element.toggleClass( 've-ui-mediaSizeWidget-input-hasError', !isValid ); + + return isValid; +}; + /** */ ve.ui.MediaSizeWidget.prototype.setOriginalDimensions = function ( dimensions ) { // Parent method diff --git a/modules/ve/ve.Scalable.js b/modules/ve/ve.Scalable.js index 01df533..775106a 100644 --- a/modules/ve/ve.Scalable.js +++ b/modules/ve/ve.Scalable.js @@ -193,6 +193,14 @@ ve.Scalable.prototype.isEnforcedMax = function () { return this.enforceMax; }; +/** + * Set enforcement of maximum dimensions + * + * @param {boolean} Enforces the maximum dimensions + */ +ve.Scalable.prototype.setEnforcedMax = function ( isEnforcedMax ) { + this.enforceMax = isEnforcedMax; +}; /** * Get the fixed aspect ratio (width/height) @@ -310,10 +318,12 @@ /** * Checks whether the current dimensions are numeric and within range * + * @param {boolean} isForced Force a re-evaluation even if this.valid is + * already set. * @returns {boolean} Current dimensions are valid */ -ve.Scalable.prototype.isCurrentDimensionsValid = function () { - if ( this.valid === null ) { +ve.Scalable.prototype.isCurrentDimensionsValid = function ( isForced ) { + if ( this.valid === null || isForced ) { var dimensions = this.getCurrentDimensions(), minDimensions = this.isEnforcedMin() && this.getMinDimensions(), maxDimensions = this.isEnforcedMax() && this.getMaxDimensions(); @@ -323,14 +333,14 @@ $.isNumeric( dimensions.height ) && ( !minDimensions || ( - dimensions.width >= minDimensions.width && - dimensions.height >= minDimensions.height + dimensions.width >= this.getMinDimensions().width && + dimensions.height >= this.getMinDimensions().height ) ) && ( !maxDimensions || ( - dimensions.width <= maxDimensions.width && - dimensions.height <= maxDimensions.height + dimensions.width <= this.getMaxDimensions().width && + dimensions.height <= this.getMaxDimensions().height ) ) ); -- To view, visit https://gerrit.wikimedia.org/r/115306 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I362c7c378c5ccd7a83495b03e4429c9b93c1e9ee Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/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