diff --git a/dist/add-to-homescreen.min.js b/dist/add-to-homescreen.min.js index 6726fd2..9c48f6a 100644 --- a/dist/add-to-homescreen.min.js +++ b/dist/add-to-homescreen.min.js @@ -1 +1 @@ -(()=>{"use strict";class e{constructor({appName:e,appIconUrl:s,assetUrl:t,showErrorMessageForUnsupportedBrowsers:n,allowUserToCloseModal:i,maxModalDisplayCount:r}){this.appName=e,this.appIconUrl=s,this.assetUrl=t,this.showErrorMessageForUnsupportedBrowsers=void 0===n||n,this.allowUserToCloseModal=void 0!==i&&i,this.maxModalDisplayCount=void 0===r?-1:r,this.closeEventListener=null}isStandAlone(){return window.navigator.standalone||window.matchMedia("(display-mode: standalone)").matches}isDeviceAndroid(){return navigator.userAgent.match(/Android/)}isDeviceIOS(){return navigator.userAgent.match(/iPhone|iPad|iPod/)}isBrowserIOSSafari(){return this.isDeviceIOS()&&window.navigator.userAgent.match(/Safari/)&&!this.isBrowserIOSChrome()&&!this.isBrowserIOSFirefox()&&!this.isBrowserIOSInAppFacebook()&&!this.isBrowserIOSInAppLinkedin()&&!this.isBrowserIOSInAppInstagram()&&!this.isBrowserIOSInAppThreads()&&!this.isBrowserIOSInAppTwitter()}isBrowserIOSChrome(){return this.isDeviceIOS()&&navigator.userAgent.match(/CriOS/)}isBrowserIOSFirefox(){return this.isDeviceIOS()&&window.navigator.userAgent.match(/FxiOS/)}isBrowserIOSInAppFacebook(){return!!this.isDeviceIOS()&&window.navigator.userAgent.match(/FBAN|FBAV/)}isBrowserIOSInAppLinkedin(){return!!this.isDeviceIOS()&&window.navigator.userAgent.match(/LinkedInApp/)}isBrowserIOSInAppInstagram(){return!(!this.isDeviceIOS()||!window.document.referrer.match("//l.instagram.com/")&&!(window.navigator.userAgent.match(/iPhone/)&&window.screen.height&&window.outerHeight&&window.outerHeight{t.classList.add("visible")}),50)}return s}close(){const e=document.querySelector(".adhs-container");e&&(e.classList.remove("visible"),setTimeout((()=>{e.remove(),this.closeEventListener&&(window.removeEventListener("touchstart",this.closeEventListener),window.removeEventListener("click",this.closeEventListener),this.closeEventListener=null)}),300))}_genLogo(){return'\n \n '}_genErrorMessage(e,s,t){var n=this._genLogo()+this._genModalStart()+'
'+s+'
'+t+'
'+this._genModalEnd();e.innerHTML=n}_genTitleWithMessage(e){return'\n
'+e+"
\n "}_genTitle(){return this._genTitleWithMessage("Install the "+this.appName+" app to continue")}_genModalStart(){return'
'}_genModalEnd(){return"
"}_genListStart(){return'
'}_genListEnd(){return"
"}_genListItem(e,s){return'\n
\n
\n
\n
'+e+'
\n
\n
\n
'+s+"
\n
"}_genAssetUrl(e){return this.assetUrl+e}_genIOSSafari(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button below.')+this._genListItem("2",'Select from the menu that pops up. You may need to scroll down to find this menu item.')+this._genListItem("3",'Open the app.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-safari")}_genIOSChrome(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button in the upper right corner.')+this._genListItem("2",'Select from the menu that pops up. You may need to scroll down to find this menu item.')+this._genListItem("3",'Open the app.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-chrome")}_genIOSInAppBrowserOpenInSystemBrowser(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button above.')+this._genListItem("2",'Tap Open in browser .')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-inappbrowser-openinsystembrowser")}_genIOSInAppBrowserOpenInSafariBrowser(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button below to open your system browser.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-inappbrowser-openinsafari")}_genAndroidChrome(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button in the browser bar.')+this._genListItem("2",'Tap or .')+this._genListItem("3",'Open the app.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-android"),e.classList.add("adhs-chrome")}_registerCloseListener(){if(this.allowUserToCloseModal){var e=this;this.closeEventListener=function(s){document.getElementsByClassName("adhs-container")[0].getElementsByClassName("adhs-modal")[0].contains(s.target)||e.close()},window.addEventListener("touchstart",this.closeEventListener),window.addEventListener("click",this.closeEventListener)}}clearModalDisplayCount(){this._isEnabledModalDisplayCount()&&window.localStorage.removeItem("adhs-modal-display-count")}_isEnabledModalDisplayCount(){return"number"==typeof this.maxModalDisplayCount&&this.maxModalDisplayCount>=0&&window.localStorage}_hasReachedMaxModalDisplayCount(){return!!this._isEnabledModalDisplayCount()&&this._getModalDisplayCount()>=this.maxModalDisplayCount}_incrModalDisplayCount(){if(!this._isEnabledModalDisplayCount())return!1;var e=this._getModalDisplayCount();return e++,window.localStorage.setItem("adhs-modal-display-count",e),!0}_getModalDisplayCount(){var e=window.localStorage.getItem("adhs-modal-display-count");return null===e?(e=0,window.localStorage.setItem("adhs-modal-display-count",e)):e=parseInt(e),e}static copyToClipboard(){const e=window.location.href;try{window.navigator.clipboard.writeText(e),document.getElementsByClassName("adhs-error-copy-link-button")[0].innerHTML="Link Copied to Clipboard!"}catch(e){document.getElementsByClassName("adhs-error-copy-link-button")[0].innerHTML='Failed to Copy to Clipboard! (Try Again from "https://" Link)'}}}e.ReturnObj=class{constructor({isStandAlone:e,canBeStandAlone:s,device:t}){this.isStandAlone=e,this.canBeStandAlone=s,this.device=t}};const s=e;window.AddToHomeScreen=s,window.AddToHomescreen={}.default})(); \ No newline at end of file +(()=>{"use strict";class e{constructor({appName:e,appIconUrl:s,assetUrl:t,showErrorMessageForUnsupportedBrowsers:n,allowUserToCloseModal:i,maxModalDisplayCount:r}){this.appName=e,this.appIconUrl=s,this.assetUrl=t,this.showErrorMessageForUnsupportedBrowsers=void 0===n||n,this.allowUserToCloseModal=void 0!==i&&i,this.maxModalDisplayCount=void 0===r?-1:r,this.closeEventListener=null}isStandAlone(){return window.navigator.standalone||window.matchMedia("(display-mode: standalone)").matches}isDeviceAndroid(){return navigator.userAgent.match(/Android/)}isDeviceIOS(){return navigator.userAgent.match(/iPhone|iPad|iPod/)}isBrowserIOSSafari(){return this.isDeviceIOS()&&window.navigator.userAgent.match(/Safari/)&&!this.isBrowserIOSChrome()&&!this.isBrowserIOSFirefox()&&!this.isBrowserIOSInAppFacebook()&&!this.isBrowserIOSInAppLinkedin()&&!this.isBrowserIOSInAppInstagram()&&!this.isBrowserIOSInAppThreads()&&!this.isBrowserIOSInAppTwitter()}isBrowserIOSChrome(){return this.isDeviceIOS()&&navigator.userAgent.match(/CriOS/)}isBrowserIOSFirefox(){return this.isDeviceIOS()&&window.navigator.userAgent.match(/FxiOS/)}isBrowserIOSInAppFacebook(){return!!this.isDeviceIOS()&&window.navigator.userAgent.match(/FBAN|FBAV/)}isBrowserIOSInAppLinkedin(){return!!this.isDeviceIOS()&&window.navigator.userAgent.match(/LinkedInApp/)}isBrowserIOSInAppInstagram(){return!(!this.isDeviceIOS()||!window.document.referrer.match("//l.instagram.com/")&&!(window.navigator.userAgent.match(/iPhone/)&&window.screen.height&&window.outerHeight&&window.outerHeight{n.classList.add("visible")}),50))}return s}close(){const e=document.querySelector(".adhs-container");e&&(e.classList.remove("visible"),setTimeout((()=>{e.remove(),this.closeEventListener&&(window.removeEventListener("touchstart",this.closeEventListener),window.removeEventListener("click",this.closeEventListener),this.closeEventListener=null)}),300))}_genLogo(){return'\n \n '}_genErrorMessage(e,s,t){var n=this._genLogo()+this._genModalStart()+'
'+s+'
'+t+'
'+this._genModalEnd();e.innerHTML=n}_genTitleWithMessage(e){return'\n
'+e+"
\n "}_genTitle(){return this._genTitleWithMessage("Install the "+this.appName+" app to continue")}_genModalStart(){return'
'}_genModalEnd(){return"
"}_genListStart(){return'
'}_genListEnd(){return"
"}_genListItem(e,s){return'\n
\n
\n
\n
'+e+'
\n
\n
\n
'+s+"
\n
"}_genAssetUrl(e){return this.assetUrl+e}_genIOSSafari(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button below.')+this._genListItem("2",'Select from the menu that pops up. You may need to scroll down to find this menu item.')+this._genListItem("3",'Open the app.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-safari")}_genIOSChrome(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button in the upper right corner.')+this._genListItem("2",'Select from the menu that pops up. You may need to scroll down to find this menu item.')+this._genListItem("3",'Open the app.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-chrome")}_genIOSInAppBrowserOpenInSystemBrowser(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button above.')+this._genListItem("2",'Tap Open in browser .')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-inappbrowser-openinsystembrowser")}_genIOSInAppBrowserOpenInSafariBrowser(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button below to open your system browser.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-ios"),e.classList.add("adhs-inappbrowser-openinsafari")}_genAndroidChrome(e){var s=this._genLogo()+this._genModalStart()+this._genTitle()+this._genListStart()+this._genListItem("1",'Tap the button in the browser bar.')+this._genListItem("2",'Tap or .')+this._genListItem("3",'Open the app.')+this._genListEnd()+this._genModalEnd()+'
\n arrow\n
';e.innerHTML=s,e.classList.add("adhs-android"),e.classList.add("adhs-chrome")}_registerCloseListener(){if(this.allowUserToCloseModal){var e=this;this.closeEventListener=function(s){document.getElementsByClassName("adhs-container")[0].getElementsByClassName("adhs-modal")[0].contains(s.target)||e.close()},window.addEventListener("touchstart",this.closeEventListener),window.addEventListener("click",this.closeEventListener)}}clearModalDisplayCount(){this._isEnabledModalDisplayCount()&&window.localStorage.removeItem("adhs-modal-display-count")}_isEnabledModalDisplayCount(){return"number"==typeof this.maxModalDisplayCount&&this.maxModalDisplayCount>=0&&window.localStorage}_hasReachedMaxModalDisplayCount(){return!!this._isEnabledModalDisplayCount()&&this._getModalDisplayCount()>=this.maxModalDisplayCount}_incrModalDisplayCount(){if(!this._isEnabledModalDisplayCount())return!1;var e=this._getModalDisplayCount();return e++,window.localStorage.setItem("adhs-modal-display-count",e),!0}_getModalDisplayCount(){var e=window.localStorage.getItem("adhs-modal-display-count");return null===e?(e=0,window.localStorage.setItem("adhs-modal-display-count",e)):e=parseInt(e),e}static copyToClipboard(){const e=window.location.href;try{window.navigator.clipboard.writeText(e),document.getElementsByClassName("adhs-error-copy-link-button")[0].innerHTML="Link Copied to Clipboard!"}catch(e){document.getElementsByClassName("adhs-error-copy-link-button")[0].innerHTML='Failed to Copy to Clipboard! (Try Again from "https://" Link)'}}}e.ReturnObj=class{constructor({isStandAlone:e,canBeStandAlone:s,device:t}){this.isStandAlone=e,this.canBeStandAlone=s,this.device=t}};const s=e;window.AddToHomeScreen=s,window.AddToHomescreen={}.default})(); \ No newline at end of file diff --git a/src/index.js b/src/index.js index 4f4d48a..a0f9b89 100644 --- a/src/index.js +++ b/src/index.js @@ -171,8 +171,9 @@ class AddToHomeScreen { show() { var ret; - + var shouldShowModal = false; if (this.isStandAlone()) { + shouldShowModal = false; ret = new AddToHomeScreen.ReturnObj( { isStandAlone: true, @@ -182,6 +183,7 @@ class AddToHomeScreen { ); return ret; } else if (this._hasReachedMaxModalDisplayCount()) { + shouldShowModal = false; ret = new AddToHomeScreen.ReturnObj( { isStandAlone: null, @@ -190,7 +192,8 @@ class AddToHomeScreen { } ); return ret; - } else { + } else { + shouldShowModal = true; this._incrModalDisplayCount(); const container = document.createElement('div'); container.classList.add('adhs-container'); @@ -258,6 +261,8 @@ class AddToHomeScreen { `Please open this website with the Safari or Chrome app.`, `Adding to home screen is only supported in Safari or Chrome on IOS.` ); + } else { + shouldShowModal = false; } } } else if (this.isDeviceAndroid()) { // android @@ -293,6 +298,8 @@ class AddToHomeScreen { `Please open this website with the Chrome app.`, `Adding to home screen is only supported in Chrome on Android.` ); + } else { + shouldShowModal = false; } } } else { // desktop @@ -309,14 +316,18 @@ class AddToHomeScreen { `Please open this website on a mobile device.`, `Installing to your home screen is currently only supported on IOS and Android.` ); + } else { + shouldShowModal = false; } } - document.body.appendChild(container); - this._registerCloseListener(); - setTimeout(() => { - container.classList.add('visible'); - }, 50); + if (shouldShowModal) { + document.body.appendChild(container); + this._registerCloseListener(); + setTimeout(() => { + container.classList.add('visible'); + }, 50); + } } return ret;