PageSourceSearch

https://terrafermata.com/assets/global/js/add2home.js

js terrafermata.com collected 2026-09-26 13:35:46 UTC 14,582 bytes, 344 lines download raw bytes

1/*!
2 * Add to Homescreen v2.0.11 ~ Copyright (c) 2013 Matteo Spinelli, http://cubiq.org
3 * Released under MIT license, http://cubiq.org/license
4 */
5var addToHome = (function (w) {
6	var nav = w.navigator,
7		isIDevice = 'platform' in nav && (/iphone|ipod|ipad/gi).test(nav.platform),
8		isIPad,
9		isRetina,
10		isSafari,
11		isStandalone,
12		OSVersion,
13		startX = 0,
14		startY = 0,
15		lastVisit = 0,
16		isExpired,
17		isSessionActive,
18		isReturningVisitor,
19		balloon,
20		overrideChecks,
21
22		positionInterval,
23		closeTimeout,
24
25		options = {
26			autostart: true,			// Automatically open the balloon
27			returningVisitor: false,	// Show the balloon to returning visitors only (setting this to true is highly recommended)
28			animationIn: 'drop',		// drop || bubble || fade
29			animationOut: 'fade',		// drop || bubble || fade
30			startDelay: 2000,			// 2 seconds from page load before the balloon appears
31			lifespan: 7000,			    // 15 seconds before it is automatically destroyed
32			bottomOffset: 14,			// Distance of the balloon from bottom
33			expire: 5,					// Minutes to wait before showing the popup again (0 = always displayed)
34			message: '',				// Customize your message or force a language ('' = automatic)
35			touchIcon: true,			// Display the touch icon
36			arrow: true,				// Display the balloon arrow
37			hookOnLoad: true,			// Should we hook to onload event? (really advanced usage)
38			closeButton: true,			// Let the user close the balloon
39			iterations: 100				// Internal/debug use
40		},
41
42		intl = {
43			ar:    '<span dir="rtl">قم بتثبيت هذا التطبيق على <span dir="ltr">%device:</span>انقر<span dir="ltr">%icon</span> ،<strong>ثم اضفه الى الشاشة الرئيسية.</strong></span>',
44			ca_es: 'Per instal·lar aquesta aplicació al vostre %device premeu %icon i llavors <strong>Afegir a pantalla d\'inici</strong>.',
45			cs_cz: 'Pro instalaci aplikace na Váš %device, stiskněte %icon a v nabídce <strong>Přidat na plochu</strong>.',
46			da_dk: 'Tilføj denne side til din %device: tryk på %icon og derefter <strong>Føj til hjemmeskærm</strong>.',
47			de_de: 'Installieren Sie diese App auf Ihrem %device: %icon antippen und dann <strong>Zum Home-Bildschirm</strong>.',
48			el_gr: 'Εγκαταστήσετε αυτήν την Εφαρμογή στήν συσκευή σας %device: %icon μετά πατάτε <strong>Προσθήκη σε Αφετηρία</strong>.',
49			en_us: 'Install this web app on your %device: tap %icon and then <strong>Add to Home Screen</strong>.',
50			es_es: 'Para instalar esta app en su %device, pulse %icon y seleccione <strong>Añadir a pantalla de inicio</strong>.',
51			fi_fi: 'Asenna tämä web-sovellus laitteeseesi %device: paina %icon ja sen jälkeen valitse <strong>Lisää Koti-valikkoon</strong>.',
52			fr_fr: 'Ajoutez cette application sur votre %device en cliquant sur %icon, puis <strong>Ajouter à l\'écran d\'accueil</strong>.',
53			he_il: '<span dir="rtl">התקן אפליקציה זו על ה-%device שלך: הקש %icon ואז <strong>הוסף למסך הבית</strong>.</span>',
54			hr_hr: 'Instaliraj ovu aplikaciju na svoj %device: klikni na %icon i odaberi <strong>Dodaj u početni zaslon</strong>.',
55			hu_hu: 'Telepítse ezt a web-alkalmazást az Ön %device-jára: nyomjon a %icon-ra majd a <strong>Főképernyőhöz adás</strong> gombra.',
56			it_it: 'Installa questa applicazione sul tuo %device: premi su %icon e poi <strong>Aggiungi a Home</strong>.',
57			ja_jp: 'このウェブアプリをあなたの%deviceにインストールするには%iconをタップして<strong>ホーム画面に追加</strong>を選んでください。',
58			ko_kr: '%device에 웹앱을 설치하려면 %icon을 터치 후 "홈화면에 추가"를 선택하세요',
59			nb_no: 'Installer denne appen på din %device: trykk på %icon og deretter <strong>Legg til på Hjem-skjerm</strong>',
60			nl_nl: 'Installeer deze webapp op uw %device: tik %icon en dan <strong>Voeg toe aan beginscherm</strong>.',
61			pl_pl: 'Aby zainstalować tę aplikacje na %device: naciśnij %icon a następnie <strong>Dodaj jako ikonę</strong>.',
62			pt_br: 'Instale este aplicativo em seu %device: aperte %icon e selecione <strong>Adicionar à Tela Inicio</strong>.',
63			pt_pt: 'Para instalar esta aplicação no seu %device, prima o %icon e depois em <strong>Adicionar ao ecrã principal</strong>.',
64			ru_ru: 'Установите это веб-приложение на ваш %device: нажмите %icon, затем <strong>Добавить в «Домой»</strong>.',
65			sv_se: 'Lägg till denna webbapplikation på din %device: tryck på %icon och därefter <strong>Lägg till på hemskärmen</strong>.',
66			th_th: 'ติดตั้งเว็บแอพฯ นี้บน %device ของคุณ: แตะ %icon และ <strong>เพิ่มที่หน้าจอโฮม</strong>',
67			tr_tr: 'Bu uygulamayı %device\'a eklemek için %icon simgesine sonrasında <strong>Ana Ekrana Ekle</strong> düğmesine basın.',
68			uk_ua: 'Встановіть цей веб сайт на Ваш %device: натисніть %icon, а потім <strong>На початковий екран</strong>.',
69			zh_cn: '您可以将此应用程式安装到您的 %device 上。请按 %icon 然后点选<strong>
69添加至主屏幕</strong>。',
70			zh_tw: '您可以將此應用程式安裝到您的 %device 上。請按 %icon 然後點選<strong>加入主畫面螢幕</strong>。'
71		};
72
73	function init () {
74		// Preliminary check, all further checks are performed on iDevices only
75		if ( !isIDevice ) return;
76
77		var now = Date.now(),
78			i;
79
80		// Merge local with global options
81		if ( w.addToHomeConfig ) {
82			for ( i in w.addToHomeConfig ) {
83				options[i] = w.addToHomeConfig[i];
84			}
85		}
86		if ( !options.autostart ) options.hookOnLoad = false;
87
88		isIPad = (/ipad/gi).test(nav.platform);
89		isRetina = w.devicePixelRatio && w.devicePixelRatio > 1;
90		isSafari = (/Safari/i).test(nav.appVersion) && !(/CriOS/i).test(nav.appVersion);
91		isStandalone = nav.standalone;
92		OSVersion = nav.appVersion.match(/OS (\d+_\d+)/i);
93		OSVersion = OSVersion && OSVersion[1] ? +OSVersion[1].replace('_', '.') : 0;
94
95		lastVisit = +w.localStorage.getItem('addToHome');
96
97		isSessionActive = w.sessionStorage.getItem('addToHomeSession');
98		isReturningVisitor = options.returningVisitor ? lastVisit && lastVisit + 28*24*60*60*1000 > now : true;
99
100		if ( !lastVisit ) lastVisit = now;
101
102		// If it is expired we need to reissue a new balloon
103		isExpired = isReturningVisitor && lastVisit <= now;
104
105		if ( options.hookOnLoad ) w.addEventListener('load', loaded, false);
106		else if ( !options.hookOnLoad && options.autostart ) loaded();
107	}
108
109	function loaded () {
110		w.removeEventListener('load', loaded, false);
111
112		if ( !isReturningVisitor ) w.localStorage.setItem('addToHome', Date.now());
113		else if ( options.expire && isExpired ) w.localStorage.setItem('addToHome', Date.now() + options.expire * 60000);
114
115		if ( !overrideChecks && ( !isSafari || !isExpired || isSessionActive || isStandalone || !isReturningVisitor ) ) return;
116
117		var touchIcon = '',
118			platform = nav.platform.split(' ')[0],
119			language = nav.language.replace('-', '_');
120
121		balloon = document.createElement('div');
122		balloon.id = 'addToHomeScreen';
123		balloon.style.cssText += 'left:-9999px;-webkit-transition-property:-webkit-transform,opacity;-webkit-transition-duration:0;-webkit-transform:translate3d(0,0,0);position:' + (OSVersion < 5 ? 'absolute' : 'fixed');
124
125		// Localize message
126		if ( options.message in intl ) {		// You may force a language despite the user's locale
127			language = options.message;
128			options.message = '';
129		}
130		if ( options.message === '' ) {			// We look for a suitable language (defaulted to en_us)
131			options.message = language in intl ? intl[language] : intl['en_us'];
132		}
133
134		if ( options.touchIcon ) {
135			touchIcon = isRetina ?
136				document.querySelector('head link[rel^=apple-touch-icon][sizes="114x114"],head link[rel^=apple-touch-icon][sizes="144x144"],head link[rel^=apple-touch-icon]') :
137				document.querySelector('head link[rel^=apple-touch-icon][sizes="57x57"],head link[rel^=apple-touch-icon]');
138
139			if ( touchIcon ) {
140				touchIcon = '<span style="background-image:url(' + touchIcon.href + ')" class="addToHomeTouchIcon"></span>';
141			}
142		}
143
144		balloon.className = (OSVersion >=7 ? 'addToHomeIOS7 ' : '') + (isIPad ? 'addToHomeIpad' : 'addToHomeIphone') + (touchIcon ? ' addToHomeWide' : '');
145		balloon.innerHTML = touchIcon +
146			options.message.replace('%device', platform).replace('%icon', OSVersion >= 4.2 ? '<span class="addToHomeShare"></span>' : '<span class="addToHomePlus">+</span>') +
147			(options.arrow ? '<span class="addToHomeArrow"' + (OSVersion >= 7 && isIPad && touchIcon ? ' style="margin-left:-32px"' : '') + '></span>' : '') +
148			(options.closeButton ? '<span class="addToHomeClose">\u00D7</span>' : '');
149
150		document.body.appendChild(balloon);
151
152		// Add the close action
153		if ( options.closeButton ) balloon.addEventListener('click', clicked, false);
154
155		if ( !isIPad && OSVersion >= 6 ) window.addEventListener('orientationchange', orientationCheck, false);
156
157		setTimeout(show, options.startDelay);
158	}
159
160	function show () {
161		var duration,
162			iPadXShift = 208;
163
164		// Set the initial position
165		if ( isIPad ) {
166			if ( OSVersion < 5 ) {
167				startY = w.scrollY;
168				startX = w.scrollX;
169			} else if ( OSVersion < 6 ) {
170				iPadXShift = 160;
171			} else if ( OSVersion >= 7 ) {
172				iPadXShift = 143;
173			}
174
175			balloon.style.top = startY + options.bottomOffset + 'px';
176			balloon.style.left = Math.max(startX + iPadXShift - Math.round(balloon.offsetWidth / 2), 9) + 'px';
177
178			switch ( options.animationIn ) {
179				case 'drop':
180					duration = '0.6s';
181					balloon.style.webkitTransform = 'translate3d(0,' + -(w.scrollY + options.bottomOffset + balloon.offsetHeight) + 'px,0)';
182					break;
183				case 'bubble':
184					duration = '0.6s';
185					balloon.style.opacity = '0';
186					balloon.style.webkitTransform = 'translate3d(0,' + (startY + 50) + 'px,0)';
187					break;
188				default:
189					duration = '1s';
190					balloon.style.opacity = '0';
191			}
192		} else {
193			startY = w.innerHeight + w.scrollY;
194
195			if ( OSVersion < 5 ) {
196				startX = Math.round((w.innerWidth - balloon.offsetWidth) / 2) + w.scrollX;
197				balloon.style.left = startX + 'px';
198				balloon.style.top = startY - balloon.offsetHeight - options.bottomOffset + 'px';
199			} else {
200				balloon.style.left = '50%';
201				balloon.style.marginLeft = -Math.round(balloon.offsetWidth / 2) - ( w.orientation%180 && OSVersion >= 6 && OSVersion < 7 ? 40 : 0 ) + 'px';
202				balloon.style.bottom = options.bottomOffset + 'px';
203			}
204
205			switch (options.animationIn) {
206				case 'drop':
207					duration = '1s';
208					balloon.style.webkitTransform = 'translate3d(0,' + -(startY + options.bottomOffset) + 'px,0)';
209					break;
210				case 'bubble':
211					duration = '0.6s';
212					balloon.style.webkitTransform = 'translate3d(0,' + (balloon.offsetHeight + options.bottomOffset + 50) + 'px,0)';
213					break;
214				default:
215					duration = '1s';
216					balloon.style.opacity = '0';
217			}
218		}
219
220		balloon.offsetHeight;	// repaint trick
221		balloon.style.webkitTransitionDuration = duration;
222		balloon.style.opacity = '1';
223		balloon.style.webkitTransform = 'translate3d(0,0,0)';
224		balloon.addEventListener('webkitTransitionEnd', transitionEnd, false);
225
226		closeTimeout = setTimeout(close, options.lifespan);
227	}
228
229	function manualShow (override) {
230		if ( !isIDevice || balloon ) return;
231
232		overrideChecks = override;
233		loaded();
234	}
235
236	function close () {
237		clearInterval( positionInterval );
238		clearTimeout( closeTimeout );
239		closeTimeout = null;
240
241		// check if the popup is displayed and prevent errors
242		if ( !balloon ) return;
243
244		var posY = 0,
245			posX = 0,
246			opacity = '1',
247			duration = '0';
248
249		if ( options.closeButton ) balloon.removeEventListener('click', clicked, false);
250		if ( !isIPad && OSVersion >= 6 ) window.removeEventListener('orientationchange', orientationCheck, false);
251
252		if ( OSVersion < 5 ) {
253			posY = isIPad ? w.scrollY - startY : w.scrollY + w.innerHeight - startY;
254			posX = isIPad ? w.scrollX - startX : w.scrollX + Math.round((w.innerWidth - balloon.offsetWidth)/2) - startX;
255		}
256
257		balloon.style.webkitTransitionProperty = '-webkit-transform,opacity';
258
259		switch ( options.animationOut ) {
260			case 'drop':
261				if ( isIPad ) {
262					duration = '0.4s';
263					opacity = '0';
264					posY += 50;
265				} else {
266					duration = '0.6s';
267					posY += balloon.offsetHeight + options.bottomOffset + 50;
268				}
269				break;
270			case 'bubble':
271				if ( isIPad ) {
272					duration = '0.8s';
273					posY -= balloon.offsetHeight + options.bottomOffset + 50;
274				} else {
275					duration = '0.4s';
276					opacity = '0';
277					posY -= 50;
278				}
279				break;
280			default:
281				duration = '0.8s';
282				opacity = '0';
283		}
284
285		balloon.addEventListener('webkitTransitionEnd', transitionEnd, false);
286		balloon.style.opacity = opacity;
287		balloon.style.webkitTransitionDuration = duration;
288		balloon.style.webkitTransform = 'translate3d(' + posX + 'px,' + posY + 'px,0)';
289	}
290
291
292	function clicked () {
293		w.sessionStorage.setItem('addToHomeSession', '1');
294		isSessionActive = true;
295		close();
296	}
297
298	function transitionEnd () {
299		balloon.removeEventListener('webkitTransitionEnd', transitionEnd, false);
300
301		balloon.style.webkitTransitionProperty = '-webkit-transform';
302		balloon.style.webkitTransitionDuration = '0.2s';
303
304		// We reached the end!
305		if ( !closeTimeout ) {
306			balloon.parentNode.removeChild(balloon);
307			balloon = null;
308			return;
309		}
310
311		// On iOS 4 we start checking the element position
312		if ( OSVersion < 5 && closeTimeout ) positionInterval = setInterval(setPosition, options.iterations);
313	}
314
315	function setPosition () {
316		var matrix = new WebKitCSSMatrix(w.getComputedStyle(balloon, null).webkitTransform),
317			posY = isIPad ? w.scrollY - startY : w.scrollY + w.innerHeight - startY,
318			posX = isIPad ? w.scrollX - startX : w.scrollX + Math.round((w.innerWidth - balloon.offsetWidth) / 2) - startX;
319
320		// Screen didn't move
321		if ( posY == matrix.m42 && posX == matrix.m41 ) return;
322
323		balloon.style.webkitTransform = 'translate3d(' + posX + 'px,' + posY + 'px,0)';
324	}
325
326	// Clear local and session storages (this is useful primarily in development)
327	function reset () {
328		w.localStorage.removeItem('addToHome');
329		w.sessionStorage.removeItem('addToHomeSession');
330	}
331
332	function orientationCheck () {
333		balloon.style.marginLeft = -Math.round(balloon.offsetWidth / 2) - ( w.orientation%180 && OSVersion >= 6 && OSVersion < 7 ? 40 : 0 ) + 'px';
334	}
335
336	// Bootstrap!
337	init();
338
339	return {
340		show: manualShow,
341		close: close,
342		reset: reset
343	};
344})(window);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.