-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
calculator.pug
217 lines (196 loc) · 7.69 KB
/
calculator.pug
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
extends pug/layout.pug
block head
style.
.pricing-slider {
width: 400px;
margin-left: 10px;
}
.pricing-input {
width: 80px;
margin-left: 10px;
}
.pricing-fromto {
width: 80px;
margin: 0 10px;
}
.pricing-row {
display: flex;
align-items: center;
}
.pricing-subResult {
display: inline-block;
margin-left: 30px;
}
.pricing-label {
display: inline-block;
width: 150px;
margin-right: 10px;
}
.pricing-results {
margin-top: 40px;
}
.pricing-resultTotal {
font-weight: 700;
}
.pricing-sets {
margin: 0 0 40px 0;
}
title locize - price calculator
block content
section.section-tertiary
.container
.row
.col-lg-12.text-center
.section-heading
h2 Price Calculator
hr
section.section-gray(style="padding: 0;")
.container
.row
.col-md-8.col-md-offset-2(style="position: relative;")
.legal(style="background-color: #fff; padding: 20px; border: solid 1px #ccc; position: relative; top: -100px; width: 100%; border-radius: 4px;")
.pricing-table
#sets.pricing-sets
div
.pricing-row
span.pricing-label words
span(translated='') 0
input#words.pricing-slider(translated='' type='range' min='0' max='900000' value='9000' step='1')
span.pricing-fromto(translated='') 900000
input#words_input.pricing-input(type='number')
.pricing-row
span.pricing-label modifications
span(translated='') 0
input#modifications.pricing-slider(translated='' type='range' min='0' max='20000' value='400' step='1')
span.pricing-fromto(translated='') 20000
input#modifications_input.pricing-input(type='number')
.pricing-row
span.pricing-label downloads
span(translated='') 0
input#downloads.pricing-slider(translated='' type='range' min='0' max='10000000' value='40000' step='1')
span.pricing-fromto(translated='') 10000000
input#downloads_input.pricing-input(type='number')
.pricing-results
div
span.pricing-label subscription
span#resultSubscription(translated='')
div
span.pricing-label words
span#resultWords(translated='')
div
span.pricing-label modifications
span#resultModifications(translated='')
div
span.pricing-label downloads
span#resultDownloads(translated='')
div
span.pricing-label
strong total
span#resultTotal.pricing-resultTotal(translated='')
div
small(style='font-size: 12px;') prices excl. VAT | billed on a recurring monthly basis
script.
var prices = {
subscription: 5,
words: [
{ next: 10000, price: 0.004 },
{ next: 20000, price: 0.003 },
{ next: 20000, price: 0.002 },
{ next: 200000, price: 0.001 },
{ price: 0.0005 }
],
downloads: [
{ next: 500000, price: 0.0001 },
{ next: 1000000, price: 0.000075 },
{ price: 0.00005 }
],
modifications: [
{ next: 1000, price: 0.02 },
{ next: 2000, price: 0.015 },
{ next: 2000, price: 0.01 },
{ next: 20000, price: 0.005 },
{ price: 0.003 }
],
auditEntries: [
{ price: 0.02 }
]
};
var setData = [
{ name: 'small', words: 2000, downloads: 10000, modifications: 100 },
{ name: 'medium', words: 10000, downloads: 50000, modifications: 200 },
{ name: 'large', words: 37000, downloads: 1000000, modifications: 500 },
// { name: 'xlarge', words: 75000, downloads: 500000, modifications: 750 },
];
// elements
var selWord = document.getElementById('words');
var resWord = document.getElementById('resultWords');
var wordsInput = document.getElementById('words_input');
var selDownload = document.getElementById('downloads');
var resDownload = document.getElementById('resultDownloads');
var downloadsInput = document.getElementById('downloads_input');
var selModification = document.getElementById('modifications');
var resModification = document.getElementById('resultModifications');
var modificationsInput = document.getElementById('modifications_input');
var resSubscription = document.getElementById('resultSubscription');
var resTotal = document.getElementById('resultTotal');
var sets = document.getElementById('sets');
// buttons with presets
function setValues(data) {
selWord.value = data.words;
selDownload.value = data.downloads;
selModification.value = data.modifications;
render(calculate());
};
setData.forEach(function(d) {
var btn = document.createElement('button');
btn.innerHTML = d.name;
btn.setAttribute('class', 'btn btn-signup');
btn.setAttribute('style', 'margin-right: 20px');
btn.addEventListener('click', function(e) {
setValues(d);
});
sets.appendChild(btn);
});
function calcOne(name, amount) {
var ret = 0;
var rest = amount;
var itemPrices = prices[name];
itemPrices.forEach(function(p) {
if (rest <= 0) return;
var newRest = p.next ? rest - p.next : -1;
var charge = newRest >= 0 ? p.next : rest;
ret = ret + (charge * p.price);
rest = newRest;
});
return ret;
}
function calculate() {
if (selWord.value !== wordsInput.value) wordsInput.value = selWord.value
if (selDownload.value !== downloadsInput.value) downloadsInput.value = selDownload.value
if (selModification.value !== modificationsInput.value) modificationsInput.value = selModification.value
var costWords = calcOne('words', selWord.value);
var costDownloads = calcOne('downloads', selDownload.value);
var costModifications = calcOne('modifications', selModification.value);
return {
words: selWord.value,
costWords: costWords,
downloads: selDownload.value,
costDownloads: costDownloads,
modifications: selModification.value,
costModifications: costModifications
}
}
function render(costs) {
resWord.innerHTML = costs.costWords.toFixed(2) + '$ (' + costs.words + ')';
resDownload.innerHTML = costs.costDownloads.toFixed(2) + '$ (' + costs.downloads + ')';
resModification.innerHTML = costs.costModifications.toFixed(2) + '$ (' + costs.modifications + ')';
resSubscription.innerHTML = prices.subscription.toFixed(2) + '$ (' + 1 + ')';
resTotal.innerHTML = (costs.costModifications + costs.costWords + costs.costDownloads + prices.subscription).toFixed(2) + '$';
}
selWord.addEventListener('change', function(e) { render(calculate()); });
selDownload.addEventListener('change', function(e) { render(calculate()); });
selModification.addEventListener('change', function(e) { render(calculate()); });
wordsInput.addEventListener('change', function(e) { selWord.value = wordsInput.value; render(calculate()); });
downloadsInput.addEventListener('change', function(e) { selDownload.value = downloadsInput.value; render(calculate()); });
modificationsInput.addEventListener('change', function(e) { selModification.value = modificationsInput.value; render(calculate()); });
render(calculate());