RA-#13 Dont show install promt when welcome banner active
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
header('Content-Type: text/javascript');
|
header('Content-Type: text/javascript');
|
||||||
|
|
||||||
require_once(__DIR__ . '/../../server/version.php');
|
require_once(__DIR__ . '/../../server/version.php');
|
||||||
require_once(__DIR__ . '/../../server/config.php');
|
require_once(__DIR__ . '/../../server/config.php');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
//Loading the Service Worker
|
//Loading the Service Worker
|
||||||
var swRegistration = null;
|
var swRegistration = null;
|
||||||
@@ -16,31 +16,31 @@ if ('serviceWorker' in navigator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
var pwaVersion = '<?php echo PWA_VERSION; ?>'; //must be identical to _manifest.json version. If not it will create update window loop
|
var pwaVersion = '<?php echo PWA_VERSION; ?>'; //must be identical to _manifest.json version. If not it will create update window loop
|
||||||
var pwaCookie = true; // if set to false, the PWA prompt will appear even if the user selects "maybe later"
|
var pwaCookie = true; // if set to false, the PWA prompt will appear even if the user selects "maybe later"
|
||||||
var pwaNoCache = false; // always keep the cache clear to serve the freshest possible content
|
var pwaNoCache = false; // always keep the cache clear to serve the freshest possible content
|
||||||
|
|
||||||
|
|
||||||
$('[data-pwa-version]').data('pwa-version', pwaVersion);
|
$('[data-pwa-version]').data('pwa-version', pwaVersion);
|
||||||
|
|
||||||
|
|
||||||
//Creating Cookie System for PWA Hide
|
//Creating Cookie System for PWA Hide
|
||||||
function createCookie(e, t, n) {if (n) {var o = new Date;o.setTime(o.getTime() + n * 365 * 24 * 3600 * 1e3);var r = "; expires=" + o.toGMTString()} else var r = "";document.cookie = e + "=" + t + r + "; path=/"}
|
function createCookie(e, t, n) {if (n) {var o = new Date;o.setTime(o.getTime() + n * 365 * 24 * 3600 * 1e3);var r = "; expires=" + o.toGMTString()} else var r = "";document.cookie = e + "=" + t + r + "; path=/"}
|
||||||
function readCookie(e) {for (var t = e + "=", n = document.cookie.split(";"), o = 0; o < n.length; o++) {for (var r = n[o];" " == r.charAt(0);) r = r.substring(1, r.length);if (0 == r.indexOf(t)) return r.substring(t.length, r.length)}return null}
|
function readCookie(e) {for (var t = e + "=", n = document.cookie.split(";"), o = 0; o < n.length; o++) {for (var r = n[o];" " == r.charAt(0);) r = r.substring(1, r.length);if (0 == r.indexOf(t)) return r.substring(t.length, r.length)}return null}
|
||||||
function eraseCookie(e) {createCookie(e, "", -1)}
|
function eraseCookie(e) {createCookie(e, "", -1)}
|
||||||
|
|
||||||
//Enabling dismiss button
|
//Enabling dismiss button
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$('.pwa-dismiss').on('click',function(){
|
$('.pwa-dismiss').on('click',function(){
|
||||||
console.log('User Closed Add to Home / PWA Prompt')
|
console.log('User Closed Add to Home / PWA Prompt')
|
||||||
createCookie('Sticky_pwa_rejected_install', true, 1);
|
createCookie('Sticky_pwa_rejected_install', true, 1);
|
||||||
$('body').find('#menu-install-pwa-android, #menu-install-pwa-ios, .menu-hider').removeClass('menu-active');
|
$('body').find('#menu-install-pwa-android, #menu-install-pwa-ios, .menu-hider').removeClass('menu-active');
|
||||||
});
|
});
|
||||||
},1500);
|
},1500);
|
||||||
|
|
||||||
//Detecting Mobile Operating Systems
|
//Detecting Mobile Operating Systems
|
||||||
var isMobile = {
|
var isMobile = {
|
||||||
Android: function() {return navigator.userAgent.match(/Android/i);},
|
Android: function() {return navigator.userAgent.match(/Android/i);},
|
||||||
@@ -49,8 +49,8 @@ $(document).ready(function(){
|
|||||||
};
|
};
|
||||||
var isInWebAppiOS = (window.navigator.standalone == true);
|
var isInWebAppiOS = (window.navigator.standalone == true);
|
||||||
var isInWebAppChrome = (window.matchMedia('(display-mode: standalone)').matches);
|
var isInWebAppChrome = (window.matchMedia('(display-mode: standalone)').matches);
|
||||||
|
|
||||||
//Firing PWA prompts for specific versions and when not on home screen.
|
//Firing PWA prompts for specific versions and when not on home screen.
|
||||||
if (isMobile.Android()) {
|
if (isMobile.Android()) {
|
||||||
console.log('Android Detected');
|
console.log('Android Detected');
|
||||||
function showInstallPromotion(){
|
function showInstallPromotion(){
|
||||||
@@ -60,7 +60,7 @@ $(document).ready(function(){
|
|||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$('.add-to-home').addClass('add-to-home-visible add-to-home-android');
|
$('.add-to-home').addClass('add-to-home-visible add-to-home-android');
|
||||||
$('#menu-install-pwa-android, .menu-hider').addClass('menu-active')
|
$('#menu-install-pwa-android, .menu-hider').addClass('menu-active')
|
||||||
},4500);
|
},3000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('The div #menu-install-pwa-android was not found. Please add this div to show the install window')
|
console.log('The div #menu-install-pwa-android was not found. Please add this div to show the install window')
|
||||||
@@ -70,7 +70,12 @@ $(document).ready(function(){
|
|||||||
window.addEventListener('beforeinstallprompt', (e) => {
|
window.addEventListener('beforeinstallprompt', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
deferredPrompt = e;
|
deferredPrompt = e;
|
||||||
showInstallPromotion();
|
var welcomActive = $('#menu-welcome').hasClass('menu-active');
|
||||||
|
if (welcomActive) {
|
||||||
|
$('#menu-welcome-a-okay').click(showInstallPromotion);
|
||||||
|
} else {
|
||||||
|
showInstallPromotion();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
$('.pwa-install').on('click',function(e){
|
$('.pwa-install').on('click',function(e){
|
||||||
deferredPrompt.prompt();
|
deferredPrompt.prompt();
|
||||||
@@ -87,26 +92,34 @@ $(document).ready(function(){
|
|||||||
window.addEventListener('appinstalled', (evt) => {
|
window.addEventListener('appinstalled', (evt) => {
|
||||||
$('#menu-install-pwa-android, .menu-hider').removeClass('menu-active')
|
$('#menu-install-pwa-android, .menu-hider').removeClass('menu-active')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMobile.iOS()) {
|
if (isMobile.iOS()) {
|
||||||
if(!isInWebAppiOS){
|
if(!isInWebAppiOS){
|
||||||
console.log('iOS Detected');
|
console.log('iOS Detected');
|
||||||
if($('#menu-install-pwa-ios, .add-to-home').length){
|
if($('#menu-install-pwa-ios, .add-to-home').length){
|
||||||
if (!readCookie('Sticky_pwa_rejected_install')) {
|
if (!readCookie('Sticky_pwa_rejected_install')) {
|
||||||
console.log('Triggering PWA / Add to Home Screen Menu for iOS');
|
function triggerPwaInstallIos() {
|
||||||
setTimeout(function(){
|
console.log('Triggering PWA / Add to Home Screen Menu for iOS');
|
||||||
$('.add-to-home').addClass('add-to-home-visible add-to-home-ios');
|
setTimeout(function(){
|
||||||
$('#menu-install-pwa-ios, .menu-hider').addClass('menu-active');
|
$('.add-to-home').addClass('add-to-home-visible add-to-home-ios');
|
||||||
},4500);
|
$('#menu-install-pwa-ios, .menu-hider').addClass('menu-active');
|
||||||
|
},3000);
|
||||||
|
}
|
||||||
|
var welcomActive = $('#menu-welcome').hasClass('menu-active');
|
||||||
|
if (welcomActive) {
|
||||||
|
$('#menu-welcome-a-okay').click(triggerPwaInstallIos);
|
||||||
|
} else {
|
||||||
|
triggerPwaInstallIos();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
console.log('The div #menu-install-pwa-ios was not found. Please add this div to show the install window')
|
console.log('The div #menu-install-pwa-ios was not found. Please add this div to show the install window')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Creating Update Modal
|
//Creating Update Modal
|
||||||
function updateModal(){
|
function updateModal(){
|
||||||
var body = $('body');
|
var body = $('body');
|
||||||
@@ -116,7 +129,7 @@ $(document).ready(function(){
|
|||||||
if(!updateModal.length){
|
if(!updateModal.length){
|
||||||
body.append('<div id="menu-update"></div>');
|
body.append('<div id="menu-update"></div>');
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
body.find('#menu-update').load('menu-update.html?ver='+menuUpdate);
|
body.find('#menu-update').load('menu-update.html?ver='+menuUpdate);
|
||||||
},250);
|
},250);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -132,8 +145,8 @@ $(document).ready(function(){
|
|||||||
window.location.reload(true)
|
window.location.reload(true)
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
caches.delete('workbox-runtime').then(function() {
|
caches.delete('workbox-runtime').then(function() {
|
||||||
console.log('Content Updated - Cache Removed!');
|
console.log('Content Updated - Cache Removed!');
|
||||||
});
|
});
|
||||||
//localStorage.clear();
|
//localStorage.clear();
|
||||||
sessionStorage.clear()
|
sessionStorage.clear()
|
||||||
@@ -143,17 +156,17 @@ $(document).ready(function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//Check Version
|
//Check Version
|
||||||
function check_version(){
|
function check_version(){
|
||||||
if($('link[data-pwa-version]').length){
|
if($('link[data-pwa-version]').length){
|
||||||
function versionCheck(){
|
function versionCheck(){
|
||||||
var dt = new Date();
|
var dt = new Date();
|
||||||
var maniTimeVersion = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
|
var maniTimeVersion = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
|
||||||
var localVersionNumber = $('link[rel="manifest"]').data('pwa-version');
|
var localVersionNumber = $('link[rel="manifest"]').data('pwa-version');
|
||||||
var onlineVersionJSON = "<?php echo SERVER_ADDR; ?>/manifest.json.php?ver=" + maniTimeVersion;
|
var onlineVersionJSON = "<?php echo SERVER_ADDR; ?>/manifest.json.php?ver=" + maniTimeVersion;
|
||||||
var onlineVersionNumber = "Connection Offline. Waiting to Reconect";
|
var onlineVersionNumber = "Connection Offline. Waiting to Reconect";
|
||||||
$.getJSON(onlineVersionJSON, function(onlineData) {onlineVersionNumber = onlineData.version;});
|
$.getJSON(onlineVersionJSON, function(onlineData) {onlineVersionNumber = onlineData.version;});
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
//console.log(' Checking PWA Content for updates...\n PWA Server Version: ' + onlineVersionNumber + '\n' + ' PWA Cached Version: ' + localVersionNumber);
|
//console.log(' Checking PWA Content for updates...\n PWA Server Version: ' + onlineVersionNumber + '\n' + ' PWA Cached Version: ' + localVersionNumber);
|
||||||
if(onlineVersionNumber != localVersionNumber && onlineVersionNumber != "Connection Offline. Waiting to Reconect"){
|
if(onlineVersionNumber != localVersionNumber && onlineVersionNumber != "Connection Offline. Waiting to Reconect"){
|
||||||
@@ -161,16 +174,16 @@ $(document).ready(function(){
|
|||||||
console.log('New Version of Content Available. Refreshing. On Desktop Browsers a manual refresh maybe required.')
|
console.log('New Version of Content Available. Refreshing. On Desktop Browsers a manual refresh maybe required.')
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
$('body').find('#menu-update').addClass('menu-active');
|
$('body').find('#menu-update').addClass('menu-active');
|
||||||
$('.menu-hider').addClass('menu-active-no-click');
|
$('.menu-hider').addClass('menu-active-no-click');
|
||||||
updateButton();
|
updateButton();
|
||||||
},500);
|
},500);
|
||||||
}
|
}
|
||||||
if(onlineVersionNumber == localVersionNumber){/*No update required. Versions Identical*/}
|
if(onlineVersionNumber == localVersionNumber){/*No update required. Versions Identical*/}
|
||||||
if(onlineVersionNumber === "undefined"){/*Error Checking for Updates*/}
|
if(onlineVersionNumber === "undefined"){/*Error Checking for Updates*/}
|
||||||
if(onlineVersionNumber === "Finding Online Version..."){
|
if(onlineVersionNumber === "Finding Online Version..."){
|
||||||
$('.reloadme').addClass('disabled');
|
$('.reloadme').addClass('disabled');
|
||||||
$('body').find('#menu-update').removeClass('menu-active');
|
$('body').find('#menu-update').removeClass('menu-active');
|
||||||
$('.menu-hider').removeClass('menu-active-no-click');
|
$('.menu-hider').removeClass('menu-active-no-click');
|
||||||
}
|
}
|
||||||
},3000);
|
},3000);
|
||||||
}
|
}
|
||||||
@@ -184,15 +197,15 @@ $(document).ready(function(){
|
|||||||
if(pwaCookie == false){
|
if(pwaCookie == false){
|
||||||
eraseCookie('Sticky_pwa_rejected_install');
|
eraseCookie('Sticky_pwa_rejected_install');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reload To Clear Button
|
//Reload To Clear Button
|
||||||
$('body').on('click', '.page-update, .reloadme', function() {
|
$('body').on('click', '.page-update, .reloadme', function() {
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Check for Version Change if Online If not Kill the Function
|
//Check for Version Change if Online If not Kill the Function
|
||||||
if (navigator.onLine) {check_version();} else {function check_version(){}}
|
if (navigator.onLine) {check_version();} else {function check_version(){}}
|
||||||
|
|
||||||
//Adding Offline Alerts
|
//Adding Offline Alerts
|
||||||
var offlineAlerts = $('.offline-message');
|
var offlineAlerts = $('.offline-message');
|
||||||
|
|
||||||
@@ -200,24 +213,24 @@ $(document).ready(function(){
|
|||||||
$('body').append('<p class="offline-message bg-red2-dark color-white center-text uppercase ultrabold">' + strings['inetMsgOffline'] + '</p>');
|
$('body').append('<p class="offline-message bg-red2-dark color-white center-text uppercase ultrabold">' + strings['inetMsgOffline'] + '</p>');
|
||||||
$('body').append('<p class="online-message bg-green1-dark color-white center-text uppercase ultrabold">' + strings['inetMsgOnline'] + '</p>');
|
$('body').append('<p class="online-message bg-green1-dark color-white center-text uppercase ultrabold">' + strings['inetMsgOnline'] + '</p>');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Offline Function Show
|
//Offline Function Show
|
||||||
function isOffline(){
|
function isOffline(){
|
||||||
$('.offline-message').addClass('offline-message-active');
|
$('.offline-message').addClass('offline-message-active');
|
||||||
$('.online-message').removeClass('online-message-active');
|
$('.online-message').removeClass('online-message-active');
|
||||||
setTimeout(function(){$('.offline-message').removeClass('offline-message-active');},2000);
|
setTimeout(function(){$('.offline-message').removeClass('offline-message-active');},2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Online Function Show
|
//Online Function Show
|
||||||
function isOnline(){
|
function isOnline(){
|
||||||
$('.online-message').addClass('online-message-active');
|
$('.online-message').addClass('online-message-active');
|
||||||
$('.offline-message').removeClass('offline-message-active');
|
$('.offline-message').removeClass('offline-message-active');
|
||||||
setTimeout(function(){$('.online-message').removeClass('online-message-active');},2000);
|
setTimeout(function(){$('.online-message').removeClass('online-message-active');},2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.simulate-offline').on('click',function(){isOffline();})
|
$('.simulate-offline').on('click',function(){isOffline();})
|
||||||
$('.simulate-online').on('click',function(){isOnline();})
|
$('.simulate-online').on('click',function(){isOnline();})
|
||||||
|
|
||||||
//Disable links to other pages if offline.
|
//Disable links to other pages if offline.
|
||||||
//Warning! Enabling offline for iOS can cause issues
|
//Warning! Enabling offline for iOS can cause issues
|
||||||
//To allow offline functionality delete the next 7 lines
|
//To allow offline functionality delete the next 7 lines
|
||||||
@@ -226,9 +239,9 @@ $(document).ready(function(){
|
|||||||
if(detectHREF.match(/.html/)){
|
if(detectHREF.match(/.html/)){
|
||||||
isOffline();
|
isOffline();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if Online / Offline
|
//Check if Online / Offline
|
||||||
function updateOnlineStatus(event) {
|
function updateOnlineStatus(event) {
|
||||||
var condition = navigator.onLine ? "online" : "offline";
|
var condition = navigator.onLine ? "online" : "offline";
|
||||||
@@ -243,10 +256,10 @@ $(document).ready(function(){
|
|||||||
}
|
}
|
||||||
window.addEventListener('online', updateOnlineStatus);
|
window.addEventListener('online', updateOnlineStatus);
|
||||||
window.addEventListener('offline', updateOfflineStatus);
|
window.addEventListener('offline', updateOfflineStatus);
|
||||||
|
|
||||||
|
|
||||||
if(pwaNoCache == true){
|
if(pwaNoCache == true){
|
||||||
caches.delete('workbox-runtime').then(function() {
|
caches.delete('workbox-runtime').then(function() {
|
||||||
});
|
});
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
sessionStorage.clear()
|
sessionStorage.clear()
|
||||||
@@ -256,6 +269,6 @@ $(document).ready(function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user