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

85.71% Statements 18/21
80% Branches 4/5
66.66% Functions 2/3
85.71% Lines 18/21

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                                1x   1x     1x   1x       1x 1x       1x   1x         1x       1x   1x   1x   1x   1x             1x 24x           1x                       1x  
/*!
 * VisualEditor TableContextItem class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Context item for tables.
 *
 * @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.TableContextItem = function VeUiTableContextItem( context, model, config ) {
	// Parent constructor
	ve.ui.TableContextItem.super.call( this, context, model, config );
 
	// Initialization
	this.$element.addClass( 've-ui-tableContextItem' );
 
	this.deleteButton = new OO.ui.ButtonWidget( {
		label: ve.msg( 'visualeditor-contextitemwidget-label-remove' ),
		flags: [ 'destructive' ]
	} );
	Eif ( !this.isReadOnly() ) {
		this.actionButtons.addItems( [ this.deleteButton, this.editButton ] );
	}
 
	// Events
	this.deleteButton.connect( this, { click: 'onDeleteButtonClick' } );
 
	this.editButton.setLabel( ve.msg( 'visualeditor-table-contextitem-properties' ) );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.TableContextItem, ve.ui.LinearContextItem );
 
/* Static Properties */
 
ve.ui.TableContextItem.static.name = 'table';
 
ve.ui.TableContextItem.static.icon = 'table';
 
ve.ui.TableContextItem.static.label = OO.ui.deferMsg( 'visualeditor-toolbar-table' );
 
ve.ui.TableContextItem.static.commandName = 'table';
 
ve.ui.TableContextItem.static.embeddable = false;
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.TableContextItem.static.isCompatibleWith = function ( model ) {
	return model instanceof ve.dm.Node && model.isCellable() && !OO.ui.isMobile();
};
 
/**
 * Handle delete button click events.
 */
ve.ui.TableContextItem.prototype.onDeleteButtonClick = function () {
	const surfaceModel = this.getFragment().getSurface();
 
	surfaceModel.getLinearFragment(
		surfaceModel.getSelectedNode().findParent( ve.dm.TableNode ).getOuterRange()
	).delete();
 
	ve.track( 'activity.table', { action: 'context-delete' } );
};
 
/* Registration */
 
ve.ui.contextItemFactory.register( ve.ui.TableContextItem );