2021-04-22 16:59:30 +00:00
|
|
|
/**
|
|
|
|
* 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] Configuration options
|
|
|
|
*/
|
|
|
|
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' );
|
|
|
|
|
2021-06-26 13:27:52 +00:00
|
|
|
var element = this,
|
|
|
|
collapsedHeight = this.getLineHeight(),
|
|
|
|
toggle = new OO.ui.ButtonWidget( {
|
|
|
|
framed: false,
|
|
|
|
flags: [ 'progressive' ],
|
|
|
|
label: ve.msg( 'visualeditor-expandable-more' ),
|
2021-06-26 13:39:14 +00:00
|
|
|
classes: [ 've-ui-expandableContent-toggle' ],
|
|
|
|
icon: 'expand'
|
2021-06-26 13:27:52 +00:00
|
|
|
} );
|
|
|
|
|
2021-04-22 16:59:30 +00:00
|
|
|
toggle.on( 'click', function () {
|
|
|
|
if ( element.collapsed ) {
|
|
|
|
toggle.setLabel( ve.msg( 'visualeditor-expandable-more' ) );
|
|
|
|
element.$content.css( { height: collapsedHeight } );
|
2021-06-26 13:39:14 +00:00
|
|
|
toggle.setIcon( 'expand' );
|
2021-04-22 16:59:30 +00:00
|
|
|
} else {
|
|
|
|
toggle.setLabel( ve.msg( 'visualeditor-expandable-less' ) );
|
|
|
|
element.$content.css( { height: element.$content.prop( 'scrollHeight' ) + collapsedHeight } );
|
2021-06-26 13:39:14 +00:00
|
|
|
toggle.setIcon( 'collapse' );
|
2021-04-22 16:59:30 +00:00
|
|
|
}
|
|
|
|
element.collapsed = !element.collapsed;
|
|
|
|
} );
|
|
|
|
|
|
|
|
$( '<div>' )
|
2021-06-26 13:27:52 +00:00
|
|
|
.addClass( 've-ui-expandableContent-container' )
|
|
|
|
.append(
|
|
|
|
$( '<div>' )
|
|
|
|
.addClass( 've-ui-expandableContent-fade' )
|
|
|
|
)
|
2021-04-22 16:59:30 +00:00
|
|
|
.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();
|
|
|
|
}
|
|
|
|
};
|