PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
← All changes | admin/js/edit/data/contextmenu.js +55 -55 trunk3.0 View file →
@@ -7,9 +7,9 @@
7 7 * @since 2.0.0
8 8 */
9 9
10 10 /* globals tp */
11 -/* eslint-disable jsdoc/check-param-names, jsdoc/no-undefined-types */
11 +/* eslint-disable jsdoc/check-param-names, jsdoc/valid-types, jsdoc/no-undefined-types */
12 12
13 13 /**
14 14 * WordPress dependencies.
15 15 */
@@ -25,22 +25,22 @@
25 25 * @param {[type]} e [description]
26 26 * @return {Array} Context menu items.
27 27 */
28 28 const contextMenu = ( obj /*, x, y, e */ ) => {
29 - const numRows = tp.editor.options.data.length;
30 - const numColumns = tp.editor.options.columns.length;
31 - const numSelectedRows = tp.helpers.selection.rows.length;
32 - const numSelectedColumns = tp.helpers.selection.columns.length;
33 - const isMac = window?.navigator?.platform?.includes( 'Mac' );
34 - const metaKey = isMac ?
29 + const num_rows = tp.editor.options.data.length;
30 + const num_columns = tp.editor.options.columns.length;
31 + const num_selected_rows = tp.helpers.selection.rows.length;
32 + const num_selected_columns = tp.helpers.selection.columns.length;
33 + const is_mac = window?.navigator?.platform?.includes( 'Mac' );
34 + const meta_key = is_mac ?
35 35 _x( '⌘', 'keyboard shortcut modifier key on a Mac keyboard', 'tablepress' ) :
36 36 _x( 'Ctrl+', 'keyboard shortcut modifier key on a non-Mac keyboard', 'tablepress' );
37 - const optionKey = isMac ?
37 + const option_key = is_mac ?
38 38 _x( '⌥', 'keyboard shortcut option key on a Mac keyboard', 'tablepress' ) :
39 39 _x( 'Alt+', 'keyboard shortcut Alt key on a non-Mac keyboard', 'tablepress' );
40 40
41 41 // Call-by-reference object for the cell_merge_allowed() call.
42 - const errorMessage = {
42 + const error_message = {
43 43 text: '',
44 44 };
45 45
46 46 tp.helpers.visibility.update();
@@ -48,15 +48,15 @@
48 48 const items = [
49 49 // Undo/Redo.
50 50 {
51 51 title: __( 'Undo', 'tablepress' ),
52 - shortcut: sprintf( _x( '%1$sZ', 'keyboard shortcut for Undo', 'tablepress' ), metaKey ),
52 + shortcut: sprintf( _x( '%1$sZ', 'keyboard shortcut for Undo', 'tablepress' ), meta_key ),
53 53 onclick: obj.undo,
54 54 disabled: ( -1 === obj.historyIndex ),
55 55 },
56 56 {
57 57 title: __( 'Redo', 'tablepress' ),
58 - shortcut: sprintf( _x( '%1$sY', 'keyboard shortcut for Redo', 'tablepress' ), metaKey ),
58 + shortcut: sprintf( _x( '%1$sY', 'keyboard shortcut for Redo', 'tablepress' ), meta_key ),
59 59 onclick: obj.redo,
60 60 disabled: ( obj.historyIndex === obj.history.length - 1 ),
61 61 },
62 62
@@ -65,9 +65,9 @@
65 65 type: 'divisor',
66 66 },
67 67 {
68 68 title: __( 'Cut', 'tablepress' ),
69 - shortcut: sprintf( _x( '%1$sX', 'keyboard shortcut for Cut', 'tablepress' ), metaKey ),
69 + shortcut: sprintf( _x( '%1$sX', 'keyboard shortcut for Cut', 'tablepress' ), meta_key ),
70 70 onclick() {
71 71 /* eslint-disable @wordpress/no-global-active-element */
72 72 if ( 'TEXTAREA' === document.activeElement.tagName && document.activeElement.selectionStart !== document.activeElement.selectionEnd ) {
73 73 document.execCommand( 'copy' ); // If text is selected in the actively edited cell, only copy that.
@@ -82,9 +82,9 @@
82 82 },
83 83 },
84 84 {
85 85 title: __( 'Copy', 'tablepress' ),
86 - shortcut: sprintf( _x( '%1$sC', 'keyboard shortcut for Copy', 'tablepress' ), metaKey ),
86 + shortcut: sprintf( _x( '%1$sC', 'keyboard shortcut for Copy', 'tablepress' ), meta_key ),
87 87 onclick() {
88 88 if ( 'TEXTAREA' === document.activeElement.tagName && document.activeElement.selectionStart !== document.activeElement.selectionEnd ) { // eslint-disable-line @wordpress/no-global-active-element
89 89 document.execCommand( 'copy' ); // If text is selected in the actively edited cell, only copy that.
90 90 } else {
@@ -93,9 +93,9 @@
93 93 },
94 94 },
95 95 {
96 96 title: __( 'Paste', 'tablepress' ),
97 - shortcut: sprintf( _x( '%1$sV', 'keyboard shortcut for Paste', 'tablepress' ), metaKey ),
97 + shortcut: sprintf( _x( '%1$sV', 'keyboard shortcut for Paste', 'tablepress' ), meta_key ),
98 98 onclick() {
99 99 /* eslint-disable @wordpress/no-global-active-element */
100 100 if ( 'TEXTAREA' === document.activeElement.tagName ) {
101 101 window.navigator.clipboard.readText().then( ( text ) => {
@@ -124,19 +124,19 @@
124 124 type: 'divisor',
125 125 },
126 126 {
127 127 title: __( 'Insert Link', 'tablepress' ),
128 - shortcut: sprintf( _x( '%1$sL', 'keyboard shortcut for Insert Link', 'tablepress' ), metaKey ),
128 + shortcut: sprintf( _x( '%1$sL', 'keyboard shortcut for Insert Link', 'tablepress' ), meta_key ),
129 129 onclick: tp.callbacks.insert_link.open_dialog.bind( null, ( 'TEXTAREA' === document.activeElement.tagName ) ? document.activeElement : null ), // eslint-disable-line @wordpress/no-global-active-element
130 130 },
131 131 {
132 132 title: __( 'Insert Image', 'tablepress' ),
133 - shortcut: sprintf( _x( '%1$sI', 'keyboard shortcut for Insert Image', 'tablepress' ), metaKey ),
133 + shortcut: sprintf( _x( '%1$sI', 'keyboard shortcut for Insert Image', 'tablepress' ), meta_key ),
134 134 onclick: tp.callbacks.insert_image.open_dialog.bind( null, ( 'TEXTAREA' === document.activeElement.tagName ) ? document.activeElement : null ), // eslint-disable-line @wordpress/no-global-active-element
135 135 },
136 136 {
137 137 title: __( 'Advanced Editor', 'tablepress' ),
138 - shortcut: sprintf( _x( '%1$sE', 'keyboard shortcut for Advanced Editor', 'tablepress' ), metaKey ),
138 + shortcut: sprintf( _x( '%1$sE', 'keyboard shortcut for Advanced Editor', 'tablepress' ), meta_key ),
139 139 onclick: tp.callbacks.advanced_editor.open_dialog.bind( null, ( 'TEXTAREA' === document.activeElement.tagName ) ? document.activeElement : null ), // eslint-disable-line @wordpress/no-global-active-element
140 140 },
141 141
142 142 // Duplicate/Insert/Append/Delete.
@@ -146,13 +146,13 @@
146 146 {
147 147 title: __( 'Duplicate …', 'tablepress' ),
148 148 submenu: [
149 149 {
150 - title: _n( 'Duplicate row', 'Duplicate rows', numSelectedRows, 'tablepress' ),
150 + title: _n( 'Duplicate row', 'Duplicate rows', num_selected_rows, 'tablepress' ),
151 151 onclick: tp.callbacks.insert_duplicate.bind( null, 'duplicate', 'rows' ),
152 152 },
153 153 {
154 - title: _n( 'Duplicate column', 'Duplicate columns', numSelectedColumns, 'tablepress' ),
154 + title: _n( 'Duplicate column', 'Duplicate columns', num_selected_columns, 'tablepress' ),
155 155 onclick: tp.callbacks.insert_duplicate.bind( null, 'duplicate', 'columns' ),
156 156 },
157 157 ],
158 158 },
@@ -159,21 +159,21 @@
159 159 {
160 160 title: __( 'Insert …', 'tablepress' ),
161 161 submenu: [
162 162 {
163 - title: _n( 'Insert row above', 'Insert rows above', numSelectedRows, 'tablepress' ),
163 + title: _n( 'Insert row above', 'Insert rows above', num_selected_rows, 'tablepress' ),
164 164 onclick: tp.callbacks.insert_duplicate.bind( null, 'insert', 'rows', 'before' ),
165 165 },
166 166 {
167 - title: _n( 'Insert row below', 'Insert rows below', numSelectedRows, 'tablepress' ),
167 + title: _n( 'Insert row below', 'Insert rows below', num_selected_rows, 'tablepress' ),
168 168 onclick: tp.callbacks.insert_duplicate.bind( null, 'insert', 'rows', 'after' ),
169 169 },
170 170 {
171 - title: _n( 'Insert column on the left', 'Insert columns on the left', numSelectedColumns, 'tablepress' ),
171 + title: _n( 'Insert column on the left', 'Insert columns on the left', num_selected_columns, 'tablepress' ),
172 172 onclick: tp.callbacks.insert_duplicate.bind( null, 'insert', 'columns', 'before' ),
173 173 },
174 174 {
175 - title: _n( 'Insert column on the right', 'Insert columns on the right', numSelectedColumns, 'tablepress' ),
175 + title: _n( 'Insert column on the right', 'Insert columns on the right', num_selected_columns, 'tablepress' ),
176 176 onclick: tp.callbacks.insert_duplicate.bind( null, 'insert', 'columns', 'after' ),
177 177 },
178 178 ],
179 179 },
@@ -193,18 +193,18 @@
193 193 {
194 194 title: __( 'Delete …', 'tablepress' ),
195 195 submenu: [
196 196 {
197 - title: _n( 'Delete row', 'Delete rows', numSelectedRows, 'tablepress' ),
197 + title: _n( 'Delete row', 'Delete rows', num_selected_rows, 'tablepress' ),
198 198 onclick: tp.callbacks.remove.bind( null, 'rows' ),
199 - disabled: numRows === numSelectedRows,
200 - tooltip: numRows === numSelectedRows ? __( 'This option is disabled.', 'tablepress' ) + ' ' + __( 'You can not delete all table rows!', 'tablepress' ) : '',
199 + disabled: num_rows === num_selected_rows,
200 + tooltip: num_rows === num_selected_rows ? __( 'This option is disabled.', 'tablepress' ) + ' ' + __( 'You can not delete all table rows!', 'tablepress' ) : '',
201 201 },
202 202 {
203 - title: _n( 'Delete column', 'Delete columns', numSelectedColumns, 'tablepress' ),
203 + title: _n( 'Delete column', 'Delete columns', num_selected_columns, 'tablepress' ),
204 204 onclick: tp.callbacks.remove.bind( null, 'columns' ),
205 - disabled: numColumns === numSelectedColumns,
206 - tooltip: numColumns === numSelectedColumns ? __( 'This option is disabled.', 'tablepress' ) + ' ' + __( 'You can not delete all table columns!', 'tablepress' ) : '',
205 + disabled: num_columns === num_selected_columns,
206 + tooltip: num_columns === num_selected_columns ? __( 'This option is disabled.', 'tablepress' ) + ' ' + __( 'You can not delete all table columns!', 'tablepress' ) : '',
207 207 },
208 208 ],
209 209 },
210 210
@@ -215,28 +215,28 @@
215 215 {
216 216 title: __( 'Move …', 'tablepress' ),
217 217 submenu: [
218 218 {
219 - title: _n( 'Move row up', 'Move rows up', numSelectedRows, 'tablepress' ),
220 - shortcut: sprintf( _x( '%1$s⇧↑', 'keyboard shortcut for Move up', 'tablepress' ), metaKey ),
219 + title: _n( 'Move row up', 'Move rows up', num_selected_rows, 'tablepress' ),
220 + shortcut: sprintf( _x( '%1$s⇧↑', 'keyboard shortcut for Move up', 'tablepress' ), meta_key ),
221 221 onclick: tp.callbacks.move.bind( null, 'up', 'rows' ),
222 222 disabled: ! tp.helpers.move_allowed( 'rows', 'up' ),
223 223 },
224 224 {
225 - title: _n( 'Move row down', 'Move rows down', numSelectedRows, 'tablepress' ),
226 - shortcut: sprintf( _x( '%1$s⇧↓', 'keyboard shortcut for Move down', 'tablepress' ), metaKey ),
225 + title: _n( 'Move row down', 'Move rows down', num_selected_rows, 'tablepress' ),
226 + shortcut: sprintf( _x( '%1$s⇧↓', 'keyboard shortcut for Move down', 'tablepress' ), meta_key ),
227 227 onclick: tp.callbacks.move.bind( null, 'down', 'rows' ),
228 228 disabled: ! tp.helpers.move_allowed( 'rows', 'down' ),
229 229 },
230 230 {
231 - title: _n( 'Move column left', 'Move columns left', numSelectedColumns, 'tablepress' ),
232 - shortcut: sprintf( _x( '%1$s⇧←', 'keyboard shortcut for Move left', 'tablepress' ), metaKey ),
231 + title: _n( 'Move column left', 'Move columns left', num_selected_columns, 'tablepress' ),
232 + shortcut: sprintf( _x( '%1$s⇧←', 'keyboard shortcut for Move left', 'tablepress' ), meta_key ),
233 233 onclick: tp.callbacks.move.bind( null, 'left', 'columns' ),
234 234 disabled: ! tp.helpers.move_allowed( 'columns', 'left' ),
235 235 },
236 236 {
237 - title: _n( 'Move column right', 'Move columns right', numSelectedColumns, 'tablepress' ),
238 - shortcut: sprintf( _x( '%1$s⇧→', 'keyboard shortcut for Move right', 'tablepress' ), metaKey ),
237 + title: _n( 'Move column right', 'Move columns right', num_selected_columns, 'tablepress' ),
238 + shortcut: sprintf( _x( '%1$s⇧→', 'keyboard shortcut for Move right', 'tablepress' ), meta_key ),
239 239 onclick: tp.callbacks.move.bind( null, 'right', 'columns' ),
240 240 disabled: ! tp.helpers.move_allowed( 'columns', 'right' ),
241 241 },
242 242 {
@@ -242,28 +242,28 @@
242 242 {
243 243 type: 'divisor',
244 244 },
245 245 {
246 - title: _n( 'Move row to the top', 'Move rows to the top', numSelectedRows, 'tablepress' ),
247 - shortcut: sprintf( _x( '%1$s%2$s⇧↑', 'keyboard shortcut for Move to the top', 'tablepress' ), metaKey, optionKey ),
246 + title: _n( 'Move row to the top', 'Move rows to the top', num_selected_rows, 'tablepress' ),
247 + shortcut: sprintf( _x( '%1$s%2$s⇧↑', 'keyboard shortcut for Move to the top', 'tablepress' ), meta_key, option_key ),
248 248 onclick: tp.callbacks.move.bind( null, 'top', 'rows' ),
249 249 disabled: ! tp.helpers.move_allowed( 'rows', 'top' ),
250 250 },
251 251 {
252 - title: _n( 'Move row to the bottom', 'Move rows to the bottom', numSelectedRows, 'tablepress' ),
253 - shortcut: sprintf( _x( '%1$s%2$s⇧↓', 'keyboard shortcut for Move to the bottom', 'tablepress' ), metaKey, optionKey ),
252 + title: _n( 'Move row to the bottom', 'Move rows to the bottom', num_selected_rows, 'tablepress' ),
253 + shortcut: sprintf( _x( '%1$s%2$s⇧↓', 'keyboard shortcut for Move to the bottom', 'tablepress' ), meta_key, option_key ),
254 254 onclick: tp.callbacks.move.bind( null, 'bottom', 'rows' ),
255 255 disabled: ! tp.helpers.move_allowed( 'rows', 'bottom' ),
256 256 },
257 257 {
258 - title: _n( 'Move column to first', 'Move columns to first', numSelectedColumns, 'tablepress' ),
259 - shortcut: sprintf( _x( '%1$s%2$s⇧←', 'keyboard shortcut for Move to first', 'tablepress' ), metaKey, optionKey ),
258 + title: _n( 'Move column to first', 'Move columns to first', num_selected_columns, 'tablepress' ),
259 + shortcut: sprintf( _x( '%1$s%2$s⇧←', 'keyboard shortcut for Move to first', 'tablepress' ), meta_key, option_key ),
260 260 onclick: tp.callbacks.move.bind( null, 'first', 'columns' ),
261 261 disabled: ! tp.helpers.move_allowed( 'columns', 'first' ),
262 262 },
263 263 {
264 - title: _n( 'Move column to last', 'Move columns to last', numSelectedColumns, 'tablepress' ),
265 - shortcut: sprintf( _x( '%1$s%2$s⇧→', 'keyboard shortcut for Move to last', 'tablepress' ), metaKey, optionKey ),
264 + title: _n( 'Move column to last', 'Move columns to last', num_selected_columns, 'tablepress' ),
265 + shortcut: sprintf( _x( '%1$s%2$s⇧→', 'keyboard shortcut for Move to last', 'tablepress' ), meta_key, option_key ),
266 266 onclick: tp.callbacks.move.bind( null, 'last', 'columns' ),
267 267 disabled: ! tp.helpers.move_allowed( 'columns', 'last' ),
268 268 },
269 269 ],
@@ -273,16 +273,16 @@
273 273 submenu: [
274 274 {
275 275 title: __( 'Sort by column ascending', 'tablepress' ),
276 276 onclick: tp.callbacks.sort.bind( null, 'asc' ),
277 - disabled: 1 !== numSelectedColumns,
278 - tooltip: 1 !== numSelectedColumns ? __( 'This option is disabled because more than one column was selected.', 'tablepress' ) : '',
277 + disabled: 1 !== num_selected_columns,
278 + tooltip: 1 !== num_selected_columns ? __( 'This option is disabled because more than one column was selected.', 'tablepress' ) : '',
279 279 },
280 280 {
281 281 title: __( 'Sort by column descending', 'tablepress' ),
282 282 onclick: tp.callbacks.sort.bind( null, 'desc' ),
283 - disabled: 1 !== numSelectedColumns,
284 - tooltip: 1 !== numSelectedColumns ? __( 'This option is disabled because more than one column was selected.', 'tablepress' ) : '',
283 + disabled: 1 !== num_selected_columns,
284 + tooltip: 1 !== num_selected_columns ? __( 'This option is disabled because more than one column was selected.', 'tablepress' ) : '',
285 285 },
286 286 ],
287 287 },
288 288
@@ -293,27 +293,27 @@
293 293 {
294 294 title: __( 'Hide/Show …', 'tablepress' ),
295 295 submenu: [
296 296 {
297 - title: _n( 'Hide row', 'Hide rows', numSelectedRows, 'tablepress' ),
297 + title: _n( 'Hide row', 'Hide rows', num_selected_rows, 'tablepress' ),
298 298 onclick: tp.callbacks.hide_unhide.bind( null, 'hide', 'rows' ),
299 299 disabled: ! tp.helpers.visibility.selection_contains( 'rows', 1 ),
300 300 tooltip: ! tp.helpers.visibility.selection_contains( 'rows', 1 ) ? __( 'This option is disabled because no visible rows were selected.', 'tablepress' ) : '',
301 301 },
302 302 {
303 - title: _n( 'Hide column', 'Hide columns', numSelectedColumns, 'tablepress' ),
303 + title: _n( 'Hide column', 'Hide columns', num_selected_columns, 'tablepress' ),
304 304 onclick: tp.callbacks.hide_unhide.bind( null, 'hide', 'columns' ),
305 305 disabled: ! tp.helpers.visibility.selection_contains( 'columns', 1 ),
306 306 tooltip: ! tp.helpers.visibility.selection_contains( 'columns', 1 ) ? __( 'This option is disabled because no visible columns were selected.', 'tablepress' ) : '',
307 307 },
308 308 {
309 - title: _n( 'Show row', 'Show rows', numSelectedRows, 'tablepress' ),
309 + title: _n( 'Show row', 'Show rows', num_selected_rows, 'tablepress' ),
310 310 onclick: tp.callbacks.hide_unhide.bind( null, 'unhide', 'rows' ),
311 311 disabled: ! tp.helpers.visibility.selection_contains( 'rows', 0 ),
312 312 tooltip: ! tp.helpers.visibility.selection_contains( 'rows', 0 ) ? __( 'This option is disabled because no hidden rows were selected.', 'tablepress' ) : '',
313 313 },
314 314 {
315 - title: _n( 'Show column', 'Show columns', numSelectedColumns, 'tablepress' ),
315 + title: _n( 'Show column', 'Show columns', num_selected_columns, 'tablepress' ),
316 316 onclick: tp.callbacks.hide_unhide.bind( null, 'unhide', 'columns' ),
317 317 disabled: ! tp.helpers.visibility.selection_contains( 'columns', 0 ),
318 318 tooltip: ! tp.helpers.visibility.selection_contains( 'columns', 0 ) ? __( 'This option is disabled because no hidden columns were selected.', 'tablepress' ) : '',
319 319 },
@@ -326,10 +326,10 @@
326 326 },
327 327 {
328 328 title: __( 'Combine/Merge cells', 'tablepress' ),
329 329 onclick: tp.callbacks.merge_cells,
330 - disabled: ( 1 === numSelectedRows && 1 === numSelectedColumns ) || ! tp.helpers.cell_merge_allowed( 'no-alert' ),
331 - tooltip: ( 1 === numSelectedRows && 1 === numSelectedColumns ) || ! tp.helpers.cell_merge_allowed( 'no-alert', errorMessage ) ? __( 'This option is disabled.', 'tablepress' ) + ' ' + errorMessage.text : '',
330 + disabled: ( 1 === num_selected_rows && 1 === num_selected_columns ) || ! tp.helpers.cell_merge_allowed( 'no-alert' ),
331 + tooltip: ( 1 === num_selected_rows && 1 === num_selected_columns ) || ! tp.helpers.cell_merge_allowed( 'no-alert', error_message ) ? __( 'This option is disabled.', 'tablepress' ) + ' ' + error_message.text : '',
332 332 },
333 333 ];
334 334
335 335 // Allow other scripts to modify the context menu.