|
|
|
@ -110,15 +110,30 @@ function fixShortcut(name) {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create dropdown block
|
|
|
|
|
*/
|
|
|
|
|
function createToolbarDropdown(options, enableTooltips, shortcuts, parent) {
|
|
|
|
|
var el = createToolbarButton(options, enableTooltips, shortcuts, 'div');
|
|
|
|
|
el.className += ' easymde-dropdown';
|
|
|
|
|
var content = document.createElement('div');
|
|
|
|
|
content.className = 'easymde-dropdown-content';
|
|
|
|
|
for (var childrenIndex = 0; childrenIndex < options.children.length; childrenIndex++) {
|
|
|
|
|
var child = createToolbarButton(options.children[childrenIndex], enableTooltips, shortcuts, 'button', parent);
|
|
|
|
|
content.appendChild(child);
|
|
|
|
|
}
|
|
|
|
|
el.appendChild(content);
|
|
|
|
|
return el;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create button element for toolbar.
|
|
|
|
|
*/
|
|
|
|
|
function createToolbarButton(options, enableTooltips, shortcuts) {
|
|
|
|
|
function createToolbarButton(options, enableTooltips, shortcuts, markup, parent) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
var el = document.createElement('button');
|
|
|
|
|
var el = document.createElement(markup);
|
|
|
|
|
el.className = options.name;
|
|
|
|
|
el.setAttribute('type', 'button');
|
|
|
|
|
el.setAttribute('type', markup);
|
|
|
|
|
enableTooltips = (enableTooltips == undefined) ? true : enableTooltips;
|
|
|
|
|
|
|
|
|
|
// Properly hande custom shortcuts
|
|
|
|
@ -167,6 +182,20 @@ function createToolbarButton(options, enableTooltips, shortcuts) {
|
|
|
|
|
}
|
|
|
|
|
el.appendChild(icon);
|
|
|
|
|
|
|
|
|
|
if (options.action) {
|
|
|
|
|
if (typeof options.action === 'function') {
|
|
|
|
|
el.onclick = function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
options.action(parent);
|
|
|
|
|
};
|
|
|
|
|
} else if (typeof options.action === 'string') {
|
|
|
|
|
el.onclick = function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
window.open(options.action, '_blank');
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return el;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -2254,24 +2283,14 @@ EasyMDE.prototype.createToolbar = function (items) {
|
|
|
|
|
if (item === '|') {
|
|
|
|
|
el = createSep();
|
|
|
|
|
} else {
|
|
|
|
|
el = createToolbarButton(item, self.options.toolbarTips, self.options.shortcuts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// bind events, special for info
|
|
|
|
|
if (item.action) {
|
|
|
|
|
if (typeof item.action === 'function') {
|
|
|
|
|
el.onclick = function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
item.action(self);
|
|
|
|
|
};
|
|
|
|
|
} else if (typeof item.action === 'string') {
|
|
|
|
|
el.onclick = function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
window.open(item.action, '_blank');
|
|
|
|
|
};
|
|
|
|
|
if (item.children) {
|
|
|
|
|
el = createToolbarDropdown(item, self.options.toolbarTips, self.options.shortcuts, self);
|
|
|
|
|
} else {
|
|
|
|
|
el = createToolbarButton(item, self.options.toolbarTips, self.options.shortcuts, 'button', self);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toolbarData[item.name || item] = el;
|
|
|
|
|
bar.appendChild(el);
|
|
|
|
|
|
|
|
|
|