@refinitiv-ui/efx-grid 6.0.117 → 6.0.118
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/grid/index.js +1 -1
- package/lib/grid/themes/halo/dark/efx-grid.js +1 -1
- package/lib/grid/themes/halo/dark/es5/all-elements.js +1 -1
- package/lib/grid/themes/halo/light/efx-grid.js +1 -1
- package/lib/grid/themes/halo/light/es5/all-elements.js +1 -1
- package/lib/grid/themes/solar/charcoal/efx-grid.js +1 -1
- package/lib/grid/themes/solar/charcoal/es5/all-elements.js +1 -1
- package/lib/grid/themes/solar/pearl/efx-grid.js +1 -1
- package/lib/grid/themes/solar/pearl/es5/all-elements.js +1 -1
- package/lib/row-segmenting/es6/RowSegmenting.js +7 -5
- package/lib/tr-grid-auto-tooltip/es6/AutoTooltip.d.ts +1 -0
- package/lib/tr-grid-auto-tooltip/es6/AutoTooltip.js +200 -26
- package/lib/tr-grid-contextmenu/es6/ContextMenu.js +11 -0
- package/lib/tr-grid-contextmenu/es6/MenuItem.d.ts +3 -1
- package/lib/tr-grid-contextmenu/es6/MenuItem.js +28 -28
- package/lib/tr-grid-contextmenu/es6/PopupMenu.d.ts +5 -1
- package/lib/tr-grid-contextmenu/es6/PopupMenu.js +48 -40
- package/lib/tr-grid-util/es6/GroupDefinitions.js +1 -1
- package/lib/types/es6/MenuEventAPI.d.ts +1 -1
- package/lib/types/es6/MenuItem.d.ts +3 -1
- package/lib/types/es6/PopupMenu.d.ts +5 -1
- package/lib/versions.json +4 -4
- package/package.json +2 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
import { Ext } from "../../tr-grid-util/es6/Ext.js";
|
2
2
|
import { GridPlugin } from "../../tr-grid-util/es6/GridPlugin.js";
|
3
|
+
import { Conflator } from "../../tr-grid-util/es6/Conflator.js";
|
3
4
|
|
4
5
|
var isSafari = navigator.vendor &&
|
5
6
|
navigator.vendor.indexOf('Apple') > -1 &&
|
@@ -26,11 +27,20 @@ var isSafari = navigator.vendor &&
|
|
26
27
|
* @extends {GridPlugin}
|
27
28
|
*/
|
28
29
|
var AutoTooltipPlugin = function (options) {
|
29
|
-
this.requestTooltipUpdate = this.requestTooltipUpdate.bind(this);
|
30
30
|
this.applyTooltipToAllColumns = this.applyTooltipToAllColumns.bind(this);
|
31
31
|
this._onPreSectionDataBinding = this._onPreSectionDataBinding.bind(this);
|
32
|
+
this._onPostSectionDataBinding = this._onPostSectionDataBinding.bind(this);
|
32
33
|
this._onColumnAdded = this._onColumnAdded.bind(this);
|
33
34
|
|
35
|
+
this._requestNonContentSectionUpdate = this._requestNonContentSectionUpdate.bind(this);
|
36
|
+
this._nonContentSectionUpdateConflator = new Conflator(300, this._requestNonContentSectionUpdate);
|
37
|
+
|
38
|
+
this._requestContentSectionUpdate = this._requestContentSectionUpdate.bind(this);
|
39
|
+
this._contentSectionUpdateConflator = new Conflator(300, this._requestContentSectionUpdate);
|
40
|
+
|
41
|
+
this.requestTooltipUpdate = this.requestTooltipUpdate.bind(this);
|
42
|
+
this._tooltipUpdateConflator = new Conflator(300, this.requestTooltipUpdate);
|
43
|
+
|
34
44
|
this._hosts = [];
|
35
45
|
|
36
46
|
if (options) {
|
@@ -39,6 +49,39 @@ var AutoTooltipPlugin = function (options) {
|
|
39
49
|
};
|
40
50
|
Ext.inherits(AutoTooltipPlugin, GridPlugin);
|
41
51
|
|
52
|
+
/** @private
|
53
|
+
* @param {Object} column
|
54
|
+
* @return {boolean}
|
55
|
+
*/
|
56
|
+
AutoTooltipPlugin._isColumnVisible = function(column) {
|
57
|
+
if(!column) {
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
|
61
|
+
if(column.getVisibility && !column.getVisibility()) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
|
65
|
+
var colElem = column.getElement();
|
66
|
+
if(!colElem) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
|
70
|
+
return true;
|
71
|
+
};
|
72
|
+
|
73
|
+
/** @private
|
74
|
+
* @param {Array.<Object>} hosts
|
75
|
+
* @return {boolean}
|
76
|
+
*/
|
77
|
+
AutoTooltipPlugin._isUpdateRequired = function(hosts) {
|
78
|
+
var len = hosts.length;
|
79
|
+
if(len <= 0 || isSafari) {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
return true;
|
83
|
+
};
|
84
|
+
|
42
85
|
/** If true, include title sections into the calculation
|
43
86
|
* @type {boolean}
|
44
87
|
* @private
|
@@ -63,6 +106,11 @@ AutoTooltipPlugin.prototype._applyTimer = 0;
|
|
63
106
|
*/
|
64
107
|
AutoTooltipPlugin.prototype._calcDelay = 300;
|
65
108
|
|
109
|
+
/** @type {boolean}
|
110
|
+
* @private
|
111
|
+
*/
|
112
|
+
AutoTooltipPlugin.prototype._nonContentSectionUpdated = false;
|
113
|
+
|
66
114
|
/** @public
|
67
115
|
* @return {string}
|
68
116
|
*/
|
@@ -87,12 +135,12 @@ AutoTooltipPlugin.prototype.initialize = function (host, options) {
|
|
87
135
|
return;
|
88
136
|
}
|
89
137
|
host.listen("preSectionDataBinding", this._onPreSectionDataBinding);
|
90
|
-
host.listen("postSectionDataBinding", this.
|
138
|
+
host.listen("postSectionDataBinding", this._onPostSectionDataBinding);
|
91
139
|
host.listen("widthChanged", this.requestTooltipUpdate);
|
92
140
|
host.listen("columnAdded", this._onColumnAdded);
|
93
141
|
|
94
142
|
// In case of lazy loading
|
95
|
-
this.
|
143
|
+
this._requestAllSectionsUpdate();
|
96
144
|
};
|
97
145
|
|
98
146
|
/** @public
|
@@ -104,15 +152,13 @@ AutoTooltipPlugin.prototype.unload = function (host) {
|
|
104
152
|
this._hosts.splice(at, 1);
|
105
153
|
|
106
154
|
host.unlisten("preSectionDataBinding", this._onPreSectionDataBinding);
|
107
|
-
host.unlisten("postSectionDataBinding", this.
|
155
|
+
host.unlisten("postSectionDataBinding", this._onPostSectionDataBinding);
|
108
156
|
host.unlisten("widthChanged", this.requestTooltipUpdate);
|
109
157
|
host.unlisten("columnAdded", this._onColumnAdded);
|
110
158
|
|
111
159
|
if (!this._hosts.length) {
|
112
|
-
|
113
|
-
|
114
|
-
this._applyTimer = 0;
|
115
|
-
}
|
160
|
+
this._tooltipUpdateConflator.reset();
|
161
|
+
this._nonContentSectionUpdateConflator.reset();
|
116
162
|
}
|
117
163
|
|
118
164
|
this._dispose();
|
@@ -131,9 +177,9 @@ AutoTooltipPlugin.prototype.config = function (options) {
|
|
131
177
|
if (val != null) {
|
132
178
|
this._title = val ? true : false;
|
133
179
|
}
|
134
|
-
|
135
|
-
if (
|
136
|
-
this._footer =
|
180
|
+
val = extOptions["footer"];
|
181
|
+
if (val != null) {
|
182
|
+
this._footer = val ? true : false;
|
137
183
|
}
|
138
184
|
// Enable auto tooltip to all column by default
|
139
185
|
val = extOptions["content"];
|
@@ -142,7 +188,7 @@ AutoTooltipPlugin.prototype.config = function (options) {
|
|
142
188
|
}
|
143
189
|
}
|
144
190
|
|
145
|
-
// Retrive auto tooltip data from
|
191
|
+
// Retrive auto tooltip data from columns
|
146
192
|
var columns = options["columns"];
|
147
193
|
if (columns) {
|
148
194
|
var len = columns.length;
|
@@ -217,28 +263,28 @@ AutoTooltipPlugin.prototype._configColumn = function(colIndex, columnConfig) {
|
|
217
263
|
* @param {number=} toR End row index
|
218
264
|
*/
|
219
265
|
AutoTooltipPlugin.prototype.applyTooltip = function (colIndex, fromR, toR) {
|
220
|
-
var
|
221
|
-
if
|
266
|
+
var hosts = this._hosts;
|
267
|
+
if(!AutoTooltipPlugin._isUpdateRequired(hosts)) {
|
222
268
|
return;
|
223
269
|
}
|
224
270
|
|
225
|
-
for (var i = 0; i <
|
271
|
+
for (var i = 0; i < hosts.length; ++i) {
|
226
272
|
var host = this._hosts[i];
|
227
273
|
if (this._title) {
|
228
274
|
var titles = host.getAllSections("title");
|
229
275
|
for (var t = titles.length; --t >= 0;) {
|
230
|
-
this.
|
276
|
+
this._updateNonContentSection(titles[t], colIndex);
|
231
277
|
}
|
232
278
|
}
|
233
279
|
if (this._footer) {
|
234
280
|
var footers = host.getAllSections("footer");
|
235
281
|
for (var j = footers.length; --j >= 0;) {
|
236
|
-
this.
|
282
|
+
this._updateNonContentSection(footers[j], colIndex);
|
237
283
|
}
|
238
284
|
}
|
239
285
|
|
240
286
|
if(this._isTooltipCandidate(colIndex)) {
|
241
|
-
this.
|
287
|
+
this._updateContentSection(host.getSection("content"), colIndex, fromR, toR);
|
242
288
|
}
|
243
289
|
}
|
244
290
|
};
|
@@ -268,6 +314,135 @@ AutoTooltipPlugin.prototype.applyTooltipToAllColumns = function () {
|
|
268
314
|
}
|
269
315
|
};
|
270
316
|
|
317
|
+
/** This is similar applyTooltipToColumns() method, but it consolidate multiple requests into one for better performance
|
318
|
+
* @public
|
319
|
+
*/
|
320
|
+
AutoTooltipPlugin.prototype.requestTooltipUpdate = function () {
|
321
|
+
if(this._tooltipUpdateConflator.conflate()) {
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
|
325
|
+
this.applyTooltipToAllColumns();
|
326
|
+
};
|
327
|
+
|
328
|
+
/**
|
329
|
+
* @private
|
330
|
+
*/
|
331
|
+
AutoTooltipPlugin.prototype._requestAllSectionsUpdate = function () {
|
332
|
+
if(!this._nonContentSectionUpdated) {
|
333
|
+
this._requestNonContentSectionUpdate();
|
334
|
+
}
|
335
|
+
|
336
|
+
this._requestContentSectionUpdate();
|
337
|
+
};
|
338
|
+
|
339
|
+
/** @private
|
340
|
+
*/
|
341
|
+
AutoTooltipPlugin.prototype._requestNonContentSectionUpdate = function () {
|
342
|
+
if(this._nonContentSectionUpdateConflator.conflate()) {
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
|
346
|
+
var hosts = this._hosts;
|
347
|
+
if(!AutoTooltipPlugin._isUpdateRequired(hosts)) {
|
348
|
+
return;
|
349
|
+
}
|
350
|
+
|
351
|
+
this._nonContentSectionUpdated = true;
|
352
|
+
|
353
|
+
var colCount = this.getColumnCount();
|
354
|
+
var sections, s, c;
|
355
|
+
for(var i = 0; i < hosts.length; ++i) {
|
356
|
+
var host = hosts[i];
|
357
|
+
|
358
|
+
sections = host.getAllSections("title");
|
359
|
+
for(s = 0; s < sections.length; s++) {
|
360
|
+
for(c = 0; c < colCount; c++) {
|
361
|
+
this._updateNonContentSection(sections[s], c);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
sections = host.getAllSections("footer");
|
366
|
+
for(s = 0; s < sections.length; s++) {
|
367
|
+
for(c = 0; c < colCount; c++) {
|
368
|
+
this._updateNonContentSection(sections[s], c);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
}
|
372
|
+
};
|
373
|
+
|
374
|
+
|
375
|
+
/** @private
|
376
|
+
*/
|
377
|
+
AutoTooltipPlugin.prototype._requestContentSectionUpdate = function () {
|
378
|
+
if(this._contentSectionUpdateConflator.conflate()) {
|
379
|
+
return;
|
380
|
+
}
|
381
|
+
|
382
|
+
var hosts = this._hosts;
|
383
|
+
if(!AutoTooltipPlugin._isUpdateRequired(hosts)) {
|
384
|
+
return;
|
385
|
+
}
|
386
|
+
|
387
|
+
var colCount = this.getColumnCount();
|
388
|
+
for(var i = 0; i < hosts.length; ++i) {
|
389
|
+
var section = hosts[i].getSection("content");
|
390
|
+
for(var c = 0; c < colCount; c++) {
|
391
|
+
if(this._isTooltipCandidate(c)) {
|
392
|
+
this._updateContentSection(section, c);
|
393
|
+
}
|
394
|
+
}
|
395
|
+
}
|
396
|
+
};
|
397
|
+
|
398
|
+
/**
|
399
|
+
* @private
|
400
|
+
* @param {Object} section ILayoutGrid
|
401
|
+
* @param {number} colIndex Column index
|
402
|
+
* @return {boolean} True if there is any change, otherwise false
|
403
|
+
*/
|
404
|
+
AutoTooltipPlugin.prototype._updateNonContentSection = function (section, colIndex) {
|
405
|
+
if(!section) { return false; }
|
406
|
+
|
407
|
+
var column = section.getColumn(colIndex);
|
408
|
+
if(!AutoTooltipPlugin._isColumnVisible(column)) {
|
409
|
+
return false;
|
410
|
+
}
|
411
|
+
|
412
|
+
var rowCount = section.getRowCount();
|
413
|
+
for(var r = 0; r < rowCount; ++r) {
|
414
|
+
var cell = section.getCell(colIndex, r, false); // Ignore cell span
|
415
|
+
if(!cell || !cell.isVisible()) { return false; }
|
416
|
+
|
417
|
+
var elem = cell.getContent();
|
418
|
+
if(!elem) { return false; }
|
419
|
+
|
420
|
+
// Set tooltip only if text's length is longer than column width.
|
421
|
+
var tooltip = cell.getAttribute("tooltip") || cell.getTooltip();
|
422
|
+
|
423
|
+
var sw = elem.scrollWidth;
|
424
|
+
if(sw && sw > elem.offsetWidth) {
|
425
|
+
if(!tooltip) {
|
426
|
+
tooltip = cell.getTextContent(); // TODO: Allow custom tooltip text
|
427
|
+
cell._autoTooltip = true;
|
428
|
+
}
|
429
|
+
} else {
|
430
|
+
if(cell._autoTooltip) {
|
431
|
+
tooltip = "";
|
432
|
+
cell._autoTooltip = false;
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
436
|
+
cell.setTooltip(tooltip); // TODO: Avoiding using getter and setter in the same loop
|
437
|
+
if(tooltip) {
|
438
|
+
cell.setAttribute("ef-title", tooltip); // to make sure ef-title value will actually change
|
439
|
+
} else {
|
440
|
+
cell.removeAttribute("ef-title");
|
441
|
+
}
|
442
|
+
}
|
443
|
+
return true;
|
444
|
+
};
|
445
|
+
|
271
446
|
/**
|
272
447
|
* @private
|
273
448
|
* @param {Object} section ILayoutGrid
|
@@ -276,7 +451,7 @@ AutoTooltipPlugin.prototype.applyTooltipToAllColumns = function () {
|
|
276
451
|
* @param {number=} toR End row index
|
277
452
|
* @return {boolean} True if there is any change, otherwise false
|
278
453
|
*/
|
279
|
-
AutoTooltipPlugin.prototype.
|
454
|
+
AutoTooltipPlugin.prototype._updateContentSection = function (section, colIndex, fromR, toR) {
|
280
455
|
if (!section) { return false; }
|
281
456
|
|
282
457
|
if (fromR == null) {
|
@@ -390,7 +565,7 @@ AutoTooltipPlugin.prototype._clearTooltipCache = function (section, colIndex, fr
|
|
390
565
|
* @param {Event} e event from preSectionDataBinding
|
391
566
|
*/
|
392
567
|
AutoTooltipPlugin.prototype._onPreSectionDataBinding = function (e) {
|
393
|
-
if (e &&
|
568
|
+
if (e && e.sectionType === "content") {
|
394
569
|
var colCount = this.getColumnCount();
|
395
570
|
var isDataChange = e.actualUpdate === true;
|
396
571
|
for (var c = 0; c < colCount; ++c) {
|
@@ -399,13 +574,11 @@ AutoTooltipPlugin.prototype._onPreSectionDataBinding = function (e) {
|
|
399
574
|
}
|
400
575
|
};
|
401
576
|
|
402
|
-
/**
|
403
|
-
* @
|
577
|
+
/** @private
|
578
|
+
* @param {Event} e event from preSectionDataBinding
|
404
579
|
*/
|
405
|
-
AutoTooltipPlugin.prototype.
|
406
|
-
|
407
|
-
this._applyTimer = setTimeout(this.applyTooltipToAllColumns, this._calcDelay);
|
408
|
-
}
|
580
|
+
AutoTooltipPlugin.prototype._onPostSectionDataBinding = function (e) {
|
581
|
+
this._requestAllSectionsUpdate();
|
409
582
|
};
|
410
583
|
|
411
584
|
/** @private
|
@@ -414,6 +587,7 @@ AutoTooltipPlugin.prototype.requestTooltipUpdate = function () {
|
|
414
587
|
AutoTooltipPlugin.prototype._onColumnAdded = function(e) {
|
415
588
|
if(e.context && e.colIndex != null) {
|
416
589
|
this._configColumn(e.colIndex, e.context);
|
590
|
+
this._nonContentSectionUpdated = false; // Allow title/footer update in postSectionDataBinding
|
417
591
|
}
|
418
592
|
};
|
419
593
|
|
@@ -308,6 +308,17 @@ ContextMenuPlugin.prototype.getMenuModel = function () {
|
|
308
308
|
return this._contextMenu;
|
309
309
|
};
|
310
310
|
|
311
|
+
/** @public
|
312
|
+
* @ignore
|
313
|
+
* @returns {Object}
|
314
|
+
*/
|
315
|
+
ContextMenuPlugin.prototype._getEventHandlers = function() {
|
316
|
+
return {
|
317
|
+
contextmenu: this._rightClickedHandler
|
318
|
+
};
|
319
|
+
};
|
320
|
+
|
321
|
+
|
311
322
|
/** @private
|
312
323
|
* @param {Object} e
|
313
324
|
* @return {!Object} Mouse related information
|
@@ -3,7 +3,7 @@ import Ext from "../../tr-grid-util/es6/Ext.js";
|
|
3
3
|
|
4
4
|
declare class MenuItem extends EventDispatcher {
|
5
5
|
|
6
|
-
constructor(options
|
6
|
+
constructor(options?: any);
|
7
7
|
|
8
8
|
public dispose(): void;
|
9
9
|
|
@@ -33,6 +33,8 @@ declare class MenuItem extends EventDispatcher {
|
|
33
33
|
|
34
34
|
public getElement(): Element|null;
|
35
35
|
|
36
|
+
public getOptions(): any;
|
37
|
+
|
36
38
|
}
|
37
39
|
|
38
40
|
export default MenuItem;
|
@@ -3,7 +3,7 @@ import Ext from "../../tr-grid-util/es6/Ext.js";
|
|
3
3
|
|
4
4
|
/** @constructor
|
5
5
|
* @extends {EventDispatcher}
|
6
|
-
* @param {Object} options
|
6
|
+
* @param {Object=} options
|
7
7
|
*/
|
8
8
|
let MenuItem = function (options) {
|
9
9
|
let t = this;
|
@@ -11,7 +11,12 @@ let MenuItem = function (options) {
|
|
11
11
|
t._onItemHovered = t._onItemHovered.bind(t);
|
12
12
|
t._onItemClicked = t._onItemClicked.bind(t);
|
13
13
|
|
14
|
-
|
14
|
+
let li = document.createElement("li");
|
15
|
+
li.className = "tr-contextmenu-item";
|
16
|
+
li.addEventListener("mouseover", t._onItemHovered);
|
17
|
+
li.addEventListener("click", t._onItemClicked);
|
18
|
+
t._elem = li;
|
19
|
+
|
15
20
|
t._config(options);
|
16
21
|
};
|
17
22
|
Ext.inherits(MenuItem, EventDispatcher);
|
@@ -49,19 +54,6 @@ MenuItem.prototype._value = null;
|
|
49
54
|
*/
|
50
55
|
MenuItem.prototype._items = null;
|
51
56
|
|
52
|
-
/** @private
|
53
|
-
* @param {Object} options
|
54
|
-
*/
|
55
|
-
MenuItem.prototype._init = function(options) {
|
56
|
-
let t = this;
|
57
|
-
|
58
|
-
let li = document.createElement("li");
|
59
|
-
li.className = "tr-contextmenu-item";
|
60
|
-
li.addEventListener("mouseover", t._onItemHovered);
|
61
|
-
li.addEventListener("click", t._onItemClicked);
|
62
|
-
t._elem = li;
|
63
|
-
t._options = options || null;
|
64
|
-
};
|
65
57
|
/** @public */
|
66
58
|
MenuItem.prototype.dispose = function() {
|
67
59
|
let t = this;
|
@@ -77,36 +69,37 @@ MenuItem.prototype.dispose = function() {
|
|
77
69
|
};
|
78
70
|
|
79
71
|
/** @private
|
80
|
-
* @param {
|
72
|
+
* @param {*=} options
|
81
73
|
*/
|
82
|
-
MenuItem.prototype._config = function(
|
83
|
-
if (!
|
84
|
-
|
85
|
-
|
74
|
+
MenuItem.prototype._config = function(options) {
|
75
|
+
if (!options) {
|
76
|
+
options = {};
|
77
|
+
}
|
86
78
|
|
87
79
|
let t = this;
|
80
|
+
t._options = options;
|
88
81
|
|
89
|
-
pref =
|
82
|
+
let pref = options["id"];
|
90
83
|
if (pref) {
|
91
84
|
t.setId(pref);
|
92
85
|
}
|
93
86
|
|
94
|
-
pref =
|
87
|
+
pref = options["type"];
|
95
88
|
if (pref) {
|
96
89
|
t.setType(pref);
|
97
90
|
}
|
98
91
|
|
99
|
-
pref =
|
92
|
+
pref = options["text"];
|
100
93
|
if (pref) {
|
101
94
|
t.setText(pref);
|
102
95
|
}
|
103
96
|
|
104
|
-
pref =
|
105
|
-
if (pref) {
|
97
|
+
pref = options["value"];
|
98
|
+
if (pref != null) {
|
106
99
|
t.setValue(pref);
|
107
100
|
}
|
108
101
|
|
109
|
-
pref =
|
102
|
+
pref = options["isDisabled"];
|
110
103
|
if (pref != null) {
|
111
104
|
if (pref === true) {
|
112
105
|
t.setSelectable(false);
|
@@ -115,7 +108,7 @@ MenuItem.prototype._config = function(opt_model) {
|
|
115
108
|
}
|
116
109
|
}
|
117
110
|
|
118
|
-
pref =
|
111
|
+
pref = options["isSelectable"];
|
119
112
|
if (pref != null) {
|
120
113
|
if (pref === false) {
|
121
114
|
t.setSelectable(false);
|
@@ -124,7 +117,7 @@ MenuItem.prototype._config = function(opt_model) {
|
|
124
117
|
}
|
125
118
|
}
|
126
119
|
|
127
|
-
pref =
|
120
|
+
pref = options["items"];
|
128
121
|
if (Array.isArray(pref)) {
|
129
122
|
t.setItems(pref);
|
130
123
|
}
|
@@ -279,6 +272,13 @@ MenuItem.prototype.getElement = function() {
|
|
279
272
|
return this._elem;
|
280
273
|
};
|
281
274
|
|
275
|
+
/** @public
|
276
|
+
* @returns {Object}
|
277
|
+
*/
|
278
|
+
MenuItem.prototype.getOptions = function() {
|
279
|
+
return this._options;
|
280
|
+
};
|
281
|
+
|
282
282
|
|
283
283
|
|
284
284
|
export default MenuItem;
|
@@ -21,7 +21,11 @@ declare class PopupMenu extends EventDispatcher {
|
|
21
21
|
|
22
22
|
public addPopupChild(element: Element|null, popupMenu: PopupMenu|null): void;
|
23
23
|
|
24
|
-
public setMenu(
|
24
|
+
public setMenu(menuOptions: (any)[]|null): void;
|
25
|
+
|
26
|
+
public getMenuItems(): (MenuItem)[]|null;
|
27
|
+
|
28
|
+
public getChildPopups(): (PopupMenu)[]|null;
|
25
29
|
|
26
30
|
}
|
27
31
|
|
@@ -30,11 +30,11 @@ PopupMenu.prototype._evtArg;
|
|
30
30
|
/** @type {Array.<PopupMenu>}
|
31
31
|
* @private
|
32
32
|
*/
|
33
|
-
PopupMenu.prototype.
|
33
|
+
PopupMenu.prototype._nestedPopups;
|
34
34
|
/** @type {Array.<MenuItem>}
|
35
35
|
* @private
|
36
36
|
*/
|
37
|
-
PopupMenu.prototype.
|
37
|
+
PopupMenu.prototype._menuItems;
|
38
38
|
/** @type {Element}
|
39
39
|
* @private
|
40
40
|
*/
|
@@ -59,6 +59,10 @@ PopupMenu.prototype._ulElem;
|
|
59
59
|
* @private
|
60
60
|
*/
|
61
61
|
PopupMenu.prototype._isMounted;
|
62
|
+
/** @type {string}
|
63
|
+
* @private
|
64
|
+
*/
|
65
|
+
PopupMenu.prototype._id = "";
|
62
66
|
|
63
67
|
/** @private
|
64
68
|
* @param {Element} parentElement
|
@@ -76,8 +80,8 @@ PopupMenu.prototype._init = function(parentElement) {
|
|
76
80
|
t._popup.setPositioning("custom");
|
77
81
|
t._ulElem = ul;
|
78
82
|
|
79
|
-
t.
|
80
|
-
t.
|
83
|
+
t._nestedPopups = [];
|
84
|
+
t._menuItems = [];
|
81
85
|
t._x = 0;
|
82
86
|
t._y = 0;
|
83
87
|
t._isMounted = true;
|
@@ -121,10 +125,10 @@ let _disposeObject = function(obj) {
|
|
121
125
|
*/
|
122
126
|
PopupMenu.prototype._disposeChildren = function () {
|
123
127
|
let t = this;
|
124
|
-
t.
|
125
|
-
t.
|
126
|
-
t.
|
127
|
-
t.
|
128
|
+
t._nestedPopups.forEach(_disposeObject);
|
129
|
+
t._menuItems.forEach(_disposeObject);
|
130
|
+
t._nestedPopups.length = 0;
|
131
|
+
t._menuItems.length = 0;
|
128
132
|
};
|
129
133
|
|
130
134
|
/** @public */
|
@@ -191,32 +195,30 @@ PopupMenu.prototype.addPopupChild = function(element, popupMenu) {
|
|
191
195
|
if (popupMenu instanceof PopupMenu) {
|
192
196
|
popupMenu.attachTo(element, "right");
|
193
197
|
this._popup.addFocusElement(popupMenu._popup);
|
194
|
-
this.
|
198
|
+
this._nestedPopups.push(popupMenu);
|
195
199
|
}
|
196
200
|
};
|
197
201
|
|
198
202
|
/** @public
|
199
|
-
* @param {Array.<Object>}
|
203
|
+
* @param {Array.<Object>} menuOptions Array of MenuItem options
|
200
204
|
*/
|
201
|
-
PopupMenu.prototype.setMenu = function (
|
202
|
-
if (!menuItems || !Array.isArray(menuItems)) { return; }
|
203
|
-
|
205
|
+
PopupMenu.prototype.setMenu = function (menuOptions) {
|
204
206
|
let t = this;
|
205
207
|
|
206
|
-
// Clear existing before set a new items
|
207
|
-
if (
|
208
|
+
// Clear existing before set a new items
|
209
|
+
if (t._menuItems.length) {
|
208
210
|
t._disposeChildren();
|
209
211
|
}
|
210
212
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
let item = menuItems[i];
|
213
|
+
if (!menuOptions || !Array.isArray(menuOptions)) {
|
214
|
+
return;
|
215
|
+
}
|
215
216
|
|
216
|
-
|
217
|
+
for (let i = 0; i < menuOptions.length; i++) {
|
218
|
+
let menuItem = new MenuItem(menuOptions[i]);
|
217
219
|
menuItem.addEventListener("itemHovered", t._hoveredItem);
|
218
220
|
menuItem.addEventListener("itemClicked", t._clickedItem);
|
219
|
-
t.
|
221
|
+
t._menuItems.push(menuItem);
|
220
222
|
|
221
223
|
if (Array.isArray(menuItem.getItems())) {
|
222
224
|
let pm = new PopupMenu(t._parentElement);
|
@@ -230,6 +232,18 @@ PopupMenu.prototype.setMenu = function (menuItems) {
|
|
230
232
|
t._ulElem.appendChild(menuItem.getElement());
|
231
233
|
}
|
232
234
|
};
|
235
|
+
/** @public
|
236
|
+
* @returns {Array.<MenuItem>}
|
237
|
+
*/
|
238
|
+
PopupMenu.prototype.getMenuItems = function () {
|
239
|
+
return this._menuItems;
|
240
|
+
};
|
241
|
+
/** @public
|
242
|
+
* @returns {Array.<PopupMenu>}
|
243
|
+
*/
|
244
|
+
PopupMenu.prototype.getChildPopups = function () {
|
245
|
+
return this._nestedPopups;
|
246
|
+
};
|
233
247
|
|
234
248
|
/** @private
|
235
249
|
* @param {Event} e
|
@@ -252,18 +266,20 @@ PopupMenu.prototype._clickedChildItem = function (e) {
|
|
252
266
|
PopupMenu.prototype._hoveredItem = function (e) {
|
253
267
|
let t = this;
|
254
268
|
let evt = t._evtArg;
|
255
|
-
let
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
269
|
+
let elem = e.srcElement;
|
270
|
+
|
271
|
+
if (elem) {
|
272
|
+
let pms = t._nestedPopups;
|
273
|
+
let pmCount = pms.length;
|
274
|
+
let elemId = elem.getAttribute("id");
|
275
|
+
for (let i = 0; i < pmCount; i++) {
|
276
|
+
let pm = pms[i];
|
277
|
+
if (pm._id === elemId) {
|
278
|
+
pm.show();
|
263
279
|
} else {
|
264
|
-
|
280
|
+
pm.hide();
|
265
281
|
}
|
266
|
-
}
|
282
|
+
} // WARNING: evt or _evtArg is not customized to reflect the item that is hovered
|
267
283
|
} else {
|
268
284
|
evt = e;
|
269
285
|
}
|
@@ -276,15 +292,7 @@ PopupMenu.prototype._hoveredItem = function (e) {
|
|
276
292
|
*/
|
277
293
|
PopupMenu.prototype._clickedItem = function(e) {
|
278
294
|
let t = this;
|
279
|
-
|
280
|
-
for (let i = 0; i < t._menuItems.length; i++) {
|
281
|
-
let menuItem = t._menuItems[i];
|
282
|
-
if (menuItem.id === e.item.id) {
|
283
|
-
t._evtArg["item"] = menuItem;
|
284
|
-
break;
|
285
|
-
}
|
286
|
-
}
|
287
|
-
}
|
295
|
+
t._evtArg["item"] = e["item"];
|
288
296
|
t._dispatch("itemClicked", t._evtArg);
|
289
297
|
t.hide();
|
290
298
|
};
|