Skip to content

Commit 71a3fb4

Browse files
committed
remove css utils from global scope
1 parent 7bc1db4 commit 71a3fb4

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/js/tabs/pid_tuning.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { i18n } from "../localization";
2+
import { colorTables, getColorForPercentage } from '../utils/css.js';
23

34
const pid_tuning = {
45
RATE_PROFILE_MASK: 128,
@@ -2962,7 +2963,7 @@ pid_tuning.updatePIDColors = function(clear = false) {
29622963
}
29632964

29642965
const change = (currentValue - mspValue) / 50;
2965-
element.css({ "background-color": cssUtil.getColorForPercentage(change, cssUtil.colorTables.pidSlider) });
2966+
element.css({ "background-color": getColorForPercentage(change, colorTables.pidSlider) });
29662967
};
29672968

29682969
FC.PID_NAMES.forEach(function(elementPid, indexPid) {

src/js/utils/css.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
'use strict';
2-
31
/*
42
This utility contains CSS helpers.
53
*/
64

7-
const CSSUtil = function () {};
8-
9-
CSSUtil.prototype.colorTables = {
5+
export const colorTables = {
106
redWhiteGreen: [
117
{ percentage: -1, color: { r: 0xff, g: 0x00, b: 0x00, a: 1.0 } },
128
{ percentage: 0, color: { r: 0xff, g: 0xff, b: 0xff, a: 1.0 } },
@@ -20,19 +16,19 @@ CSSUtil.prototype.colorTables = {
2016
};
2117

2218
// Stack Overflow: https://stackoverflow.com/a/7128796/4107016
23-
CSSUtil.prototype.getColorForPercentage = function(percentage, colorTable = null) {
24-
colorTable = colorTable || cssUtil.colorTables.redWhiteGreen;
19+
export function getColorForPercentage(percentage, colorTableOverride = null) {
20+
colorTableOverride = colorTableOverride || colorTables.redWhiteGreen;
2521

2622
percentage = Math.min(1, Math.max(-1, percentage));
2723

2824
let index;
29-
for (index = 1; index < colorTable.length - 1; index++) {
30-
if (percentage < colorTable[index].percentage) {
25+
for (index = 1; index < colorTableOverride.length - 1; index++) {
26+
if (percentage < colorTableOverride[index].percentage) {
3127
break;
3228
}
3329
}
34-
const lower = colorTable[index - 1];
35-
const upper = colorTable[index];
30+
const lower = colorTableOverride[index - 1];
31+
const upper = colorTableOverride[index];
3632
const range = upper.percentage - lower.percentage;
3733
const rangePercentage = (percentage - lower.percentage) / range;
3834
const percentageLower = 1 - rangePercentage;
@@ -45,7 +41,3 @@ CSSUtil.prototype.getColorForPercentage = function(percentage, colorTable = null
4541
};
4642
return `rgba(${[color.r, color.g, color.b, color.a].join(",")})`;
4743
};
48-
49-
const cssUtil = new CSSUtil();
50-
window.cssUtil = cssUtil;
51-
export default cssUtil;

src/main.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@
7979
<script type="text/javascript" src="./js/libraries/jquery.ba-throttle-debounce.min.js"></script>
8080
<script type="text/javascript" src="./node_modules/inflection/inflection.min.js"></script>
8181
<script type="text/javascript" src="./js/libraries/analytics.js"></script>
82-
<!-- TODO: remove when using modules fully -->
83-
<script type="module" src="./js/utils/css.js"></script>
8482
<script type="text/javascript" src="./js/utils/window_watchers.js"></script>
8583
<script type="text/javascript" src="./js/utils/VtxDeviceStatus/VtxDeviceStatusFactory.js"></script>
8684
<script type="text/javascript" src="./js/utils/VtxDeviceStatus/VtxDeviceStatus.js"></script>

0 commit comments

Comments
 (0)