Akron | e51eaa3 | 2020-11-10 09:35:53 +0100 | [diff] [blame] | 1 | "use strict"; |
2 | |||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 3 | define(['menu/item'], function (itemClass) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 4 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 5 | /** |
6 | * Menu item for tree view choice. | ||||
7 | */ | ||||
8 | |||||
9 | return { | ||||
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 10 | |
11 | /** | ||||
12 | * Create new menu item | ||||
13 | * for tree views. | ||||
14 | */ | ||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 15 | create : function (params) { |
16 | return Object.create(itemClass) | ||||
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 17 | .upgradeTo(this)._init(params); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 18 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 19 | |
20 | /** | ||||
21 | * Get or set the content of the | ||||
22 | * menu item. | ||||
23 | */ | ||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 24 | content : function (content) { |
25 | if (arguments.length === 1) { | ||||
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 26 | this._content = content; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 27 | }; |
28 | return this._content; | ||||
29 | }, | ||||
30 | |||||
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 31 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 32 | /** |
33 | * The foundry attribute of the menu item. | ||||
34 | */ | ||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 35 | foundry : function () { |
36 | return this._foundry; | ||||
37 | }, | ||||
38 | |||||
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 39 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 40 | /** |
41 | * The layer attribute of the menu item. | ||||
42 | */ | ||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 43 | layer : function () { |
44 | return this._layer; | ||||
45 | }, | ||||
46 | |||||
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 47 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 48 | /** |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 49 | * The type attribute of the menu item. |
50 | * Is either "spans" or "rels". | ||||
51 | */ | ||||
52 | type : function () { | ||||
53 | return this._type; | ||||
54 | }, | ||||
55 | |||||
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 56 | |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 57 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 58 | * Override click action of the menu item. |
59 | */ | ||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 60 | onclick : function (e) { |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 61 | const menu = this.menu(); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 62 | menu.hide(); |
63 | e.halt(); | ||||
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 64 | |
Akron | 7f9a6a3 | 2018-07-18 15:05:23 +0200 | [diff] [blame] | 65 | if (menu.panel() !== undefined) { |
66 | menu.panel().addTree(this._foundry, this._layer, this._type); | ||||
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 67 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 68 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 69 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 70 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 71 | // Initialize tree menu item. |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 72 | _init : function (params) { |
73 | if (params[0] === undefined) | ||||
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 74 | throw new Error("Missing parameters"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 75 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 76 | const t = this; |
77 | |||||
78 | t._name = params[0]; | ||||
79 | t._foundry = params[1]; | ||||
80 | t._layer = params[2]; | ||||
81 | t._type = params[3]; | ||||
82 | t._content = document.createTextNode(t._name); | ||||
83 | t._lcField = ' ' + t.content().textContent.toLowerCase(); | ||||
84 | return t; | ||||
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 85 | } |
86 | }; | ||||
87 | }); |