From da7135bccc4ddf36c2e4e14c7ee247359e0a42a6 Mon Sep 17 00:00:00 2001 From: Dan Panzarella Date: Sat, 1 Dec 2012 10:16:58 -0500 Subject: [PATCH 1/2] Added globalStorage for older FF userData for IE7- --- aware.js | 64 ++++++++++++++++++++++++++++++++++++++++++------------- demo.html | 23 +++++++++++--------- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/aware.js b/aware.js index f81630b..1c31ef0 100644 --- a/aware.js +++ b/aware.js @@ -8,7 +8,9 @@ by Ben Brown ben@xoxco.com */ - var lastVisit = false; + var lastVisit = false, + setLastVisit, + getLastVisit; /* Helpful little date helper here! */ Date.prototype.getDOY = function() { @@ -16,24 +18,56 @@ return Math.ceil((this - onejan) / 86400000); } - function setLastVisit(date) { - if (window.localStorage) { - window.localStorage.setItem('lastVisit',date); - } else { - // fix this - // set a cookie - } + + /* Browser fallback stack from https://github.com/marcuswestin/store.js */ + function usesLocalStorage(){ + try { return !!('localStorage' in window && window.localStorage); } + catch(err){ return false } + } + function usesGlobalStorage(){ + try { return !!('globalStorage' in window && window.globalStorage); } + catch(err){ return false } } - - function getLastVisit() { - if (window.localStorage) { - return window.localStorage.getItem('lastVisit'); - } else { - // fix this - // return from cookie + if (usesLocalStorage()){ + setLastVisit = function(date) { window.localStorage.setItem('lastVisit',date); } + getLastVisit = function() { return window.localStorage.getItem('lastVisit'); } + } else if (usesGlobalStorage()){ + setLastVisit = function(date) { window.globalStorage[window.location.hostname]['lastVisit'] = date; } + getLastVisit = function(){ return window.globalStorage[window.location.hostname]['lastvisit']; } + } else if (window.document.documentElement.addBehavior){ + var storageContainer, + storageOwner, + elem; + try { + storageContainer = new ActiveXObject('htmlfile'); + storageContainer.open(); + storageContainer.write('document.w=window