All files / src/ui/tools ve.ui.ChangeDirectionalityTool.js

50% Statements 11/22
0% Branches 0/6
0% Functions 0/2
50% Lines 11/22

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                              1x                     1x       1x   1x   1x   1x     1x   1x   1x             1x                                           1x  
/*!
 * VisualEditor UserInterface ChangeDirectionalityTool class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * UserInterface change view directionality tool.
 *
 * @class
 * @extends ve.ui.Tool
 * @constructor
 * @param {OO.ui.ToolGroup} toolGroup
 * @param {Object} [config] Configuration options
 */
ve.ui.ChangeDirectionalityTool = function VeUiChangeDirectionalityTool() {
	// Parent constructor
	ve.ui.ChangeDirectionalityTool.super.apply( this, arguments );
 
	this.modelDir = null;
 
	this.setDisabled( false );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.ChangeDirectionalityTool, ve.ui.Tool );
 
/* Static Properties */
 
ve.ui.ChangeDirectionalityTool.static.name = 'changeDirectionality';
 
ve.ui.ChangeDirectionalityTool.static.group = 'utility';
 
ve.ui.ChangeDirectionalityTool.static.icon = 'textDirRTL';
 
ve.ui.ChangeDirectionalityTool.static.title =
	OO.ui.deferMsg( 'visualeditor-changedir-rtl' );
 
ve.ui.ChangeDirectionalityTool.static.autoAddToCatchall = false;
 
ve.ui.ChangeDirectionalityTool.static.commandName = 'changeDirectionality';
 
ve.ui.ChangeDirectionalityTool.static.deactivateOnSelect = false;
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.ChangeDirectionalityTool.prototype.onUpdateState = function ( fragment ) {
	// Parent method
	ve.ui.ChangeDirectionalityTool.super.prototype.onUpdateState.apply( this, arguments );
 
	var modelDir = fragment.getDocument().getDir();
 
	if ( modelDir !== this.modelDir ) {
		// Icons used here textDirLTR, textDirRTL
		this.setIcon( 'textDir' + ( modelDir === 'ltr' ? 'RTL' : 'LTR' ) );
		// The following messages are used here:
		// * visualeditor-changedir-tool-ltr
		// * visualeditor-changedir-tool-rtl
		this.setTitle( ve.msg( 'visualeditor-changedir-tool-' + ( modelDir === 'ltr' ? 'rtl' : 'ltr' ) ) );
		this.modelDir = modelDir;
	}
 
	var viewDir = this.toolbar.getSurface().getView().getDocument().getDir();
	this.setActive( viewDir !== modelDir );
};
 
/* Registration */
 
ve.ui.toolFactory.register( ve.ui.ChangeDirectionalityTool );