2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-09-24 16:40:55 -06:00

Add label inside toolbar if option is present

This commit is contained in:
Tristan Pouliquen 2019-04-05 11:46:00 +02:00
parent 77038e4883
commit 7f07aa39ff

View File

@ -166,6 +166,13 @@ function createToolbarButton(options, enableTooltips, shortcuts) {
return el; return el;
} }
function createLabel(label) {
var el = document.createElement('label');
el.className = "editor-label";
el.innerHTML = label;
return el;
}
function createSep() { function createSep() {
var el = document.createElement('i'); var el = document.createElement('i');
el.className = 'separator'; el.className = 'separator';
@ -1674,22 +1681,22 @@ EasyMDE.prototype.autosave = function () {
console.log('EasyMDE: You must set a uniqueId to use the autosave feature'); console.log('EasyMDE: You must set a uniqueId to use the autosave feature');
return; return;
} }
if(this.options.autosave.binded !== true) { if(this.options.autosave.binded !== true) {
if (easyMDE.element.form != null && easyMDE.element.form != undefined) { if (easyMDE.element.form != null && easyMDE.element.form != undefined) {
easyMDE.element.form.addEventListener('submit', function () { easyMDE.element.form.addEventListener('submit', function () {
clearTimeout(easyMDE.autosaveTimeoutId); clearTimeout(easyMDE.autosaveTimeoutId);
easyMDE.autosaveTimeoutId = undefined; easyMDE.autosaveTimeoutId = undefined;
localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId); localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId);
// Restart autosaving in case the submit will be cancelled down the line // Restart autosaving in case the submit will be cancelled down the line
setTimeout(function() { setTimeout(function() {
easyMDE.autosave(); easyMDE.autosave();
}, easyMDE.options.autosave.delay || 10000); }, easyMDE.options.autosave.delay || 10000);
}); });
} }
this.options.autosave.binded = true; this.options.autosave.binded = true;
} }
@ -1788,6 +1795,7 @@ EasyMDE.prototype.createSideBySide = function () {
EasyMDE.prototype.createToolbar = function (items) { EasyMDE.prototype.createToolbar = function (items) {
items = items || this.options.toolbar; items = items || this.options.toolbar;
label = this.options.label;
if (!items || items.length === 0) { if (!items || items.length === 0) {
return; return;
@ -1864,6 +1872,18 @@ EasyMDE.prototype.createToolbar = function (items) {
})(items[i]); })(items[i]);
} }
if (label) {
var labelEl = document.createElement("label");
labelEl.className = "editor-label";
labelEl.innerHTML = label;
var labelBar = document.createElement("div");
labelBar.className = "editor-toolbar-label";
labelBar.appendChild(labelEl);
labelBar.appendChild(bar);
bar = labelBar;
}
self.toolbarElements = toolbarData; self.toolbarElements = toolbarData;
var cm = this.codemirror; var cm = this.codemirror;