Skip to content

Commit 79b4bb1

Browse files
committed
- Removed store.js requirement for viewing site.
- Added message in Favorites to mention that it required for them. - Updated settings to use an object cache if store is not available.
1 parent db42016 commit 79b4bb1

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

js/Settings.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SOFTWARE.
2525
"use strict";
2626

2727
var s = {};
28+
s._values = {};
2829

2930
createjs.EventDispatcher.initialize(s);
3031

@@ -33,7 +34,7 @@ SOFTWARE.
3334
};
3435

3536
s.getRating = function(id) {
36-
return store.get("r"+id) || 0;
37+
return s._geValue("r"+id) || 0;
3738
};
3839

3940
s.setFavorite = function(id, value) {
@@ -46,7 +47,7 @@ SOFTWARE.
4647
};
4748

4849
s.getFavorite = function(id) {
49-
return store.get("f"+id) == 1?true:false;
50+
return s._geValue("f"+id) == 1?true:false;
5051
};
5152

5253
s.getAllFavorites = function() {
@@ -70,7 +71,7 @@ SOFTWARE.
7071
};
7172

7273
s.getUpdateToken = function(patternID) {
73-
return store.get("s"+patternID);
74+
return s._geValue("s"+patternID);
7475
};
7576

7677
s.cleanSaveTokens = function() {
@@ -85,19 +86,31 @@ SOFTWARE.
8586
};
8687

8788
s.trackVisit = function() {
88-
var visitCount = store.get("v") || 0;
89+
var visitCount = s._geValue("v") || 0;
8990
s._saveValue("v", ++visitCount);
9091
};
9192

9293
s.getVisitCount = function() {
93-
return store.get("v") || 0;
94+
return s._geValue("v") || 0;
9495
};
9596

9697
s._saveValue = function(key, value) {
97-
store.set(key, value);
98+
if (store.enabled) {
99+
store.set(key, value);
100+
} else {
101+
s._values[key] = value;
102+
}
98103
s.dispatchEvent(new DataEvent("change", {type:key, value:value}));
99104
};
100105

106+
s._geValue = function(id) {
107+
if (store.enabled) {
108+
return store.get(id);
109+
} else {
110+
return s._values[id];
111+
}
112+
};
113+
101114
scope.Settings = s;
102115

103116
}(window));

js/utils/Utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Utils.populateSelector = function (selector, items) {
183183

184184
Utils.isSupported = function() {
185185
// This should catch all the not supported browsers.
186-
return $.isCanvasSupported() && $.isCalcSupported() && store.enabled;
186+
return $.isCanvasSupported() && $.isCalcSupported();
187187
};
188188

189189
Utils.partialSupport = function() {

js/views/Favorites.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ SOFTWARE.
9595

9696
Settings.addEventListener("change", this._settingsChangeProxy);
9797

98+
if (!store.enabled) {
99+
$.addClass(this.favoriteBtn, "hidden");
100+
}
101+
98102
this.createRating();
99103
this.search();
100104
this.onListChange();
@@ -169,7 +173,19 @@ SOFTWARE.
169173
p.handleFavoritesLoad = function(data) {
170174
if (!this._visible) { return; }
171175

172-
if (data && data.results) {
176+
if (!store.enabled) {
177+
var promotionData = {
178+
content: "Favorites requires local storage to be enabled.",
179+
description: "Your local storage may be disabled due to security restrictions, or could simply be disabled. Check your browsers settings to find out.",
180+
id: "-1",
181+
name: "Local storage is not available",
182+
pattern: "/(Favo)u?(rite)(s?)/ig",
183+
replace: "$1$2$3",
184+
weightedVote: "0",
185+
author:"gskinner.com"
186+
};
187+
this.list.setData([promotionData]);
188+
} else if (data && data.results) {
173189
this.list.setData(data.results);
174190
} else {
175191
var promotionData = {

0 commit comments

Comments
 (0)