diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js index 4bc24e48e3..11ba3fac7f 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWMediaDialog.js @@ -619,11 +619,9 @@ ve.ui.MWMediaDialog.prototype.buildMediaInfoPanel = function ( imageinfo ) { $info.outerWidth( Math.floor( windowWidth - $thumbContainer.outerWidth( true ) - 15 ) ); } - // Adjust height-limited fields + // Initialize fields for ( field in fields ) { - if ( fields[field].getType() === 'description' ) { - fields[field].toggleReadMoreButton(); - } + fields[field].initialize(); } // Let the scrollbar appear naturally if it should this.mediaImageInfoPanel.$element.css( 'overflow', '' ); diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWMediaInfoFieldWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWMediaInfoFieldWidget.js index ff0316e16a..6742faa3b7 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWMediaInfoFieldWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWMediaInfoFieldWidget.js @@ -106,15 +106,38 @@ OO.mixinClass( ve.ui.MWMediaInfoFieldWidget, OO.ui.LabelElement ); ve.ui.MWMediaInfoFieldWidget.static.tagName = 'div'; +/** + * Define a height threshold for the description fields. + * If the rendered field's height is under the defined limit + * (max-height + threshold) we should remove the max-height + * and display the field as-is. + * This prevents cases where "read more" appears but only + * exposes only a few pixels or a line extra. + * + * @property {number} Threshold in pixels + */ +ve.ui.MWMediaInfoFieldWidget.static.threshold = 24; + /** * Toggle the read more button according to whether it should be * visible or not. */ -ve.ui.MWMediaInfoFieldWidget.prototype.toggleReadMoreButton = function () { - var show = this.$text.height() < this.$text.prop( 'scrollHeight' ); - // Only show the readMore button if it should be shown, and not while - // the expansion animation is ongoing - this.readMoreButton.toggle( show ); +ve.ui.MWMediaInfoFieldWidget.prototype.initialize = function () { + var actualHeight, containerHeight; + + if ( this.getType() === 'description' ) { + actualHeight = this.$text.prop( 'scrollHeight' ); + containerHeight = this.$text.outerHeight( true ); + + if ( actualHeight < containerHeight + this.constructor.static.threshold ) { + // The contained result is big enough to show. Remove the maximum height + this.$text + .css( 'maxHeight', '' ); + } else { + // Only show the readMore button if it should be shown + this.readMoreButton.toggle( containerHeight < actualHeight ); + } + } }; /**