diff --git a/media/js/zamboni/discovery.js b/media/js/zamboni/discovery.js index e928910115..25a435ed2f 100644 --- a/media/js/zamboni/discovery.js +++ b/media/js/zamboni/discovery.js @@ -8,7 +8,11 @@ $(document).ready(function(){ function storeBrowserInfo() { // Store the pane URL (with the browser version and platform) so we can // link back from the add-on detail pages. - localStorage.setItem("discopane-url", location); + if (hasLocalStorage) { + localStorage.setItem("discopane-url", location); + } else { + $.cookie("discopane-url", location, {path: "/"}); + } } @@ -40,7 +44,7 @@ function initRecs() { } }); } - if (!location.hash || !guids.length) { + if (hasLocalStorage && (!location.hash || !guids.length)) { // If the user has opted out of recommendations, clear out any // existing recommendations. localStorage.removeItem("discopane-recs"); @@ -88,13 +92,16 @@ function initRecs() { if (guids.length > MIN_ADDONS) { $("body").removeClass("no-recs").addClass("recs"); - var cacheObject = localStorage.getItem("discopane-recs"); - if (cacheObject) { - // Load local data. - cacheObject = JSON.parse(cacheObject); + var cacheObject; + if (hasLocalStorage) { + cacheObject = localStorage.getItem("discopane-recs"); if (cacheObject) { - datastore = cacheObject; - token = cacheObject.token; + // Load local data. + cacheObject = JSON.parse(cacheObject); + if (cacheObject) { + datastore = cacheObject; + token = cacheObject.token; + } } } @@ -102,7 +109,7 @@ function initRecs() { // if the user has new installed add-ons. var findRecs = !cacheObject; var updateRecs = ( - cacheObject && + cacheObject && hasLocalStorage && localStorage.getItem("discopane-guids") != guids.toString() ); if (findRecs || updateRecs) { @@ -130,14 +137,18 @@ function initRecs() { $("#recs .loading").remove(); datastore = JSON.parse(raw_data); populateRecs(); - localStorage.setItem("discopane-recs", raw_data); - localStorage.setItem("discopane-guids", guids); + if (hasLocalStorage) { + localStorage.setItem("discopane-recs", raw_data); + localStorage.setItem("discopane-guids", guids); + } }, error: function(raw_data) { $("#recs .loading").remove(); populateRecs(); - localStorage.setItem("discopane-recs", "{}"); - localStorage.setItem("discopane-guids", guids); + if (hasLocalStorage) { + localStorage.setItem("discopane-recs", "{}"); + localStorage.setItem("discopane-guids", guids); + } } }); } else { diff --git a/media/js/zamboni/discovery_pane.js b/media/js/zamboni/discovery_pane.js index 14cc790d67..0895325a57 100644 --- a/media/js/zamboni/discovery_pane.js +++ b/media/js/zamboni/discovery_pane.js @@ -194,12 +194,21 @@ function css(el, prop) { })(jQuery); +var hasLocalStorage = ("localStorage" in window) && window["localStorage"] !== null; + + $(document).ready(function(){ if ($(".detail").length) { $(".install-action a").attr("target", "_self"); // Replace with the URL back to the discovery promo pane. - $("p#back a").attr("href", localStorage.getItem("discopane-url")); + var pane_url; + if (hasLocalStorage) { + pane_url = localStorage.getItem("discopane-url"); + } else { + pane_url = $.cookie("discopane-url"); + } + $("p#back a").attr("href", pane_url); $("#images").fadeIn("slow").addClass("js").jCarouselLite({ btnNext: "#images .nav-next a", diff --git a/settings.py b/settings.py index 33fc9026cf..c8dc2318b5 100644 --- a/settings.py +++ b/settings.py @@ -447,20 +447,19 @@ MINIFY_BUNDLES = { 'js/zamboni/personas.js', 'js/zamboni/truncation.js', + 'js/jquery.cookie.js', 'js/zamboni/discovery_pane.js', 'js/zamboni/discovery.js', ), 'zamboni/discovery-addons': ( 'js/zamboni/jquery-1.4.2.min.js', 'js/zamboni/jquery-ui/custom-1.8.5.min.js', - 'js/zamboni/underscore-min.js', 'js/zamboni/browser.js', - 'js/amo2009/addons.js', 'js/zamboni/init.js', 'js/zamboni/format.js', - 'js/zamboni/buttons.js', # Add-ons details page + 'js/zamboni/buttons.js', 'js/jquery-ui/ui.lightbox.js', # Personas