Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3662 from stephaniehobson/1226283-localstorage-fe…
Browse files Browse the repository at this point in the history
…ature-test

Fix Bug 1226283: Local Storage feature test
  • Loading branch information
groovecoder committed Dec 2, 2015
2 parents 0fe11ed + a3a35ea commit 8468896
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kuma/static/js/auth.js
Expand Up @@ -144,7 +144,7 @@
Show notifications about account association status as part of the
registration process.
*/
if('localStorage' in win) (function() {
if(win.mdn.features.localStorage) (function() {
try {
var $browserRegister = $('#browser_register');
var matchKey = 'account-match-for';
Expand Down Expand Up @@ -186,7 +186,7 @@
/*
Fire off events when the user logs in and logs out.
*/
if('localStorage' in win) (function() {
if(win.mdn.features.localStorage) (function() {
var serviceKey = 'login-service';
var serviceStored = localStorage.getItem(serviceKey);
var serviceCurrent = $(doc.body).data(serviceKey);
Expand Down
2 changes: 1 addition & 1 deletion kuma/static/js/helpfulness.js
Expand Up @@ -3,7 +3,7 @@
var waitBeforeAsking = 60000;
var articleTracker = doc.location.pathname + '#answered-helpful';
// this feature requires localStorage
if (('localStorage' in win)) {
if (win.mdn.features.localStorage) {
var ignore = localStorage.getItem('helpful-ignore') === 'true'; // true if ever clicked ignore
var articleAskedRecently = parseInt(localStorage.getItem(articleTracker), 10) > Date.now();
var helpfulnessAskedRecently = parseInt(localStorage.getItem('helpfulnessTracker'), 10) > Date.now();
Expand Down
17 changes: 17 additions & 0 deletions kuma/static/js/main.js
Expand Up @@ -6,6 +6,23 @@
*/
mdn.analytics.trackClientErrors();

/*
Feature detection
*/

win.mdn.features.localStorage = (function() {
var uid = new Date;
var result;
try {
localStorage.setItem(uid, uid);
result = localStorage.getItem(uid) == uid;
localStorage.removeItem(uid);
return result;
} catch (exception) {
return false;
}
}());

/*
Submenus
- main and secondary navigation
Expand Down
2 changes: 1 addition & 1 deletion kuma/static/js/wiki-edit.js
Expand Up @@ -187,7 +187,7 @@
var DRAFT_NAME;
var DRAFT_TIMEOUT_ID;

var supportsLocalStorage = ('localStorage' in win);
var supportsLocalStorage = win.mdn.features.localStorage;
var $form = $('#wiki-page-edit');
var isTranslation;
var isTemplate;
Expand Down

0 comments on commit 8468896

Please sign in to comment.