Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | // Field menu item |
| 2 | define(['menu/item'], function (itemClass) { |
| 3 | return { |
| 4 | create : function (params) { |
| 5 | return Object.create(itemClass) |
| 6 | .upgradeTo(this) |
| 7 | ._init(params); |
| 8 | }, |
| 9 | |
| 10 | _init : function (params) { |
| 11 | if (params[0] === undefined) |
| 12 | throw new Error("Missing parameters"); |
| 13 | |
| 14 | this._name = params[0]; |
| 15 | this._value = params[1]; |
| 16 | this._type = params[2]; |
| 17 | |
| 18 | this._lcField = ' ' + this._name.toLowerCase(); |
| 19 | |
| 20 | return this; |
| 21 | }, |
| 22 | |
| 23 | name : function () { |
| 24 | return this._name; |
| 25 | }, |
| 26 | |
| 27 | type : function () { |
| 28 | return this._type; |
| 29 | }, |
| 30 | |
| 31 | element : function () { |
| 32 | // already defined |
| 33 | if (this._element !== undefined) |
| 34 | return this._element; |
| 35 | |
| 36 | // Create list item |
| 37 | var li = document.createElement("li"); |
| 38 | li.setAttribute("data-type", this._type); |
| 39 | li.setAttribute("data-value", this._value); |
| 40 | li.appendChild(document.createTextNode(this._name)); |
| 41 | return this._element = li; |
| 42 | } |
| 43 | }; |
| 44 | }); |