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

50% Statements 13/26
50% Branches 2/4
16.66% Functions 1/6
50% Lines 13/26

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                                1x                                               1x       1x   1x   1x   1x   1x   1x 24x               1x                   1x       1x           1x  
/*!
 * VisualEditor Alignable class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Context item for an alignable node.
 *
 * @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.AlignableContextItem = function VeUiAlignableContextItem( context, model, config ) {
	// Parent constructor
	ve.ui.AlignableContextItem.super.call( this, context, model, config );
 
	var align = model.getAttribute( 'align' );
 
	this.align = new ve.ui.AlignWidget( {
		dir: this.context.getSurface().getDir()
	} );
	this.align.selectItemByData( align );
	this.align.connect( this, { choose: 'onAlignChoose' } );
 
	if ( OO.ui.isMobile() ) {
		this.align.items.forEach( function ( item ) {
			item.setInvisibleLabel( true );
		} );
	}
 
	// Initialization
	this.$element.addClass( 've-ui-alignableContextItem' );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.AlignableContextItem, ve.ui.LinearContextItem );
 
/* Static Properties */
 
ve.ui.AlignableContextItem.static.name = 'alignable';
 
ve.ui.AlignableContextItem.static.icon = 'alignLeft';
 
ve.ui.AlignableContextItem.static.label = OO.ui.deferMsg( 'visualeditor-alignablecontextitem-title' );
 
ve.ui.AlignableContextItem.static.editable = false;
 
ve.ui.AlignableContextItem.static.exclusive = false;
 
ve.ui.AlignableContextItem.static.isCompatibleWith = function ( model ) {
	return model instanceof ve.dm.Node && model.isAlignable();
};
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.AlignableContextItem.prototype.setup = function () {
	this.align.setDisabled( this.context.getSurface().isReadOnly() );
 
	// Parent method
	ve.ui.AlignableContextItem.super.prototype.setup.apply( this, arguments );
};
 
/**
 * @inheritdoc
 */
ve.ui.AlignableContextItem.prototype.renderBody = function () {
	this.$body.empty().append( this.align.$element );
};
 
ve.ui.AlignableContextItem.prototype.onAlignChoose = function ( item ) {
	this.getFragment().changeAttributes( { align: item.getData() } );
};
 
/* Registration */
 
ve.ui.contextItemFactory.register( ve.ui.AlignableContextItem );