Mint: A Fresh Look at your Site Minted
  1. 1 jQuery(function() {
  2. 2 'use strict';
  3. 3 var daftplugPublic = jQuery('.daftplugPublic[data-daftplug-plugin="daftplug_instantify"]');
  4. 4 var optionName = daftplugPublic.attr('data-daftplug-plugin');
  5. 5 var objectName = window[optionName + '_public_js_vars'];
  6. 6 var client = new ClientJS();
  7. 7 var pushButton = daftplugPublic.find('.daftplugPublicPushButton');
  8. 8 var pushPrompt = daftplugPublic.find('.daftplugPublicPushPrompt');
  9. 9 var navigationTabBar = daftplugPublic.find('.daftplugPublicNavigationTabBar');
  10. 10 var isMobilePad = client.isMobile() || client.isIpad();
  11. 11 var isAndroidChrome = client.isMobileAndroid() && client.isChrome();
  12. 12 var isAndroidFirefox = client.isMobileAndroid() && client.isFirefox();
  13. 13 var isIosSafari = client.isMobileIOS() && client.isSafari();
  14. 14 var isAndroidPwa = client.isMobileAndroid() && isPwa();
  15. 15 var isIosPwa = client.isMobileIOS() && isPwa();
  16. 16 var isFullscreenOverlayShown = getCookie('fullscreenOverlay');
  17. 17 var isHeaderOverlayShown = getCookie('headerOverlay');
  18. 18 var isMenuOverlayShown = getCookie('menuOverlay');
  19. 19 var isCheckoutOverlayShown = getCookie('checkoutOverlay');
  20. 20 var isPostOverlayShown = getCookie('postOverlay');
  21. 21 var isPushPromptShown = getCookie('pushPrompt');
  22. 22 var fullscreenOverlay = daftplugPublic.find('.daftplugPublicFullscreenOverlay');
  23. 23 var chromeFullscreenOverlay = fullscreenOverlay.filter('.-chrome');
  24. 24 var chrome2FullscreenOverlay = fullscreenOverlay.filter('.-chrome2');
  25. 25 var firefoxFullscreenOverlay = fullscreenOverlay.filter('.-firefox');
  26. 26 var safariFullscreenOverlay = fullscreenOverlay.filter('.-safari');
  27. 27 var headerOverlay = daftplugPublic.find('.daftplugPublicHeaderOverlay');
  28. 28 var menuOverlay = daftplugPublic.find('.daftplugPublicMenuOverlay');
  29. 29 var checkoutOverlay = daftplugPublic.find('.daftplugPublicCheckoutOverlay');
  30. 30 var postOverlay = daftplugPublic.find('.daftplugPublicPostOverlay');
  31. 31 var installButton = daftplugPublic.find('.daftplugPublicInstallButton');
  32. 32 var rotateNotice = daftplugPublic.find('.daftplugPublicRotateNotice');
  33. 33
  34. 34 // Check if PWA
  35. 35 function isPwa() {
  36. 36 return ['fullscreen', 'standalone', 'minimal-ui'].some(
  37. 37 (displayMode) => window.matchMedia('(display-mode: '+displayMode+')').matches
  38. 38 );
  39. 39 }
  40. 40
  41. 41 // Set cookie
  42. 42 function setCookie(name, value, days) {
  43. 43 var expires = '';
  44. 44 if (days) {
  45. 45 var date = new Date();
  46. 46 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  47. 47 expires = '; expires=' + date.toUTCString();
  48. 48 }
  49. 49 document.cookie = name + '=' + (value || '') + expires + '; path=/';
  50. 50 }
  51. 51
  52. 52 // Get cookie
  53. 53 function getCookie(name) {
  54. 54 var nameEQ = name + '=';
  55. 55 var ca = document.cookie.split(';');
  56. 56 for (var i = 0; i < ca.length; i++) {
  57. 57 var c = ca[i];
  58. 58 while (c.charAt(0) == ' ') c = c.substring(1, c.length);
  59. 59 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  60. 60 }
  61. 61 return null;
  62. 62 }
  63. 63
  64. 64 // Change push button states
  65. 65 function changePushButtonState(state) {
  66. 66 switch (state) {
  67. 67 case 'enabled':
  68. 68 pushButton.removeClass('-loading').removeClass('-on').addClass('-off');
  69. 69 break;
  70. 70 case 'disabled':
  71. 71 pushButton.removeClass('-loading').removeClass('-off').addClass('-on');
  72. 72 break;
  73. 73 case 'computing':
  74. 74 pushButton.removeClass('-on').removeClass('-off').addClass('-loading');
  75. 75 break;
  76. 76 case 'incompatible':
  77. 77 pushButton.removeClass('-loading').removeClass('-off').addClass('-on').addClass('-disabled');
  78. 78 break;
  79. 79 case 'hidden':
  80. 80 pushButton.removeClass('-loading').removeClass('-off').removeClass('-on').addClass('-hidden');
  81. 81 break;
  82. 82 default:
  83. 83 console.error('Unhandled push button state', state);
  84. 84 break;
  85. 85 }
  86. 86 }
  87. 87
  88. 88 // Base 64 to Unit8Array
  89. 89 function urlBase64ToUint8Array(base64String) {
  90. 90 const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
  91. 91 const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
  92. 92 const rawData = window.atob(base64);
  93. 93 const outputArray = new Uint8Array(rawData.length);
  94. 94 for (let i = 0; i < rawData.length; ++i) {
  95. 95 outputArray[i] = rawData.charCodeAt(i);
  96. 96 }
  97. 97 return outputArray;
  98. 98 }
  99. 99
  100. 100 // Check notification permission
  101. 101 function checkNotificationPermission() {
  102. 102 return new Promise((resolve, reject) => {
  103. 103 if (Notification.permission === 'denied') {
  104. 104 return reject(new Error('Push messages are blocked.'));
  105. 105 }
  106. 106 if (Notification.permission === 'granted') {
  107. 107 return resolve();
  108. 108 }
  109. 109 if (Notification.permission === 'default') {
  110. 110 return Notification.requestPermission().then(result => {
  111. 111 if (result !== 'granted') {
  112. 112 reject(new Error('Bad permission result'));
  113. 113 }
  114. 114 resolve();
  115. 115 });
  116. 116 }
  117. 117 });
  118. 118 }
  119. 119
  120. 120 // Register push device
  121. 121 function registerPushDevice() {
  122. 122 changePushButtonState('computing');
  123. 123 return checkNotificationPermission()
  124. 124 .then(() => navigator.serviceWorker.ready)
  125. 125 .then(serviceWorkerRegistration =>
  126. 126 serviceWorkerRegistration.pushManager.subscribe({
  127. 127 userVisibleOnly: true,
  128. 128 applicationServerKey: urlBase64ToUint8Array(objectName.pwaPublicKey),
  129. 129 })
  130. 130 )
  131. 131 .then(subscription => {
  132. 132 jQuery.toast({
  133. 133 title: objectName.pwaSubscribeOnMsg,
  134. 134 duration: 2500,
  135. 135 position: 'bottom',
  136. 136 });
  137. 137 return handleSubscription(subscription, 'add');
  138. 138 })
  139. 139 .then(subscription => subscription && changePushButtonState('enabled'))
  140. 140 .catch(e => {
  141. 141 if (Notification.permission === 'denied') {
  142. 142 console.warn('Notifications are denied by the user.');
  143. 143 changePushButtonState('incompatible');
  144. 144 } else {
  145. 145 console.error('Impossible to subscribe to push notifications', e);
  146. 146 changePushButtonState('disabled');
  147. 147 }
  148. 148 });
  149. 149 }
  150. 150
  151. 151 // Update push device
  152. 152 function updatePushDevice() {
  153. 153 navigator.serviceWorker.ready
  154. 154 .then(serviceWorkerRegistration => serviceWorkerRegistration.pushManager.getSubscription())
  155. 155 .then(subscription => {
  156. 156 changePushButtonState('disabled');
  157. 157 if (!subscription) {
  158. 158 return;
  159. 159 }
  160. 160 return handleSubscription(subscription, 'update');
  161. 161 })
  162. 162 .then(subscription => subscription && changePushButtonState('enabled'))
  163. 163 .catch(e => {
  164. 164 console.error('Error when updating the subscription', e);
  165. 165 });
  166. 166 }
  167. 167
  168. 168 // Deregister push device
  169. 169 function deregisterPushDevice() {
  170. 170 changePushButtonState('computing');
  171. 171 navigator.serviceWorker.ready
  172. 172 .then(serviceWorkerRegistration => serviceWorkerRegistration.pushManager.getSubscription())
  173. 173 .then(subscription => {
  174. 174 if (!subscription) {
  175. 175 changePushButtonState('disabled');
  176. 176 return;
  177. 177 }
  178. 178 jQuery.toast({
  179. 179 title: objectName.pwaSubscribeOffMsg,
  180. 180 duration: 2500,
  181. 181 position: 'bottom',
  182. 182 });
  183. 183 return handleSubscription(subscription, 'remove');
  184. 184 })
  185. 185 .then(subscription => subscription.unsubscribe())
  186. 186 .then(() => changePushButtonState('disabled'))
  187. 187 .catch(e => {
  188. 188 console.error('Error when unsubscribing the user', e);
  189. 189 changePushButtonState('disabled');
  190. 190 });
  191. 191 }
  192. 192
  193. 193 // Handle subscription
  194. 194 function handleSubscription(subscription, method) {
  195. 195 const action = optionName + '_handle_subscription';
  196. 196 const endpoint = subscription.endpoint;
  197. 197 const userKey = subscription.getKey('p256dh');
  198. 198 const userAuth = subscription.getKey('auth');
  199. 199 const deviceInfo = client.getBrowser() + ' ' + client.getBrowserMajorVersion() + ' on ' + client.getOS() + ' ' + client.getOSVersion();
  200. 200 const contentEncoding = (PushManager.supportedContentEncodings || ['aesgcm'])[0];
  201. 201
  202. 202 return jQuery.ajax({
  203. 203 url: objectName.ajaxUrl,
  204. 204 type: 'POST',
  205. 205 data: {
  206. 206 method: method,
  207. 207 action: action,
  208. 208 endpoint: endpoint,
  209. 209 userKey: userKey ? btoa(String.fromCharCode.apply(null, new Uint8Array(userKey))) : null,
  210. 210 userAuth: userAuth ? btoa(String.fromCharCode.apply(null, new Uint8Array(userAuth))) : null,
  211. 211 deviceInfo: deviceInfo,
  212. 212 contentEncoding,
  213. 213 },
  214. 214 beforeSend: function() {
  215. 215
  216. 216 },
  217. 217 success: function(response, textStatus, jqXhr) {
  218. 218
  219. 219 },
  220. 220 complete: function() {
  221. 221
  222. 222 },
  223. 223 error: function(jqXhr, textStatus, errorThrown) {
  224. 224
  225. 225 }
  226. 226 }).then(() => subscription);
  227. 227 }
  228. 228
  229. 229 // Handle push
  230. 230 if ('serviceWorker' in navigator && 'PushManager' in window && !jQuery('meta[name="onesignal"]').length) {
  231. 231 navigator.serviceWorker.ready.then(function(registration) {
  232. 232 registration.pushManager.getSubscription().then(function(subscription) {
  233. 233 updatePushDevice();
  234. 234 // Handle push prompt
  235. 235 if (objectName.settings.pwaPushPrompt == 'on') {
  236. 236 if (!subscription && Notification.permission !== 'denied' && isPushPromptShown == null && pushPrompt.length) {
  237. 237 setTimeout(function() {
  238. 238 pushPrompt.addClass('-show').on('click', '.daftplugPublicPushPrompt_allow', function(e) {
  239. 239 pushPrompt.addClass('-hide').one("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function(){
  240. 240 pushPrompt.remove();
  241. 241 });
  242. 242 registerPushDevice();
  243. 243 }).on('click', '.daftplugPublicPushPrompt_dismiss', function(e) {
  244. 244 pushPrompt.addClass('-hide').one("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function(){
  245. 245 pushPrompt.remove();
  246. 246 });
  247. 247 setCookie('pushPrompt', 'shown', 1);
  248. 248 });
  249. 249 }, 2000);
  250. 250 }
  251. 251 }
  252. 252
  253. 253 // Handle push button
  254. 254 if (objectName.settings.pwaPushButton == 'on') {
  255. 255 if (subscription) {
  256. 256 if (objectName.settings.pwaPushButtonBehavior == 'shown') {
  257. 257 changePushButtonState('enabled');
  258. 258 pushButton.css('display', 'flex').on('click', function(e) {
  259. 259 deregisterPushDevice();
  260. 260 });
  261. 261 }
  262. 262 } else {
  263. 263 changePushButtonState('disabled');
  264. 264 pushButton.css('display', 'flex').on('click', function(e) {
  265. 265 if (objectName.settings.pwaPushButtonBehavior == 'hidden') {
  266. 266 registerPushDevice().then(() => changePushButtonState('hidden'));
  267. 267 } else {
  268. 268 registerPushDevice();
  269. 269 }
  270. 270 });
  271. 271 }
  272. 272 }
  273. 273 });
  274. 274 });
  275. 275 }
  276. 276
  277. 277 // Handle offline forms
  278. 278 if (objectName.settings.pwaOfflineForms == 'on') {
  279. 279 Array.from(document.querySelectorAll('form')).forEach(form => {
  280. 280 new OfflineForm(form);
  281. 281 })
  282. 282 };
  283. 283
  284. 284 // Handle ajaxify
  285. 285 if (objectName.settings.pwaAjaxify == 'on') {
  286. 286 if (objectName.settings.pwaAjaxifySelectors == '') {
  287. 287 var additionalSelectors = 'a:not(.no-ajaxy)';
  288. 288 } else {
  289. 289 var additionalSelectors = 'a:not(.no-ajaxy),' + objectName.settings.pwaAjaxifySelectors;
  290. 290 }
  291. 291
  292. 292 if (objectName.settings.pwaAjaxifyForms == 'on') {
  293. 293 var formsSelector = 'form:not(.no-ajaxy)';
  294. 294 } else {
  295. 295 var formsSelector = false;
  296. 296 }
  297. 297
  298. 298 jQuery('body').ajaxify({
  299. 299 selector: additionalSelectors,
  300. 300 forms: formsSelector,
  301. 301 refresh: true,
  302. 302 deltas: false,
  303. 303 alwayshints: 'daftplug-instantify',
  304. 304 });
  305. 305 }
  306. 306
  307. 307 // Handle preloader
  308. 308 if (objectName.settings.pwaPreloader == 'on') {
  309. 309 if (objectName.settings.pwaPreloaderStyle == 'percent') {
  310. 310 var perfData = window.performance.timing,
  311. 311 EstimatedTime = -(perfData.loadEventEnd - perfData.navigationStart),
  312. 312 time = parseInt((EstimatedTime / 1000) % 60) * 100,
  313. 313 progBar = jQuery('.daftplugPublicPreloader_fill'),
  314. 314 start = 0,
  315. 315 end = 70,
  316. 316 duration = time,
  317. 317 counter = jQuery('.daftplugPublicPreloader_counter');
  318. 318
  319. 319 animateValue(progBar, start, end, duration);
  320. 320
  321. 321 function animateValue(element, start, end, duration) {
  322. 322 var range = end - start,
  323. 323 current = start,
  324. 324 increment = end > start ? 1 : -1,
  325. 325 stepTime = Math.abs(Math.floor(duration / range)),
  326. 326 obj = element;
  327. 327
  328. 328 var timer = setInterval(function() {
  329. 329 if (current < end) {
  330. 330 current += increment;
  331. 331 }
  332. 332 if (obj !== null) {
  333. 333 obj.css({
  334. 334 'transition-duration': '0.001s',
  335. 335 'width': current + '%',
  336. 336 });
  337. 337 }
  338. 338
  339. 339 counter.text(current + '%');
  340. 340
  341. 341 if ((current == end && perfData.loadEventEnd > 0) || perfData.loadEventEnd > 0) {
  342. 342 var endLoading = setInterval(function() {
  343. 343 current += increment;
  344. 344 if (obj !== null) {
  345. 345 obj.css('width', current + '%');
  346. 346 }
  347. 347
  348. 348 counter.text(current + '%');
  349. 349
  350. 350 if (current == 100) {
  351. 351 setTimeout(function() {
  352. 352 jQuery('.daftplugPublicPreloader').fadeOut('slow');
  353. 353 }, 300);
  354. 354 clearInterval(endLoading);
  355. 355 }
  356. 356 }, 1)
  357. 357 clearInterval(timer);
  358. 358 }
  359. 359 }, stepTime);
  360. 360 }
  361. 361 } else {
  362. 362 jQuery(window).on('beforeunload pronto.request', function(e) {
  363. 363 e.returnValue = '';
  364. 364 jQuery('.daftplugPublicPreloader').css('display', 'flex').hide().fadeIn(200);
  365. 365 }).on('load pronto.render', function(e) {
  366. 366 jQuery('.daftplugPublicPreloader').fadeOut('slow');
  367. 367 });
  368. 368 }
  369. 369 }
  370. 370
  371. 371 // Handle mobile staff
  372. 372 if (isMobilePad) {
  373. 373 // Handle navigation tab bar
  374. 374 if (objectName.settings.pwaNavigationTabBar == 'on') {
  375. 375 if (navigationTabBar.find('li').length == 0) {
  376. 376 navigationTabBar.hide();
  377. 377 }
  378. 378
  379. 379 if (navigationTabBar.is(':visible') && pushButton.length) {
  380. 380 setInterval(function(e) {
  381. 381 jQuery('#daftplugPublicToastMessage').css('bottom', '85px');
  382. 382 }, 10);
  383. 383
  384. 384 if (objectName.settings.pwaPushButton == 'on' && objectName.settings.pwaPushButtonPosition.indexOf('bottom') >= 0) {
  385. 385 pushButton.css('bottom', '75px');
  386. 386 }
  387. 387 }
  388. 388
  389. 389 var directSearchItem = navigationTabBar.find('.daftplugPublicNavigationTabBar_item.-directSearch');
  390. 390 var directSearchLink = directSearchItem.find('.daftplugPublicNavigationTabBar_link');
  391. 391 directSearchLink.click(function(e) {
  392. 392 e.preventDefault();
  393. 393 var self = jQuery(this);
  394. 394 var searchContainer = self.prev();
  395. 395 var searchForm = searchContainer.find('.daftplugPublicNavigationTabBar_searchForm');
  396. 396 var searchField = searchForm.find('.daftplugPublicNavigationTabBar_searchField');
  397. 397 searchContainer.fadeIn('fast', function(e) {
  398. 398 searchField.focus().blur(function(e) {
  399. 399 searchForm[0].reset();
  400. 400 searchContainer.fadeOut('fast');
  401. 401 });
  402. 402 });
  403. 403 });
  404. 404 }
  405. 405
  406. 406 // Handle pull down navigation
  407. 407 if (objectName.settings.pwaPullDownNavigation == 'on') {
  408. 408 PullToNavigate();
  409. 409 jQuery('#daftplugPublicPullDownNavigation').css('background', objectName.settings.pwaPullDownNavigationBgColor);
  410. 410 }
  411. 411
  412. 412 // Handle swipe navigation
  413. 413 if (objectName.settings.pwaSwipeNavigation == 'on') {
  414. 414 jQuery('body').attr('data-xthreshold', '111').swipeleft(function() {
  415. 415 window.history.back();
  416. 416 jQuery.toast({
  417. 417 title: objectName.settings.pwaSwipeBackMsg,
  418. 418 duration: 3000,
  419. 419 position: 'bottom',
  420. 420 });
  421. 421 }).swiperight(function() {
  422. 422 window.history.forward();
  423. 423 jQuery.toast({
  424. 424 title: objectName.settings.pwaSwipeForwardMsg,
  425. 425 duration: 3000,
  426. 426 position: 'bottom',
  427. 427 });
  428. 428 });
  429. 429 }
  430. 430
  431. 431 // Handle shake to refresh
  432. 432 if (objectName.settings.pwaShakeToRefresh == 'on') {
  433. 433 var shakeEvent = new Shake({threshold: 15});
  434. 434 shakeEvent.start();
  435. 435 window.addEventListener('shake', function() {
  436. 436 location.reload();
  437. 437 }, false);
  438. 438 }
  439. 439
  440. 440 // Handle vibration
  441. 441 if (objectName.settings.pwaVibration == 'on') {
  442. 442 jQuery('body').vibrate();
  443. 443 }
  444. 444
  445. 445 // Handle installation overlays
  446. 446 if (objectName.settings.pwaOverlays == 'on') {
  447. 447 // Handle fullscreen installation overlays
  448. 448 if (objectName.settings.pwaOverlaysTypes.includes('fullscreen') && isAndroidPwa == false && isIosPwa == false && isFullscreenOverlayShown == null && fullscreenOverlay.length) {
  449. 449 if (objectName.settings.pwaOverlaysBrowsers.includes('chrome') && isAndroidChrome && chromeFullscreenOverlay.length && chrome2FullscreenOverlay.length) {
  450. 450 var isFullBeforeinstallprompt = false;
  451. 451 var isFullscreenOverlayFired = false;
  452. 452 var installPromptEvent = void 0;
  453. 453 window.addEventListener('beforeinstallprompt', function(event) {
  454. 454 event.preventDefault();
  455. 455 isFullBeforeinstallprompt = true;
  456. 456 installPromptEvent = event;
  457. 457 if (!isFullscreenOverlayFired) {
  458. 458 setTimeout(function() {
  459. 459 chromeFullscreenOverlay.fadeIn('fast', function(e) {
  460. 460 isFullscreenOverlayFired = true;
  461. 461 chromeFullscreenOverlay.on('click', '.daftplugPublicFullscreenOverlay_button', function(e) {
  462. 462 chromeFullscreenOverlay.fadeOut('fast', function(e) {
  463. 463 setCookie('fullscreenOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  464. 464 installPromptEvent.prompt();
  465. 465 installPromptEvent = null;
  466. 466 });
  467. 467 });
  468. 468 });
  469. 469 }, 5000);
  470. 470 }
  471. 471 });
  472. 472 setTimeout(function() {
  473. 473 if (isFullBeforeinstallprompt == false) {
  474. 474 chrome2FullscreenOverlay.fadeIn('fast');
  475. 475 }
  476. 476 }, 5000);
  477. 477 } else if (objectName.settings.pwaOverlaysBrowsers.includes('firefox') && isAndroidFirefox && firefoxFullscreenOverlay.length) {
  478. 478 setTimeout(function() {
  479. 479 firefoxFullscreenOverlay.fadeIn('fast');
  480. 480 }, 5000);
  481. 481 } else if (objectName.settings.pwaOverlaysBrowsers.includes('safari') && isIosSafari && safariFullscreenOverlay.length) {
  482. 482 setTimeout(function() {
  483. 483 safariFullscreenOverlay.fadeIn('fast');
  484. 484 }, 5000);
  485. 485 }
  486. 486
  487. 487 fullscreenOverlay.on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  488. 488 fullscreenOverlay.fadeOut('fast', function(e) {
  489. 489 setCookie('fullscreenOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  490. 490 });
  491. 491 });
  492. 492 }
  493. 493
  494. 494 // Handle header installation overlay
  495. 495 if (objectName.settings.pwaOverlaysTypes.includes('header') && isAndroidPwa == false && isIosPwa == false && isHeaderOverlayShown == null && headerOverlay.length) {
  496. 496 if (objectName.settings.pwaOverlaysBrowsers.includes('chrome') && isAndroidChrome && chrome2FullscreenOverlay.length) {
  497. 497 var isHeaderBeforeinstallprompt = false;
  498. 498 var isHeaderOverlayFired = false;
  499. 499 var installPromptEvent = void 0;
  500. 500 window.addEventListener('beforeinstallprompt', function(event) {
  501. 501 event.preventDefault();
  502. 502 isHeaderBeforeinstallprompt = true;
  503. 503 installPromptEvent = event;
  504. 504 if (!isHeaderOverlayFired) {
  505. 505 setTimeout(function() {
  506. 506 headerOverlay.css('display', 'flex').hide().fadeIn('fast', function(e) {
  507. 507 isHeaderOverlayFired = true;
  508. 508 headerOverlay.on('click', '.daftplugPublicHeaderOverlay_button', function(e) {
  509. 509 headerOverlay.fadeOut('fast', function(e) {
  510. 510 setCookie('headerOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  511. 511 installPromptEvent.prompt();
  512. 512 installPromptEvent = null;
  513. 513 });
  514. 514 });
  515. 515 });
  516. 516 }, 5000);
  517. 517 }
  518. 518 });
  519. 519 setTimeout(function() {
  520. 520 if (isHeaderBeforeinstallprompt == false) {
  521. 521 headerOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicHeaderOverlay_button', function(e) {
  522. 522 headerOverlay.fadeOut('fast', function(e) {
  523. 523 setCookie('headerOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  524. 524 chrome2FullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  525. 525 chrome2FullscreenOverlay.fadeOut('fast');
  526. 526 });
  527. 527 });
  528. 528 });
  529. 529 }
  530. 530 }, 5000);
  531. 531 } else if (objectName.settings.pwaOverlaysBrowsers.includes('firefox') && isAndroidFirefox && firefoxFullscreenOverlay.length) {
  532. 532 setTimeout(function() {
  533. 533 headerOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicHeaderOverlay_button', function(e) {
  534. 534 headerOverlay.fadeOut('fast', function(e) {
  535. 535 setCookie('headerOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  536. 536 firefoxFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  537. 537 firefoxFullscreenOverlay.fadeOut('fast');
  538. 538 });
  539. 539 });
  540. 540 });
  541. 541 }, 5000);
  542. 542 } else if (objectName.settings.pwaOverlaysBrowsers.includes('safari') && isIosSafari && safariFullscreenOverlay.length) {
  543. 543 setTimeout(function() {
  544. 544 headerOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicHeaderOverlay_button', function(e) {
  545. 545 headerOverlay.fadeOut('fast', function(e) {
  546. 546 setCookie('headerOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  547. 547 safariFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  548. 548 safariFullscreenOverlay.fadeOut('fast');
  549. 549 });
  550. 550 });
  551. 551 });
  552. 552 }, 5000);
  553. 553 }
  554. 554
  555. 555 headerOverlay.on('click', '.daftplugPublicHeaderOverlay_dismiss', function(e) {
  556. 556 headerOverlay.fadeOut('fast', function(e) {
  557. 557 setCookie('headerOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  558. 558 });
  559. 559 });
  560. 560 }
  561. 561
  562. 562 // Handle menu installation overlay
  563. 563 if (objectName.settings.pwaOverlaysTypes.includes('menu') && isAndroidPwa == false && isIosPwa == false && isMenuOverlayShown == null && menuOverlay.length) {
  564. 564 if (objectName.settings.pwaOverlaysBrowsers.includes('chrome') && isAndroidChrome && chrome2FullscreenOverlay.length) {
  565. 565 var isMenuBeforeinstallprompt = false;
  566. 566 var installPromptEvent = void 0;
  567. 567 var isMenuOverlayFired = false;
  568. 568 window.addEventListener('beforeinstallprompt', function(event) {
  569. 569 event.preventDefault();
  570. 570 isMenuBeforeinstallprompt = true;
  571. 571 installPromptEvent = event;
  572. 572 setTimeout(function() {
  573. 573 if (!isMenuOverlayFired) {
  574. 574 menuOverlay.css('display', 'flex').hide().fadeIn('fast', function(e) {
  575. 575 isMenuOverlayFired = true;
  576. 576 menuOverlay.on('click', '.daftplugPublicMenuOverlay_install', function(e) {
  577. 577 menuOverlay.fadeOut('fast', function(e) {
  578. 578 setCookie('menuOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  579. 579 installPromptEvent.prompt();
  580. 580 installPromptEvent = null;
  581. 581 });
  582. 582 });
  583. 583 });
  584. 584 }
  585. 585 }, 3000);
  586. 586 });
  587. 587 setTimeout(function() {
  588. 588 if (isMenuBeforeinstallprompt == false) {
  589. 589 menuOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicMenuOverlay_install', function(e) {
  590. 590 menuOverlay.fadeOut('fast', function(e) {
  591. 591 setCookie('menuOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  592. 592 chrome2FullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  593. 593 chrome2FullscreenOverlay.fadeOut('fast');
  594. 594 });
  595. 595 });
  596. 596 });
  597. 597 }
  598. 598 }, 3000);
  599. 599 } else if (objectName.settings.pwaOverlaysBrowsers.includes('firefox') && isAndroidFirefox && firefoxFullscreenOverlay.length) {
  600. 600 setTimeout(function() {
  601. 601 menuOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicMenuOverlay_install', function(e) {
  602. 602 menuOverlay.fadeOut('fast', function(e) {
  603. 603 setCookie('menuOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  604. 604 firefoxFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  605. 605 firefoxFullscreenOverlay.fadeOut('fast');
  606. 606 });
  607. 607 });
  608. 608 });
  609. 609 }, 3000);
  610. 610 } else if (objectName.settings.pwaOverlaysBrowsers.includes('safari') && isIosSafari && safariFullscreenOverlay.length) {
  611. 611 setTimeout(function() {
  612. 612 menuOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicMenuOverlay_install', function(e) {
  613. 613 menuOverlay.fadeOut('fast', function(e) {
  614. 614 setCookie('menuOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  615. 615 safariFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  616. 616 safariFullscreenOverlay.fadeOut('fast');
  617. 617 });
  618. 618 });
  619. 619 });
  620. 620 }, 3000);
  621. 621 }
  622. 622
  623. 623 menuOverlay.on('click', '.daftplugPublicMenuOverlay_dismiss', function(e) {
  624. 624 menuOverlay.fadeOut('fast', function(e) {
  625. 625 setCookie('menuOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  626. 626 });
  627. 627 });
  628. 628 }
  629. 629
  630. 630 // Handle checkout installation overlay
  631. 631 if (objectName.settings.pwaOverlaysTypes.includes('checkout') && isAndroidPwa == false && isIosPwa == false && isCheckoutOverlayShown == null && checkoutOverlay.length) {
  632. 632 if (objectName.settings.pwaOverlaysBrowsers.includes('chrome') && isAndroidChrome && chrome2FullscreenOverlay.length) {
  633. 633 var isCheckoutBeforeinstallprompt = false;
  634. 634 var installPromptEvent = void 0;
  635. 635 var isCheckoutOverlayFired = false;
  636. 636 window.addEventListener('beforeinstallprompt', function(event) {
  637. 637 event.preventDefault();
  638. 638 isCheckoutBeforeinstallprompt = true;
  639. 639 installPromptEvent = event;
  640. 640 setTimeout(function() {
  641. 641 if (!isCheckoutOverlayFired) {
  642. 642 checkoutOverlay.css('display', 'flex').hide().fadeIn('fast', function(e) {
  643. 643 isCheckoutOverlayFired = true;
  644. 644 checkoutOverlay.on('click', '.daftplugPublicCheckoutOverlay_install', function(e) {
  645. 645 checkoutOverlay.fadeOut('fast', function(e) {
  646. 646 setCookie('checkoutOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  647. 647 installPromptEvent.prompt();
  648. 648 installPromptEvent = null;
  649. 649 });
  650. 650 });
  651. 651 });
  652. 652 }
  653. 653 }, 3000);
  654. 654 });
  655. 655 setTimeout(function() {
  656. 656 if (isCheckoutBeforeinstallprompt == false) {
  657. 657 checkoutOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicCheckoutOverlay_install', function(e) {
  658. 658 checkoutOverlay.fadeOut('fast', function(e) {
  659. 659 setCookie('checkoutOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  660. 660 chrome2FullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  661. 661 chrome2FullscreenOverlay.fadeOut('fast');
  662. 662 });
  663. 663 });
  664. 664 });
  665. 665 }
  666. 666 }, 3000);
  667. 667 } else if (objectName.settings.pwaOverlaysBrowsers.includes('firefox') && isAndroidFirefox && firefoxFullscreenOverlay.length) {
  668. 668 setTimeout(function() {
  669. 669 checkoutOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicCheckoutOverlay_install', function(e) {
  670. 670 checkoutOverlay.fadeOut('fast', function(e) {
  671. 671 setCookie('checkoutOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  672. 672 firefoxFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  673. 673 firefoxFullscreenOverlay.fadeOut('fast');
  674. 674 });
  675. 675 });
  676. 676 });
  677. 677 }, 3000);
  678. 678 } else if (objectName.settings.pwaOverlaysBrowsers.includes('safari') && isIosSafari && safariFullscreenOverlay.length) {
  679. 679 setTimeout(function() {
  680. 680 checkoutOverlay.css('display', 'flex').hide().fadeIn('fast').on('click', '.daftplugPublicCheckoutOverlay_install', function(e) {
  681. 681 checkoutOverlay.fadeOut('fast', function(e) {
  682. 682 setCookie('checkoutOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  683. 683 safariFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  684. 684 safariFullscreenOverlay.fadeOut('fast');
  685. 685 });
  686. 686 });
  687. 687 });
  688. 688 }, 3000);
  689. 689 }
  690. 690
  691. 691 checkoutOverlay.on('click', '.daftplugPublicCheckoutOverlay_dismiss', function(e) {
  692. 692 checkoutOverlay.fadeOut('fast', function(e) {
  693. 693 setCookie('checkoutOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  694. 694 });
  695. 695 });
  696. 696 }
  697. 697
  698. 698 // Handle post installation overlay
  699. 699 if (objectName.settings.pwaOverlaysTypes.includes('post') && isAndroidPwa == false && isIosPwa == false && isPostOverlayShown == null && postOverlay.length) {
  700. 700 if (objectName.settings.pwaOverlaysBrowsers.includes('chrome') && isAndroidChrome && chrome2FullscreenOverlay.length) {
  701. 701 var isPostBeforeinstallprompt = false;
  702. 702 var installPromptEvent = void 0;
  703. 703 var isPostOverlayFired = false;
  704. 704 window.addEventListener('beforeinstallprompt', function(event) {
  705. 705 event.preventDefault();
  706. 706 isPostBeforeinstallprompt = true;
  707. 707 installPromptEvent = event;
  708. 708 setTimeout(function() {
  709. 709 if (!isPostOverlayFired) {
  710. 710 postOverlay.fadeIn('fast', function(e) {
  711. 711 isPostOverlayFired = true;
  712. 712 postOverlay.on('click', '.daftplugPublicPostOverlayAction_button.-install', function(e) {
  713. 713 postOverlay.fadeOut('fast', function(e) {
  714. 714 setCookie('postOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  715. 715 installPromptEvent.prompt();
  716. 716 installPromptEvent = null;
  717. 717 });
  718. 718 });
  719. 719 });
  720. 720 }
  721. 721 }, 5000);
  722. 722 });
  723. 723 setTimeout(function() {
  724. 724 if (isPostBeforeinstallprompt == false) {
  725. 725 postOverlay.fadeIn('fast').on('click', '.daftplugPublicPostOverlayAction_button.-install', function(e) {
  726. 726 postOverlay.fadeOut('fast', function(e) {
  727. 727 setCookie('postOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  728. 728 chrome2FullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  729. 729 chrome2FullscreenOverlay.fadeOut('fast');
  730. 730 });
  731. 731 });
  732. 732 });
  733. 733 }
  734. 734 }, 5000);
  735. 735 } else if (objectName.settings.pwaOverlaysBrowsers.includes('firefox') && isAndroidFirefox && firefoxFullscreenOverlay.length) {
  736. 736 setTimeout(function() {
  737. 737 postOverlay.fadeIn('fast').on('click', '.daftplugPublicPostOverlayAction_button.-install', function(e) {
  738. 738 postOverlay.fadeOut('fast', function(e) {
  739. 739 setCookie('postOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  740. 740 firefoxFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  741. 741 firefoxFullscreenOverlay.fadeOut('fast');
  742. 742 });
  743. 743 });
  744. 744 });
  745. 745 }, 5000);
  746. 746 } else if (objectName.settings.pwaOverlaysBrowsers.includes('safari') && isIosSafari && safariFullscreenOverlay.length) {
  747. 747 setTimeout(function() {
  748. 748 postOverlay.fadeIn('fast').on('click', '.daftplugPublicPostOverlayAction_button.-install', function(e) {
  749. 749 postOverlay.fadeOut('fast', function(e) {
  750. 750 setCookie('postOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  751. 751 safariFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  752. 752 safariFullscreenOverlay.fadeOut('fast');
  753. 753 });
  754. 754 });
  755. 755 });
  756. 756 }, 5000);
  757. 757 }
  758. 758
  759. 759 postOverlay.on('click', '.daftplugPublicPostOverlayAction_button.-dismiss', function(e) {
  760. 760 postOverlay.fadeOut('fast', function(e) {
  761. 761 setCookie('postOverlay', 'shown', objectName.settings.pwaOverlaysShowAgain);
  762. 762 });
  763. 763 });
  764. 764 }
  765. 765 }
  766. 766
  767. 767 // Handle installation button
  768. 768 if (objectName.settings.pwaInstallButton == 'on') {
  769. 769 if (isAndroidPwa == false && isIosPwa == false && installButton.length) {
  770. 770 if (objectName.settings.pwaInstallButtonBrowsers.includes('chrome') && isAndroidChrome && chrome2FullscreenOverlay.length) {
  771. 771 var isButtonBeforeinstallprompt = false;
  772. 772 var installPromptEvent = void 0;
  773. 773 window.addEventListener('beforeinstallprompt', function(event) {
  774. 774 isButtonBeforeinstallprompt = true;
  775. 775 event.preventDefault();
  776. 776 installPromptEvent = event;
  777. 777 setTimeout(function() {
  778. 778 installButton.css('display', 'inline-block').on('click', function(e) {
  779. 779 installPromptEvent.prompt();
  780. 780 installPromptEvent = null;
  781. 781 });
  782. 782 }, 1000);
  783. 783 });
  784. 784 setTimeout(function() {
  785. 785 if (isMenuBeforeinstallprompt == false) {
  786. 786 installButton.css('display', 'inline-block').on('click', function(e) {
  787. 787 chrome2FullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  788. 788 chrome2FullscreenOverlay.fadeOut('fast');
  789. 789 });
  790. 790 });
  791. 791 }
  792. 792 }, 1000);
  793. 793 } else if (objectName.settings.pwaInstallButtonBrowsers.includes('firefox') && isAndroidFirefox && firefoxFullscreenOverlay.length) {
  794. 794 setTimeout(function() {
  795. 795 installButton.css('display', 'inline-block').on('click', function(e) {
  796. 796 firefoxFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  797. 797 firefoxFullscreenOverlay.fadeOut('fast');
  798. 798 });
  799. 799 });
  800. 800 }, 1000);
  801. 801 } else if (objectName.settings.pwaInstallButtonBrowsers.includes('safari') && isIosSafari && safariFullscreenOverlay.length) {
  802. 802 setTimeout(function() {
  803. 803 installButton.css('display', 'inline-block').on('click', function(e) {
  804. 804 safariFullscreenOverlay.fadeIn('fast').on('click', '.daftplugPublicFullscreenOverlay_close', function(e) {
  805. 805 safariFullscreenOverlay.fadeOut('fast');
  806. 806 });
  807. 807 });
  808. 808 }, 1000);
  809. 809 }
  810. 810 }
  811. 811 }
  812. 812
  813. 813 // Handle iOS pwa stuff
  814. 814 if (isIosPwa) {
  815. 815 //Stop link clicks out of the iOS pwa
  816. 816 var noddy, remotes = false;
  817. 817 document.addEventListener('click', function(event) {
  818. 818 noddy = event.target;
  819. 819 if (noddy.tagName.toLowerCase() !== 'a' || noddy.hostname !== window.location.hostname || noddy.pathname !== window.location.pathname || !/#/.test(noddy.href)) return;
  820. 820
  821. 821 while (noddy.nodeName !== 'A' && noddy.nodeName !== 'HTML') {
  822. 822 noddy = noddy.parentNode;
  823. 823 }
  824. 824
  825. 825 if ('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
  826. 826 event.preventDefault();
  827. 827 document.location.href = noddy.href;
  828. 828 }
  829. 829 }, false);
  830. 830
  831. 831 // Display rotate device notice based on orientation
  832. 832 setInterval(function() {
  833. 833 if ((objectName.settings.pwaOrientation == 'portrait' && window.matchMedia('(orientation: landscape)').matches) || (objectName.settings.pwaOrientation == 'landscape' && window.matchMedia('(orientation: portrait)').matches)) {
  834. 834 rotateNotice.css('display', 'flex');
  835. 835 window.onorientationchange = function(e) {
  836. 836 rotateNotice.hide();
  837. 837 };
  838. 838 }
  839. 839 }, 100);
  840. 840 }
  841. 841
  842. 842 // Handle both pwa stuff
  843. 843 if (isPwa()) {
  844. 844 if (jQuery('form').length) {
  845. 845 jQuery('form').attr('data-persist', 'garlic');
  846. 846 }
  847. 847 }
  848. 848 }
  849. 849
  850. 850 // Handle PWA installation analytics
  851. 851 window.onappinstalled = function(e) {
  852. 852 jQuery.ajax({
  853. 853 url: objectName.ajaxUrl,
  854. 854 dataType: 'text',
  855. 855 type: 'POST',
  856. 856 data: {
  857. 857 action: optionName + '_save_installation_analytics',
  858. 858 },
  859. 859 beforeSend: function() {
  860. 860 console.log('saving');
  861. 861 },
  862. 862 success: function(response, textStatus, jqXhr) {
  863. 863 console.log('saved');
  864. 864 },
  865. 865 complete: function() {
  866. 866
  867. 867 },
  868. 868 error: function(jqXhr, textStatus, errorThrown) {
  869. 869 console.log(jqXhr);
  870. 870 }
  871. 871 });
  872. 872 };
  873. 873 });
Bookmark: javascript:location='http://shauninman.com/vs/?url='+escape(location)