Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/widgets/ve.ui.ContextOptionWidget.js

raw symbols SCIP
1 /*!
2 * VisualEditor Context Item widget class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Proxy for a tool, displaying information about the current context.
9 *
10 * Use with ve.ui.ContextSelectWidget.
11 *
12 * @class
13 * @extends OO.ui.DecoratedOptionWidget
14 *
15 * @constructor
16 * @param {Function} tool Tool item is a proxy for
17 * @param {ve.dm.Node|ve.dm.Annotation} model Node or annotation item is related to
18 * @param {Object} [config] Configuration options
19 */
20 ve.ui.ContextOptionWidget = function VeUiContextOptionWidget( tool, model, config ) {
21 // Config initialization
22 config = config || {};
23
24 // Parent constructor
25 ve.ui.ContextOptionWidget.super.call( this, config );
26
27 // Properties
28 this.tool = tool;
29 this.model = model;
30
31 // Initialization
32 this.$element.addClass( 've-ui-contextOptionWidget' );
33 this.setIcon( this.tool.static.icon );
34
35 this.setLabel( this.getDescription() );
36 };
37
38 /* Setup */
39
40 OO.inheritClass( ve.ui.ContextOptionWidget, OO.ui.DecoratedOptionWidget );
41
42 /* Methods */
43
44 /**
45 * Get a description of the model.
46 *
47 * @return {string} Description of model
48 */
49 ve.ui.ContextOptionWidget.prototype.getDescription = function () {
50 let description;
51
52 if ( this.model instanceof ve.dm.Annotation ) {
53 description = ve.ce.annotationFactory.getDescription( this.model );
54 } else if ( this.model instanceof ve.dm.Node ) {
55 description = ve.ce.nodeFactory.getDescription( this.model );
56 }
57 if ( !description ) {
58 description = this.tool.static.title;
59 }
60
61 return description;
62 };
63
64 /**
65 * Get the command for this item.
66 *
67 * @return {ve.ui.Command}
68 */
69 ve.ui.ContextOptionWidget.prototype.getCommand = function () {
70 return this.tool.static.getCommand( this.context.getSurface() );
71 };