Created
July 29, 2016 21:52
-
-
Save mr-feek/9be688441b7ae73d60c19fd1eda66c75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Feek on 7/29/16. | |
*/ | |
define([ | |
'backbone', | |
'marionette' | |
], function ( | |
Backbone, | |
Marionette | |
) { | |
var StorageHelper = Marionette.Object.extend({ | |
storageAvailable: null, | |
initialize: function(options) { | |
this.storageAvailable = this.checkIfStorageIsAvailable(); | |
}, | |
/** | |
* determine whether or not we have access to storage on this device | |
* @returns {boolean} | |
*/ | |
checkIfStorageIsAvailable: function () { | |
try { | |
var storage = window['sessionStorage'], | |
x = '__storage_test__'; | |
storage.setItem(x, x); | |
storage.removeItem(x); | |
return true; | |
} | |
catch (e) { | |
return false; | |
} | |
}, | |
getItem: function (key) { | |
if (this.storageAvailable) { | |
return window.sessionStorage.getItem(key); | |
} | |
}, | |
setItem: function(key, value) { | |
if (this.storageAvailable) { | |
return window.sessionStorage.setItem(key, value); | |
} | |
} | |
}); | |
return StorageHelper; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment