From ae624852e0ed3833acba0c00248a08bbd585d559 Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Fri, 26 Jun 2015 16:04:14 -0500 Subject: [PATCH] Now there's a note in the status bar for autosaves --- README.md | 4 ++-- source files/markdownify.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4fc4fa9..c933f7b 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/source files/markdownify.js b/source files/markdownify.js index 90e2184..e991115 100644 --- a/source files/markdownify.js +++ b/source files/markdownify.js @@ -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;