diff --git a/README.md b/README.md index d1922e6..7306159 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ simplemde.value("This text will appear in the editor"); - **autosave**: *Saves the text that's being written and will load it back in the future. It will forget the text when the form it's contained in is submitted.* - **enabled**: If set to `true`, autosave the text. Defaults to `false`. - **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s). - - **unique_id**: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website. + - **uniqueId**: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website. - **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page. - **hideIcons**: An array of icon names to hide. Can be used to hide specific icons without completely customizing the toolbar. - **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`. @@ -103,7 +103,7 @@ var simplemde = new SimpleMDE({ autofocus: true, autosave: { enabled: true, - unique_id: "MyUniqueID", + uniqueId: "MyUniqueID", delay: 1000, }, element: document.getElementById("MyID"), diff --git a/src/js/simplemde.js b/src/js/simplemde.js index c473c02..3e04956 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -861,6 +861,11 @@ function SimpleMDE(options) { options.insertTexts = extend({}, insertTexts, options.insertTexts || {}); + // Change unique_id to uniqueId for backwards compatibility + if(options.autosave.unique_id != undefined && options.autosave.unique_id != "") + options.autosave.uniqueId = options.autosave.unique_id; + + // Update this options this.options = options; @@ -996,26 +1001,26 @@ SimpleMDE.prototype.render = function(el) { SimpleMDE.prototype.autosave = function() { var simplemde = this; - if(this.options.autosave.unique_id == undefined || this.options.autosave.unique_id == "") { - console.log("SimpleMDE: You must set a unique_id to use the autosave feature"); + if(this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") { + console.log("SimpleMDE: You must set a uniqueId to use the autosave feature"); return; } if(simplemde.element.form != null && simplemde.element.form != undefined) { simplemde.element.form.addEventListener("submit", function() { - localStorage.setItem(simplemde.options.autosave.unique_id, ""); + localStorage.setItem(simplemde.options.autosave.uniqueId, ""); }); } if(this.options.autosave.loaded !== true) { - if(typeof localStorage.getItem(this.options.autosave.unique_id) == "string" && localStorage.getItem(this.options.autosave.unique_id) != "") - this.codemirror.setValue(localStorage.getItem(this.options.autosave.unique_id)); + if(typeof localStorage.getItem(this.options.autosave.uniqueId) == "string" && localStorage.getItem(this.options.autosave.uniqueId) != "") + this.codemirror.setValue(localStorage.getItem(this.options.autosave.uniqueId)); this.options.autosave.loaded = true; } if(localStorage) { - localStorage.setItem(this.options.autosave.unique_id, simplemde.value()); + localStorage.setItem(this.options.autosave.uniqueId, simplemde.value()); } var el = document.getElementById("autosaved");