Now there's a note in the status bar for autosaves

pull/9/head
Wes Cossick 9 years ago
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.
- **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`.
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
@ -68,7 +68,7 @@ simplemde.value();
var simplemde = new SimpleMDE({
element: document.getElementById("MyID"),
status: false,
status: ['lines', 'words', 'cursor'], // Optional usage
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
toolbar: false,
autofocus: true,
lineWrapping: false,

@ -452,7 +452,7 @@ function SimpleMDE(options) {
// [{name: 'bold', shortcut: 'Ctrl-B', className: 'icon-bold'}]
if (!options.hasOwnProperty('status')) {
options.status = ['lines', 'words', 'cursor'];
options.status = ['autosave', 'lines', 'words', 'cursor'];
}
this.options = options;
@ -547,7 +547,6 @@ SimpleMDE.prototype.autosave = function() {
}
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.options.autosave.loaded = true;
}
@ -556,6 +555,25 @@ SimpleMDE.prototype.autosave = function() {
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() {
simplemde.autosave();
}, this.options.autosave.delay || 10000);
@ -626,6 +644,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
SimpleMDE.prototype.createStatusbar = function(status) {
status = status || this.options.status;
options = this.options;
if (!status || status.length === 0) return;
@ -653,10 +672,15 @@ SimpleMDE.prototype.createStatusbar = function(status) {
pos = cm.getCursor();
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);
})(status[i]);
}
var cmWrapper = this.codemirror.getWrapperElement();
cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
return bar;

Loading…
Cancel
Save