-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
319 lines (267 loc) · 13.6 KB
/
index.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*// The debounce function receives our function as a parameter
const debounce = (fn) => {
// This holds the requestAnimationFrame reference, so we can cancel it if we wish
let frame;
// The debounce function returns a new function that can receive a variable number of arguments
return (...params) => {
// If the frame variable has been defined, clear it now, and queue for next frame
if (frame) {
cancelAnimationFrame(frame);
}
// Queue our function call for the next frame
frame = requestAnimationFrame(() => {
// Call our function and pass any params we received
fn(...params);
});
}
};
// Reads out the scroll position and stores it in the data attribute
// so we can use it in our stylesheets
const storeScroll = () => {
document.documentElement.dataset.scroll = window.scrollY;
}
// Listen for new scroll events, here we debounce our `storeScroll` function
document.addEventListener('scroll', debounce(storeScroll), { passive: true });
// Update scroll position for first time
storeScroll();*/
// The debounce function receives our function as a parameter
function debounce(fn) {
// This holds the requestAnimationFrame reference, so we can cancel it if we wish
let frame;
function myfunc() {
// If the frame variable has been defined, clear it now, and queue for next frame
if (frame) {
cancelAnimationFrame(frame);
}
// Queue our function call for the next frame
frame = requestAnimationFrame(function() {
// Call our function and pass any params we received
fn();
});
}
return myfunc;
};
// Reads out the scroll position and stores it in the data attribute
// so we can use it in our stylesheets
function storeScroll() {
// need to use setAttribute instead of dataset, because IE11 won't pick up on it in the CSS changes otherwise
document.documentElement.setAttribute('data-scroll', window.pageYOffset);
}
// Listen for new scroll events, here we debounce our `storeScroll` function
document.addEventListener('scroll', debounce(storeScroll), { passive: true });
// Update scroll position for first time
storeScroll();
// polyfill for IE11
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
}
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = function (callback, thisArg) {
thisArg = thisArg || window;
for (var i = 0; i < this.length; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}
document.addEventListener('DOMContentLoaded', function() {
// add data-label attributes
var tables = document.body.querySelectorAll('section.resources-section table, section.post-section table');
for (var i = 0; i<tables.length; i++) {
var headers = tables[i].querySelectorAll('th');
var rows = tables[i].querySelectorAll('tbody > tr');
for (var r = 0; r<rows.length; r++) {
var cells = rows[r].querySelectorAll('td');
for (var c = 0; c<headers.length; c++) {
if (c < cells.length) {
cells[c].dataset.label = headers[c].innerText;
}
}
}
}
// on the pricing page, add the data-labels to all product rows
var columnLayoutRows = document.body.querySelectorAll('div.column-layout div.features > ul > li');
if (columnLayoutRows.length) {
var columnLayoutContentColumnList = document.body.querySelectorAll('div.column-layout div.content > ul');
for (var i = 0; i < columnLayoutContentColumnList.length; i++) {
var rows = columnLayoutContentColumnList[i].querySelectorAll('li');
var columnLayoutRowCounter = 0;
for (var r = 0; r < rows.length; r++) {
columnLayoutContentColumnList[i].insertBefore(columnLayoutRows[columnLayoutRowCounter].cloneNode(true), rows[r]);
columnLayoutRowCounter++;
if (columnLayoutRows[columnLayoutRowCounter-1].classList.contains('head') ||
columnLayoutRows[columnLayoutRowCounter-1].classList.contains('sub-head')) {
columnLayoutContentColumnList[i].insertBefore(columnLayoutRows[columnLayoutRowCounter].cloneNode(true), rows[r]);
columnLayoutRowCounter++;
}
}
}
}
if (window.location.pathname.endsWith('/pricing/') || window.location.pathname.endsWith('/pricing') || window.location.pathname.endsWith('/pricing.html/') || window.location.pathname.endsWith('/pricing.html')) {
// read params
let params = {};
window.location.search.substr(1).split('&').forEach(function(part) {
var parts = part.split('=');
if (parts.length > 1) {
params[parts[0]] = decodeURIComponent(parts[1])
}
});
// read all product codes and set toggle to 3 years if selected is already 3 years
if (params.currentProductId) {
var isThreeYearsProduct = false;
document.querySelectorAll('section.pricing div.content a.footer').forEach(function(productFooter) {
if (productFooter.dataset['productid_three_years'] == params.currentProductId) {
isThreeYearsProduct = true;
}
})
if (isThreeYearsProduct) {
document.getElementById('duration-toggle').checked = true;
}
}
var THREE_YEARS_FACTOR = 0.75;
// calculate prices correctly
function recalculatePrices() {
function determinePrice(options) {
var r =
(
options.basePrice
+ Math.max(0, Math.min(options.numProjects, options.numProjectsMax) - options.numProjectsIncluded) * options.pricePerProject
+ Math.max(0, Math.min(options.numUsers, options.numUsersMax) - options.numUsersIncluded ) * options.pricePerUser
)
* (options.threeYears ? THREE_YEARS_FACTOR : 1);
return r
}
function format(price, currency) {
var n = Math.round(parseFloat(price));
return currency == '€' ? ( n + ' €') : ( '$' + n );
}
var currency = document.getElementById('currency-toggle').checked ? '€' : '$';
var threeYears = document.getElementById('duration-toggle').checked;
var numProjects = parseInt(document.getElementById('num-projects-input').value, 10);
var numUsers = parseInt(document.getElementById('num-users-input').value, 10);
var numSubscriptionsAvailable = 0;
document.querySelectorAll('section.pricing div.content').forEach(function(productCtn) {
var basePrice = parseInt(productCtn.querySelector('.price').dataset.base_price, 10);
var numProjectsIncluded = parseInt(productCtn.querySelector('.num-projects').dataset.num_projects_included, 10);
var numProjectsMax = parseInt(productCtn.querySelector('.num-projects').dataset.num_projects_max, 10);
var pricePerProject = parseInt(productCtn.querySelector('.num-projects').dataset.price_per_project, 10);
var numUsersIncluded = parseInt(productCtn.querySelector('.num-users').dataset.num_users_included, 10);
var numUsersMax = parseInt(productCtn.querySelector('.num-users').dataset.num_users_max, 10);
var pricePerUser = parseInt(productCtn.querySelector('.num-users').dataset.price_per_user, 10);
var numReleaseSignings = parseInt(productCtn.querySelector('.num-release-signings').dataset.value, 10);
var numTestSignings = parseInt(productCtn.querySelector('.num-test-signings').dataset.value, 10);
var numGBPerProject = parseInt(productCtn.querySelector('.num-gb-per-project').dataset.value, 10);
var numCIPipelines = parseInt(productCtn.querySelector('.num-ci-pipelines').dataset.value, 10);
var ciPipelinesPerProject = productCtn.querySelector('.num-ci-pipelines').dataset.ci_pipelines_per_project == 'true';
if (numProjects > numProjectsMax || numUsers > numUsersMax) {
productCtn.classList.add('match-failed');
} else {
productCtn.classList.remove('match-failed');
numSubscriptionsAvailable++;
}
var actualProjects = Math.min(Math.max(numProjectsIncluded, numProjects), numProjectsMax);
productCtn.querySelector('.num-projects').innerHTML = actualProjects;
productCtn.querySelector('.num-users').innerHTML = Math.min(Math.max(numUsersIncluded, numUsers), numUsersMax);
var options = {
basePrice: basePrice,
threeYears: threeYears,
numProjects: numProjects,
numProjectsIncluded: numProjectsIncluded,
numProjectsMax: numProjectsMax,
pricePerProject: pricePerProject,
numUsers: numUsers,
numUsersIncluded: numUsersIncluded,
numUsersMax: numUsersMax,
pricePerUser: pricePerUser
}
var actualReleaseSignings = numReleaseSignings * actualProjects;
var actualTestSignings = numTestSignings * actualProjects;
productCtn.querySelector('.price').innerText = format(determinePrice(options), currency);
productCtn.querySelector('.price-sub').style.visibility = threeYears ? 'visible' : 'hidden';
productCtn.querySelector('.num-release-signings').innerHTML = actualReleaseSignings;
productCtn.querySelector('.num-test-signings').innerHTML = actualTestSignings;
productCtn.querySelector('.num-gb-per-project').innerHTML = numGBPerProject * actualProjects;
productCtn.querySelector('.num-individual-signatures-per-project').innerHTML = new Intl.NumberFormat().format( (actualReleaseSignings + actualTestSignings) * 100);
if (ciPipelinesPerProject) {
productCtn.querySelector('.num-ci-pipelines').innerHTML = numCIPipelines * actualProjects;
}
productCtn.querySelectorAll('.currency-amount').forEach(function(ctn) {
ctn.innerText = format(parseFloat(ctn.dataset.value) * (threeYears ? THREE_YEARS_FACTOR : 1), currency);
});
var productid = productCtn.querySelector('a.footer').dataset[threeYears ? 'productid_three_years' : 'productid_one_year']
if (params.currentProductId) { // update links
productCtn.querySelector('a.footer').innerText = 'Change';
productCtn.querySelector('a.footer').href = document.documentElement.dataset.appurl
+ '/Web/'
+ params.organizationId
+ '/Subscription/CompleteChange?productId='
+ productid
+ '&paymentToken='
+ encodeURIComponent(params.paymentToken)
+ '&AdditionalCheckoutParameters='
+ encodeURIComponent('&OPTIONS=' + encodeURIComponent(
'num_projects_' + productid + '=' + Math.min(Math.max(numProjects, numProjectsIncluded), numProjectsMax)
+ ',num_users_' + productid + '=' + Math.min(Math.max(numUsers, numUsersIncluded), numUsersMax)
));
} else {
productCtn.querySelector('a.footer').href = 'https://secure.avangate.com/order/checkout.php?PRODS='
+ productid
+ '&QTY=1&CART=1&CARD=1&CLEAN_CART=1&CURRENCY='
+ (currency == '$' ? 'USD' : 'EUR')
+ '&DCURRENCY=' + (currency == '$' ? 'USD' : 'EUR')
+ '&OPTIONS' + productid + '='
+ 'num_projects_' + productid + encodeURIComponent('=' + Math.min(Math.max(numProjects, numProjectsIncluded), numProjectsMax))
+ ',num_users_' + productid + encodeURIComponent('=' + Math.min(Math.max(numUsers, numUsersIncluded), numUsersMax));
}
})
document.querySelector('.editions-dialog').style.display = numSubscriptionsAvailable > 0 ? 'none' : 'block';
}
document.querySelectorAll('section.pricing div.toggle input').forEach(function(input) {
input.addEventListener('change', recalculatePrices);
});
document.querySelectorAll('section.pricing div.number-select > input').forEach(function(input) {
input.addEventListener('change', recalculatePrices);
})
document.querySelectorAll('section.pricing div.number-select > svg').forEach(function(i) {
function changeCounter(e) {
var input = e.target.parentNode.querySelector('input');
input.value = i.classList.contains('plus-circle') ? parseInt(input.value, 10) + 1 : Math.max(1, parseInt(input.value, 10) -1);
recalculatePrices();
}
i.addEventListener('click', changeCounter);
})
recalculatePrices();
window.addEventListener("pageshow", () => {
document.getElementById('num-users-input').value = params['num_users'] || 1;
// '9223372036854775807' is added as a fix because old subscriptions, which don't have a num_projects quota yet will have int64 max value set
document.getElementById('num-projects-input').value = params['num_projects'] !== '9223372036854775807' ? (params['num_projects'] || 1) : 1;
recalculatePrices();
});
}
/** DEVOPS PAGE **/
document.querySelectorAll('section.devops-section div.tabs > ul > li > a').forEach(function(a) {
a.addEventListener('click', function(e) {
var tab = this.dataset.tabkey;
document.querySelectorAll('section.devops-section div.tabs > div.panel > *').forEach(function(panel) {
if (panel.dataset.tabcontent == tab) {
panel.classList.add('active');
} else {
panel.classList.remove('active');
}
})
document.querySelectorAll('section.devops-section div.tabs > ul > li > a').forEach(function(header) {
if (header.dataset.tabkey == tab) {
header.parentNode.classList.add('active');
} else {
header.parentNode.classList.remove('active');
}
})
e.preventDefault();
return false;
});
});
})