Refactor default toolbar organization; Allow showIcons setting (#170)

patch-ionaru
Wes Cossick 9 years ago
parent 4dbe95fe80
commit 36f97604f4

@ -666,19 +666,20 @@ function wordCount(data) {
return count; return count;
} }
var toolbarBuiltInButtons = { var toolbarBuiltInButtons = {
"bold": { "bold": {
name: "bold", name: "bold",
action: toggleBold, action: toggleBold,
className: "fa fa-bold", className: "fa fa-bold",
title: "Bold (Ctrl+B)" title: "Bold (Ctrl+B)",
default: true
}, },
"italic": { "italic": {
name: "italic", name: "italic",
action: toggleItalic, action: toggleItalic,
className: "fa fa-italic", className: "fa fa-italic",
title: "Italic (Ctrl+I)" title: "Italic (Ctrl+I)",
default: true
}, },
"strikethrough": { "strikethrough": {
name: "strikethrough", name: "strikethrough",
@ -690,7 +691,8 @@ var toolbarBuiltInButtons = {
name: "heading", name: "heading",
action: toggleHeadingSmaller, action: toggleHeadingSmaller,
className: "fa fa-header", className: "fa fa-header",
title: "Heading (Ctrl+H)" title: "Heading (Ctrl+H)",
default: true
}, },
"heading-smaller": { "heading-smaller": {
name: "heading-smaller", name: "heading-smaller",
@ -722,6 +724,9 @@ var toolbarBuiltInButtons = {
className: "fa fa-header fa-header-x fa-header-3", className: "fa fa-header fa-header-x fa-header-3",
title: "Small Heading" title: "Small Heading"
}, },
"separator-1": {
name: "separator-1"
},
"code": { "code": {
name: "code", name: "code",
action: toggleCodeBlock, action: toggleCodeBlock,
@ -732,31 +737,39 @@ var toolbarBuiltInButtons = {
name: "quote", name: "quote",
action: toggleBlockquote, action: toggleBlockquote,
className: "fa fa-quote-left", className: "fa fa-quote-left",
title: "Quote (Ctrl+')" title: "Quote (Ctrl+')",
default: true
}, },
"unordered-list": { "unordered-list": {
name: "unordered-list", name: "unordered-list",
action: toggleUnorderedList, action: toggleUnorderedList,
className: "fa fa-list-ul", className: "fa fa-list-ul",
title: "Generic List (Ctrl+L)" title: "Generic List (Ctrl+L)",
default: true
}, },
"ordered-list": { "ordered-list": {
name: "ordered-list", name: "ordered-list",
action: toggleOrderedList, action: toggleOrderedList,
className: "fa fa-list-ol", className: "fa fa-list-ol",
title: "Numbered List (Ctrl+Alt+L)" title: "Numbered List (Ctrl+Alt+L)",
default: true
},
"separator-2": {
name: "separator-2"
}, },
"link": { "link": {
name: "link", name: "link",
action: drawLink, action: drawLink,
className: "fa fa-link", className: "fa fa-link",
title: "Create Link (Ctrl+K)" title: "Create Link (Ctrl+K)",
default: true
}, },
"image": { "image": {
name: "image", name: "image",
action: drawImage, action: drawImage,
className: "fa fa-picture-o", className: "fa fa-picture-o",
title: "Insert Image (Ctrl+Alt+I)" title: "Insert Image (Ctrl+Alt+I)",
default: true
}, },
"table": { "table": {
name: "table", name: "table",
@ -770,29 +783,36 @@ var toolbarBuiltInButtons = {
className: "fa fa-minus", className: "fa fa-minus",
title: "Insert Horizontal Line" title: "Insert Horizontal Line"
}, },
"separator-3": {
name: "separator-3"
},
"preview": { "preview": {
name: "preview", name: "preview",
action: togglePreview, action: togglePreview,
className: "fa fa-eye no-disable", className: "fa fa-eye no-disable",
title: "Toggle Preview (Ctrl+P)" title: "Toggle Preview (Ctrl+P)",
default: true
}, },
"side-by-side": { "side-by-side": {
name: "side-by-side", name: "side-by-side",
action: toggleSideBySide, action: toggleSideBySide,
className: "fa fa-columns no-disable no-mobile", className: "fa fa-columns no-disable no-mobile",
title: "Toggle Side by Side (F9)" title: "Toggle Side by Side (F9)",
default: true
}, },
"fullscreen": { "fullscreen": {
name: "fullscreen", name: "fullscreen",
action: toggleFullScreen, action: toggleFullScreen,
className: "fa fa-arrows-alt no-disable no-mobile", className: "fa fa-arrows-alt no-disable no-mobile",
title: "Toggle Fullscreen (F11)" title: "Toggle Fullscreen (F11)",
default: true
}, },
"guide": { "guide": {
name: "guide", name: "guide",
action: "http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide", action: "http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide",
className: "fa fa-question-circle", className: "fa fa-question-circle",
title: "Markdown Guide" title: "Markdown Guide",
default: true
} }
}; };
@ -857,10 +877,28 @@ function SimpleMDE(options) {
} }
// Handle toolbar and status bar // Handle toolbar
if(options.toolbar !== false) if(options.toolbar === undefined) {
options.toolbar = options.toolbar || SimpleMDE.toolbar; // Initialize
options.toolbar = [];
// Loop over the built in buttons, to get the preferred order
for(var key in toolbarBuiltInButtons) {
if(toolbarBuiltInButtons.hasOwnProperty(key)) {
if(key.indexOf("separator-") != -1) {
options.toolbar.push("|");
}
if(toolbarBuiltInButtons[key].default === true || (options.showIcons && options.showIcons.constructor === Array && options.showIcons.indexOf(key) != -1)) {
options.toolbar.push(key);
}
}
}
}
// Handle status bar
if(!options.hasOwnProperty("status")) { if(!options.hasOwnProperty("status")) {
options.status = ["autosave", "lines", "words", "cursor"]; options.status = ["autosave", "lines", "words", "cursor"];
} }
@ -908,11 +946,6 @@ function SimpleMDE(options) {
} }
} }
/**
* Default toolbar elements.
*/
SimpleMDE.toolbar = ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "|", "preview", "side-by-side", "fullscreen", "guide"];
/** /**
* Default markdown render. * Default markdown render.
*/ */

Loading…
Cancel
Save