mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2024-05-17 21:26:38 +02:00
Allow reverting back to the initial textarea (fixes #142)
This commit is contained in:
parent
b6bee016c2
commit
fd8e6a7825
10
README.md
10
README.md
|
@ -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
|
||||
The following self-explanatory methods may be of use while developing with SimpleMDE.
|
||||
|
||||
|
|
16
dist/simplemde.min.js
vendored
16
dist/simplemde.min.js
vendored
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") || ""
|
||||
});
|
||||
|
||||
this.gui = {};
|
||||
|
||||
if(options.toolbar !== false) {
|
||||
this.createToolbar();
|
||||
this.gui.toolbar = this.createToolbar();
|
||||
}
|
||||
if(options.status !== false) {
|
||||
this.createStatusbar();
|
||||
this.gui.statusbar = this.createStatusbar();
|
||||
}
|
||||
if(options.autosave != undefined && options.autosave.enabled === true) {
|
||||
this.autosave();
|
||||
}
|
||||
|
||||
this.createSideBySide();
|
||||
this.gui.sideBySide = this.createSideBySide();
|
||||
|
||||
this._rendered = this.element;
|
||||
};
|
||||
|
@ -1236,7 +1238,7 @@ SimpleMDE.prototype.autosave = function() {
|
|||
el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd;
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
this.autosaveTimeoutId = setTimeout(function() {
|
||||
simplemde.autosave();
|
||||
}, this.options.autosave.delay || 10000);
|
||||
} else {
|
||||
|
@ -1295,7 +1297,7 @@ SimpleMDE.prototype.createSideBySide = function() {
|
|||
var move = (cm.getScrollInfo().height - cm.getScrollInfo().clientHeight) * ratio;
|
||||
cm.scrollTo(0, move);
|
||||
};
|
||||
return true;
|
||||
return preview;
|
||||
};
|
||||
|
||||
SimpleMDE.prototype.createToolbar = function(items) {
|
||||
|
@ -1648,4 +1650,21 @@ SimpleMDE.prototype.getState = function() {
|
|||
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;
|
||||
|
|
Loading…
Reference in a new issue