Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Should fix issue #20

  • Loading branch information...
commit 508e4799ca77217030eb5bf61e6ca456aceae451 1 parent e2cf5a8
@cubiq authored
Showing with 20 additions and 14 deletions.
  1. +1 −1  README.md
  2. +6 −4 examples/hash-trick/index.html
  3. +13 −9 src/add2home.js
View
2  README.md
@@ -3,7 +3,7 @@ Add to Home Screen Floating Layer
The script places a floating balloon to your mobile website inviting the user to add your app to the home screen. This is compatible with iPhone/4/iPod-touch and iPad, iOS >= 3.1.1.
-Version: 2.0 - [Official homepage](http://cubiq.org/add-to-home-screen) - [Video](http://vimeo.com/19090537)
+Version: 2.0.1 - [Official homepage](http://cubiq.org/add-to-home-screen) - [Video](http://vimeo.com/19090537)
## Usage
Include the script and the stylesheet in your page HEAD. That's all. Look at the examples for advanced features. Documentation on [cubiq.org](http://cubiq.org/add-to-home-screen).
View
10 examples/hash-trick/index.html
@@ -14,10 +14,15 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<script type="text/javascript">
-
var addToHomeConfig = {
autostart: false
};
+</script>
+
+ <link rel="stylesheet" href="../../style/add2home.css">
+ <script type="application/javascript" src="../../src/add2home.js" charset="utf-8"></script>
+
+<script type="text/javascript">
function loaded () {
if ( window.location.hash.match('ATHS') ) return;
@@ -29,9 +34,6 @@
window.addEventListener('load', loaded, false);
</script>
-
- <link rel="stylesheet" href="../../style/add2home.css">
- <script type="application/javascript" src="../../src/add2home.js" charset="utf-8"></script>
</head>
<body>
View
22 src/add2home.js
@@ -1,5 +1,5 @@
/*!
- * Add to Homescreen v2.0 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
+ * Add to Homescreen v2.0.1 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
* Released under MIT license, http://cubiq.org/license
*/
var addToHome = (function (w) {
@@ -12,6 +12,7 @@ var addToHome = (function (w) {
OSVersion,
startX = 0,
startY = 0,
+ lastVisit = 0,
isExpired,
isSessionActive,
isReturningVisitor,
@@ -39,7 +40,8 @@ var addToHome = (function (w) {
intl = {
ca_es: 'Per instal·lar aquesta aplicació al vostre %device premeu %icon i llavors <strong>Afegir a pantalla d\'inici</strong>.',
- da_dk: 'Tilføj denne side til din %device: tryk på %icon og derefter <strong>Tilføj til hjemmeskærm</strong>.',
+ cs_cz: 'Pro instalaci aplikace na Váš %device, stiskněte %icon a v nabídce <strong>Přidat na plochu</strong>.',
+ da_dk: 'Tilføj denne side til din %device: tryk på %icon og derefter <strong>Føj til hjemmeskærm</strong>.',
de_de: 'Installieren Sie diese App auf Ihrem %device: %icon antippen und dann <strong>Zum Home-Bildschirm</strong>.',
el_gr: 'Εγκαταστήσετε αυτήν την Εφαρμογή στήν συσκευή σας %device: %icon μετά πατάτε <strong>Προσθήκη σε Αφετηρία</strong>.',
en_us: 'Install this web app on your %device: tap %icon and then <strong>Add to Home Screen</strong>.',
@@ -87,12 +89,15 @@ var addToHome = (function (w) {
OSVersion = nav.appVersion.match(/OS (\d+_\d+)/i);
OSVersion = OSVersion[1] ? +OSVersion[1].replace('_', '.') : 0;
- isExpired = +w.localStorage.getItem('addToHome') || now;
+ lastVisit = +w.localStorage.getItem('addToHome');
+
isSessionActive = w.sessionStorage.getItem('addToHomeSession');
- isReturningVisitor = !options.returningVisitor || ( isExpired && isExpired + 28*24*60*60*1000 > now ); // You are considered a "returning visitor" if you access the site more than once/month
+ isReturningVisitor = options.returningVisitor ? lastVisit && lastVisit + 28*24*60*60*1000 > now : true;
+
+ if ( !lastVisit ) lastVisit = now;
// If it is expired we need to reissue a new balloon
- isExpired = ( !options.expire || isExpired <= now );
+ isExpired = isReturningVisitor && lastVisit <= now;
if ( options.hookOnLoad ) w.addEventListener('load', loaded, false);
else if ( !options.hookOnLoad && options.autostart ) loaded();
@@ -101,11 +106,10 @@ var addToHome = (function (w) {
function loaded () {
w.removeEventListener('load', loaded, false);
- if ( !overrideChecks && (!isSafari || !isExpired || isSessionActive || isStandalone || !isReturningVisitor) ) return;
+ if ( !isReturningVisitor ) w.localStorage.setItem('addToHome', Date.now());
+ else if ( options.expire && isExpired ) w.localStorage.setItem('addToHome', Date.now() + options.expire * 60000);
- if ( options.expire || options.returningVisitor ) {
- w.localStorage.setItem('addToHome', Date.now() + options.expire * 60000);
- }
+ if ( !overrideChecks && ( !isSafari || !isExpired || isSessionActive || isStandalone || !isReturningVisitor ) ) return;
var icons = options.touchIcon ? document.querySelectorAll('head link[rel=apple-touch-icon],head link[rel=apple-touch-icon-precomposed]') : [],
sizes,
Please sign in to comment.
Something went wrong with that request. Please try again.