web-manager 3.2.54 → 3.2.57
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +1452 -1382
- package/package.json +3 -3
package/index.js
CHANGED
@@ -133,1603 +133,1673 @@ function Manager() {
|
|
133
133
|
store = self.storage();
|
134
134
|
}
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
136
|
+
/**
|
137
|
+
* METHODS
|
138
|
+
*/
|
139
|
+
Manager.prototype.get = function(path) {
|
140
|
+
var self = this;
|
141
141
|
|
142
|
-
|
143
|
-
|
142
|
+
return utilities.get(self, 'properties.' + path);
|
143
|
+
}
|
144
144
|
|
145
|
-
|
146
|
-
|
145
|
+
Manager.prototype.set = function(path, value) {
|
146
|
+
var self = this;
|
147
147
|
|
148
|
-
|
149
|
-
|
148
|
+
return utilities.set(self, 'properties.' + path, value);
|
149
|
+
}
|
150
150
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
// Setup click handler
|
155
|
-
document.addEventListener('click', function (event) {
|
156
|
-
var target = event.target;
|
157
|
-
|
158
|
-
// auth events
|
159
|
-
if (target.matches('.auth-signin-email-btn')) {
|
160
|
-
self.auth().signIn('email');
|
161
|
-
} else if (target.matches('.auth-signup-email-btn')) {
|
162
|
-
self.auth().signUp('email');
|
163
|
-
} else if (target.matches('.auth-signin-provider-btn')) {
|
164
|
-
self.auth().signIn(target.getAttribute('data-provider'));
|
165
|
-
} else if (target.matches('.auth-signup-provider-btn')) {
|
166
|
-
self.auth().signUp(target.getAttribute('data-provider'));
|
167
|
-
} else if (target.matches('.auth-signout-all-btn')) {
|
168
|
-
self.auth().signOut();
|
169
|
-
} else if (target.matches('.auth-forgot-email-btn')) {
|
170
|
-
self.auth().forgot();
|
171
|
-
} else if (target.matches('#prechat-btn')) {
|
172
|
-
load_chatsy(self, self.properties.options);
|
173
|
-
} else if (target.matches('.auth-subscribe-notifications-btn')) {
|
174
|
-
self.notifications().subscribe()
|
175
|
-
} else if (target.matches('.master-alert-close')) {
|
176
|
-
target.parentElement.setAttribute('hidden', true);
|
177
|
-
}
|
151
|
+
Manager.prototype.setEventListeners = function() {
|
152
|
+
var self = this;
|
178
153
|
|
179
|
-
|
180
|
-
|
181
|
-
|
154
|
+
// Setup click handler
|
155
|
+
document.addEventListener('click', function (event) {
|
156
|
+
var target = event.target;
|
157
|
+
|
158
|
+
// auth events
|
159
|
+
if (target.matches('.auth-signin-email-btn')) {
|
160
|
+
self.auth().signIn('email');
|
161
|
+
} else if (target.matches('.auth-signup-email-btn')) {
|
162
|
+
self.auth().signUp('email');
|
163
|
+
} else if (target.matches('.auth-signin-provider-btn')) {
|
164
|
+
self.auth().signIn(target.getAttribute('data-provider'));
|
165
|
+
} else if (target.matches('.auth-signup-provider-btn')) {
|
166
|
+
self.auth().signUp(target.getAttribute('data-provider'));
|
167
|
+
} else if (target.matches('.auth-signout-all-btn')) {
|
168
|
+
self.auth().signOut();
|
169
|
+
} else if (target.matches('.auth-forgot-email-btn')) {
|
170
|
+
self.auth().forgot();
|
171
|
+
} else if (target.matches('#prechat-btn')) {
|
172
|
+
load_chatsy(self, self.properties.options);
|
173
|
+
} else if (target.matches('.auth-subscribe-notifications-btn')) {
|
174
|
+
self.notifications().subscribe()
|
175
|
+
} else if (target.matches('.master-alert-close')) {
|
176
|
+
target.parentElement.setAttribute('hidden', true);
|
177
|
+
}
|
182
178
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
}
|
179
|
+
// Autorequest
|
180
|
+
if (!self._notificationRequested && self.properties.options.pushNotifications.autoRequest) {
|
181
|
+
self._notificationRequested = true;
|
187
182
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
183
|
+
setTimeout(function () {
|
184
|
+
self.notifications().subscribe()
|
185
|
+
}, self.properties.options.pushNotifications.autoRequest * 1000);
|
186
|
+
}
|
187
|
+
|
188
|
+
});
|
189
|
+
|
190
|
+
// Mouse leave event
|
191
|
+
document.addEventListener('mouseleave', function () {
|
192
|
+
showExitPopup(self);
|
193
|
+
});
|
194
|
+
|
195
|
+
// Window blur event
|
196
|
+
window.addEventListener('blur', function () {
|
197
|
+
showExitPopup(self);
|
198
|
+
});
|
199
|
+
|
200
|
+
// Re-focus events
|
201
|
+
window.addEventListener('focus', function () {
|
202
|
+
refreshNewVersion(self);
|
203
|
+
});
|
204
|
+
window.addEventListener('online', function () {
|
205
|
+
refreshNewVersion(self);
|
206
|
+
});
|
207
|
+
setInterval(function () {
|
208
|
+
refreshNewVersion(self);
|
209
|
+
}, 1000 * 60 * 60); // Fetch new version every 1 hour
|
210
210
|
|
211
|
+
}
|
212
|
+
|
213
|
+
function _authStateHandler(self, user) {
|
214
|
+
// self.log('----authStateHandler', user);
|
215
|
+
if (!user || user.isAnonymous) {
|
216
|
+
return _authHandle_out(self);
|
211
217
|
}
|
212
218
|
|
213
|
-
|
214
|
-
// self.log('----authStateHandler', user);
|
215
|
-
if (!user || user.isAnonymous) {
|
216
|
-
return _authHandle_out(self);
|
217
|
-
}
|
219
|
+
_authHandle_in_normal(self, user);
|
218
220
|
|
219
|
-
|
221
|
+
self.notifications().subscribe().catch(function (e) {
|
222
|
+
console.error(e);
|
223
|
+
});
|
224
|
+
}
|
220
225
|
|
221
|
-
|
222
|
-
|
223
|
-
|
226
|
+
// MOVED TO UJ - 12/15/23
|
227
|
+
// function _authHandle_in(self, user) {
|
228
|
+
// // self.log('_authHandle_in', user);
|
229
|
+
// // if (self.properties.page.status.didSignUp) {
|
230
|
+
// var done;
|
231
|
+
// var hoursSinceCreation = Math.abs(new Date() - new Date(+user.metadata.createdAt)) / 36e5;
|
232
|
+
|
233
|
+
// function _done() {
|
234
|
+
// if (!done) {
|
235
|
+
// done = true;
|
236
|
+
// store.set('didSignUp', true)
|
237
|
+
// _authHandle_in_normal(self, user);
|
238
|
+
// }
|
239
|
+
// }
|
240
|
+
|
241
|
+
// if (!store.get('didSignUp') && hoursSinceCreation < 0.5) {
|
242
|
+
// user.getIdToken(false)
|
243
|
+
// .then(function(token) {
|
244
|
+
|
245
|
+
// fetch('https://us-central1-' + self.properties.options.libraries.firebase_app.config.projectId + '.cloudfunctions.net/bm_api', {
|
246
|
+
// method: 'POST',
|
247
|
+
// body: JSON.stringify({
|
248
|
+
// authenticationToken: token,
|
249
|
+
// command: 'user:sign-up',
|
250
|
+
// payload: {
|
251
|
+
// newsletterSignUp: select('.auth-newsletter-input').getValue(),
|
252
|
+
// // affiliateCode: store.get('auth.affiliateCode', ''),
|
253
|
+
// affiliateCode: store.get('affiliateCode', ''),
|
254
|
+
// },
|
255
|
+
// }),
|
256
|
+
// })
|
257
|
+
// .catch(function () {})
|
258
|
+
// .finally(_done);
|
259
|
+
|
260
|
+
// setTimeout(function () {
|
261
|
+
// _done()
|
262
|
+
// }, 5000);
|
263
|
+
|
264
|
+
// })
|
265
|
+
// .catch(function(error) {
|
266
|
+
// console.error(error);
|
267
|
+
// _done();
|
268
|
+
// });
|
269
|
+
// } else {
|
270
|
+
// _done();
|
271
|
+
// }
|
272
|
+
// }
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
function _authHandle_in_normal(self, user) {
|
277
|
+
var returnUrl = self.properties.page.queryString.get('auth_redirect');
|
278
|
+
|
279
|
+
// Check if we have a return URL and it is valid
|
280
|
+
if (returnUrl && self.isValidRedirectUrl(returnUrl)) {
|
281
|
+
window.location.href = decodeURIComponent(returnUrl);
|
282
|
+
return;
|
224
283
|
}
|
225
284
|
|
226
|
-
//
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
// var done;
|
231
|
-
// var hoursSinceCreation = Math.abs(new Date() - new Date(+user.metadata.createdAt)) / 36e5;
|
232
|
-
|
233
|
-
// function _done() {
|
234
|
-
// if (!done) {
|
235
|
-
// done = true;
|
236
|
-
// store.set('didSignUp', true)
|
237
|
-
// _authHandle_in_normal(self, user);
|
238
|
-
// }
|
239
|
-
// }
|
240
|
-
|
241
|
-
// if (!store.get('didSignUp') && hoursSinceCreation < 0.5) {
|
242
|
-
// user.getIdToken(false)
|
243
|
-
// .then(function(token) {
|
244
|
-
|
245
|
-
// fetch('https://us-central1-' + self.properties.options.libraries.firebase_app.config.projectId + '.cloudfunctions.net/bm_api', {
|
246
|
-
// method: 'POST',
|
247
|
-
// body: JSON.stringify({
|
248
|
-
// authenticationToken: token,
|
249
|
-
// command: 'user:sign-up',
|
250
|
-
// payload: {
|
251
|
-
// newsletterSignUp: select('.auth-newsletter-input').getValue(),
|
252
|
-
// // affiliateCode: store.get('auth.affiliateCode', ''),
|
253
|
-
// affiliateCode: store.get('affiliateCode', ''),
|
254
|
-
// },
|
255
|
-
// }),
|
256
|
-
// })
|
257
|
-
// .catch(function () {})
|
258
|
-
// .finally(_done);
|
259
|
-
|
260
|
-
// setTimeout(function () {
|
261
|
-
// _done()
|
262
|
-
// }, 5000);
|
263
|
-
|
264
|
-
// })
|
265
|
-
// .catch(function(error) {
|
266
|
-
// console.error(error);
|
267
|
-
// _done();
|
268
|
-
// });
|
269
|
-
// } else {
|
270
|
-
// _done();
|
271
|
-
// }
|
272
|
-
// }
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
function _authHandle_in_normal(self, user) {
|
277
|
-
var returnUrl = self.properties.page.queryString.get('auth_redirect');
|
278
|
-
if (returnUrl && self.isValidRedirectUrl(returnUrl)) {
|
279
|
-
window.location.href = decodeURIComponent(returnUrl);
|
280
|
-
return;
|
281
|
-
}
|
282
|
-
if (self.properties.options.auth.state === 'prohibited') {
|
283
|
-
window.location.href = self.properties.options.auth.sends.prohibited;
|
284
|
-
return;
|
285
|
-
}
|
286
|
-
select('.auth-signedin-true-element').show();
|
287
|
-
select('.auth-signedin-false-element').hide();
|
288
|
-
select('.auth-email-element').each(function(e, i) {
|
289
|
-
if (e.tagName === 'INPUT') {
|
290
|
-
select(e).setValue(user.email)
|
291
|
-
} else {
|
292
|
-
select(e).setInnerHTML(user.email)
|
293
|
-
}
|
294
|
-
});
|
295
|
-
select('.auth-uid-element').each(function(e, i) {
|
296
|
-
if (e.tagName === 'INPUT') {
|
297
|
-
select(e).setValue(user.uid)
|
298
|
-
} else {
|
299
|
-
select(e).setInnerHTML(user.uid)
|
300
|
-
}
|
301
|
-
});
|
285
|
+
// If auth is prohibited, redirect to the prohibited page
|
286
|
+
if (self.properties.options.auth.state === 'prohibited') {
|
287
|
+
window.location.href = self.properties.options.auth.sends.prohibited;
|
288
|
+
return;
|
302
289
|
}
|
303
290
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
291
|
+
// Handle visibility
|
292
|
+
// select('.auth-signedin-true-element').show();
|
293
|
+
// select('.auth-signedin-false-element').hide();
|
294
|
+
select('.auth-signedin-true-element').each(function ($el) {
|
295
|
+
var $el2 = select($el);
|
296
|
+
$el2.show();
|
297
|
+
|
298
|
+
console.warn('DEPRECATED: auth-signedin-true-element', $el);
|
299
|
+
});
|
300
|
+
select('.auth-signedin-false-element').each(function ($el) {
|
301
|
+
var $el2 = select($el);
|
302
|
+
$el2.hide();
|
303
|
+
|
304
|
+
console.warn('DEPRECATED: auth-signedin-false-element', $el);
|
305
|
+
});
|
306
|
+
_authHandleState(self, 'signed-in');
|
307
|
+
|
308
|
+
// Set user email
|
309
|
+
select('.auth-email-element').each(function(e, i) {
|
310
|
+
if (e.tagName === 'INPUT') {
|
311
|
+
select(e).setValue(user.email)
|
312
|
+
} else {
|
313
|
+
select(e).setInnerHTML(user.email)
|
314
|
+
}
|
315
|
+
});
|
316
|
+
|
317
|
+
// Set user id
|
318
|
+
select('.auth-uid-element').each(function(e, i) {
|
319
|
+
if (e.tagName === 'INPUT') {
|
320
|
+
select(e).setValue(user.uid)
|
321
|
+
} else {
|
322
|
+
select(e).setInnerHTML(user.uid)
|
311
323
|
}
|
324
|
+
});
|
325
|
+
}
|
312
326
|
|
313
|
-
|
314
|
-
|
327
|
+
function _authHandle_out(self) {
|
328
|
+
// If auth is required, redirect to the required page
|
329
|
+
if (self.properties.options.auth.state === 'required') {
|
330
|
+
var sendSplit = self.properties.options.auth.sends.required.split('?');
|
331
|
+
var newQuery = new URLSearchParams(sendSplit[1]);
|
332
|
+
newQuery.set('auth_redirect', window.location.href);
|
333
|
+
window.location.href = sendSplit[0] + '?' + newQuery.toString();
|
334
|
+
return;
|
315
335
|
}
|
316
336
|
|
317
|
-
|
318
|
-
|
319
|
-
|
337
|
+
// select('.auth-signedin-true-element').hide();
|
338
|
+
// select('.auth-signedin-false-element').show();
|
339
|
+
select('.auth-signedin-true-element').each(function ($el) {
|
340
|
+
var $el2 = select($el);
|
341
|
+
$el2.hide();
|
320
342
|
|
321
|
-
|
322
|
-
|
343
|
+
console.warn('DEPRECATED: auth-signedin-true-element', $el);
|
344
|
+
});
|
345
|
+
select('.auth-signedin-false-element').each(function ($el) {
|
346
|
+
var $el2 = select($el);
|
347
|
+
$el2.show();
|
323
348
|
|
324
|
-
|
349
|
+
console.warn('DEPRECATED: auth-signedin-false-element', $el);
|
350
|
+
});
|
325
351
|
|
326
|
-
|
327
|
-
|
328
|
-
self.ready(fn, options);
|
329
|
-
}, options.interval);
|
330
|
-
} else {
|
331
|
-
// Performance
|
332
|
-
self.performance().mark('manager_ready');
|
352
|
+
_authHandleState(self, 'signed-out');
|
353
|
+
}
|
333
354
|
|
334
|
-
|
355
|
+
function _authHandleState(self, state) {
|
356
|
+
var $stateAll = select('.auth-state-listener');
|
357
|
+
|
358
|
+
// Loop through all elements with the class and hide first
|
359
|
+
$stateAll
|
360
|
+
.each(function ($el) {
|
361
|
+
$el.setAttribute('hidden', true);
|
362
|
+
})
|
363
|
+
|
364
|
+
// Loop through all elements with the class and check the data-state attribute
|
365
|
+
$stateAll
|
366
|
+
.each(function ($el) {
|
367
|
+
var s = $el.getAttribute('data-state');
|
368
|
+
|
369
|
+
// If we are in the correct status
|
370
|
+
if (s !== state) {
|
371
|
+
// Hide the element
|
372
|
+
return $el.setAttribute('hidden', true);
|
335
373
|
}
|
374
|
+
|
375
|
+
// Show the element
|
376
|
+
$el.removeAttribute('hidden');
|
377
|
+
})
|
378
|
+
}
|
379
|
+
|
380
|
+
Manager.prototype.ready = function(fn, options) {
|
381
|
+
var self = this;
|
382
|
+
var waitFor = true;
|
383
|
+
|
384
|
+
options = options || {};
|
385
|
+
options.interval = options.interval || 100;
|
386
|
+
|
387
|
+
waitFor = !options.waitFor || (options.waitFor && options.waitFor())
|
388
|
+
|
389
|
+
if (!utilities.get(this, 'properties.page.status.ready', false) || !waitFor) {
|
390
|
+
setTimeout(function () {
|
391
|
+
self.ready(fn, options);
|
392
|
+
}, options.interval);
|
393
|
+
} else {
|
394
|
+
// Performance
|
395
|
+
self.performance().mark('manager_ready');
|
396
|
+
|
397
|
+
return fn();
|
336
398
|
}
|
399
|
+
}
|
337
400
|
|
338
|
-
|
339
|
-
|
340
|
-
|
401
|
+
Manager.prototype.serviceWorker = function() {
|
402
|
+
var self = this;
|
403
|
+
var SWAvailable = 'serviceWorker' in navigator;
|
341
404
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
405
|
+
if (SWAvailable) {
|
406
|
+
try {
|
407
|
+
var swref = self.properties.references.serviceWorker.active || navigator.serviceWorker.controller;
|
408
|
+
} catch (e) {}
|
409
|
+
}
|
347
410
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
try {
|
355
|
-
var messageChannel = new MessageChannel();
|
356
|
-
messageChannel.port1.onmessage = function(event) {
|
357
|
-
if (!event.data.error && args[1]) {
|
358
|
-
args[1](event.data);
|
359
|
-
}
|
360
|
-
};
|
361
|
-
// navigator.serviceWorker.controller.postMessage(args[0], [messageChannel.port2]);
|
362
|
-
swref.postMessage(args[0], [messageChannel.port2]);
|
363
|
-
} catch (e) {
|
364
|
-
console.error(e);
|
365
|
-
}
|
411
|
+
return {
|
412
|
+
postMessage: function() {
|
413
|
+
// var args = getArgs(arguments);
|
414
|
+
var args = arguments;
|
415
|
+
if (!SWAvailable) {return};
|
366
416
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
//
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
// }
|
379
|
-
// };
|
380
|
-
// navigator.serviceWorker.controller.postMessage(args[0], [messageChannel.port2])
|
381
|
-
// }
|
417
|
+
try {
|
418
|
+
var messageChannel = new MessageChannel();
|
419
|
+
messageChannel.port1.onmessage = function(event) {
|
420
|
+
if (!event.data.error && args[1]) {
|
421
|
+
args[1](event.data);
|
422
|
+
}
|
423
|
+
};
|
424
|
+
// navigator.serviceWorker.controller.postMessage(args[0], [messageChannel.port2]);
|
425
|
+
swref.postMessage(args[0], [messageChannel.port2]);
|
426
|
+
} catch (e) {
|
427
|
+
console.error(e);
|
382
428
|
}
|
429
|
+
|
430
|
+
// if (!navigator.serviceWorker.controller) {
|
431
|
+
// self.log('postMessage...');
|
432
|
+
// setTimeout(function () {
|
433
|
+
// self.serviceWorker().postMessage(args[0], args[1]);
|
434
|
+
// }, 100);
|
435
|
+
// } else {
|
436
|
+
// // post message: https://stackoverflow.com/questions/30177782/chrome-serviceworker-postmessage
|
437
|
+
// var messageChannel = new MessageChannel();
|
438
|
+
// messageChannel.port1.onmessage = function(event) {
|
439
|
+
// if (!event.data.error && args[1]) {
|
440
|
+
// args[1](event.data);
|
441
|
+
// }
|
442
|
+
// };
|
443
|
+
// navigator.serviceWorker.controller.postMessage(args[0], [messageChannel.port2])
|
444
|
+
// }
|
383
445
|
}
|
384
446
|
}
|
447
|
+
}
|
385
448
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
449
|
+
// init with polyfills
|
450
|
+
Manager.prototype.init = function(configuration, callback) {
|
451
|
+
var self = this;
|
452
|
+
var status = self.properties.page.status;
|
453
|
+
|
454
|
+
if (
|
455
|
+
!status.ready
|
456
|
+
&& !status.initilizing
|
457
|
+
) {
|
458
|
+
|
459
|
+
// Performance
|
460
|
+
self.performance().mark('manager_init');
|
461
|
+
|
462
|
+
// set initializing to true
|
463
|
+
self.properties.page.status.initializing = true;
|
464
|
+
|
465
|
+
// set other properties
|
466
|
+
self.properties.meta.environment = window.location.host.match(/:40|ngrok/)
|
467
|
+
? 'development'
|
468
|
+
: 'production';
|
469
|
+
|
470
|
+
// Load polyfills
|
471
|
+
init_loadPolyfills(self, configuration, function() {
|
472
|
+
self.properties.page.status.initializing = false;
|
473
|
+
// self.properties.genericPromise = new Promise(resolve => { resolve() });
|
474
|
+
var options_defaults = {
|
475
|
+
// debug: {
|
476
|
+
// environment: self.properties.meta.environment,
|
477
|
+
// },
|
478
|
+
// queryString: {
|
479
|
+
// saveToStorage: false
|
480
|
+
// },
|
481
|
+
pushNotifications: {
|
482
|
+
autoRequest: 60, // how long to wait before auto ask, 0 to disable
|
483
|
+
},
|
484
|
+
serviceWorker: {
|
485
|
+
path: '',
|
486
|
+
},
|
487
|
+
initChecks: {
|
488
|
+
features: [], // an array of javascript and dom features to check for (NIY)
|
489
|
+
},
|
490
|
+
auth: {
|
491
|
+
state: 'default', // required, prohibited, default
|
492
|
+
sends: {
|
493
|
+
required: '/signup',
|
494
|
+
prohibited: '/',
|
426
495
|
},
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
496
|
+
},
|
497
|
+
exitPopup: {
|
498
|
+
enabled: true,
|
499
|
+
config: {
|
500
|
+
timeout: 1000 * 60 * 60 * 4,
|
501
|
+
handler: null,
|
502
|
+
title: 'Special Offer!',
|
503
|
+
message: 'Get 15% off your purchase of our <strong>Premium plans</strong>. <br><br> Get access to all features and unlimited usage.',
|
504
|
+
okButton: {
|
505
|
+
text: 'Claim 15% Discount',
|
506
|
+
link: '/pricing?utm_source=exit-popup&utm_medium=popup&utm_campaign={pathname}',
|
432
507
|
},
|
433
508
|
},
|
434
|
-
|
509
|
+
},
|
510
|
+
libraries: {
|
511
|
+
firebase_app: {
|
435
512
|
enabled: true,
|
513
|
+
load: false,
|
436
514
|
config: {
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
515
|
+
apiKey: '',
|
516
|
+
authDomain: '',
|
517
|
+
databaseURL: '',
|
518
|
+
projectId: '',
|
519
|
+
storageBucket: '',
|
520
|
+
messagingSenderId: '',
|
521
|
+
appId: '',
|
522
|
+
measurementId: '',
|
445
523
|
},
|
446
524
|
},
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
load: false,
|
465
|
-
},
|
466
|
-
firebase_firestore: {
|
467
|
-
enabled: true,
|
468
|
-
load: false,
|
469
|
-
},
|
470
|
-
firebase_messaging: {
|
471
|
-
enabled: true,
|
472
|
-
load: false,
|
473
|
-
},
|
474
|
-
firebase_appCheck: {
|
475
|
-
enabled: true,
|
476
|
-
load: false,
|
477
|
-
config: {
|
478
|
-
siteKey: '',
|
479
|
-
},
|
480
|
-
},
|
481
|
-
lazysizes: {
|
482
|
-
enabled: true,
|
525
|
+
firebase_auth: {
|
526
|
+
enabled: true,
|
527
|
+
load: false,
|
528
|
+
},
|
529
|
+
firebase_firestore: {
|
530
|
+
enabled: true,
|
531
|
+
load: false,
|
532
|
+
},
|
533
|
+
firebase_messaging: {
|
534
|
+
enabled: true,
|
535
|
+
load: false,
|
536
|
+
},
|
537
|
+
firebase_appCheck: {
|
538
|
+
enabled: true,
|
539
|
+
load: false,
|
540
|
+
config: {
|
541
|
+
siteKey: '',
|
483
542
|
},
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
543
|
+
},
|
544
|
+
lazysizes: {
|
545
|
+
enabled: true,
|
546
|
+
},
|
547
|
+
sentry: {
|
548
|
+
enabled: true,
|
549
|
+
config: {
|
550
|
+
dsn: '',
|
551
|
+
release: '',
|
552
|
+
replaysSessionSampleRate: 0.01,
|
553
|
+
replaysOnErrorSampleRate: 0.01,
|
492
554
|
},
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
555
|
+
},
|
556
|
+
chatsy: {
|
557
|
+
enabled: true,
|
558
|
+
config: {
|
559
|
+
accountId: '',
|
560
|
+
chatId: '',
|
561
|
+
settings: {
|
562
|
+
openChatButton: {
|
563
|
+
background: '#237afc',
|
564
|
+
text: '#fff',
|
503
565
|
},
|
504
566
|
},
|
505
567
|
},
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
button: {
|
515
|
-
background: '#fff',
|
516
|
-
text: '#237afc',
|
517
|
-
},
|
568
|
+
},
|
569
|
+
cookieconsent: {
|
570
|
+
enabled: true,
|
571
|
+
config: {
|
572
|
+
palette: {
|
573
|
+
popup: {
|
574
|
+
background: '#237afc',
|
575
|
+
text: '#fff',
|
518
576
|
},
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
showLink: false,
|
523
|
-
content: {
|
524
|
-
message: 'We use cookies to ensure you get the best experience on our website. By continuing to use the site, you agree to our<a href="/terms" class="cc-link" style="padding-right: 0">terms of service</a>.',
|
525
|
-
// dismiss: 'Got it!',
|
526
|
-
dismiss: 'I understand',
|
577
|
+
button: {
|
578
|
+
background: '#fff',
|
579
|
+
text: '#237afc',
|
527
580
|
},
|
528
581
|
},
|
582
|
+
theme: 'classic',
|
583
|
+
position: 'bottom-left',
|
584
|
+
type: '',
|
585
|
+
showLink: false,
|
586
|
+
content: {
|
587
|
+
message: 'We use cookies to ensure you get the best experience on our website. By continuing to use the site, you agree to our<a href="/terms" class="cc-link" style="padding-right: 0">terms of service</a>.',
|
588
|
+
// dismiss: 'Got it!',
|
589
|
+
dismiss: 'I understand',
|
590
|
+
},
|
529
591
|
},
|
530
592
|
},
|
531
|
-
}
|
593
|
+
},
|
594
|
+
};
|
532
595
|
|
533
|
-
|
534
|
-
|
535
|
-
|
596
|
+
var options_user = {};
|
597
|
+
function eachRecursive(obj, parent) {
|
598
|
+
parent = (!parent) ? '' : parent;
|
536
599
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
}
|
600
|
+
for (var key in obj) {
|
601
|
+
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
|
602
|
+
eachRecursive(obj[key], parent + key + '.');
|
603
|
+
} else {
|
604
|
+
utilities.set(options_user, parent + key, utilities.get(options_defaults, parent + key) );
|
605
|
+
var t_globalItem = utilities.get(configuration, 'global.settings.' + parent + key, undefined);
|
606
|
+
var t_pageItem = utilities.get(configuration, 'page.settings.' + parent + key, undefined);
|
607
|
+
if (typeof t_globalItem !== 'undefined') {
|
608
|
+
utilities.set(options_user, parent + key, t_globalItem);
|
609
|
+
}
|
610
|
+
if (typeof t_pageItem !== 'undefined') {
|
611
|
+
utilities.set(options_user, parent + key, t_pageItem);
|
550
612
|
}
|
551
613
|
}
|
552
614
|
}
|
615
|
+
}
|
553
616
|
|
554
|
-
|
555
|
-
|
617
|
+
eachRecursive(options_defaults);
|
618
|
+
self.properties.options = options_user;
|
556
619
|
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
620
|
+
// set non-option properties
|
621
|
+
self.properties.global.app = configuration.global.app;
|
622
|
+
self.properties.global.version = configuration.global.version;
|
623
|
+
self.properties.global.url = configuration.global.url;
|
624
|
+
self.properties.global.buildTime = new Date((+configuration.global.buildTime * 1000) || new Date())
|
625
|
+
self.properties.global.cacheBreaker = configuration.global.cacheBreaker;
|
563
626
|
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
627
|
+
self.properties.global.brand = configuration.global.brand;
|
628
|
+
self.properties.global.contact = configuration.global.contact;
|
629
|
+
self.properties.global.download = configuration.global.download;
|
630
|
+
self.properties.global.extension = configuration.global.extension;
|
568
631
|
|
569
|
-
|
570
|
-
|
571
|
-
|
632
|
+
self.properties.global.validRedirectHosts = configuration.global.validRedirectHosts;
|
633
|
+
self.properties.meta.environment = utilities.get(configuration, 'global.settings.debug.environment', self.properties.meta.environment);
|
634
|
+
self.properties.page.queryString = new URLSearchParams(window.location.search);
|
572
635
|
|
573
|
-
|
574
|
-
|
636
|
+
var pagePathname = window.location.pathname;
|
637
|
+
var redirect = false;
|
575
638
|
|
576
|
-
|
577
|
-
|
639
|
+
var previousUTMTimestamp = new Date(store.get('utm.timestamp', 0));
|
640
|
+
var UTMDifferenceInHours = (new Date() - previousUTMTimestamp) / 36e5;
|
578
641
|
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
642
|
+
self.properties.page.queryString.forEach(function (value, key) {
|
643
|
+
if (key.startsWith('utm_') && UTMDifferenceInHours > 72) {
|
644
|
+
store.set('utm.tags.' + key, value);
|
645
|
+
store.set('utm.timestamp', new Date().toISOString());
|
646
|
+
}
|
584
647
|
|
585
|
-
|
586
|
-
|
587
|
-
|
648
|
+
if (key === 'aff') {
|
649
|
+
store.set('affiliateCode', value);
|
650
|
+
}
|
588
651
|
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
652
|
+
if (key === 'redirect') {
|
653
|
+
// redirect = decodeURIComponent(value) // 9/22/23 - Removed this and replace without the decode
|
654
|
+
redirect = value;
|
655
|
+
}
|
656
|
+
})
|
657
|
+
|
658
|
+
// Redirect if we have a redirect query
|
659
|
+
if (redirect && self.isValidRedirectUrl(redirect)) {
|
660
|
+
return window.location.href = redirect;
|
661
|
+
}
|
662
|
+
|
663
|
+
// Detect if we are on a page that requires authentication
|
664
|
+
if (pagePathname.match(/\/(authentication-required|authentication-success|authentication-token|forgot|oauth2|signin|signout|signup)/)) {
|
665
|
+
import('./helpers/auth-pages.js')
|
666
|
+
.then(function(mod) {
|
667
|
+
mod.default()
|
593
668
|
})
|
669
|
+
}
|
594
670
|
|
595
|
-
|
596
|
-
|
597
|
-
|
671
|
+
// load critical libraries
|
672
|
+
function postCrucial() {
|
673
|
+
// console.log('HERE 5');
|
598
674
|
|
599
|
-
|
600
|
-
|
601
|
-
.
|
602
|
-
|
675
|
+
// handle firebase user
|
676
|
+
if (typeof firebase !== 'undefined' && firebase.auth) {
|
677
|
+
firebase.auth().onAuthStateChanged(function(user) {
|
678
|
+
self.properties.page.status.authReady = true;
|
679
|
+
self.properties.auth.user = user || false;
|
680
|
+
_authStateHandler(self, user);
|
603
681
|
})
|
604
682
|
}
|
605
683
|
|
606
|
-
//
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
if (
|
612
|
-
|
613
|
-
|
614
|
-
self.properties.auth.user = user || false;
|
615
|
-
_authStateHandler(self, user);
|
616
|
-
})
|
684
|
+
// setup
|
685
|
+
self.setEventListeners();
|
686
|
+
|
687
|
+
// display outdated if it is
|
688
|
+
try {
|
689
|
+
if (!self.properties.page.isSupportedBrowser) {
|
690
|
+
var box = document.getElementsByClassName('master-alert-outdated')[0];
|
691
|
+
box.removeAttribute('hidden');
|
617
692
|
}
|
693
|
+
} catch (e) {
|
694
|
+
console.error(e);
|
695
|
+
}
|
618
696
|
|
619
|
-
|
620
|
-
|
697
|
+
// run the init callback
|
698
|
+
self.properties.page.status.ready = true;
|
621
699
|
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
}
|
628
|
-
} catch (e) {
|
629
|
-
console.error(e);
|
630
|
-
}
|
700
|
+
try {
|
701
|
+
callback();
|
702
|
+
} catch (e) {
|
703
|
+
console.error(e);
|
704
|
+
}
|
631
705
|
|
632
|
-
|
633
|
-
|
706
|
+
var chatsyOps = options_user.libraries.chatsy;
|
707
|
+
if (chatsyOps.enabled) {
|
708
|
+
var $preChatBtn = select('#prechat-btn');
|
709
|
+
var $preChatBtnSvg = select('#prechat-btn svg path');
|
710
|
+
var openChatButtonSettings = chatsyOps.config.settings.openChatButton;
|
634
711
|
|
635
|
-
|
636
|
-
|
637
|
-
}
|
638
|
-
|
712
|
+
$preChatBtn.css({
|
713
|
+
background: openChatButtonSettings.background,
|
714
|
+
})
|
715
|
+
.show();
|
716
|
+
|
717
|
+
$preChatBtnSvg.each(function ($el) {
|
718
|
+
$el.setAttribute('fill', openChatButtonSettings.text)
|
719
|
+
})
|
720
|
+
|
721
|
+
window.chatsy = {};
|
722
|
+
window.chatsy.open = function() {
|
723
|
+
$preChatBtn.get(0).click();
|
639
724
|
}
|
725
|
+
}
|
640
726
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
var openChatButtonSettings = chatsyOps.config.settings.openChatButton;
|
727
|
+
// load non-critical libraries
|
728
|
+
load_lazysizes(self, options_user);
|
729
|
+
load_cookieconsent(self, options_user);
|
730
|
+
subscriptionManager(self, options_user);
|
646
731
|
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
.show();
|
732
|
+
// self.log('Manager', self);
|
733
|
+
return;
|
734
|
+
}
|
651
735
|
|
652
|
-
|
653
|
-
|
654
|
-
|
736
|
+
Promise.all([
|
737
|
+
load_sentry(self, options_user),
|
738
|
+
load_firebase(self, options_user),
|
739
|
+
])
|
740
|
+
.then(function() {
|
741
|
+
postCrucial();
|
742
|
+
})
|
743
|
+
.catch(function (e) {
|
744
|
+
console.error('Lib error', e);
|
745
|
+
})
|
746
|
+
})
|
655
747
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
}
|
660
|
-
}
|
748
|
+
} else {
|
749
|
+
return;
|
750
|
+
}
|
661
751
|
|
662
|
-
|
663
|
-
load_lazysizes(self, options_user);
|
664
|
-
load_cookieconsent(self, options_user);
|
665
|
-
subscriptionManager(self, options_user);
|
752
|
+
}
|
666
753
|
|
667
|
-
|
668
|
-
|
669
|
-
|
754
|
+
Manager.prototype.sentry = function() {
|
755
|
+
// var en = (Sentry && Sentry)
|
756
|
+
return {
|
757
|
+
configureScope: function (cb) {
|
758
|
+
try {
|
759
|
+
Sentry.configureScope(function (scope) {
|
760
|
+
cb(scope);
|
761
|
+
})
|
762
|
+
} catch (e) {
|
670
763
|
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
})
|
678
|
-
.catch(function (e) {
|
679
|
-
console.error('Lib error', e);
|
680
|
-
})
|
681
|
-
})
|
764
|
+
}
|
765
|
+
},
|
766
|
+
captureException: function (e) {
|
767
|
+
try {
|
768
|
+
Sentry.captureException(e)
|
769
|
+
} catch (e) {
|
682
770
|
|
683
|
-
|
684
|
-
return;
|
771
|
+
}
|
685
772
|
}
|
773
|
+
};
|
774
|
+
}
|
775
|
+
|
776
|
+
Manager.prototype.auth = function() {
|
777
|
+
var self = this;
|
778
|
+
var firebaseActive = typeof firebase !== 'undefined';
|
779
|
+
var $error = select('.auth-error-message-element');
|
686
780
|
|
781
|
+
function _displayError(msg) {
|
782
|
+
console.error(msg);
|
783
|
+
$error.show().setInnerHTML(msg);
|
784
|
+
}
|
785
|
+
function _preDisplayError() {
|
786
|
+
$error.hide().setInnerHTML('');
|
687
787
|
}
|
688
788
|
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
789
|
+
function setAuthButtonDisabled(button, status) {
|
790
|
+
var el = select('.auth-' + button + '-email-btn');
|
791
|
+
var disabled = 'disabled';
|
792
|
+
if (status) {
|
793
|
+
el.setAttribute(disabled, true);
|
794
|
+
} else {
|
795
|
+
el.removeAttribute(disabled);
|
796
|
+
}
|
797
|
+
}
|
698
798
|
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
799
|
+
function selectAuthInput(mode, input) {
|
800
|
+
var prefix = '.auth-';
|
801
|
+
var inputSelector = prefix + input + '-input';
|
802
|
+
var formSelector = prefix + mode + '-form ';
|
803
|
+
var formInput = select(formSelector + inputSelector);
|
804
|
+
var input = select(inputSelector);
|
705
805
|
|
706
|
-
|
707
|
-
}
|
708
|
-
};
|
806
|
+
return formInput.exists() ? formInput : input;
|
709
807
|
}
|
710
808
|
|
711
|
-
|
712
|
-
var
|
713
|
-
var firebaseActive = typeof firebase !== 'undefined';
|
714
|
-
var $error = select('.auth-error-message-element');
|
809
|
+
function resolveAuthInputValue(existing, mode, input) {
|
810
|
+
var result = existing || selectAuthInput(mode, input).getValue();
|
715
811
|
|
716
|
-
|
717
|
-
|
718
|
-
$error.show().setInnerHTML(msg);
|
719
|
-
}
|
720
|
-
function _preDisplayError() {
|
721
|
-
$error.hide().setInnerHTML('');
|
722
|
-
}
|
812
|
+
return input === 'email' ? result.trim().toLowerCase() : result;
|
813
|
+
}
|
723
814
|
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
815
|
+
function uxHandler(email, password, passwordConfirm, mode) {
|
816
|
+
if (!email) {
|
817
|
+
selectAuthInput(mode, 'email').get(0).focus();
|
818
|
+
} else {
|
819
|
+
selectAuthInput(mode, 'password').get(0).focus();
|
820
|
+
if (mode === 'signup') {
|
821
|
+
selectAuthInput(mode, 'password-confirm').get(0).focus();
|
731
822
|
}
|
732
823
|
}
|
824
|
+
}
|
733
825
|
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
var
|
826
|
+
return {
|
827
|
+
isAuthenticated: function () {
|
828
|
+
return firebaseActive ? !!firebase.auth().currentUser : false;
|
829
|
+
},
|
830
|
+
getUser: function () {
|
831
|
+
var defaultUser = {email: null, uid: null};
|
832
|
+
return firebaseActive ? firebase.auth().currentUser || defaultUser : defaultUser;
|
833
|
+
},
|
834
|
+
ready: function (fn, options) {
|
835
|
+
options = options || {};
|
836
|
+
options.interval = options.interval || 100;
|
740
837
|
|
741
|
-
|
742
|
-
|
838
|
+
if (!utilities.get(self, 'properties.page.status.authReady', false)) {
|
839
|
+
setTimeout(function () {
|
840
|
+
self.auth().ready(fn, options);
|
841
|
+
}, options.interval);
|
842
|
+
} else {
|
743
843
|
|
744
|
-
|
745
|
-
|
844
|
+
// Set up listener for redirect (for provider login)
|
845
|
+
// @@@ DISABLED NOV 8, 2023
|
846
|
+
// if (!self._redirectResultSetup) {
|
847
|
+
// self._redirectResultSetup = true;
|
848
|
+
// firebase.auth()
|
849
|
+
// .getRedirectResult()
|
850
|
+
// .catch(function (error) {
|
851
|
+
// _displayError(error.message);
|
852
|
+
// });
|
853
|
+
// }
|
746
854
|
|
747
|
-
|
748
|
-
|
855
|
+
// Performance
|
856
|
+
self.performance().mark('manager_authReady');
|
749
857
|
|
750
|
-
|
751
|
-
|
752
|
-
|
858
|
+
return fn(self.auth().getUser());
|
859
|
+
}
|
860
|
+
},
|
861
|
+
signIn: function (method, email, password) {
|
862
|
+
var mode = 'signin';
|
863
|
+
method = method || 'email';
|
864
|
+
_preDisplayError();
|
865
|
+
// self.log('Signin attempt: ', method, email, password);
|
866
|
+
if (method === 'email') {
|
867
|
+
// email = (email || select('.auth-email-input').getValue()).trim().toLowerCase();
|
868
|
+
email = resolveAuthInputValue(email, mode, 'email');
|
869
|
+
// password = password || select('.auth-password-input').getValue();
|
870
|
+
password = resolveAuthInputValue(password, mode, 'password');
|
871
|
+
// console.log('Signin attempt: ', method, email, password);
|
872
|
+
|
873
|
+
// Handler
|
874
|
+
uxHandler(email, password, undefined, mode);
|
875
|
+
|
876
|
+
// signinButtonDisabled(true);
|
877
|
+
setAuthButtonDisabled(mode, true);
|
878
|
+
|
879
|
+
firebase.auth().signInWithEmailAndPassword(email, password)
|
880
|
+
.then(function(credential) {
|
881
|
+
// _postAuthSubscriptionCheck(self)
|
882
|
+
// .then(function () {
|
883
|
+
//
|
884
|
+
// })
|
885
|
+
self.properties.page.status.didSignIn = true;
|
886
|
+
// signinButtonDisabled(false);
|
887
|
+
setAuthButtonDisabled(mode, false);
|
888
|
+
// self.log('Good signin');
|
889
|
+
})
|
890
|
+
.catch(function(error) {
|
891
|
+
// signinButtonDisabled(false);
|
892
|
+
setAuthButtonDisabled(mode, false);
|
893
|
+
_displayError(error.message);
|
894
|
+
// self.log('Error', error.message);
|
895
|
+
});
|
753
896
|
} else {
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
}
|
897
|
+
firebase.auth().signInWithRedirect(new firebase.auth.OAuthProvider(method))
|
898
|
+
.catch(function (e) {
|
899
|
+
_displayError(e);
|
900
|
+
})
|
901
|
+
}
|
902
|
+
},
|
903
|
+
signUp: function(method, email, password, passwordConfirm) {
|
904
|
+
var mode = 'signup';
|
905
|
+
method = method || 'email';
|
906
|
+
|
907
|
+
_preDisplayError();
|
908
|
+
// self.log('Signup attempt: ', method, email, password, passwordConfirm);
|
909
|
+
// var acceptedTerms
|
910
|
+
// var termEl = select('.auth-terms-input');
|
911
|
+
// if (termEl.exists() && !termEl.getValue() === true) {
|
912
|
+
// _displayError('Please review and accept our terms.');
|
913
|
+
// return;
|
914
|
+
// }
|
915
|
+
var termsSelector = '.auth-terms-input';
|
916
|
+
var termSpecificEl = select('.auth-signup-form ' + termsSelector)
|
917
|
+
var termGenericEl = select(termsSelector)
|
918
|
+
if ((termSpecificEl.exists() && !termSpecificEl.getValue() === true) || (termGenericEl.exists() && !termGenericEl.getValue() === true)) {
|
919
|
+
_displayError('Please review and accept our terms.');
|
920
|
+
return;
|
758
921
|
}
|
759
|
-
}
|
760
922
|
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
ready: function (fn, options) {
|
770
|
-
options = options || {};
|
771
|
-
options.interval = options.interval || 100;
|
772
|
-
|
773
|
-
if (!utilities.get(self, 'properties.page.status.authReady', false)) {
|
774
|
-
setTimeout(function () {
|
775
|
-
self.auth().ready(fn, options);
|
776
|
-
}, options.interval);
|
777
|
-
} else {
|
923
|
+
if (method === 'email') {
|
924
|
+
// email = (email || select('.auth-email-input').getValue()).trim().toLowerCase();
|
925
|
+
email = resolveAuthInputValue(email, mode, 'email');
|
926
|
+
// password = password || select('.auth-password-input').getValue();
|
927
|
+
password = resolveAuthInputValue(password, mode, 'password');
|
928
|
+
// passwordConfirm = passwordConfirm || select('.auth-password-confirm-input').getValue();
|
929
|
+
passwordConfirm = resolveAuthInputValue(passwordConfirm, mode, 'password-confirm');
|
930
|
+
// console.log('Signup attempt: ', method, email, password, passwordConfirm);
|
778
931
|
|
779
|
-
|
780
|
-
|
781
|
-
// if (!self._redirectResultSetup) {
|
782
|
-
// self._redirectResultSetup = true;
|
783
|
-
// firebase.auth()
|
784
|
-
// .getRedirectResult()
|
785
|
-
// .catch(function (error) {
|
786
|
-
// _displayError(error.message);
|
787
|
-
// });
|
788
|
-
// }
|
789
|
-
|
790
|
-
// Performance
|
791
|
-
self.performance().mark('manager_authReady');
|
792
|
-
|
793
|
-
return fn(self.auth().getUser());
|
794
|
-
}
|
795
|
-
},
|
796
|
-
signIn: function (method, email, password) {
|
797
|
-
var mode = 'signin';
|
798
|
-
method = method || 'email';
|
799
|
-
_preDisplayError();
|
800
|
-
// self.log('Signin attempt: ', method, email, password);
|
801
|
-
if (method === 'email') {
|
802
|
-
// email = (email || select('.auth-email-input').getValue()).trim().toLowerCase();
|
803
|
-
email = resolveAuthInputValue(email, mode, 'email');
|
804
|
-
// password = password || select('.auth-password-input').getValue();
|
805
|
-
password = resolveAuthInputValue(password, mode, 'password');
|
806
|
-
// console.log('Signin attempt: ', method, email, password);
|
807
|
-
|
808
|
-
// Handler
|
809
|
-
uxHandler(email, password, undefined, mode);
|
810
|
-
|
811
|
-
// signinButtonDisabled(true);
|
812
|
-
setAuthButtonDisabled(mode, true);
|
932
|
+
// Handler
|
933
|
+
uxHandler(email, password, passwordConfirm, mode);
|
813
934
|
|
814
|
-
|
935
|
+
if (password === passwordConfirm) {
|
936
|
+
// signupButtonDisabled(true);
|
937
|
+
setAuthButtonDisabled(mode, true);
|
938
|
+
firebase.auth().createUserWithEmailAndPassword(email, password)
|
815
939
|
.then(function(credential) {
|
816
|
-
//
|
817
|
-
// .
|
818
|
-
//
|
819
|
-
// })
|
820
|
-
self.properties.page.status.didSignIn = true;
|
821
|
-
// signinButtonDisabled(false);
|
822
|
-
setAuthButtonDisabled(mode, false);
|
823
|
-
// self.log('Good signin');
|
940
|
+
// self.properties.page.status.didSignUp = true;
|
941
|
+
// self.log('Good signup');
|
942
|
+
// signupButtonDisabled(false);
|
824
943
|
})
|
825
944
|
.catch(function(error) {
|
826
|
-
//
|
945
|
+
// signupButtonDisabled(false);
|
827
946
|
setAuthButtonDisabled(mode, false);
|
828
947
|
_displayError(error.message);
|
829
|
-
// self.log('
|
948
|
+
// self.log('error', error.message);
|
830
949
|
});
|
831
950
|
} else {
|
832
|
-
|
833
|
-
.catch(function (e) {
|
834
|
-
_displayError(e);
|
835
|
-
})
|
951
|
+
_displayError("Passwords don't match.");
|
836
952
|
}
|
837
|
-
}
|
838
|
-
|
839
|
-
|
840
|
-
method = method || 'email';
|
841
|
-
|
842
|
-
_preDisplayError();
|
843
|
-
// self.log('Signup attempt: ', method, email, password, passwordConfirm);
|
844
|
-
// var acceptedTerms
|
845
|
-
// var termEl = select('.auth-terms-input');
|
846
|
-
// if (termEl.exists() && !termEl.getValue() === true) {
|
847
|
-
// _displayError('Please review and accept our terms.');
|
848
|
-
// return;
|
849
|
-
// }
|
850
|
-
var termsSelector = '.auth-terms-input';
|
851
|
-
var termSpecificEl = select('.auth-signup-form ' + termsSelector)
|
852
|
-
var termGenericEl = select(termsSelector)
|
853
|
-
if ((termSpecificEl.exists() && !termSpecificEl.getValue() === true) || (termGenericEl.exists() && !termGenericEl.getValue() === true)) {
|
854
|
-
_displayError('Please review and accept our terms.');
|
855
|
-
return;
|
856
|
-
}
|
857
|
-
|
858
|
-
if (method === 'email') {
|
859
|
-
// email = (email || select('.auth-email-input').getValue()).trim().toLowerCase();
|
860
|
-
email = resolveAuthInputValue(email, mode, 'email');
|
861
|
-
// password = password || select('.auth-password-input').getValue();
|
862
|
-
password = resolveAuthInputValue(password, mode, 'password');
|
863
|
-
// passwordConfirm = passwordConfirm || select('.auth-password-confirm-input').getValue();
|
864
|
-
passwordConfirm = resolveAuthInputValue(passwordConfirm, mode, 'password-confirm');
|
865
|
-
// console.log('Signup attempt: ', method, email, password, passwordConfirm);
|
866
|
-
|
867
|
-
// Handler
|
868
|
-
uxHandler(email, password, passwordConfirm, mode);
|
869
|
-
|
870
|
-
if (password === passwordConfirm) {
|
871
|
-
// signupButtonDisabled(true);
|
872
|
-
setAuthButtonDisabled(mode, true);
|
873
|
-
firebase.auth().createUserWithEmailAndPassword(email, password)
|
874
|
-
.then(function(credential) {
|
875
|
-
// self.properties.page.status.didSignUp = true;
|
876
|
-
// self.log('Good signup');
|
877
|
-
// signupButtonDisabled(false);
|
878
|
-
})
|
879
|
-
.catch(function(error) {
|
880
|
-
// signupButtonDisabled(false);
|
881
|
-
setAuthButtonDisabled(mode, false);
|
882
|
-
_displayError(error.message);
|
883
|
-
// self.log('error', error.message);
|
884
|
-
});
|
885
|
-
} else {
|
886
|
-
_displayError("Passwords don't match.");
|
887
|
-
}
|
888
|
-
} else {
|
889
|
-
self.auth().signIn(method);
|
890
|
-
}
|
891
|
-
|
892
|
-
},
|
893
|
-
signOut: function() {
|
894
|
-
// self.log('signOut()');
|
895
|
-
// var self = this;
|
896
|
-
return firebase.auth().signOut()
|
897
|
-
.catch(function(e) {
|
898
|
-
console.error(e);
|
899
|
-
// self.log('signOut failed: ', error);
|
900
|
-
});
|
901
|
-
// return firebase.auth().signOut()
|
902
|
-
// .then(function() {
|
903
|
-
// // self.log('signOut success.');
|
904
|
-
// })
|
905
|
-
// .catch(function(e) {
|
906
|
-
// // console.error(e);
|
907
|
-
// // self.log('signOut failed: ', error);
|
908
|
-
// });
|
909
|
-
},
|
910
|
-
forgot: function(email) {
|
911
|
-
// self.log('forgot()');
|
912
|
-
var mode = 'forgot';
|
913
|
-
// email = email || select('.auth-email-input').getValue();
|
914
|
-
email = resolveAuthInputValue(email, mode, 'email')
|
915
|
-
|
916
|
-
// forgotButtonDisabled(true);
|
917
|
-
setAuthButtonDisabled(mode, true);
|
918
|
-
_preDisplayError();
|
953
|
+
} else {
|
954
|
+
self.auth().signIn(method);
|
955
|
+
}
|
919
956
|
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
.
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
957
|
+
},
|
958
|
+
signOut: function() {
|
959
|
+
// self.log('signOut()');
|
960
|
+
// var self = this;
|
961
|
+
return firebase.auth().signOut()
|
962
|
+
.catch(function(e) {
|
963
|
+
console.error(e);
|
964
|
+
// self.log('signOut failed: ', error);
|
965
|
+
});
|
966
|
+
// return firebase.auth().signOut()
|
967
|
+
// .then(function() {
|
968
|
+
// // self.log('signOut success.');
|
969
|
+
// })
|
970
|
+
// .catch(function(e) {
|
971
|
+
// // console.error(e);
|
972
|
+
// // self.log('signOut failed: ', error);
|
973
|
+
// });
|
974
|
+
},
|
975
|
+
forgot: function(email) {
|
976
|
+
// self.log('forgot()');
|
977
|
+
var mode = 'forgot';
|
978
|
+
// email = email || select('.auth-email-input').getValue();
|
979
|
+
email = resolveAuthInputValue(email, mode, 'email')
|
980
|
+
|
981
|
+
// forgotButtonDisabled(true);
|
982
|
+
setAuthButtonDisabled(mode, true);
|
983
|
+
_preDisplayError();
|
984
|
+
|
985
|
+
firebase.auth().sendPasswordResetEmail(email)
|
986
|
+
.then(function() {
|
987
|
+
// forgotButtonDisabled(false);
|
988
|
+
setAuthButtonDisabled(mode, false);
|
989
|
+
// self.log('forgot success.');
|
990
|
+
_displayError('A reset link has been sent to you.');
|
991
|
+
})
|
992
|
+
.catch(function(error) {
|
993
|
+
// forgotButtonDisabled(false);
|
994
|
+
setAuthButtonDisabled(mode, false);
|
995
|
+
// self.log('forgot failed: ', error);
|
996
|
+
_displayError(error.message);
|
997
|
+
});
|
998
|
+
},
|
934
999
|
|
935
|
-
}
|
936
1000
|
}
|
1001
|
+
}
|
937
1002
|
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
1003
|
+
//@@@NOTIFICATIONS
|
1004
|
+
Manager.prototype.notifications = function(options) {
|
1005
|
+
var self = this;
|
1006
|
+
var supported = (typeof firebase.messaging !== 'undefined') && ('serviceWorker' in navigator) && ('Notification' in window);
|
1007
|
+
|
1008
|
+
return {
|
1009
|
+
isSubscribed: function () {
|
1010
|
+
// self.log('isSubscribed()');
|
1011
|
+
return new Promise(function(resolve, reject) {
|
1012
|
+
if (!supported || Notification.permission !== 'granted') {return resolve(false)};
|
1013
|
+
return resolve(true);
|
1014
|
+
})
|
1015
|
+
},
|
1016
|
+
subscribe: function () {
|
1017
|
+
// self.log('subscribe()');
|
1018
|
+
return new Promise(function(resolve, reject) {
|
1019
|
+
// var subscribed = !self.notifications().isSubscribed();
|
1020
|
+
if (!supported) {
|
1021
|
+
return resolve(false)
|
1022
|
+
}
|
1023
|
+
firebase.messaging().getToken({
|
1024
|
+
serviceWorkerRegistration: self.properties.references.serviceWorker,
|
949
1025
|
})
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
.
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
var
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
// Run if local hash is different than the user hash OR it was last updated more than 1 day ago
|
975
|
-
if (localHash !== userHash || dateDifference > 1) {
|
976
|
-
var timestamp = currentDate.toISOString();
|
977
|
-
var timestampUNIX = Math.floor((+new Date(timestamp)) / 1000);
|
978
|
-
var subscriptionRef = firebase.firestore().doc('notifications/subscriptions/all/' + token);
|
979
|
-
|
980
|
-
function saveLocal() {
|
981
|
-
// console.log('---------saveLocal');
|
982
|
-
// self.log('Saved local token: ', token);
|
983
|
-
store.set('notifications', {uid: user.uid, token: token, lastSynced: timestamp});
|
984
|
-
}
|
1026
|
+
.then(function (token) {
|
1027
|
+
var user = self.auth().getUser();
|
1028
|
+
var localSubscription = store.get('notifications', {});
|
1029
|
+
var localHash = localSubscription.token + '|' + localSubscription.uid;
|
1030
|
+
var userHash = token + '|' + user.uid;
|
1031
|
+
// console.log('user', user);
|
1032
|
+
// console.log('localHash', localHash);
|
1033
|
+
// console.log('userHash', userHash);
|
1034
|
+
|
1035
|
+
// var override = false;
|
1036
|
+
var currentDate = new Date();
|
1037
|
+
var dateDifference = (currentDate.getTime() - new Date(localSubscription.lastSynced || 0).getTime()) / (1000 * 3600 * 24);
|
1038
|
+
|
1039
|
+
// Run if local hash is different than the user hash OR it was last updated more than 1 day ago
|
1040
|
+
if (localHash !== userHash || dateDifference > 1) {
|
1041
|
+
var timestamp = currentDate.toISOString();
|
1042
|
+
var timestampUNIX = Math.floor((+new Date(timestamp)) / 1000);
|
1043
|
+
var subscriptionRef = firebase.firestore().doc('notifications/subscriptions/all/' + token);
|
1044
|
+
|
1045
|
+
function saveLocal() {
|
1046
|
+
// console.log('---------saveLocal');
|
1047
|
+
// self.log('Saved local token: ', token);
|
1048
|
+
store.set('notifications', {uid: user.uid, token: token, lastSynced: timestamp});
|
1049
|
+
}
|
985
1050
|
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
1051
|
+
function saveServer(doc) {
|
1052
|
+
// console.log('-------saveServer', !doc.exists, !self.utilities().get(doc.data(), 'link.user.data.uid', ''), user.uid);
|
1053
|
+
// Run if it (DOES NOT EXIST on server) OR (it does AND the uid field is null AND the current user is not null)
|
1054
|
+
if (!doc.exists || (doc.exists && !self.utilities().get(doc.data(), 'link.user.data.uid', '') && user.uid)) {
|
1055
|
+
subscriptionRef
|
1056
|
+
.set(
|
1057
|
+
{
|
1058
|
+
meta: {
|
1059
|
+
dateSubscribed: {
|
1060
|
+
timestamp: timestamp,
|
1061
|
+
timestampUNIX: timestampUNIX
|
1062
|
+
},
|
1063
|
+
url: window.location.href,
|
1064
|
+
},
|
1065
|
+
token: token,
|
1066
|
+
link: {
|
1067
|
+
user: {
|
1068
|
+
lastLinked: {
|
995
1069
|
timestamp: timestamp,
|
996
1070
|
timestampUNIX: timestampUNIX
|
997
1071
|
},
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
user: {
|
1003
|
-
lastLinked: {
|
1004
|
-
timestamp: timestamp,
|
1005
|
-
timestampUNIX: timestampUNIX
|
1006
|
-
},
|
1007
|
-
pk: user.uid,
|
1008
|
-
data: {
|
1009
|
-
uid: user.uid,
|
1010
|
-
email: user.email
|
1011
|
-
}
|
1072
|
+
pk: user.uid,
|
1073
|
+
data: {
|
1074
|
+
uid: user.uid,
|
1075
|
+
email: user.email
|
1012
1076
|
}
|
1013
|
-
}
|
1014
|
-
tags: ['general']
|
1077
|
+
}
|
1015
1078
|
},
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
})
|
1025
|
-
} else {
|
1079
|
+
tags: ['general']
|
1080
|
+
},
|
1081
|
+
{
|
1082
|
+
merge: true
|
1083
|
+
}
|
1084
|
+
)
|
1085
|
+
.then(function(data) {
|
1086
|
+
// self.log('Updated token: ', token);
|
1026
1087
|
saveLocal();
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1088
|
+
resolve(true);
|
1089
|
+
})
|
1090
|
+
} else {
|
1091
|
+
saveLocal();
|
1092
|
+
// self.log('Skip sync, server data exists.');
|
1093
|
+
resolve(false);
|
1030
1094
|
}
|
1031
|
-
|
1032
|
-
// Get the doc first and then run a check to see if it needs to be updated
|
1033
|
-
subscriptionRef
|
1034
|
-
.get()
|
1035
|
-
.then(function (doc) {
|
1036
|
-
saveServer(doc);
|
1037
|
-
})
|
1038
|
-
.catch(function () {
|
1039
|
-
saveServer({exists: false})
|
1040
|
-
})
|
1041
|
-
} else {
|
1042
|
-
// self.log('Skip sync, recently done.');
|
1043
|
-
resolve(false);
|
1044
1095
|
}
|
1045
1096
|
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1097
|
+
// Get the doc first and then run a check to see if it needs to be updated
|
1098
|
+
subscriptionRef
|
1099
|
+
.get()
|
1100
|
+
.then(function (doc) {
|
1101
|
+
saveServer(doc);
|
1102
|
+
})
|
1103
|
+
.catch(function () {
|
1104
|
+
saveServer({exists: false})
|
1105
|
+
})
|
1106
|
+
} else {
|
1107
|
+
// self.log('Skip sync, recently done.');
|
1108
|
+
resolve(false);
|
1109
|
+
}
|
1110
|
+
|
1050
1111
|
})
|
1051
|
-
|
1112
|
+
.catch(function (e) {
|
1113
|
+
reject(e);
|
1114
|
+
})
|
1115
|
+
})
|
1052
1116
|
}
|
1053
1117
|
}
|
1118
|
+
}
|
1054
1119
|
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1120
|
+
/*
|
1121
|
+
HELPERS
|
1122
|
+
*/
|
1123
|
+
function subscriptionManager(self, options_user) {
|
1124
|
+
if (
|
1125
|
+
!('serviceWorker' in navigator)
|
1126
|
+
|| (typeof firebase === 'undefined')
|
1127
|
+
|| (typeof firebase.messaging === 'undefined')
|
1128
|
+
) {
|
1129
|
+
return
|
1130
|
+
}
|
1131
|
+
|
1132
|
+
// service worker guide: https://developers.google.com/web/updates/2018/06/fresher-sw
|
1133
|
+
navigator.serviceWorker.register(
|
1134
|
+
'/' + (options_user.serviceWorker.path || 'master-service-worker.js')
|
1135
|
+
+ '?config=' + encodeURIComponent(JSON.stringify({
|
1136
|
+
name: self.properties.global.brand.name,
|
1137
|
+
app: self.properties.global.app,
|
1138
|
+
env: self.properties.meta.environment,
|
1139
|
+
v: self.properties.global.version,
|
1140
|
+
cb: self.properties.global.cacheBreaker,
|
1141
|
+
firebase: options_user.libraries.firebase_app.config
|
1142
|
+
}))
|
1143
|
+
)
|
1144
|
+
.then(function (registration) {
|
1145
|
+
// firebase.messaging().useServiceWorker(registration);
|
1146
|
+
self.properties.references.serviceWorker = registration;
|
1147
|
+
|
1148
|
+
// TODO: https://googlechrome.github.io/samples/service-worker/post-message/
|
1149
|
+
// --- leverage this example ^^^ for caching! It's grat and you can do one page at a time through postMessage!
|
1150
|
+
|
1151
|
+
// function listenForWaitingServiceWorker(reg, callback) {
|
1152
|
+
// function awaitStateChange() {
|
1153
|
+
// reg.installing.addEventListener('statechange', function() {
|
1154
|
+
// if (this.state === 'installed') callback(reg);
|
1155
|
+
// });
|
1156
|
+
// }
|
1157
|
+
// if (!reg) return;
|
1158
|
+
// if (reg.waiting) return callback(reg);
|
1159
|
+
// if (reg.installing) awaitStateChange();
|
1160
|
+
// reg.addEventListener('updatefound', awaitStateChange);
|
1161
|
+
// }
|
1162
|
+
//
|
1163
|
+
// // reload once when the new Service Worker starts activating
|
1164
|
+
// var refreshing;
|
1165
|
+
// navigator.serviceWorker.addEventListener('controllerchange',
|
1166
|
+
// function() {
|
1167
|
+
// if (refreshing) return;
|
1168
|
+
// refreshing = true;
|
1169
|
+
// window.location.reload();
|
1170
|
+
// }
|
1171
|
+
// );
|
1172
|
+
// function promptUserToRefresh(reg) {
|
1173
|
+
// // this is just an example
|
1174
|
+
// // don't use window.confirm in real life; it's terrible
|
1175
|
+
// if (window.confirm("New version available! OK to refresh?")) {
|
1176
|
+
// reg.waiting.postMessage({command: 'skipWaiting'});
|
1177
|
+
// }
|
1178
|
+
// }
|
1179
|
+
// listenForWaitingServiceWorker(registration, promptUserToRefresh);
|
1180
|
+
|
1181
|
+
// self.log('SW Registered.');
|
1182
|
+
//@@@NOTIFICATIONS
|
1183
|
+
// _setupTokenRefreshHandler(self);
|
1184
|
+
|
1185
|
+
try {
|
1186
|
+
// Normally, notifications are not displayed when user is ON PAGE but we will display it here anyway
|
1187
|
+
firebase.messaging().onMessage(function (payload) {
|
1188
|
+
new Notification(payload.notification.title, payload.notification)
|
1189
|
+
.onclick = function(event) {
|
1190
|
+
event.preventDefault(); // prevent the browser from focusing the Notification's tab
|
1191
|
+
window.open(payload.notification.click_action, '_blank');
|
1192
|
+
}
|
1193
|
+
})
|
1194
|
+
} catch (e) {
|
1195
|
+
console.error(e);
|
1065
1196
|
}
|
1066
1197
|
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
app: self.properties.global.app,
|
1073
|
-
env: self.properties.meta.environment,
|
1074
|
-
v: self.properties.global.version,
|
1075
|
-
cb: self.properties.global.cacheBreaker,
|
1076
|
-
firebase: options_user.libraries.firebase_app.config
|
1077
|
-
}))
|
1078
|
-
)
|
1079
|
-
.then(function (registration) {
|
1080
|
-
// firebase.messaging().useServiceWorker(registration);
|
1081
|
-
self.properties.references.serviceWorker = registration;
|
1082
|
-
|
1083
|
-
// TODO: https://googlechrome.github.io/samples/service-worker/post-message/
|
1084
|
-
// --- leverage this example ^^^ for caching! It's grat and you can do one page at a time through postMessage!
|
1085
|
-
|
1086
|
-
// function listenForWaitingServiceWorker(reg, callback) {
|
1087
|
-
// function awaitStateChange() {
|
1088
|
-
// reg.installing.addEventListener('statechange', function() {
|
1089
|
-
// if (this.state === 'installed') callback(reg);
|
1090
|
-
// });
|
1091
|
-
// }
|
1092
|
-
// if (!reg) return;
|
1093
|
-
// if (reg.waiting) return callback(reg);
|
1094
|
-
// if (reg.installing) awaitStateChange();
|
1095
|
-
// reg.addEventListener('updatefound', awaitStateChange);
|
1096
|
-
// }
|
1097
|
-
//
|
1098
|
-
// // reload once when the new Service Worker starts activating
|
1099
|
-
// var refreshing;
|
1100
|
-
// navigator.serviceWorker.addEventListener('controllerchange',
|
1101
|
-
// function() {
|
1102
|
-
// if (refreshing) return;
|
1103
|
-
// refreshing = true;
|
1104
|
-
// window.location.reload();
|
1105
|
-
// }
|
1106
|
-
// );
|
1107
|
-
// function promptUserToRefresh(reg) {
|
1108
|
-
// // this is just an example
|
1109
|
-
// // don't use window.confirm in real life; it's terrible
|
1110
|
-
// if (window.confirm("New version available! OK to refresh?")) {
|
1111
|
-
// reg.waiting.postMessage({command: 'skipWaiting'});
|
1112
|
-
// }
|
1113
|
-
// }
|
1114
|
-
// listenForWaitingServiceWorker(registration, promptUserToRefresh);
|
1198
|
+
})
|
1199
|
+
.catch(function (e) {
|
1200
|
+
// console.log('***2');
|
1201
|
+
console.error(e);
|
1202
|
+
});
|
1115
1203
|
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1204
|
+
// Service Worker Ready
|
1205
|
+
// navigator.serviceWorker.ready.then(function(registration) {
|
1206
|
+
// });
|
1207
|
+
}
|
1119
1208
|
|
1120
|
-
|
1121
|
-
|
1122
|
-
firebase.messaging().onMessage(function (payload) {
|
1123
|
-
new Notification(payload.notification.title, payload.notification)
|
1124
|
-
.onclick = function(event) {
|
1125
|
-
event.preventDefault(); // prevent the browser from focusing the Notification's tab
|
1126
|
-
window.open(payload.notification.click_action, '_blank');
|
1127
|
-
}
|
1128
|
-
})
|
1129
|
-
} catch (e) {
|
1130
|
-
console.error(e);
|
1131
|
-
}
|
1209
|
+
function showExitPopup(self) {
|
1210
|
+
var exitPopupSettings = self.properties.options.exitPopup;
|
1132
1211
|
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
console.error(e);
|
1137
|
-
});
|
1212
|
+
if (!exitPopupSettings.enabled) {
|
1213
|
+
return;
|
1214
|
+
};
|
1138
1215
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1216
|
+
var lastTriggered = new Date(storage.get('exitPopup.lastTriggered', 0));
|
1217
|
+
var now = new Date();
|
1218
|
+
var diff = now - lastTriggered;
|
1219
|
+
|
1220
|
+
if (diff < exitPopupSettings.config.timeout) {
|
1221
|
+
return;
|
1222
|
+
};
|
1223
|
+
|
1224
|
+
showBootstrapModal(exitPopupSettings);
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
function showBootstrapModal(exitPopupSettings) {
|
1228
|
+
var proceed = exitPopupSettings.config.handler
|
1229
|
+
? exitPopupSettings.config.handler()
|
1230
|
+
: true;
|
1231
|
+
|
1232
|
+
if (!proceed) {
|
1233
|
+
return;
|
1142
1234
|
}
|
1143
1235
|
|
1144
|
-
|
1145
|
-
|
1236
|
+
var $el = document.getElementById('modal-exit-popup');
|
1237
|
+
try {
|
1238
|
+
var modal = new bootstrap.Modal($el);
|
1239
|
+
modal.show();
|
1240
|
+
$el.removeAttribute('hidden');
|
1146
1241
|
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1242
|
+
var $title = $el.querySelector('.modal-title');
|
1243
|
+
var $message = $el.querySelector('.modal-body');
|
1244
|
+
var $okButton = $el.querySelector('.modal-footer .btn-primary');
|
1245
|
+
var config = exitPopupSettings.config;
|
1150
1246
|
|
1151
|
-
var
|
1152
|
-
|
1153
|
-
var diff = now - lastTriggered;
|
1247
|
+
var link = config.okButton.link
|
1248
|
+
.replace(/{pathname}/ig, window.location.pathname)
|
1154
1249
|
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1250
|
+
$title.innerHTML = config.title;
|
1251
|
+
$message.innerHTML = config.message;
|
1252
|
+
$okButton.innerHTML = config.okButton.text;
|
1253
|
+
$okButton.setAttribute('href', link);
|
1158
1254
|
|
1159
|
-
|
1255
|
+
storage.set('exitPopup.lastTriggered', new Date().toISOString());
|
1256
|
+
} catch (e) {
|
1257
|
+
console.warn(e);
|
1160
1258
|
}
|
1259
|
+
}
|
1161
1260
|
|
1162
|
-
|
1163
|
-
|
1164
|
-
? exitPopupSettings.config.handler()
|
1165
|
-
: true;
|
1261
|
+
function refreshNewVersion(self) {
|
1262
|
+
console.log('refreshNewVersion()');
|
1166
1263
|
|
1167
|
-
|
1168
|
-
|
1264
|
+
// Make request to get the build time (live)
|
1265
|
+
fetch('/@output/build/build.json?cb=' + new Date().getTime())
|
1266
|
+
.then(function (res) {
|
1267
|
+
if (res.ok) {
|
1268
|
+
return res.json();
|
1269
|
+
} else {
|
1270
|
+
throw new Error('Bad response');
|
1169
1271
|
}
|
1272
|
+
})
|
1273
|
+
.then(function (data) {
|
1274
|
+
var buildTimeCurrent = self.properties.global.buildTime;
|
1275
|
+
var buildTimeLive = new Date(data['npm-build'].timestamp);
|
1170
1276
|
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1277
|
+
// Set buildTimeCurrent to 1 hour ahead to account for the npm-build time which will ALWAYS be set to later since it happens later
|
1278
|
+
buildTimeCurrent.setHours(buildTimeCurrent.getHours() + 1);
|
1279
|
+
|
1280
|
+
// Log
|
1281
|
+
console.log('refreshNewVersion()', data, buildTimeCurrent, buildTimeLive);
|
1176
1282
|
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
var config = exitPopupSettings.config;
|
1283
|
+
// If the live time is newer, refresh
|
1284
|
+
if (buildTimeCurrent < buildTimeLive) {
|
1285
|
+
console.log('refreshNewVersion(): Refreshing...');
|
1181
1286
|
|
1182
|
-
|
1183
|
-
|
1287
|
+
if (self.isDevelopment()) {
|
1288
|
+
return;
|
1289
|
+
}
|
1184
1290
|
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1291
|
+
// Force page reload
|
1292
|
+
window.onbeforeunload = function () {
|
1293
|
+
return undefined;
|
1294
|
+
}
|
1189
1295
|
|
1190
|
-
|
1191
|
-
|
1192
|
-
console.warn(e);
|
1296
|
+
// Refresh
|
1297
|
+
window.location.reload(true);
|
1193
1298
|
}
|
1194
|
-
}
|
1299
|
+
})
|
1300
|
+
.catch(function (e) {
|
1301
|
+
console.error(e);
|
1302
|
+
})
|
1303
|
+
}
|
1195
1304
|
|
1196
|
-
|
1197
|
-
|
1305
|
+
/*
|
1306
|
+
EXTERNAL LIBS
|
1307
|
+
*/
|
1308
|
+
var load_firebase = function(self, options) {
|
1309
|
+
return new Promise(function(resolve, reject) {
|
1310
|
+
// Set shortcuts
|
1311
|
+
var setting = options.libraries.firebase_app
|
1312
|
+
|
1313
|
+
// Skip if not enabled
|
1314
|
+
if (!setting.enabled) {
|
1315
|
+
return resolve();
|
1316
|
+
}
|
1198
1317
|
|
1199
|
-
//
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1318
|
+
// Setup Firebase
|
1319
|
+
function _post() {
|
1320
|
+
// Initialize Firebase
|
1321
|
+
window.app = firebase.initializeApp(setting.config);
|
1322
|
+
|
1323
|
+
// Load Firebase libraries
|
1324
|
+
Promise.all([
|
1325
|
+
load_firebase_auth(self, options),
|
1326
|
+
load_firebase_firestore(self, options),
|
1327
|
+
load_firebase_messaging(self, options),
|
1328
|
+
load_firebase_appCheck(self, options),
|
1329
|
+
])
|
1330
|
+
.then(resolve)
|
1331
|
+
.catch(reject);
|
1332
|
+
}
|
1211
1333
|
|
1212
|
-
|
1213
|
-
|
1334
|
+
// Load Firebase
|
1335
|
+
if (setting.load) {
|
1336
|
+
setting.load(self)
|
1337
|
+
.then(_post)
|
1338
|
+
.catch(reject);
|
1339
|
+
} else {
|
1340
|
+
// import('firebase/app')
|
1341
|
+
import('firebase/compat/app')
|
1342
|
+
.then(function(mod) {
|
1343
|
+
window.firebase = mod.default;
|
1344
|
+
_post()
|
1345
|
+
})
|
1346
|
+
.catch(reject);
|
1347
|
+
}
|
1348
|
+
});
|
1349
|
+
}
|
1214
1350
|
|
1215
|
-
// Log
|
1216
|
-
console.log('refreshNewVersion()', data, buildTimeCurrent, buildTimeLive);
|
1217
1351
|
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1352
|
+
var load_firebase_auth = function(self, options) {
|
1353
|
+
return new Promise(function(resolve, reject) {
|
1354
|
+
// Set shortcuts
|
1355
|
+
var setting = options.libraries.firebase_auth;
|
1221
1356
|
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1357
|
+
// Skip if not enabled
|
1358
|
+
if (!setting.enabled) {
|
1359
|
+
return resolve();
|
1360
|
+
}
|
1225
1361
|
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1362
|
+
// Load Firebase Auth
|
1363
|
+
if (setting.load) {
|
1364
|
+
setting.load(self)
|
1365
|
+
.then(resolve)
|
1366
|
+
.catch(reject);
|
1367
|
+
} else {
|
1368
|
+
// import('firebase/auth')
|
1369
|
+
import('firebase/compat/auth')
|
1370
|
+
.then(resolve)
|
1371
|
+
.catch(reject);
|
1372
|
+
}
|
1373
|
+
});
|
1374
|
+
}
|
1230
1375
|
|
1231
|
-
// Refresh
|
1232
|
-
window.location.reload(true);
|
1233
|
-
}
|
1234
|
-
})
|
1235
|
-
.catch(function (e) {
|
1236
|
-
console.error(e);
|
1237
|
-
})
|
1238
|
-
}
|
1239
1376
|
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
return new Promise(function(resolve, reject) {
|
1245
|
-
// if (typeof window.firebase !== 'undefined') {
|
1246
|
-
// return resolve();
|
1247
|
-
// }
|
1248
|
-
var setting = options.libraries.firebase_app
|
1249
|
-
if (setting.enabled === true) {
|
1250
|
-
function _post() {
|
1251
|
-
// self.log('Loaded Firebase.');
|
1252
|
-
// console.log('_post.');
|
1253
|
-
window.app = firebase.initializeApp(setting.config);
|
1254
|
-
|
1255
|
-
Promise.all([
|
1256
|
-
load_firebase_auth(self, options),
|
1257
|
-
load_firebase_firestore(self, options),
|
1258
|
-
load_firebase_messaging(self, options),
|
1259
|
-
load_firebase_appCheck(self, options),
|
1260
|
-
])
|
1261
|
-
.then(resolve)
|
1262
|
-
.catch(reject);
|
1263
|
-
}
|
1264
|
-
if (setting.load) {
|
1265
|
-
setting.load(self)
|
1266
|
-
.then(_post)
|
1267
|
-
.catch(reject);
|
1268
|
-
} else {
|
1269
|
-
// import('firebase/app')
|
1270
|
-
import('firebase/compat/app')
|
1271
|
-
.then(function(mod) {
|
1272
|
-
window.firebase = mod.default;
|
1273
|
-
_post()
|
1274
|
-
})
|
1275
|
-
.catch(reject);
|
1276
|
-
}
|
1277
|
-
} else {
|
1278
|
-
resolve();
|
1279
|
-
}
|
1280
|
-
});
|
1281
|
-
}
|
1377
|
+
var load_firebase_firestore = function(self, options) {
|
1378
|
+
return new Promise(function(resolve, reject) {
|
1379
|
+
// Set shortcuts
|
1380
|
+
var setting = options.libraries.firebase_firestore;
|
1282
1381
|
|
1382
|
+
// Skip if not enabled
|
1383
|
+
if (!setting.enabled) {
|
1384
|
+
return resolve();
|
1385
|
+
}
|
1283
1386
|
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
import('firebase/compat/auth')
|
1298
|
-
.then(resolve)
|
1299
|
-
.catch(reject);
|
1300
|
-
}
|
1301
|
-
} else {
|
1302
|
-
resolve();
|
1303
|
-
}
|
1387
|
+
// Load Firebase Firestore
|
1388
|
+
if (setting.load) {
|
1389
|
+
setting.load(self)
|
1390
|
+
.then(resolve)
|
1391
|
+
.catch(reject);
|
1392
|
+
} else {
|
1393
|
+
// import('firebase/firestore')
|
1394
|
+
import('firebase/compat/firestore')
|
1395
|
+
.then(resolve)
|
1396
|
+
.catch(reject);
|
1397
|
+
}
|
1398
|
+
});
|
1399
|
+
}
|
1304
1400
|
|
1305
|
-
|
1306
|
-
|
1401
|
+
var load_firebase_messaging = function(self, options) {
|
1402
|
+
return new Promise(function(resolve, reject) {
|
1403
|
+
// Set shortcuts
|
1404
|
+
var setting = options.libraries.firebase_messaging;
|
1307
1405
|
|
1406
|
+
// Skip if not enabled
|
1407
|
+
if (!setting.enabled) {
|
1408
|
+
return resolve();
|
1409
|
+
}
|
1308
1410
|
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
import('firebase/compat/firestore')
|
1323
|
-
.then(resolve)
|
1324
|
-
.catch(reject);
|
1325
|
-
}
|
1326
|
-
} else {
|
1327
|
-
resolve();
|
1328
|
-
}
|
1329
|
-
});
|
1330
|
-
}
|
1411
|
+
// Load Firebase Messaging
|
1412
|
+
if (setting.load) {
|
1413
|
+
setting.load(self)
|
1414
|
+
.then(resolve)
|
1415
|
+
.catch(reject);
|
1416
|
+
} else {
|
1417
|
+
// import('firebase/messaging')
|
1418
|
+
import('firebase/compat/messaging')
|
1419
|
+
.then(resolve)
|
1420
|
+
.catch(reject);
|
1421
|
+
}
|
1422
|
+
});
|
1423
|
+
}
|
1331
1424
|
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1425
|
+
var load_firebase_appCheck = function(self, options) {
|
1426
|
+
return new Promise(function(resolve, reject) {
|
1427
|
+
// Set shortcuts
|
1428
|
+
var setting = options.libraries.firebase_appCheck;
|
1429
|
+
|
1430
|
+
// Skip if not enabled
|
1431
|
+
if (!setting.enabled) {
|
1432
|
+
return resolve();
|
1433
|
+
}
|
1434
|
+
|
1435
|
+
// Load Firebase AppCheck
|
1436
|
+
if (setting.load) {
|
1437
|
+
setting.load(self)
|
1438
|
+
.then(resolve)
|
1439
|
+
.catch(reject);
|
1440
|
+
} else {
|
1441
|
+
// import('firebase/app-check')
|
1442
|
+
import('firebase/compat/app-check')
|
1443
|
+
.then(function (mod) {
|
1444
|
+
var appCheck = firebase.appCheck;
|
1445
|
+
var siteKey = setting.config.siteKey;
|
1446
|
+
|
1447
|
+
if (!siteKey) {
|
1448
|
+
return resolve();
|
1348
1449
|
}
|
1349
|
-
|
1450
|
+
|
1451
|
+
appCheck().activate(
|
1452
|
+
new appCheck.ReCaptchaEnterpriseProvider(siteKey),
|
1453
|
+
true,
|
1454
|
+
);
|
1455
|
+
|
1350
1456
|
resolve();
|
1351
|
-
}
|
1352
|
-
|
1353
|
-
|
1457
|
+
})
|
1458
|
+
.catch(reject);
|
1459
|
+
}
|
1460
|
+
});
|
1461
|
+
}
|
1354
1462
|
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
.then(resolve)
|
1362
|
-
.catch(reject);
|
1363
|
-
} else {
|
1364
|
-
// import('firebase/app-check')
|
1365
|
-
import('firebase/compat/app-check')
|
1366
|
-
.then(function (mod) {
|
1367
|
-
var appCheck = firebase.appCheck;
|
1368
|
-
var siteKey = setting.config.siteKey;
|
1369
|
-
|
1370
|
-
if (!siteKey) {
|
1371
|
-
return resolve();
|
1372
|
-
}
|
1463
|
+
var load_lazysizes = function(self, options) {
|
1464
|
+
return new Promise(function(resolve, reject) {
|
1465
|
+
// Skip if not enabled
|
1466
|
+
if (!options.libraries.lazysizes.enabled) {
|
1467
|
+
return resolve();
|
1468
|
+
}
|
1373
1469
|
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1470
|
+
// Load Lazysizes
|
1471
|
+
import('lazysizes')
|
1472
|
+
.then(function (mod) {
|
1473
|
+
window.lazysizes = mod.default;
|
1474
|
+
|
1475
|
+
// configs come from official lazysizes demo
|
1476
|
+
var expand = Math.max(Math.min(document.documentElement.clientWidth, document.documentElement.clientHeight, 1222) - 1, 359);
|
1477
|
+
window.lazySizesConfig = {
|
1478
|
+
loadMode: 1,
|
1479
|
+
expand: expand,
|
1480
|
+
expFactor: expand < 380 ? 3 : 2,
|
1481
|
+
};
|
1482
|
+
// self.log('Loaded Lazysizes.');
|
1483
|
+
})
|
1484
|
+
.catch(reject);
|
1485
|
+
});
|
1486
|
+
}
|
1378
1487
|
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
}
|
1386
|
-
});
|
1387
|
-
}
|
1488
|
+
var load_cookieconsent = function(self, options) {
|
1489
|
+
return new Promise(function(resolve, reject) {
|
1490
|
+
// Skip if not enabled
|
1491
|
+
if (!options.libraries.cookieconsent.enabled) {
|
1492
|
+
return resolve();
|
1493
|
+
}
|
1388
1494
|
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
//
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
// configs come from official lazysizes demo
|
1400
|
-
var expand = Math.max(Math.min(document.documentElement.clientWidth, document.documentElement.clientHeight, 1222) - 1, 359);
|
1401
|
-
window.lazySizesConfig = {
|
1402
|
-
loadMode: 1,
|
1403
|
-
expand: expand,
|
1404
|
-
expFactor: expand < 380 ? 3 : 2,
|
1405
|
-
};
|
1406
|
-
// self.log('Loaded Lazysizes.');
|
1407
|
-
})
|
1408
|
-
.catch(reject);
|
1409
|
-
} else {
|
1410
|
-
resolve();
|
1411
|
-
}
|
1412
|
-
});
|
1413
|
-
}
|
1495
|
+
// Load Cookieconsent
|
1496
|
+
import('cookieconsent')
|
1497
|
+
.then(function(mod) {
|
1498
|
+
window.cookieconsent.initialise(options.libraries.cookieconsent.config);
|
1499
|
+
// self.log('Loaded Cookieconsent.');
|
1500
|
+
resolve();
|
1501
|
+
})
|
1502
|
+
.catch(reject);
|
1503
|
+
});
|
1504
|
+
}
|
1414
1505
|
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
import('cookieconsent')
|
1422
|
-
.then(function(mod) {
|
1423
|
-
window.cookieconsent.initialise(options.libraries.cookieconsent.config);
|
1424
|
-
// self.log('Loaded Cookieconsent.');
|
1425
|
-
resolve();
|
1426
|
-
})
|
1427
|
-
.catch(reject);
|
1428
|
-
} else {
|
1429
|
-
resolve();
|
1430
|
-
}
|
1506
|
+
var load_chatsy = function(self, options) {
|
1507
|
+
return new Promise(function(resolve, reject) {
|
1508
|
+
// Skip if not enabled or already requested
|
1509
|
+
if (!options.libraries.chatsy.enabled || self.properties.page._chatsyRequested) {
|
1510
|
+
return resolve();
|
1511
|
+
}
|
1431
1512
|
|
1432
|
-
|
1433
|
-
|
1513
|
+
var chatsyPath = 'libraries.chatsy.config';
|
1514
|
+
|
1515
|
+
// Immediately hide the fake button
|
1516
|
+
select('#prechat-btn').hide();
|
1517
|
+
|
1518
|
+
// Load the script
|
1519
|
+
loadScript({
|
1520
|
+
src: 'https://app.chatsy.ai/resources/script.js',
|
1521
|
+
// src: 'http://localhost:4001/resources/script.js',
|
1522
|
+
attributes: [
|
1523
|
+
{name: 'data-account-id', value: utilities.get(options, chatsyPath + '.accountId', '')},
|
1524
|
+
{name: 'data-chat-id', value: utilities.get(options, chatsyPath + '.chatId', '')},
|
1525
|
+
{name: 'data-settings', value: JSON.stringify(utilities.get(options, chatsyPath + '.settings', ''))},
|
1526
|
+
],
|
1527
|
+
crossorigin: true,
|
1528
|
+
})
|
1529
|
+
.then(function () {
|
1530
|
+
// Listen for Chatsy status
|
1531
|
+
chatsy.on('status', function(event, status) {
|
1532
|
+
if (status === 'loaded') {
|
1533
|
+
chatsy.open();
|
1534
|
+
}
|
1535
|
+
})
|
1434
1536
|
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
if (
|
1439
|
-
options.libraries.chatsy.enabled === true
|
1440
|
-
&& !self.properties.page._chatsyRequested
|
1441
|
-
) {
|
1442
|
-
var chatsyPath = 'libraries.chatsy.config';
|
1443
|
-
|
1444
|
-
// Immediately hide the fake button
|
1445
|
-
select('#prechat-btn').hide();
|
1446
|
-
|
1447
|
-
// Load the script
|
1448
|
-
loadScript({
|
1449
|
-
src: 'https://app.chatsy.ai/resources/script.js',
|
1450
|
-
// src: 'http://localhost:4001/resources/script.js',
|
1451
|
-
attributes: [
|
1452
|
-
{name: 'data-account-id', value: utilities.get(options, chatsyPath + '.accountId', '')},
|
1453
|
-
{name: 'data-chat-id', value: utilities.get(options, chatsyPath + '.chatId', '')},
|
1454
|
-
{name: 'data-settings', value: JSON.stringify(utilities.get(options, chatsyPath + '.settings', ''))},
|
1455
|
-
],
|
1456
|
-
crossorigin: true,
|
1457
|
-
})
|
1458
|
-
.then(function () {
|
1459
|
-
// Listen for Chatsy status
|
1460
|
-
chatsy.on('status', function(event, status) {
|
1461
|
-
if (status === 'loaded') {
|
1462
|
-
chatsy.open();
|
1463
|
-
}
|
1464
|
-
})
|
1537
|
+
resolve();
|
1538
|
+
})
|
1465
1539
|
|
1466
|
-
|
1467
|
-
|
1540
|
+
self.properties.page._chatsyRequested = true;
|
1541
|
+
});
|
1542
|
+
}
|
1468
1543
|
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1544
|
+
var load_sentry = function(self, options) {
|
1545
|
+
return new Promise(function(resolve, reject) {
|
1546
|
+
// Skip if not enabled
|
1547
|
+
if (!options.libraries.sentry.enabled) {
|
1548
|
+
return resolve();
|
1549
|
+
}
|
1475
1550
|
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
// Set global
|
1482
|
-
window.Sentry = mod;
|
1483
|
-
|
1484
|
-
// Set config
|
1485
|
-
var config = options.libraries.sentry.config;
|
1486
|
-
config.release = config.release + '@' + self.properties.global.version;
|
1487
|
-
config.environment = self.properties.meta.environment;
|
1488
|
-
config.integrations = config.integrations || [];
|
1489
|
-
|
1490
|
-
// if (self.isDevelopment()) {
|
1491
|
-
// config.dsn = 'https://901db748bbb9469f860dc36fb07a4374@o1120154.ingest.sentry.io/6155285';
|
1492
|
-
// }
|
1493
|
-
|
1494
|
-
// Add integration: browser tracing
|
1495
|
-
config.integrations.push(Sentry.browserTracingIntegration());
|
1496
|
-
|
1497
|
-
// Add integration: replay
|
1498
|
-
if (config.replaysSessionSampleRate > 0 || config.replaysOnErrorSampleRate > 0) {
|
1499
|
-
config.integrations.push(Sentry.replayIntegration({
|
1500
|
-
maskAllText: false,
|
1501
|
-
blockAllMedia: false,
|
1502
|
-
}));
|
1503
|
-
}
|
1551
|
+
// Import Sentry
|
1552
|
+
import('@sentry/browser')
|
1553
|
+
.then(function(mod) {
|
1554
|
+
// Set global
|
1555
|
+
window.Sentry = mod;
|
1504
1556
|
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
// Setup tags
|
1511
|
-
event.tags = event.tags || {};
|
1512
|
-
event.tags['process.type'] = event.tags['process.type'] || 'browser';
|
1513
|
-
// event.tags['usage.total.opens'] = parseInt(usage.total.opens);
|
1514
|
-
// event.tags['usage.total.hours'] = usage.total.hours;
|
1515
|
-
event.tags['usage.session.hours'] = hoursSinceStart.toFixed(2);
|
1516
|
-
// event.tags['store'] = self.properties().isStore();
|
1517
|
-
|
1518
|
-
// Setup user
|
1519
|
-
event.user = event.user || {};
|
1520
|
-
event.user.email = storage.get('user.auth.email', '')
|
1521
|
-
event.user.uid = storage.get('user.auth.uid', '');
|
1522
|
-
// event.user.ip = storage.get('user.ip', '');
|
1523
|
-
|
1524
|
-
// Log to console
|
1525
|
-
console.error('[SENTRY] Caught error', event, hint);
|
1526
|
-
|
1527
|
-
// Skip processing the event
|
1528
|
-
if (self.isDevelopment()) {
|
1529
|
-
return null;
|
1530
|
-
}
|
1557
|
+
// Set config
|
1558
|
+
var config = options.libraries.sentry.config;
|
1559
|
+
config.release = config.release + '@' + self.properties.global.version;
|
1560
|
+
config.environment = self.properties.meta.environment;
|
1561
|
+
config.integrations = config.integrations || [];
|
1531
1562
|
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1563
|
+
// if (self.isDevelopment()) {
|
1564
|
+
// config.dsn = 'https://901db748bbb9469f860dc36fb07a4374@o1120154.ingest.sentry.io/6155285';
|
1565
|
+
// }
|
1535
1566
|
|
1536
|
-
|
1537
|
-
|
1567
|
+
// Add integration: browser tracing
|
1568
|
+
config.integrations.push(Sentry.browserTracingIntegration());
|
1538
1569
|
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1570
|
+
// Add integration: replay
|
1571
|
+
if (config.replaysSessionSampleRate > 0 || config.replaysOnErrorSampleRate > 0) {
|
1572
|
+
config.integrations.push(Sentry.replayIntegration({
|
1573
|
+
maskAllText: false,
|
1574
|
+
blockAllMedia: false,
|
1575
|
+
}));
|
1545
1576
|
}
|
1546
|
-
});
|
1547
|
-
}
|
1548
1577
|
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
console
|
1569
|
-
|
1570
|
-
|
1578
|
+
// Setup before send
|
1579
|
+
config.beforeSend = function (event, hint) {
|
1580
|
+
var startTime = self.properties.page.startTime;
|
1581
|
+
var hoursSinceStart = (new Date() - startTime) / (1000 * 3600);
|
1582
|
+
|
1583
|
+
// Setup tags
|
1584
|
+
event.tags = event.tags || {};
|
1585
|
+
event.tags['process.type'] = event.tags['process.type'] || 'browser';
|
1586
|
+
// event.tags['usage.total.opens'] = parseInt(usage.total.opens);
|
1587
|
+
// event.tags['usage.total.hours'] = usage.total.hours;
|
1588
|
+
event.tags['usage.session.hours'] = hoursSinceStart.toFixed(2);
|
1589
|
+
// event.tags['store'] = self.properties().isStore();
|
1590
|
+
|
1591
|
+
// Setup user
|
1592
|
+
event.user = event.user || {};
|
1593
|
+
event.user.email = storage.get('user.auth.email', '')
|
1594
|
+
event.user.uid = storage.get('user.auth.uid', '');
|
1595
|
+
// event.user.ip = storage.get('user.ip', '');
|
1596
|
+
|
1597
|
+
// Log to console
|
1598
|
+
console.error('[SENTRY] Caught error', event, hint);
|
1599
|
+
|
1600
|
+
// Skip processing the event
|
1601
|
+
if (self.isDevelopment()) {
|
1602
|
+
return null;
|
1603
|
+
}
|
1604
|
+
|
1605
|
+
// Process the event
|
1606
|
+
return event;
|
1571
1607
|
}
|
1572
|
-
}
|
1573
|
-
}
|
1574
1608
|
|
1575
|
-
|
1576
|
-
|
1577
|
-
var featuresDefault = (
|
1578
|
-
typeof Symbol !== 'undefined'
|
1579
|
-
)
|
1580
|
-
var featuresCustom = true;
|
1609
|
+
// Initialize
|
1610
|
+
Sentry.init(config);
|
1581
1611
|
|
1582
|
-
|
1583
|
-
|
1612
|
+
// Resolve
|
1613
|
+
resolve();
|
1614
|
+
})
|
1615
|
+
.catch(reject);
|
1616
|
+
});
|
1617
|
+
}
|
1618
|
+
|
1619
|
+
Manager.prototype.log = function() {
|
1620
|
+
var self = this;
|
1621
|
+
|
1622
|
+
if (self.isDevelopment()) {
|
1623
|
+
// 1. Convert args to a normal array
|
1624
|
+
var args = Array.prototype.slice.call(arguments);
|
1625
|
+
|
1626
|
+
// 2. Prepend log prefix log string
|
1627
|
+
args.unshift('[DEV @ ' + new Date().toLocaleTimeString() + ']');
|
1628
|
+
|
1629
|
+
// 3. Pass along arguments to console.log
|
1630
|
+
if (args[1] === 'error') {
|
1631
|
+
args.splice(1,1);
|
1632
|
+
console.error.apply(console, args);
|
1633
|
+
} else if (args[1] === 'warn') {
|
1634
|
+
args.splice(1,1);
|
1635
|
+
console.warn.apply(console, args);
|
1636
|
+
} else if (args[1] === 'log') {
|
1637
|
+
args.splice(1,1);
|
1638
|
+
console.log.apply(console, args);
|
1584
1639
|
} else {
|
1585
|
-
|
1586
|
-
.then(function() {
|
1587
|
-
cb();
|
1588
|
-
})
|
1640
|
+
console.log.apply(console, args);
|
1589
1641
|
}
|
1590
|
-
|
1591
1642
|
}
|
1643
|
+
}
|
1592
1644
|
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1645
|
+
function init_loadPolyfills(self, configuration, cb) {
|
1646
|
+
// https://github.com/jquintozamora/polyfill-io-feature-detection/blob/master/index.js
|
1647
|
+
var featuresDefault = (
|
1648
|
+
typeof Symbol !== 'undefined'
|
1649
|
+
)
|
1650
|
+
var featuresCustom = true;
|
1651
|
+
|
1652
|
+
if (featuresDefault && featuresCustom) {
|
1653
|
+
cb();
|
1654
|
+
} else {
|
1655
|
+
loadScript({src: 'https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?flags=always%2Cgated&features=default%2Ces5%2Ces6%2Ces7%2CPromise.prototype.finally%2C%7Ehtml5-elements%2ClocalStorage%2Cfetch%2CURLSearchParams'})
|
1656
|
+
.then(function() {
|
1657
|
+
cb();
|
1658
|
+
})
|
1598
1659
|
}
|
1599
1660
|
|
1600
|
-
|
1601
|
-
* STORAGE
|
1602
|
-
*/
|
1603
|
-
Manager.prototype.storage = function() {
|
1604
|
-
return storage;
|
1605
|
-
}
|
1661
|
+
}
|
1606
1662
|
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1663
|
+
/**
|
1664
|
+
* UTILITIES
|
1665
|
+
*/
|
1666
|
+
Manager.prototype.utilities = function() {
|
1667
|
+
return utilities;
|
1668
|
+
}
|
1613
1669
|
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1670
|
+
/**
|
1671
|
+
* STORAGE
|
1672
|
+
*/
|
1673
|
+
Manager.prototype.storage = function() {
|
1674
|
+
return storage;
|
1675
|
+
}
|
1620
1676
|
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1677
|
+
/**
|
1678
|
+
* QUERIES
|
1679
|
+
*/
|
1680
|
+
// Manager.prototype.query = function() {
|
1681
|
+
// return query;
|
1682
|
+
// }
|
1683
|
+
|
1684
|
+
/**
|
1685
|
+
* DOM OPERATIONS
|
1686
|
+
*/
|
1687
|
+
Manager.prototype.dom = function() {
|
1688
|
+
return dom;
|
1689
|
+
}
|
1690
|
+
|
1691
|
+
/**
|
1692
|
+
* ACCOUNT
|
1693
|
+
*/
|
1694
|
+
// Manager.prototype.account = function() {
|
1695
|
+
// var self = this;
|
1696
|
+
// return {
|
1697
|
+
// resolve: function (options) {
|
1698
|
+
// return import('./lib/account.js')
|
1699
|
+
// .then(function(mod) {
|
1700
|
+
// self.account = function () { return mod.default }
|
1701
|
+
// return self.account().resolve(options);
|
1702
|
+
// })
|
1703
|
+
// }
|
1704
|
+
// }
|
1705
|
+
// }
|
1706
|
+
|
1707
|
+
Manager.prototype.account = function() {
|
1708
|
+
var self = this;
|
1709
|
+
|
1710
|
+
return {
|
1711
|
+
import: function () {
|
1712
|
+
return import('./lib/account.js')
|
1713
|
+
.then(function(mod) {
|
1714
|
+
self.account = function () { return mod.default }
|
1715
|
+
mod.default.prototype.Manager = self;
|
1716
|
+
return self.account();
|
1717
|
+
})
|
1649
1718
|
}
|
1650
1719
|
}
|
1720
|
+
}
|
1651
1721
|
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1722
|
+
// Manager.prototype.fetch = function(url, options) {
|
1723
|
+
// var response = {
|
1724
|
+
// status: 500,
|
1725
|
+
// };
|
1726
|
+
// return new Promise(function(resolve, reject) {
|
1727
|
+
// fetch(url, options)
|
1728
|
+
// .then(function (res) {
|
1729
|
+
// response = res;
|
1730
|
+
// if (res.status >= 200 && res.status < 300) {
|
1731
|
+
// return resolve({response: res});
|
1732
|
+
// } else {
|
1733
|
+
// return res.text()
|
1734
|
+
// .then(function (data) {
|
1735
|
+
// throw new Error(data || res.statusTest || 'Unknown error.')
|
1736
|
+
// })
|
1737
|
+
// }
|
1738
|
+
// })
|
1739
|
+
// .catch(function (e) {
|
1740
|
+
// return reject({response: response, error: e});
|
1741
|
+
// });
|
1742
|
+
// });
|
1743
|
+
// }
|
1744
|
+
|
1745
|
+
// Manager.prototype.ajax = function() {
|
1746
|
+
// return ajax;
|
1747
|
+
// }
|
1678
1748
|
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
}
|
1749
|
+
/**
|
1750
|
+
* OTHER
|
1751
|
+
*/
|
1752
|
+
// Manager.prototype.performance = function() {
|
1753
|
+
// var supported = ('performance' in window);
|
1754
|
+
// return {
|
1755
|
+
// mark: function(mark) {
|
1756
|
+
// if (!supported) {return};
|
1757
|
+
// window.performance.mark(mark);
|
1758
|
+
// }
|
1759
|
+
// }
|
1760
|
+
// }
|
1761
|
+
Manager.prototype.performance = function () {
|
1762
|
+
return {
|
1763
|
+
mark: function(mark) {
|
1764
|
+
try {
|
1765
|
+
window.performance.mark(mark);
|
1766
|
+
} catch (e) {
|
1698
1767
|
}
|
1699
1768
|
}
|
1700
1769
|
}
|
1770
|
+
}
|
1701
1771
|
|
1702
|
-
|
1703
|
-
|
1772
|
+
Manager.prototype.isValidRedirectUrl = function (url) {
|
1773
|
+
var self = this;
|
1704
1774
|
|
1705
|
-
|
1706
|
-
|
1775
|
+
var returnUrlObject = new URL(decodeURIComponent(url));
|
1776
|
+
var currentUrlObject = new URL(window.location.href);
|
1707
1777
|
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1778
|
+
return returnUrlObject.host === currentUrlObject.host
|
1779
|
+
|| returnUrlObject.protocol === this.properties.global.app + ':'
|
1780
|
+
|| self.properties.global.validRedirectHosts.includes(returnUrlObject.host)
|
1781
|
+
}
|
1712
1782
|
|
1713
|
-
|
1714
|
-
|
1783
|
+
Manager.prototype.isDevelopment = function () {
|
1784
|
+
var self = this;
|
1715
1785
|
|
1716
|
-
|
1717
|
-
|
1786
|
+
return self.properties.meta.environment === 'development';
|
1787
|
+
}
|
1718
1788
|
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1789
|
+
// Manager.prototype.performance = function() {
|
1790
|
+
// var self = this;
|
1791
|
+
//
|
1792
|
+
// return {
|
1793
|
+
// mark2: function () {
|
1794
|
+
// return firebaseActive ? !!firebase.auth().currentUser : false;
|
1795
|
+
// },
|
1796
|
+
//
|
1797
|
+
// }
|
1798
|
+
// }
|
1729
1799
|
|
1730
1800
|
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1801
|
+
/**
|
1802
|
+
* HELPERS
|
1803
|
+
*/
|
1734
1804
|
|
1735
1805
|
module.exports = Manager;
|