blob: 8a6641dfdd2076d0add8fd73b61c021f11de5072 [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 () {
15 this._element = document.createElement('div');
16 this._element.classList.add('lengthField');
17 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 () {
39 return this._element;
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) {
47 this._element.appendChild(document.createElement('span'))
48 .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 () {
56 while (this._element.firstChild) {
57 this._element.firstChild.remove();
58 };
Akronc7448732016-04-27 14:06:58 +020059 }
60});