web-manager 3.2.53 → 3.2.56

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