mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-13 04:54:28 -06:00
Now there's a note in the status bar for autosaves
This commit is contained in:
parent
c347811e29
commit
ae624852e0
@ -53,7 +53,7 @@ simplemde.value();
|
|||||||
|
|
||||||
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
|
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
|
||||||
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
|
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
|
||||||
- Optionally, you can set an array of status bar elements to include.
|
- Optionally, you can set an array of status bar elements to include, and in what order.
|
||||||
- **toolbar**: If set to `false`, hide the toolbar. Defaults to `true`.
|
- **toolbar**: If set to `false`, hide the toolbar. Defaults to `true`.
|
||||||
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
|
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
|
||||||
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
|
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
|
||||||
@ -68,7 +68,7 @@ simplemde.value();
|
|||||||
var simplemde = new SimpleMDE({
|
var simplemde = new SimpleMDE({
|
||||||
element: document.getElementById("MyID"),
|
element: document.getElementById("MyID"),
|
||||||
status: false,
|
status: false,
|
||||||
status: ['lines', 'words', 'cursor'], // Optional usage
|
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
|
||||||
toolbar: false,
|
toolbar: false,
|
||||||
autofocus: true,
|
autofocus: true,
|
||||||
lineWrapping: false,
|
lineWrapping: false,
|
||||||
|
@ -452,7 +452,7 @@ function SimpleMDE(options) {
|
|||||||
// [{name: 'bold', shortcut: 'Ctrl-B', className: 'icon-bold'}]
|
// [{name: 'bold', shortcut: 'Ctrl-B', className: 'icon-bold'}]
|
||||||
|
|
||||||
if (!options.hasOwnProperty('status')) {
|
if (!options.hasOwnProperty('status')) {
|
||||||
options.status = ['lines', 'words', 'cursor'];
|
options.status = ['autosave', 'lines', 'words', 'cursor'];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -547,7 +547,6 @@ SimpleMDE.prototype.autosave = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(this.options.autosave.loaded !== true){
|
if(this.options.autosave.loaded !== true){
|
||||||
console.log(localStorage.getItem(this.options.autosave.unique_id));
|
|
||||||
this.codemirror.setValue(localStorage.getItem(this.options.autosave.unique_id));
|
this.codemirror.setValue(localStorage.getItem(this.options.autosave.unique_id));
|
||||||
this.options.autosave.loaded = true;
|
this.options.autosave.loaded = true;
|
||||||
}
|
}
|
||||||
@ -556,6 +555,25 @@ SimpleMDE.prototype.autosave = function() {
|
|||||||
localStorage.setItem(this.options.autosave.unique_id, content);
|
localStorage.setItem(this.options.autosave.unique_id, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var el = document.getElementById("autosaved");
|
||||||
|
if(el != null && el != undefined && el != ""){
|
||||||
|
var d = new Date();
|
||||||
|
var hh = d.getHours();
|
||||||
|
var m = d.getMinutes();
|
||||||
|
var dd = "am";
|
||||||
|
var h = hh;
|
||||||
|
if (h >= 12) {
|
||||||
|
h = hh-12;
|
||||||
|
dd = "pm";
|
||||||
|
}
|
||||||
|
if (h == 0) {
|
||||||
|
h = 12;
|
||||||
|
}
|
||||||
|
m = m<10?"0"+m:m;
|
||||||
|
|
||||||
|
el.innerHTML = "Autosaved: "+h+":"+m+" "+dd;
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
simplemde.autosave();
|
simplemde.autosave();
|
||||||
}, this.options.autosave.delay || 10000);
|
}, this.options.autosave.delay || 10000);
|
||||||
@ -626,6 +644,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
|
|||||||
|
|
||||||
SimpleMDE.prototype.createStatusbar = function(status) {
|
SimpleMDE.prototype.createStatusbar = function(status) {
|
||||||
status = status || this.options.status;
|
status = status || this.options.status;
|
||||||
|
options = this.options;
|
||||||
|
|
||||||
if (!status || status.length === 0) return;
|
if (!status || status.length === 0) return;
|
||||||
|
|
||||||
@ -653,10 +672,15 @@ SimpleMDE.prototype.createStatusbar = function(status) {
|
|||||||
pos = cm.getCursor();
|
pos = cm.getCursor();
|
||||||
el.innerHTML = pos.line + ':' + pos.ch;
|
el.innerHTML = pos.line + ':' + pos.ch;
|
||||||
});
|
});
|
||||||
|
} else if (name === 'autosave') {
|
||||||
|
if (options.autosave != undefined && options.autosave.enabled === true) {
|
||||||
|
el.setAttribute("id", "autosaved");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bar.appendChild(el);
|
bar.appendChild(el);
|
||||||
})(status[i]);
|
})(status[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmWrapper = this.codemirror.getWrapperElement();
|
var cmWrapper = this.codemirror.getWrapperElement();
|
||||||
cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
|
cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
|
||||||
return bar;
|
return bar;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user