All files / src/ui/contextitems ve.ui.MergeCellsContextItem.js

88% Statements 22/25
54.54% Branches 6/11
100% Functions 3/3
88% Lines 22/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                                1x   1x   1x     1x                 1x 1x         1x       1x   1x   1x   1x   1x             1x 24x           1x   1x     1x 1x       1x       1x   1x                                   1x  
/*!
 * VisualEditor MergeCellsContextItem class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Context item for mergeable cels.
 *
 * @class
 * @extends ve.ui.LinearContextItem
 *
 * @param {ve.ui.LinearContext} context Context the item is in
 * @param {ve.dm.Model} model Model the item is related to
 * @param {Object} [config] Configuration options
 */
ve.ui.MergeCellsContextItem = function VeUiMergeCellsContextItem( context, model, config ) {
	// Parent constructor
	ve.ui.MergeCellsContextItem.super.call( this, context, model, config );
 
	this.dimensions = new OO.ui.LabelWidget( {
		classes: [ 've-ui-mergeCellsContextItem-dimensions' ]
	} );
	Iif ( this.context.isMobile() ) {
		// Use desktop-style label-only button, as otherwise the "edit" button
		// gets collapsed to just the edit icon.
		this.editButton
			.setIcon( null )
			.setInvisibleLabel( false );
	}
 
	// Initialization
	this.$element.addClass( 've-ui-mergeCellsContextItem' );
	this.$title.append( this.dimensions.$element );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.MergeCellsContextItem, ve.ui.LinearContextItem );
 
/* Static Properties */
 
ve.ui.MergeCellsContextItem.static.name = 'mergeCells';
 
ve.ui.MergeCellsContextItem.static.icon = 'tableMergeCells';
 
ve.ui.MergeCellsContextItem.static.label = OO.ui.deferMsg( 'visualeditor-table-merge-cells' );
 
ve.ui.MergeCellsContextItem.static.commandName = 'mergeCells';
 
ve.ui.MergeCellsContextItem.static.embeddable = false;
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.MergeCellsContextItem.static.isCompatibleWith = function ( model ) {
	return model instanceof ve.dm.Node && model.isCellable();
};
 
/**
 * @inheritdoc
 */
ve.ui.MergeCellsContextItem.prototype.setup = function () {
	// Parent method
	ve.ui.MergeCellsContextItem.super.prototype.setup.apply( this, arguments );
 
	// If not disabled, selection must be table and spanning multiple matrix cells
	var selection = this.getFragment().getSurface().getSelection(),
		documentModel = this.getFragment().getDocument(),
		// There's some situations involving transclusion table cells which
		// can make us have a LinearSelection here, so make sure this will
		// work:
		isMergeable = ( selection instanceof ve.dm.TableSelection ) &&
			selection.isMergeable( documentModel ) &&
			!this.isReadOnly();
 
	if ( !isMergeable ) {
		// Ideally we would check this in isCompatibleWith, but only the model node is available there
		this.$element.detach();
	} else E{
		this.dimensions.setLabel(
			ve.msg( 'visualeditor-table-selection-dimensions',
				selection.getColCount(),
				selection.getRowCount()
			)
		);
		this.editButton.setLabel(
			selection.isSingleCell( documentModel ) ?
				ve.msg( 'visualeditor-table-merge-cells-unmerge' ) :
				ve.msg( 'visualeditor-table-merge-cells-merge' )
		);
	}
};
 
/* Registration */
 
ve.ui.contextItemFactory.register( ve.ui.MergeCellsContextItem );