mediawiki-extensions-Visual.../modules/ve-mw/ui/elements/ve.ui.MWExpandableContentElement.js
Thiemo Kreuz aa556e3ef8 Update and fix all @param config and @cfg documentation
I tried to review all of them. Some of the changes I did:
* Make sure the `config` parameter is not marked as optional
  when it is not.
* Make sure default values are mentioned.
* List individual `@cfg` options when it makes sense.

Note I don't list all options a class could accept (e.g. via all
its parent classes and mixins). That's too much. Instead I checked
how a class is actually used and list only these options.

Even then I don't list everything, e.g. unspecific options
like "classes" that can be used pretty much everywhere.

Change-Id: Idf4fbe1dc3608ace277df9e385f2f140df3a2f50
2021-09-12 12:35:27 +00:00

85 lines
2.2 KiB
JavaScript

/**
* Container for textual elements, which should be collapsed to one line by default.
*
* A "more / less" button is used to toggle additional lines.
*
* @class
* @extends OO.ui.Element
* @mixins OO.EventEmitter
*
* @constructor
* @param {Object} config
* @cfg {jQuery} $content
*/
ve.ui.MWExpandableContentElement = function VeUiMWExpandableContentElement( config ) {
// Parent constructor
ve.ui.MWExpandableContentElement.super.call( this, config );
// Mixin constructors
OO.EventEmitter.call( this );
this.$content = config.$content;
this.collapsed = false;
this.toggle( false );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWExpandableContentElement, OO.ui.Element );
OO.mixinClass( ve.ui.MWExpandableContentElement, OO.EventEmitter );
/* Methods */
ve.ui.MWExpandableContentElement.prototype.getLineHeight = function () {
return parseInt( this.$content.css( 'line-height' ) );
};
ve.ui.MWExpandableContentElement.prototype.makeCollapsible = function () {
this.$content.addClass( 've-ui-expandableContent-collapsible' );
var element = this,
collapsedHeight = this.getLineHeight(),
toggle = new OO.ui.ButtonWidget( {
framed: false,
flags: [ 'progressive' ],
label: ve.msg( 'visualeditor-expandable-more' ),
classes: [ 've-ui-expandableContent-toggle' ],
icon: 'expand'
} );
toggle.on( 'click', function () {
if ( element.collapsed ) {
toggle.setLabel( ve.msg( 'visualeditor-expandable-more' ) );
element.$content.css( { height: collapsedHeight } );
toggle.setIcon( 'expand' );
} else {
toggle.setLabel( ve.msg( 'visualeditor-expandable-less' ) );
element.$content.css( { height: element.$content.prop( 'scrollHeight' ) + collapsedHeight } );
toggle.setIcon( 'collapse' );
}
element.collapsed = !element.collapsed;
} );
$( '<div>' )
.addClass( 've-ui-expandableContent-container' )
.append(
$( '<div>' )
.addClass( 've-ui-expandableContent-fade' )
)
.append( toggle.$element )
.height( collapsedHeight )
.appendTo( this.$element );
this.$content.height( collapsedHeight );
};
ve.ui.MWExpandableContentElement.prototype.updateSize = function () {
this.toggle( true );
if ( this.$content.outerHeight() / this.getLineHeight() >= 3 ) {
this.makeCollapsible();
}
};