diff --git a/dist/add-to-homescreen.min.js b/dist/add-to-homescreen.min.js index b5024d0..6726fd2 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),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)}}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{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 diff --git a/dist/index.html b/dist/index.html index 147a293..d09ac2c 100644 --- a/dist/index.html +++ b/dist/index.html @@ -254,7 +254,7 @@ appIconUrl: './dist/assets/sample/img/aardvark-logo.png', // url of your web app icon assetUrl: './dist/assets/img/', // make sure library assets in ./dist/assets/img are web-available showErrorMessageForUnsupportedBrowsers: true, - allowUserToCloseModal: false, + allowUserToCloseModal: true, maxModalDisplayCount: -1 }); window.AddToHomeScreenInstance.show(); // only shown if web app is not already added to homescreen diff --git a/index.html b/index.html index 5717004..077a2a2 100644 --- a/index.html +++ b/index.html @@ -506,7 +506,7 @@ appIconUrl: './dist/assets/sample/img/aardvark-logo.png', // url of your web app icon assetUrl: './dist/assets/img/', // make sure library assets in ./dist/assets/img are web-available showErrorMessageForUnsupportedBrowsers: true, - allowUserToCloseModal: false, + allowUserToCloseModal: true, maxModalDisplayCount: -1 }); window.AddToHomeScreenInstance.show(); // only shown if web app is not already added to homescreen diff --git a/src/index.js b/src/index.js index 704145c..4f4d48a 100644 --- a/src/index.js +++ b/src/index.js @@ -332,6 +332,7 @@ class AddToHomeScreen { container.remove(); if (this.closeEventListener) { window.removeEventListener('touchstart', this.closeEventListener); + window.removeEventListener('click', this.closeEventListener); this.closeEventListener = null; } }, 300); @@ -506,6 +507,7 @@ class AddToHomeScreen { }; }; window.addEventListener('touchstart', this.closeEventListener); + window.addEventListener('click', this.closeEventListener); } }