mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2024-06-16 12:45:54 +02:00
Better localStorage detection
This commit is contained in:
parent
d77d4b318b
commit
26391efa26
|
@ -1510,8 +1510,24 @@ SimpleMDE.prototype.render = function(el) {
|
||||||
this._rendered = this.element;
|
this._rendered = this.element;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem throw QuotaExceededError. We're going to detect this and set a variable accordingly.
|
||||||
|
function isLocalStorageAvailable() {
|
||||||
|
if(typeof localStorage === "object") {
|
||||||
|
try {
|
||||||
|
localStorage.setItem("smde_localStorage", 1);
|
||||||
|
localStorage.removeItem("smde_localStorage");
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
SimpleMDE.prototype.autosave = function() {
|
SimpleMDE.prototype.autosave = function() {
|
||||||
if(localStorage) {
|
if(isLocalStorageAvailable()) {
|
||||||
var simplemde = this;
|
var simplemde = this;
|
||||||
|
|
||||||
if(this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
|
if(this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
|
||||||
|
@ -1564,7 +1580,7 @@ SimpleMDE.prototype.autosave = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
SimpleMDE.prototype.clearAutosavedValue = function() {
|
SimpleMDE.prototype.clearAutosavedValue = function() {
|
||||||
if(localStorage) {
|
if(isLocalStorageAvailable()) {
|
||||||
if(this.options.autosave == undefined || this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
|
if(this.options.autosave == undefined || this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
|
||||||
console.log("SimpleMDE: You must set a uniqueId to clear the autosave value");
|
console.log("SimpleMDE: You must set a uniqueId to clear the autosave value");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue