-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
173 lines (143 loc) · 7.85 KB
/
script.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
document.addEventListener('DOMContentLoaded', () => {
const slider175 = document.getElementById('slider_175');
const tooltip175 = document.getElementById('tooltip-175');
const slider = document.getElementById('spending-slider');
const spendingVar = document.getElementById('spending-var');
const noteContainer = document.getElementById('note-container');
const propTaxVar = document.getElementById('prop-tax-var');
const ntrNumerator = document.getElementById('ntr-numerator');
const ntrDenominator1 = document.getElementById('ntr-denominator1');
const ntrDenominator2 = document.getElementById('ntr-denominator2');
const ntrResult = document.getElementById('ntr-result');
const propTaxPercVar = document.getElementById('prop-tax-perc-var');
const otherTaxPercVar = document.getElementById('other-tax-perc-var');
const noteContainer175 = document.getElementById('note-container-175');
const levyCommercialVar = document.getElementById('comm-tax-levy-span');
const levyResidentialVar = document.getElementById('res-tax-levy-span');
let spendingSliderValue = 3.3284; // Default value
// Function to update the natural tax rate result
const updateNtrResult = () => {
};
if (slider) {
// Spending slider functionality
slider.addEventListener('input', () => {
const numerator = parseFloat(ntrNumerator.textContent);
const denominator1 = parseFloat(ntrDenominator1.textContent);
const denominator2 = parseFloat(ntrDenominator2.textContent);
const totalDenominator = denominator1 + denominator2;
const result = (numerator / totalDenominator) * 1000;
const value = parseFloat(slider.value);
spendingVar.textContent = value.toFixed(1);
spendingSliderValue = value;
let propTaxValue = value - 1.3;
propTaxVar.textContent = propTaxValue.toFixed(1);
ntrNumerator.textContent = propTaxValue.toFixed(2); // Update ntr-numerator
ntrResult.textContent = result.toFixed(2); // Update ntr-result
console.log(ntrResult.textContent);
let propTaxPercentage = Math.round((propTaxValue / value) * 100);
propTaxPercVar.textContent = propTaxPercentage;
otherTaxPercVar.textContent = 100 - propTaxPercentage;
if (value > 4.6) {
propTaxVar.style.color = 'red';
noteContainer.innerHTML = `
<a href="https://www.mass.gov/info-details/proposition-2-12-and-tax-rate-process"
target="_blank"
style="color: red; text-decoration: underline;">
Click here </a> for more information about how Proposition 2 1/2 limits the property tax levy.
`;
noteContainer.style.visibility = 'visible';
noteContainer.style.opacity = '1';
} else {
propTaxVar.style.color = '';
noteContainer.style.visibility = 'hidden';
noteContainer.style.opacity = '0';
}
// Recalculate levy values for slider175
const slider175Value = parseFloat(slider175.value);
let levyCommercial = (slider175Value / 100) * (propTaxValue / (156.079088 + 68.304382)) * 68.304382;
let levyResidential = propTaxValue - ((slider175Value / 100) * 0.01483 * 68.304382);
levyCommercialVar.textContent = levyCommercial.toFixed(2);
levyResidentialVar.textContent = levyResidential.toFixed(2);
});
}
if (slider175 && tooltip175) {
// Slider 175 tooltip functionality
slider175.addEventListener('input', (e) => {
const value175 = parseFloat(slider175.value);
tooltip175.textContent = value175.toFixed(1);
const sliderRect = slider175.getBoundingClientRect();
const tooltipWidth = tooltip175.offsetWidth;
const sliderWidth = sliderRect.width;
// Set tooltip position relative to slider's value
const position = (value175 / 100) * sliderWidth - tooltipWidth / 2;
tooltip175.style.left = `${position}px`;
tooltip175.style.top = `-30px`;
tooltip175.style.display = 'block'; // Show tooltip
});
slider175.addEventListener('mouseout', () => {
tooltip175.style.display = 'none'; // Hide tooltip when not hovering
});
slider175.addEventListener('input', () => {
const value175 = parseFloat(slider175.value);
// Interactivity between sliders
console.log('HEY!')
const spendingValue = parseFloat(slider.value);
const propTaxValue = spendingValue - 1.3;
propTaxVar.textContent = propTaxValue.toFixed(1);
let levyCommercial = (value175 / 100) * (propTaxValue / (156.079088 + 68.304382)) * 68.304382;
let levyResidential = propTaxValue - ((value175 / 100) * 0.01483 * 68.304382);
levyCommercialVar.textContent = levyCommercial.toFixed(2);
levyResidentialVar.textContent = levyResidential.toFixed(2);
if (value175 < 170) {
noteContainer175.innerHTML = `
<a href="https://www.mass.gov/info-details/proposition-2-12-and-tax-rate-process"
target="_blank"
style="color: red; text-decoration: underline;">
Click here </a> for more information about why the ratio cannot be lower than 170%.
`;
noteContainer175.style.visibility = 'visible';
noteContainer175.style.opacity = '1';
slider175.style.setProperty('--slider-color', 'red');
} else {
slider175.style.setProperty('--slider-color', '');
noteContainer175.style.visibility = 'hidden';
noteContainer175.style.opacity = '0';
}
// Update the natural tax rate result
updateNtrResult();
});
// Initial update of the natural tax rate result
updateNtrResult();
}
});
// Start interactivity of final tax rate block
document.addEventListener('DOMContentLoaded', () => {
const numeratorSpans = document.querySelectorAll('.numerator span');
const denominatorSpans = document.querySelectorAll('.denominator span');
const resultSpans = document.querySelectorAll('.result span');
const commPropLevy = document.getElementById('comm-tax-levy-span');
const resPropLevy = document.getElementById('res-tax-levy-span');
if (commPropLevy) {
const levyObserver = new MutationObserver(() => {
numeratorSpans[0].textContent = parseFloat(commPropLevy.textContent).toFixed(2);
numeratorSpans[1].textContent = parseFloat(resPropLevy.textContent).toFixed(2);
});
levyObserver.observe(commPropLevy, { childList: true, characterData: true, subtree: true });
}
const updateTaxRate = (index) => {
const numerator = parseFloat(numeratorSpans[index].textContent);
const denominator = parseFloat(denominatorSpans[index].textContent);
// Subtract 21.8 only if index is 1
const adjustedDenominator = index === 1 ? denominator - 21.8 : denominator;
const taxRate = (numerator / adjustedDenominator) * 1000;
resultSpans[index].textContent = taxRate.toFixed(2);
};
numeratorSpans.forEach((numeratorSpan, index) => {
const observer = new MutationObserver(() => {
updateTaxRate(index);
});
observer.observe(numeratorSpan, { childList: true, characterData: true, subtree: true });
observer.observe(denominatorSpans[index], { childList: true, characterData: true, subtree: true });
updateTaxRate(index);
});
});