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