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 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 30 | /** |
| 31 | * The foundry attribute of the menu item. |
| 32 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 33 | foundry : function () { |
| 34 | return this._foundry; |
| 35 | }, |
| 36 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 37 | /** |
| 38 | * The layer attribute of the menu item. |
| 39 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 40 | layer : function () { |
| 41 | return this._layer; |
| 42 | }, |
| 43 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 44 | /** |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 45 | * The type attribute of the menu item. |
| 46 | * Is either "spans" or "rels". |
| 47 | */ |
| 48 | type : function () { |
| 49 | return this._type; |
| 50 | }, |
| 51 | |
| 52 | /** |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 53 | * Override click action of the menu item. |
| 54 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 55 | onclick : function (e) { |
| 56 | var menu = this.menu(); |
| 57 | menu.hide(); |
| 58 | e.halt(); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 59 | if (menu.info() !== undefined) { |
Akron | 151bc87 | 2018-02-02 14:04:15 +0100 | [diff] [blame] | 60 | menu.info().showTree(this._foundry, this._layer, this._type); |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 61 | }; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 62 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 63 | |
| 64 | // Initialize tree menu item. |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 65 | _init : function (params) { |
| 66 | if (params[0] === undefined) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 67 | throw new Error("Missing parameters"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 68 | |
| 69 | this._name = params[0]; |
| 70 | this._foundry = params[1]; |
| 71 | this._layer = params[2]; |
Akron | 0988d88 | 2017-11-10 16:13:12 +0100 | [diff] [blame] | 72 | this._type = params[3]; |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 73 | this._content = document.createTextNode(this._name); |
| 74 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 75 | return this; |
| 76 | } |
| 77 | }; |
| 78 | }); |