mediawiki-extensions-Visual.../modules/ve/ui/tools/ve.ui.DialogTool.js
Trevor Parscal a3295f0939 Allow direct opening of pages in the meta dialog
Objectives:

* Hamburger menu in actions area of toolbar
* Add tools that open specific pages in the meta dialog
* Fix support for using setPage in ve.ui.PagedOutlineLayout
* Allow passing setup config objects through window open calls
* Add dialog action, similar to inspector action
* Fix incorrect or missing documentation

Change-Id: I2d2c9b87554fb2a0c90ed6944a58b38a37efa712
2013-10-29 05:58:06 +00:00

99 lines
2 KiB
JavaScript

/*!
* VisualEditor UserInterface DialogTool class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* UserInterface dialog tool.
*
* @abstract
* @class
* @extends OO.ui.Tool
* @constructor
* @param {OO.ui.ToolGroup} toolGroup
* @param {Object} [config] Configuration options
*/
ve.ui.DialogTool = function VeUiDialogTool( toolGroup, config ) {
// Parent constructor
OO.ui.Tool.call( this, toolGroup, config );
};
/* Inheritance */
OO.inheritClass( ve.ui.DialogTool, OO.ui.Tool );
/* Static Properties */
/**
* Symbolic name of dialog the tool opens.
*
* @abstract
* @static
* @property {string}
* @inheritable
*/
ve.ui.DialogTool.static.dialog = '';
/**
* Configuration options for setting up dialog.
*
* @abstract
* @static
* @property {Object}
* @inheritable
*/
ve.ui.DialogTool.static.config = {};
/**
* Annotation or node models this tool is related to.
*
* Used by #isCompatibleWith.
*
* @static
* @property {Function[]}
* @inheritable
*/
ve.ui.DialogTool.static.modelClasses = [];
/**
* @inheritdoc
*/
ve.ui.DialogTool.static.isCompatibleWith = function ( model ) {
return ve.isInstanceOfAny( model, this.modelClasses );
};
/* Methods */
/**
* Handle the tool being selected.
*
* @method
*/
ve.ui.DialogTool.prototype.onSelect = function () {
this.toolbar.getSurface().execute(
'dialog',
'open',
this.constructor.static.dialog,
this.constructor.static.config
);
this.setActive( false );
};
/**
* Handle the toolbar state being updated.
*
* @method
* @param {ve.dm.Node[]} nodes List of nodes covered by the current selection
* @param {ve.dm.AnnotationSet} full Annotations that cover all of the current selection
* @param {ve.dm.AnnotationSet} partial Annotations that cover some or all of the current selection
*/
ve.ui.DialogTool.prototype.onUpdateState = function ( nodes ) {
if ( nodes.length ) {
this.setActive(
this.toolbar.getToolFactory().getToolForNode( nodes[0] ) === this.constructor
);
}
};