-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalfredknows.js
68 lines (68 loc) · 2.85 KB
/
alfredknows.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
class AlfredKnowsPriceSlide {
constructor(elmListPriceSlide, elmTotalNumEmails, elmTotalListPrice) {
this.slide = elmListPriceSlide;
this.numE = elmTotalNumEmails;
this.lstP = elmTotalListPrice;
}
roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}
setValues() {
this.numE.value = parseFloat(this.slide.value).toLocaleString('en-US');
this.lstP.innerHTML = '$' + this.roundToTwo(this.slide.value * this.getPricePerEmail(this.slide.value)).toLocaleString('en-US');
}
setValuesOnInputChange() {
if (this.numE.value === '' || this.numE.value === '0') {
//this.numE.value = '5,000';
this.lstP.innerHTML = '$0';
} else {
this.slide.value = this.numE.value.split(',').join('');
this.numE.value = parseFloat(this.numE.value.split(',').join('')).toLocaleString('en-US');
if (this.getPricePerEmail(this.numE.value.split(',').join('')) === 'call') {
this.lstP.innerHTML = 'Contact Us';
} else {
this.lstP.innerHTML = '$' + this.roundToTwo(this.numE.value.split(',').join('') * this.getPricePerEmail(this.numE.value.split(',').join(''))).toLocaleString('en-US');
}
}
}
getPricePerEmail(num) {
if (num >= 1 && num <= 2500) {
return 0.01;
} else if (num > 2501 && num <= 100000) {
return 0.008;
} else if (num > 100001 && num <= 250000) {
return 0.006;
} else if (num > 250001 && num <= 500000) {
return 0.005;
} else if (num > 500001 && num <= 1000000) {
return 0.004;
} else if (num > 1000000) {
return 'call'
}
}
}
if (!!document.getElementById("emailListPriceSlide")) {
let alfredKnowsPrice = new AlfredKnowsPriceSlide(
document.getElementById("emailListPriceSlide"),
document.getElementById("totalNumEmails"),
document.getElementById("totalListPrice")
);
alfredKnowsPrice.setValues();
document.getElementById("emailListPriceSlide").oninput = function() {
alfredKnowsPrice.setValues();
}
let timer,
timeoutVal = 1000;
const typer = document.getElementById('totalNumEmails');
typer.addEventListener('keypress', handleKeyPress);
typer.addEventListener('keyup', handleKeyUp);
function handleKeyPress(e) {
window.clearTimeout(timer);
}
function handleKeyUp(e) {
window.clearTimeout(timer); // prevent errant multiple timeouts from being generated
timer = window.setTimeout(() => {
alfredKnowsPrice.setValuesOnInputChange();
}, timeoutVal);
}
}