mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-09-24 16:40:55 -06:00
Provide a ability that can customize some toolbar-button, and provide a hook 'whenEleCreate' for every toolbar-button.
This commit is contained in:
parent
e32fe3f91c
commit
013dc45b9f
@ -108,6 +108,11 @@ function createIcon(options, enableTooltips, shortcuts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create element hook
|
||||||
|
if(options.whenEleCreate && typeof options.whenEleCreate === "function") {
|
||||||
|
el = options.whenEleCreate(el);
|
||||||
|
}
|
||||||
|
|
||||||
el.tabIndex = -1;
|
el.tabIndex = -1;
|
||||||
el.className = options.className;
|
el.className = options.className;
|
||||||
return el;
|
return el;
|
||||||
@ -1343,23 +1348,45 @@ function SimpleMDE(options) {
|
|||||||
|
|
||||||
|
|
||||||
// Handle toolbar
|
// Handle toolbar
|
||||||
if(options.toolbar === undefined) {
|
if(options.toolbar !== false && options.toolbar instanceof Object) {
|
||||||
// Initialize
|
// Initialize
|
||||||
options.toolbar = [];
|
var toolbar = [];
|
||||||
|
|
||||||
|
|
||||||
// Loop over the built in buttons, to get the preferred order
|
// Loop over the built in buttons, to get the preferred order
|
||||||
for(var key in toolbarBuiltInButtons) {
|
for(var key in toolbarBuiltInButtons) {
|
||||||
if(toolbarBuiltInButtons.hasOwnProperty(key)) {
|
if(toolbarBuiltInButtons.hasOwnProperty(key)) {
|
||||||
if(key.indexOf("separator-") != -1) {
|
if(key.indexOf("separator-") != -1) {
|
||||||
options.toolbar.push("|");
|
toolbar.push("|");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toolbarBuiltInButtons[key].default === true || (options.showIcons && options.showIcons.constructor === Array && options.showIcons.indexOf(key) != -1)) {
|
if(toolbarBuiltInButtons[key].default === true || (options.showIcons && options.showIcons.constructor === Array && options.showIcons.indexOf(key) != -1)) {
|
||||||
options.toolbar.push(key);
|
toolbar.push(toolbarBuiltInButtons[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle some custom toolbar-button
|
||||||
|
if(options.toolbar instanceof Object) {
|
||||||
|
var i, key, customButtonInfo, buttonInfo;
|
||||||
|
|
||||||
|
for(key in options.toolbar) {
|
||||||
|
customButtonInfo = options.toolbar[key];
|
||||||
|
for(i = 0; i < toolbar.length; i++) {
|
||||||
|
buttonInfo = toolbar[i];
|
||||||
|
if(buttonInfo instanceof Object && buttonInfo.name === key) {
|
||||||
|
buttonInfo = _mergeProperties(buttonInfo, customButtonInfo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i === toolbar.length) {
|
||||||
|
toolbar.push(customButtonInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
options.toolbar = toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1707,11 +1734,6 @@ SimpleMDE.prototype.createToolbar = function(items) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var i;
|
var i;
|
||||||
for(i = 0; i < items.length; i++) {
|
|
||||||
if(toolbarBuiltInButtons[items[i]] != undefined) {
|
|
||||||
items[i] = toolbarBuiltInButtons[items[i]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var bar = document.createElement("div");
|
var bar = document.createElement("div");
|
||||||
bar.className = "editor-toolbar";
|
bar.className = "editor-toolbar";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user