Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/tools/ve.ui.FormatTool.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface FormatTool classes.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * UserInterface format tool.
9 *
10 * @abstract
11 * @class
12 * @extends ve.ui.Tool
13 * @constructor
14 * @param {OO.ui.ToolGroup} toolGroup
15 * @param {Object} [config] Configuration options
16 */
17 ve.ui.FormatTool = function VeUiFormatTool() {
18 // Parent constructor
19 ve.ui.FormatTool.super.apply( this, arguments );
20 };
21
22 /* Inheritance */
23
24 OO.inheritClass( ve.ui.FormatTool, ve.ui.Tool );
25
26 /* Static Properties */
27
28 ve.ui.FormatTool.static.deactivateOnSelect = false;
29
30 /**
31 * Format the tool applies.
32 *
33 * Object should contain a required `type` and optional `attributes` property.
34 *
35 * @abstract
36 * @static
37 * @property {Object}
38 * @inheritable
39 */
40 ve.ui.FormatTool.static.format = null;
41
42 ve.ui.FormatTool.static.fallbackIcon = 'textStyle';
43
44 /* Methods */
45
46 /**
47 * @inheritdoc
48 */
49 ve.ui.FormatTool.prototype.onUpdateState = function ( fragment ) {
50 // Parent method
51 ve.ui.FormatTool.super.prototype.onUpdateState.apply( this, arguments );
52
53 // Hide and de-activate disabled tools
54 if ( this.isDisabled() ) {
55 this.toggle( false );
56 this.setActive( false );
57 return;
58 }
59
60 this.toggle( true );
61
62 const format = this.constructor.static.format;
63 const isMatching = fragment.hasMatchingAncestor( format.type, format.attributes );
64
65 this.setActive( isMatching );
66 };
67
68 /**
69 * UserInterface paragraph tool.
70 *
71 * @class
72 * @extends ve.ui.FormatTool
73 * @constructor
74 * @param {OO.ui.ToolGroup} toolGroup
75 * @param {Object} [config] Configuration options
76 */
77 ve.ui.ParagraphFormatTool = function VeUiParagraphFormatTool() {
78 ve.ui.ParagraphFormatTool.super.apply( this, arguments );
79 };
80 OO.inheritClass( ve.ui.ParagraphFormatTool, ve.ui.FormatTool );
81 ve.ui.ParagraphFormatTool.static.name = 'paragraph';
82 ve.ui.ParagraphFormatTool.static.group = 'format';
83 ve.ui.ParagraphFormatTool.static.title =
84 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-paragraph' );
85 ve.ui.ParagraphFormatTool.static.format = { type: 'paragraph' };
86 ve.ui.ParagraphFormatTool.static.commandName = 'paragraph';
87 ve.ui.toolFactory.register( ve.ui.ParagraphFormatTool );
88
89 /**
90 * UserInterface heading 1 tool.
91 *
92 * @class
93 * @extends ve.ui.FormatTool
94 * @constructor
95 * @param {OO.ui.ToolGroup} toolGroup
96 * @param {Object} [config] Configuration options
97 */
98 ve.ui.Heading1FormatTool = function VeUiHeading1FormatTool() {
99 ve.ui.Heading1FormatTool.super.apply( this, arguments );
100 };
101 OO.inheritClass( ve.ui.Heading1FormatTool, ve.ui.FormatTool );
102 ve.ui.Heading1FormatTool.static.name = 'heading1';
103 ve.ui.Heading1FormatTool.static.group = 'format';
104 ve.ui.Heading1FormatTool.static.title =
105 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading1' );
106 ve.ui.Heading1FormatTool.static.format = { type: 'heading', attributes: { level: 1 } };
107 ve.ui.Heading1FormatTool.static.commandName = 'heading1';
108 ve.ui.toolFactory.register( ve.ui.Heading1FormatTool );
109
110 /**
111 * UserInterface heading 2 tool.
112 *
113 * @class
114 * @extends ve.ui.FormatTool
115 * @constructor
116 * @param {OO.ui.ToolGroup} toolGroup
117 * @param {Object} [config] Configuration options
118 */
119 ve.ui.Heading2FormatTool = function VeUiHeading2FormatTool() {
120 ve.ui.Heading2FormatTool.super.apply( this, arguments );
121 };
122 OO.inheritClass( ve.ui.Heading2FormatTool, ve.ui.FormatTool );
123 ve.ui.Heading2FormatTool.static.name = 'heading2';
124 ve.ui.Heading2FormatTool.static.group = 'format';
125 ve.ui.Heading2FormatTool.static.title =
126 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading2' );
127 ve.ui.Heading2FormatTool.static.format = { type: 'heading', attributes: { level: 2 } };
128 ve.ui.Heading2FormatTool.static.commandName = 'heading2';
129 ve.ui.toolFactory.register( ve.ui.Heading2FormatTool );
130
131 /**
132 * UserInterface heading 3 tool.
133 *
134 * @class
135 * @extends ve.ui.FormatTool
136 * @constructor
137 * @param {OO.ui.ToolGroup} toolGroup
138 * @param {Object} [config] Configuration options
139 */
140 ve.ui.Heading3FormatTool = function VeUiHeading3FormatTool() {
141 ve.ui.Heading3FormatTool.super.apply( this, arguments );
142 };
143 OO.inheritClass( ve.ui.Heading3FormatTool, ve.ui.FormatTool );
144 ve.ui.Heading3FormatTool.static.name = 'heading3';
145 ve.ui.Heading3FormatTool.static.group = 'format';
146 ve.ui.Heading3FormatTool.static.title =
147 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading3' );
148 ve.ui.Heading3FormatTool.static.format = { type: 'heading', attributes: { level: 3 } };
149 ve.ui.Heading3FormatTool.static.commandName = 'heading3';
150 ve.ui.toolFactory.register( ve.ui.Heading3FormatTool );
151
152 /**
153 * UserInterface heading 4 tool.
154 *
155 * @class
156 * @extends ve.ui.FormatTool
157 * @constructor
158 * @param {OO.ui.ToolGroup} toolGroup
159 * @param {Object} [config] Configuration options
160 */
161 ve.ui.Heading4FormatTool = function VeUiHeading4FormatTool() {
162 ve.ui.Heading4FormatTool.super.apply( this, arguments );
163 };
164 OO.inheritClass( ve.ui.Heading4FormatTool, ve.ui.FormatTool );
165 ve.ui.Heading4FormatTool.static.name = 'heading4';
166 ve.ui.Heading4FormatTool.static.group = 'format';
167 ve.ui.Heading4FormatTool.static.title =
168 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading4' );
169 ve.ui.Heading4FormatTool.static.format = { type: 'heading', attributes: { level: 4 } };
170 ve.ui.Heading4FormatTool.static.commandName = 'heading4';
171 ve.ui.toolFactory.register( ve.ui.Heading4FormatTool );
172
173 /**
174 * UserInterface heading 5 tool.
175 *
176 * @class
177 * @extends ve.ui.FormatTool
178 * @constructor
179 * @param {OO.ui.ToolGroup} toolGroup
180 * @param {Object} [config] Configuration options
181 */
182 ve.ui.Heading5FormatTool = function VeUiHeading5FormatTool() {
183 ve.ui.Heading5FormatTool.super.apply( this, arguments );
184 };
185 OO.inheritClass( ve.ui.Heading5FormatTool, ve.ui.FormatTool );
186 ve.ui.Heading5FormatTool.static.name = 'heading5';
187 ve.ui.Heading5FormatTool.static.group = 'format';
188 ve.ui.Heading5FormatTool.static.title =
189 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading5' );
190 ve.ui.Heading5FormatTool.static.format = { type: 'heading', attributes: { level: 5 } };
191 ve.ui.Heading5FormatTool.static.commandName = 'heading5';
192 ve.ui.toolFactory.register( ve.ui.Heading5FormatTool );
193
194 /**
195 * UserInterface heading 6 tool.
196 *
197 * @class
198 * @extends ve.ui.FormatTool
199 * @constructor
200 * @param {OO.ui.ToolGroup} toolGroup
201 * @param {Object} [config] Configuration options
202 */
203 ve.ui.Heading6FormatTool = function VeUiHeading6FormatTool() {
204 ve.ui.Heading6FormatTool.super.apply( this, arguments );
205 };
206 OO.inheritClass( ve.ui.Heading6FormatTool, ve.ui.FormatTool );
207 ve.ui.Heading6FormatTool.static.name = 'heading6';
208 ve.ui.Heading6FormatTool.static.group = 'format';
209 ve.ui.Heading6FormatTool.static.title =
210 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-heading6' );
211 ve.ui.Heading6FormatTool.static.format = { type: 'heading', attributes: { level: 6 } };
212 ve.ui.Heading6FormatTool.static.commandName = 'heading6';
213 ve.ui.toolFactory.register( ve.ui.Heading6FormatTool );
214
215 /**
216 * UserInterface preformatted tool.
217 *
218 * @class
219 * @extends ve.ui.FormatTool
220 * @constructor
221 * @param {OO.ui.ToolGroup} toolGroup
222 * @param {Object} [config] Configuration options
223 */
224 ve.ui.PreformattedFormatTool = function VeUiPreformattedFormatTool() {
225 ve.ui.PreformattedFormatTool.super.apply( this, arguments );
226 };
227 OO.inheritClass( ve.ui.PreformattedFormatTool, ve.ui.FormatTool );
228 ve.ui.PreformattedFormatTool.static.name = 'preformatted';
229 ve.ui.PreformattedFormatTool.static.group = 'format';
230 ve.ui.PreformattedFormatTool.static.title =
231 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-preformatted' );
232 ve.ui.PreformattedFormatTool.static.format = { type: 'preformatted' };
233 ve.ui.PreformattedFormatTool.static.commandName = 'preformatted';
234 ve.ui.toolFactory.register( ve.ui.PreformattedFormatTool );
235
236 /**
237 * UserInterface blockquote tool.
238 *
239 * @class
240 * @extends ve.ui.FormatTool
241 * @constructor
242 * @param {OO.ui.ToolGroup} toolGroup
243 * @param {Object} [config] Configuration options
244 */
245 ve.ui.BlockquoteFormatTool = function VeUiBlockquoteFormatTool() {
246 ve.ui.BlockquoteFormatTool.super.apply( this, arguments );
247 };
248 OO.inheritClass( ve.ui.BlockquoteFormatTool, ve.ui.FormatTool );
249 ve.ui.BlockquoteFormatTool.static.name = 'blockquote';
250 ve.ui.BlockquoteFormatTool.static.group = 'format';
251 ve.ui.BlockquoteFormatTool.static.title =
252 OO.ui.deferMsg( 'visualeditor-formatdropdown-format-blockquote' );
253 ve.ui.BlockquoteFormatTool.static.format = { type: 'blockquote' };
254 ve.ui.BlockquoteFormatTool.static.commandName = 'blockquote';
255 ve.ui.toolFactory.register( ve.ui.BlockquoteFormatTool );
256
257 /**
258 * UserInterface table cell header tool.
259 *
260 * @class
261 * @extends ve.ui.FormatTool
262 * @constructor
263 * @param {OO.ui.ToolGroup} toolGroup
264 * @param {Object} [config] Configuration options
265 */
266 ve.ui.TableCellHeaderFormatTool = function VeUiTableCellHeaderFormatTool() {
267 ve.ui.TableCellHeaderFormatTool.super.apply( this, arguments );
268 };
269 OO.inheritClass( ve.ui.TableCellHeaderFormatTool, ve.ui.FormatTool );
270 ve.ui.TableCellHeaderFormatTool.static.name = 'tableCellHeader';
271 ve.ui.TableCellHeaderFormatTool.static.group = 'format';
272 ve.ui.TableCellHeaderFormatTool.static.title =
273 OO.ui.deferMsg( 'visualeditor-table-format-header' );
274 ve.ui.TableCellHeaderFormatTool.static.format = { type: 'tableCell', attributes: { style: 'header' } };
275 ve.ui.TableCellHeaderFormatTool.static.commandName = 'tableCellHeader';
276 ve.ui.toolFactory.register( ve.ui.TableCellHeaderFormatTool );
277
278 /**
279 * UserInterface table cell data tool.
280 *
281 * @class
282 * @extends ve.ui.FormatTool
283 * @constructor
284 * @param {OO.ui.ToolGroup} toolGroup
285 * @param {Object} [config] Configuration options
286 */
287 ve.ui.TableCellDataFormatTool = function VeUiTableCellDataFormatTool() {
288 ve.ui.TableCellDataFormatTool.super.apply( this, arguments );
289 };
290 OO.inheritClass( ve.ui.TableCellDataFormatTool, ve.ui.FormatTool );
291 ve.ui.TableCellDataFormatTool.static.name = 'tableCellData';
292 ve.ui.TableCellDataFormatTool.static.group = 'format';
293 ve.ui.TableCellDataFormatTool.static.title =
294 OO.ui.deferMsg( 'visualeditor-table-format-data' );
295 ve.ui.TableCellDataFormatTool.static.format = { type: 'tableCell', attributes: { style: 'data' } };
296 ve.ui.TableCellDataFormatTool.static.commandName = 'tableCellData';
297 ve.ui.toolFactory.register( ve.ui.TableCellDataFormatTool );