blob: eed90b72fb91e845cd251f4bfe6aeba4ee50dc13 [file] [log] [blame]
Akronc53cfc82020-10-19 11:00:58 +02001"use strict";
2
Akronc7448732016-04-27 14:06:58 +02003define({
4
5 /**
6 * Create new lengthField object.
7 */
8 create : function () {
9 return Object.create(this)._init();
10 },
11
Akronc53cfc82020-10-19 11:00:58 +020012
Akronc7448732016-04-27 14:06:58 +020013 // Initialize lengthField object
14 _init : function () {
Akron24aa0052020-11-10 11:00:34 +010015 this._el = document.createElement('div');
16 this._el.classList.add('lengthField');
Akronc7448732016-04-27 14:06:58 +020017 return this;
18 },
19
Akronc53cfc82020-10-19 11:00:58 +020020
Akronc7448732016-04-27 14:06:58 +020021 /**
Akron1ff3ac22016-04-28 16:30:45 +020022 * Upgrade this object to another object,
23 * while private data stays intact.
24 *
25 * @param {Object} An object with properties.
Akronc7448732016-04-27 14:06:58 +020026 */
Akron1ff3ac22016-04-28 16:30:45 +020027 upgradeTo : function (props) {
Akronc53cfc82020-10-19 11:00:58 +020028 for (let prop in props) {
Akron1ff3ac22016-04-28 16:30:45 +020029 this[prop] = props[prop];
30 };
31 return this;
Akronc7448732016-04-27 14:06:58 +020032 },
33
Akronc53cfc82020-10-19 11:00:58 +020034
Akronc7448732016-04-27 14:06:58 +020035 /**
36 * Get the associated dom element.
37 */
38 element : function () {
Akron24aa0052020-11-10 11:00:34 +010039 return this._el;
Akron1ff3ac22016-04-28 16:30:45 +020040 },
41
Akronc53cfc82020-10-19 11:00:58 +020042
Akron1ff3ac22016-04-28 16:30:45 +020043 /**
44 * Add string to lengthField.
45 */
46 add : function (param) {
Akron24aa0052020-11-10 11:00:34 +010047 this._el.appendChild(document.createElement('span'))
Akron1ff3ac22016-04-28 16:30:45 +020048 .appendChild(document.createTextNode(param[0] + '--'));
Akroneaba63e2018-01-26 19:49:30 +010049 },
50
Akronc53cfc82020-10-19 11:00:58 +020051
Akroneaba63e2018-01-26 19:49:30 +010052 /**
53 * Remove all initialized values
54 */
55 reset : function () {
Akron24aa0052020-11-10 11:00:34 +010056 while (this._el.firstChild) {
57 this._el.firstChild.remove();
Akroneaba63e2018-01-26 19:49:30 +010058 };
Akronc7448732016-04-27 14:06:58 +020059 }
60});