asciiflow2/addtohomescreen.min.js

2 lines
12 KiB
JavaScript
Raw Normal View History

2014-05-24 09:51:01 +00:00
/* Add to Homescreen v3.0.6 ~ (c) 2014 Matteo Spinelli ~ @license: http://cubiq.org/license */
(function(window,document){var _DOMReady=false;if(document.readyState==="complete"){_DOMReady=true}else{window.addEventListener("load",loaded,false)}function loaded(){window.removeEventListener("load",loaded,false);_DOMReady=true}var _reSmartURL=/\/ath(\/)?$/;var _reQueryString=/([\?&]ath=[^&]*$|&ath=[^&]*(&))/;var _instance;function ath(options){_instance=_instance||new ath.Class(options);return _instance}ath.intl={de_de:{message:"Um diese Web-App zum Home-Bildschirm hinzuzufügen, tippen Sie auf %icon und dann <strong>%action</strong>.",action:{ios:"Zum Home-Bildschirm",android:"Zum Startbildschirm hinzufügen",windows:"Auf Startseite"}},en_us:{message:"To add this web app to the home screen: tap %icon and then <strong>%action</strong>.",action:{ios:"Add to Home Screen",android:"Add to homescreen",windows:"pin to start"}},es_es:{message:"Para añadir esta aplicación web a la pantalla de inicio: pulsa %icon y selecciona <strong>%action</strong>.",action:{ios:"Añadir a pantalla de inicio",android:"Añadir a pantalla de inicio",windows:"Añadir a inicio"}},it_it:{message:"Per Aggiungere questa web app alla schermata iniziale: premi %icon e poi <strong>%action</strong>.",action:{ios:"Aggiungi a Home",android:"Aggiungi alla homescreen",windows:"aggiungi a start"}},nl_nl:{message:"Om deze webapp op je telefoon te installeren, klik op %icon en dan <strong>%action</strong>.",action:{ios:"Voeg toe aan beginscherm",android:"Toevoegen aan startscherm",windows:"Aan startscherm vastmaken"}},zh_cn:{message:"如要把应用程式加至主屏幕,请点击%icon, 然后<strong>%action</strong>",action:{ios:"加至主屏幕",android:"加至主屏幕",windows:"按住启动"}},zh_tw:{message:"如要把應用程式加至主屏幕, 請點擊%icon, 然後<strong>%action</strong>.",action:{ios:"加至主屏幕",android:"加至主屏幕",windows:"按住啟動"}}};ath.defaults={appID:"org.cubiq.addtohome",fontSize:15,debug:false,modal:false,mandatory:false,autostart:true,skipFirstVisit:false,startDelay:1,lifespan:15,displayPace:1440,maxDisplayCount:0,icon:true,message:"",validLocation:[],onInit:null,onShow:null,onRemove:null,onAdd:null,onPrivate:null,detectHomescreen:false};var _ua=window.navigator.userAgent;var _nav=window.navigator;_extend(ath,{hasToken:document.location.hash=="#ath"||_reSmartURL.test(document.location.href)||_reQueryString.test(document.location.search),isRetina:window.devicePixelRatio&&window.devicePixelRatio>1,isIDevice:/iphone|ipod|ipad/i.test(_ua),isMobileChrome:_ua.indexOf("Android")>-1&&/Chrome\/[.0-9]*/.test(_ua),isMobileIE:_ua.indexOf("Windows Phone")>-1,language:_nav.language&&_nav.language.toLowerCase().replace("-","_")||""});if(ath.language.length==2){ath.language+="_"+ath.language}ath.language=ath.language&&ath.language in ath.intl?ath.language:"en_us";ath.isMobileSafari=ath.isIDevice&&_ua.indexOf("Safari")>-1&&_ua.indexOf("CriOS")<0;ath.OS=ath.isIDevice?"ios":ath.isMobileChrome?"android":ath.isMobileIE?"windows":"unsupported";ath.OSVersion=_ua.match(/(OS|Android) (\d+[_\.]\d+)/);ath.OSVersion=ath.OSVersion&&ath.OSVersion[2]?+ath.OSVersion[2].replace("_","."):0;ath.isStandalone=window.navigator.standalone||ath.isMobileChrome&&screen.height-document.documentElement.clientHeight<40;ath.isTablet=ath.isMobileSafari&&_ua.indexOf("iPad")>-1||ath.isMobileChrome&&_ua.indexOf("Mobile")<0;ath.isCompatible=ath.isMobileSafari&&ath.OSVersion>=6||ath.isMobileChrome;var _defaultSession={lastDisplayTime:0,returningVisitor:false,displayCount:0,optedout:false,added:false};ath.removeSession=function(appID){try{localStorage.removeItem(appID||ath.defaults.appID)}catch(e){}};ath.Class=function(options){this.options=_extend({},ath.defaults);_extend(this.options,options);this.options.mandatory=this.options.mandatory&&("standalone"in window.navigator||this.options.debug);this.options.modal=this.options.modal||this.options.mandatory;if(this.options.mandatory){this.options.startDelay=-.5}this.options.detectHomescreen=this.options.detectHomescreen===true?"hash":this.options.detectHomescreen;if(this.options.debug){ath.isCompatible=true;ath