Allow reverting back to the initial textarea (fixes #142)

pull/239/head
trwired 8 years ago
parent b6bee016c2
commit fd8e6a7825

@ -297,6 +297,16 @@ simplemde.codemirror.on("change", function(){
}); });
``` ```
## Removing SimpleMDE from textarea
You can revert to the initial textarea by calling the `toTextArea` method. Note that this clears up the autosave (if enabled) associated with it. The textarea will retain any text from the destroyed SimpleMDE instance.
```JavaScript
var simplemde = new SimpleMDE();
...
simplemde.toTextArea();
simplemde = null;
```
## Useful methods ## Useful methods
The following self-explanatory methods may be of use while developing with SimpleMDE. The following self-explanatory methods may be of use while developing with SimpleMDE.

File diff suppressed because one or more lines are too long

@ -1176,17 +1176,19 @@ SimpleMDE.prototype.render = function(el) {
placeholder: options.placeholder || el.getAttribute("placeholder") || "" placeholder: options.placeholder || el.getAttribute("placeholder") || ""
}); });
this.gui = {};
if(options.toolbar !== false) { if(options.toolbar !== false) {
this.createToolbar(); this.gui.toolbar = this.createToolbar();
} }
if(options.status !== false) { if(options.status !== false) {
this.createStatusbar(); this.gui.statusbar = this.createStatusbar();
} }
if(options.autosave != undefined && options.autosave.enabled === true) { if(options.autosave != undefined && options.autosave.enabled === true) {
this.autosave(); this.autosave();
} }
this.createSideBySide(); this.gui.sideBySide = this.createSideBySide();
this._rendered = this.element; this._rendered = this.element;
}; };
@ -1236,7 +1238,7 @@ SimpleMDE.prototype.autosave = function() {
el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd; el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd;
} }
setTimeout(function() { this.autosaveTimeoutId = setTimeout(function() {
simplemde.autosave(); simplemde.autosave();
}, this.options.autosave.delay || 10000); }, this.options.autosave.delay || 10000);
} else { } else {
@ -1295,7 +1297,7 @@ SimpleMDE.prototype.createSideBySide = function() {
var move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio; var move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
cm.scrollTo(0, move); cm.scrollTo(0, move);
}; };
return true; return preview;
}; };
SimpleMDE.prototype.createToolbar = function(items) { SimpleMDE.prototype.createToolbar = function(items) {
@ -1648,4 +1650,21 @@ SimpleMDE.prototype.getState = function() {
return getState(cm); return getState(cm);
}; };
SimpleMDE.prototype.toTextArea = function() {
var cm = this.codemirror;
var wrapper = cm.getWrapperElement();
wrapper.parentNode.removeChild(this.gui.toolbar);
wrapper.parentNode.removeChild(this.gui.statusbar);
wrapper.parentNode.removeChild(this.gui.sideBySide);
cm.toTextArea();
if(this.autosaveTimeoutId) {
clearTimeout(this.autosaveTimeoutId);
this.autosaveTimeoutId = undefined;
this.clearAutosavedValue();
}
};
module.exports = SimpleMDE; module.exports = SimpleMDE;

Loading…
Cancel
Save