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