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