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 | /** |
| 45 | * Override click action of the menu item. |
| 46 | */ |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 47 | onclick : function (e) { |
| 48 | var menu = this.menu(); |
| 49 | menu.hide(); |
| 50 | e.halt(); |
| 51 | if (menu.info() !== undefined) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 52 | menu.info().addTree(this._foundry, this._layer); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 53 | }, |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 54 | |
| 55 | // Initialize tree menu item. |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 56 | _init : function (params) { |
| 57 | if (params[0] === undefined) |
Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 58 | throw new Error("Missing parameters"); |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 59 | |
| 60 | this._name = params[0]; |
| 61 | this._foundry = params[1]; |
| 62 | this._layer = params[2]; |
| 63 | this._content = document.createTextNode(this._name); |
| 64 | this._lcField = ' ' + this.content().textContent.toLowerCase(); |
| 65 | return this; |
| 66 | } |
| 67 | }; |
| 68 | }); |