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

42.1% Statements 8/19
0% Branches 0/4
25% Functions 1/4
47.05% Lines 8/17

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                                1x             1x                         1x   1x             1x 96x           1x                                               1x      
/*!
 * VisualEditor UserInterface FragmentWindowTool classes.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * UserInterface fragment window tool.
 *
 * @abstract
 * @class
 * @extends ve.ui.WindowTool
 * @constructor
 * @param {OO.ui.ToolGroup} toolGroup
 * @param {Object} [config] Configuration options
 */
ve.ui.FragmentWindowTool = function VeUiFragmentWindowTool() {
	// Parent constructor
	ve.ui.FragmentWindowTool.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.FragmentWindowTool, ve.ui.WindowTool );
 
/* Static Properties */
 
/**
 * Annotation or node models this tool is related to.
 *
 * Used by #isCompatibleWith.
 *
 * @static
 * @property {Function[]}
 * @inheritable
 */
ve.ui.FragmentWindowTool.static.modelClasses = [];
 
ve.ui.FragmentWindowTool.static.deactivateOnSelect = false;
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.FragmentWindowTool.static.isCompatibleWith = function ( model ) {
	return ve.isInstanceOfAny( model, this.modelClasses );
};
 
/**
 * @inheritdoc
 */
ve.ui.FragmentWindowTool.prototype.onUpdateState = function ( fragment ) {
	this.setActive( false );
 
	// Grand-parent method
	// Parent method is skipped because it set's active state based on which windows
	// are open, which we override in this implementation
	ve.ui.FragmentWindowTool.super.super.prototype.onUpdateState.apply( this, arguments );
 
	var models = this.getSelectedModels( fragment );
 
	for ( var i = 0, len = models.length; i < len; i++ ) {
		if ( this.constructor.static.isCompatibleWith( models[ i ] ) ) {
			this.setActive( true );
			break;
		}
	}
};
 
/**
 * Get list of selected nodes and annotations.
 *
 * @param {ve.dm.SurfaceFragment|null} fragment Surface fragment
 * @return {ve.dm.Model[]} Selected models
 */
ve.ui.FragmentWindowTool.prototype.getSelectedModels = function ( fragment ) {
	return fragment ? fragment.getSelectedModels() : [];
};