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