Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 1 | define({ |
| 2 | |
| 3 | /** |
| 4 | * Create new lengthField object. |
| 5 | */ |
| 6 | create : function () { |
| 7 | return Object.create(this)._init(); |
| 8 | }, |
| 9 | |
| 10 | // Initialize lengthField object |
| 11 | _init : function () { |
| 12 | this._element = document.createElement('div'); |
| 13 | this._element.classList.add('lengthField'); |
| 14 | return this; |
| 15 | }, |
| 16 | |
| 17 | /** |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame^] | 18 | * Upgrade this object to another object, |
| 19 | * while private data stays intact. |
| 20 | * |
| 21 | * @param {Object} An object with properties. |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 22 | */ |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame^] | 23 | upgradeTo : function (props) { |
| 24 | for (var prop in props) { |
| 25 | this[prop] = props[prop]; |
| 26 | }; |
| 27 | return this; |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 28 | }, |
| 29 | |
| 30 | /** |
| 31 | * Get the associated dom element. |
| 32 | */ |
| 33 | element : function () { |
| 34 | return this._element; |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame^] | 35 | }, |
| 36 | |
| 37 | /** |
| 38 | * Add string to lengthField. |
| 39 | */ |
| 40 | add : function (param) { |
| 41 | this._element.appendChild(document.createElement('span')) |
| 42 | .appendChild(document.createTextNode(param[0] + '--')); |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 43 | } |
| 44 | }); |