forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalVariablesStatus.js
55 lines (40 loc) · 1.32 KB
/
globalVariablesStatus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var GlobalVariablesStatus = function () {
let self = {},
data = [];
self.set = function (condition, value) {
data[condition] = value;
}
self.get = function (condition) {
if (typeof data[condition] !== 'undefined') {
return data[condition];
} else {
return null;
}
}
self.getAll = function() {
return data;
}
self.update = function ($container) {
for (let i in self.getAll()) {
if (self.getAll().hasOwnProperty(i)) {
$container.find("[data-gvar-index=" + i + "]").html(self.get(i));
}
}
}
self.init = function ($container) {
let count = self.getAll().length;
let template = $container.find(".gvar__wrapper:first").prop("outerHTML");
$container.find(".gvar__wrapper").remove();
for (let i = 0; i < count; i++) {
$container.append(template);
let $last = $container.find(".gvar__wrapper:last");
$last.find("h2").html("GVAR " + i);
$last.find("label").attr("data-gvar-index", i);
$last.find("label").html("0");
}
$container.find(".gvar__wrapper").css("width", (100 / count) + "%");
}
return self;
};
module.exports = GlobalVariablesStatus;