Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 1 | "use strict"; |
2 | |||||
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 3 | define({ |
4 | |||||
5 | /** | ||||
6 | * Create new lengthField object. | ||||
7 | */ | ||||
8 | create : function () { | ||||
9 | return Object.create(this)._init(); | ||||
10 | }, | ||||
11 | |||||
Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 12 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 13 | // Initialize lengthField object |
14 | _init : function () { | ||||
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 15 | this._el = document.createElement('div'); |
16 | this._el.classList.add('lengthField'); | ||||
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 17 | return this; |
18 | }, | ||||
19 | |||||
Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 20 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 21 | /** |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 22 | * Upgrade this object to another object, |
23 | * while private data stays intact. | ||||
24 | * | ||||
25 | * @param {Object} An object with properties. | ||||
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 26 | */ |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 27 | upgradeTo : function (props) { |
Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 28 | for (let prop in props) { |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 29 | this[prop] = props[prop]; |
30 | }; | ||||
31 | return this; | ||||
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 32 | }, |
33 | |||||
Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 34 | |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 35 | /** |
36 | * Get the associated dom element. | ||||
37 | */ | ||||
38 | element : function () { | ||||
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 39 | return this._el; |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 40 | }, |
41 | |||||
Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 42 | |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 43 | /** |
44 | * Add string to lengthField. | ||||
45 | */ | ||||
46 | add : function (param) { | ||||
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 47 | this._el.appendChild(document.createElement('span')) |
Akron | 1ff3ac2 | 2016-04-28 16:30:45 +0200 | [diff] [blame] | 48 | .appendChild(document.createTextNode(param[0] + '--')); |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 49 | }, |
50 | |||||
Akron | c53cfc8 | 2020-10-19 11:00:58 +0200 | [diff] [blame] | 51 | |
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 52 | /** |
53 | * Remove all initialized values | ||||
54 | */ | ||||
55 | reset : function () { | ||||
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 56 | while (this._el.firstChild) { |
57 | this._el.firstChild.remove(); | ||||
Akron | eaba63e | 2018-01-26 19:49:30 +0100 | [diff] [blame] | 58 | }; |
Akron | c744873 | 2016-04-27 14:06:58 +0200 | [diff] [blame] | 59 | } |
60 | }); |