Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Hint menu item based on MenuItem |
| 3 | */ |
| 4 | define(['menu/item'], function (itemClass) { |
| 5 | return { |
| 6 | create : function (params) { |
| 7 | return Object.create(itemClass) |
| 8 | .upgradeTo(this) |
| 9 | ._init(params); |
| 10 | }, |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 11 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 12 | _init : function (params) { |
| 13 | if (params[0] === undefined || |
| 14 | params[1] === undefined) |
| 15 | throw new Error("Missing parameters"); |
| 16 | |
| 17 | this._name = params[0]; |
| 18 | this._action = params[1]; |
| 19 | this._lcField = ' ' + this._name.toLowerCase(); |
| 20 | |
| 21 | if (params.length > 2) { |
| 22 | this._desc = params[2]; |
| 23 | this._lcField += " " + this._desc.toLowerCase(); |
| 24 | }; |
| 25 | |
| 26 | return this; |
| 27 | }, |
| 28 | |
| 29 | content : function (content) { |
| 30 | if (arguments.length === 1) { |
| 31 | this._content = content; |
| 32 | }; |
| 33 | return this._content; |
| 34 | }, |
| 35 | |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 36 | onclick : function (e) { |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 37 | var m = this.menu(); |
| 38 | var h = m.hint(); |
| 39 | m.hide(); |
| 40 | |
| 41 | // Update input field |
| 42 | var input = h.inputField(); |
| 43 | input.insert(this._action); |
| 44 | input.update(); |
| 45 | |
| 46 | h.active = false; |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 47 | |
| 48 | e.halt(); |
| 49 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 50 | h.show(true); |
| 51 | }, |
Nils Diewald | 47f366b | 2015-04-15 20:06:35 +0000 | [diff] [blame] | 52 | |
Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 53 | name : function () { |
| 54 | return this._name; |
| 55 | }, |
| 56 | action : function () { |
| 57 | return this._action; |
| 58 | }, |
| 59 | desc : function () { |
| 60 | return this._desc; |
| 61 | }, |
| 62 | element : function () { |
| 63 | // already defined |
| 64 | if (this._element !== undefined) |
| 65 | return this._element; |
| 66 | |
| 67 | // Create list item |
| 68 | var li = document.createElement("li"); |
| 69 | |
| 70 | if (this.onclick !== undefined) { |
| 71 | li["onclick"] = this.onclick.bind(this); |
| 72 | }; |
| 73 | |
| 74 | // Create title |
| 75 | var name = document.createElement("span"); |
| 76 | name.appendChild(document.createTextNode(this._name)); |
| 77 | |
| 78 | li.appendChild(name); |
| 79 | |
| 80 | // Create description |
| 81 | if (this._desc !== undefined) { |
| 82 | var desc = document.createElement("span"); |
| 83 | desc.classList.add('desc'); |
| 84 | desc.appendChild(document.createTextNode(this._desc)); |
| 85 | li.appendChild(desc); |
| 86 | }; |
| 87 | return this._element = li; |
| 88 | } |
| 89 | }; |
| 90 | }); |