Merge pull request #454 from vanillajonathan/patch-8

Refactor into using a map for icon classes
pull/205/merge
Jeroen Akkerman 2 years ago committed by GitHub
commit 4d065c361e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -159,6 +159,7 @@ easyMDE.value('New input for **EasyMDE**');
- **promptTexts**: Customize the text used to prompt for URLs. - **promptTexts**: Customize the text used to prompt for URLs.
- **image**: The text to use when prompting for an image's URL. Defaults to `URL of the image:`. - **image**: The text to use when prompting for an image's URL. Defaults to `URL of the image:`.
- **link**: The text to use when prompting for a link's URL. Defaults to `URL for the link:`. - **link**: The text to use when prompting for a link's URL. Defaults to `URL for the link:`.
- **iconClassMap**: Used to specify the icon class names for the various toolbar buttons.
- **uploadImage**: If set to `true`, enables the image upload functionality, which can be triggered by drag and drop, copy-paste and through the browse-file window (opened when the user click on the *upload-image* icon). Defaults to `false`. - **uploadImage**: If set to `true`, enables the image upload functionality, which can be triggered by drag and drop, copy-paste and through the browse-file window (opened when the user click on the *upload-image* icon). Defaults to `false`.
- **imageMaxSize**: Maximum image size in bytes, checked before upload (note: never trust client, always check the image size at server-side). Defaults to `1024 * 1024 * 2` (2 MB). - **imageMaxSize**: Maximum image size in bytes, checked before upload (note: never trust client, always check the image size at server-side). Defaults to `1024 * 1024 * 2` (2 MB).
- **imageAccept**: A comma-separated list of mime-types used to check image type before upload (note: never trust client, always check file types at server-side). Defaults to `image/png, image/jpeg`. - **imageAccept**: A comma-separated list of mime-types used to check image type before upload (note: never trust client, always check file types at server-side). Defaults to `image/png, image/jpeg`.

@ -1471,62 +1471,90 @@ function wordCount(data) {
return count; return count;
} }
var iconClassMap = {
'bold': 'fa fa-bold',
'italic': 'fa fa-italic',
'strikethrough': 'fa fa-strikethrough',
'heading': 'fa fa-header fa-heading',
'heading-smaller': 'fa fa-header fa-heading header-smaller',
'heading-bigger': 'fa fa-header fa-heading header-bigger',
'heading-1': 'fa fa-header fa-heading header-1',
'heading-2': 'fa fa-header fa-heading header-2',
'heading-3': 'fa fa-header fa-heading header-3',
'code': 'fa fa-code',
'quote': 'fa fa-quote-left',
'ordered-list': 'fa fa-list-ol',
'unordered-list': 'fa fa-list-ul',
'clean-block': 'fa fa-eraser',
'link': 'fa fa-link',
'image': 'fa fa-image',
'upload-image': 'fa fa-image',
'table': 'fa fa-table',
'horizontal-rule': 'fa fa-minus',
'preview': 'fa fa-eye',
'side-by-side': 'fa fa-columns',
'fullscreen': 'fa fa-arrows-alt',
'guide': 'fa fa-question-circle',
'undo': 'fa fa-undo',
'redo': 'fa fa-repeat fa-redo',
};
var toolbarBuiltInButtons = { var toolbarBuiltInButtons = {
'bold': { 'bold': {
name: 'bold', name: 'bold',
action: toggleBold, action: toggleBold,
className: 'fa fa-bold', className: iconClassMap['bold'],
title: 'Bold', title: 'Bold',
default: true, default: true,
}, },
'italic': { 'italic': {
name: 'italic', name: 'italic',
action: toggleItalic, action: toggleItalic,
className: 'fa fa-italic', className: iconClassMap['italic'],
title: 'Italic', title: 'Italic',
default: true, default: true,
}, },
'strikethrough': { 'strikethrough': {
name: 'strikethrough', name: 'strikethrough',
action: toggleStrikethrough, action: toggleStrikethrough,
className: 'fa fa-strikethrough', className: iconClassMap['strikethrough'],
title: 'Strikethrough', title: 'Strikethrough',
}, },
'heading': { 'heading': {
name: 'heading', name: 'heading',
action: toggleHeadingSmaller, action: toggleHeadingSmaller,
className: 'fa fa-header fa-heading', className: iconClassMap['heading'],
title: 'Heading', title: 'Heading',
default: true, default: true,
}, },
'heading-smaller': { 'heading-smaller': {
name: 'heading-smaller', name: 'heading-smaller',
action: toggleHeadingSmaller, action: toggleHeadingSmaller,
className: 'fa fa-header fa-heading header-smaller', className: iconClassMap['heading-smaller'],
title: 'Smaller Heading', title: 'Smaller Heading',
}, },
'heading-bigger': { 'heading-bigger': {
name: 'heading-bigger', name: 'heading-bigger',
action: toggleHeadingBigger, action: toggleHeadingBigger,
className: 'fa fa-header fa-heading header-bigger', className: iconClassMap['heading-bigger'],
title: 'Bigger Heading', title: 'Bigger Heading',
}, },
'heading-1': { 'heading-1': {
name: 'heading-1', name: 'heading-1',
action: toggleHeading1, action: toggleHeading1,
className: 'fa fa-header fa-heading header-1', className: iconClassMap['heading-1'],
title: 'Big Heading', title: 'Big Heading',
}, },
'heading-2': { 'heading-2': {
name: 'heading-2', name: 'heading-2',
action: toggleHeading2, action: toggleHeading2,
className: 'fa fa-header fa-heading header-2', className: iconClassMap['heading-2'],
title: 'Medium Heading', title: 'Medium Heading',
}, },
'heading-3': { 'heading-3': {
name: 'heading-3', name: 'heading-3',
action: toggleHeading3, action: toggleHeading3,
className: 'fa fa-header fa-heading header-3', className: iconClassMap['heading-3'],
title: 'Small Heading', title: 'Small Heading',
}, },
'separator-1': { 'separator-1': {
@ -1535,34 +1563,34 @@ var toolbarBuiltInButtons = {
'code': { 'code': {
name: 'code', name: 'code',
action: toggleCodeBlock, action: toggleCodeBlock,
className: 'fa fa-code', className: iconClassMap['code'],
title: 'Code', title: 'Code',
}, },
'quote': { 'quote': {
name: 'quote', name: 'quote',
action: toggleBlockquote, action: toggleBlockquote,
className: 'fa fa-quote-left', className: iconClassMap['quote'],
title: 'Quote', title: 'Quote',
default: true, default: true,
}, },
'unordered-list': { 'unordered-list': {
name: 'unordered-list', name: 'unordered-list',
action: toggleUnorderedList, action: toggleUnorderedList,
className: 'fa fa-list-ul', className: iconClassMap['ordered-list'],
title: 'Generic List', title: 'Generic List',
default: true, default: true,
}, },
'ordered-list': { 'ordered-list': {
name: 'ordered-list', name: 'ordered-list',
action: toggleOrderedList, action: toggleOrderedList,
className: 'fa fa-list-ol', className: iconClassMap['unordered-list'],
title: 'Numbered List', title: 'Numbered List',
default: true, default: true,
}, },
'clean-block': { 'clean-block': {
name: 'clean-block', name: 'clean-block',
action: cleanBlock, action: cleanBlock,
className: 'fa fa-eraser', className: iconClassMap['clean-block'],
title: 'Clean block', title: 'Clean block',
}, },
'separator-2': { 'separator-2': {
@ -1571,33 +1599,33 @@ var toolbarBuiltInButtons = {
'link': { 'link': {
name: 'link', name: 'link',
action: drawLink, action: drawLink,
className: 'fa fa-link', className: iconClassMap['link'],
title: 'Create Link', title: 'Create Link',
default: true, default: true,
}, },
'image': { 'image': {
name: 'image', name: 'image',
action: drawImage, action: drawImage,
className: 'fa fa-image', className: iconClassMap['image'],
title: 'Insert Image', title: 'Insert Image',
default: true, default: true,
}, },
'upload-image': { 'upload-image': {
name: 'upload-image', name: 'upload-image',
action: drawUploadedImage, action: drawUploadedImage,
className: 'fa fa-image', className: iconClassMap['upload-image'],
title: 'Import an image', title: 'Import an image',
}, },
'table': { 'table': {
name: 'table', name: 'table',
action: drawTable, action: drawTable,
className: 'fa fa-table', className: iconClassMap['table'],
title: 'Insert Table', title: 'Insert Table',
}, },
'horizontal-rule': { 'horizontal-rule': {
name: 'horizontal-rule', name: 'horizontal-rule',
action: drawHorizontalRule, action: drawHorizontalRule,
className: 'fa fa-minus', className: iconClassMap['horizontal-rule'],
title: 'Insert Horizontal Line', title: 'Insert Horizontal Line',
}, },
'separator-3': { 'separator-3': {
@ -1606,7 +1634,7 @@ var toolbarBuiltInButtons = {
'preview': { 'preview': {
name: 'preview', name: 'preview',
action: togglePreview, action: togglePreview,
className: 'fa fa-eye', className: iconClassMap['preview'],
noDisable: true, noDisable: true,
title: 'Toggle Preview', title: 'Toggle Preview',
default: true, default: true,
@ -1614,7 +1642,7 @@ var toolbarBuiltInButtons = {
'side-by-side': { 'side-by-side': {
name: 'side-by-side', name: 'side-by-side',
action: toggleSideBySide, action: toggleSideBySide,
className: 'fa fa-columns', className: iconClassMap['side-by-side'],
noDisable: true, noDisable: true,
noMobile: true, noMobile: true,
title: 'Toggle Side by Side', title: 'Toggle Side by Side',
@ -1623,7 +1651,7 @@ var toolbarBuiltInButtons = {
'fullscreen': { 'fullscreen': {
name: 'fullscreen', name: 'fullscreen',
action: toggleFullScreen, action: toggleFullScreen,
className: 'fa fa-arrows-alt', className: iconClassMap['fullscreen'],
noDisable: true, noDisable: true,
noMobile: true, noMobile: true,
title: 'Toggle Fullscreen', title: 'Toggle Fullscreen',
@ -1635,7 +1663,7 @@ var toolbarBuiltInButtons = {
'guide': { 'guide': {
name: 'guide', name: 'guide',
action: 'https://www.markdownguide.org/basic-syntax/', action: 'https://www.markdownguide.org/basic-syntax/',
className: 'fa fa-question-circle', className: iconClassMap['guide'],
noDisable: true, noDisable: true,
title: 'Markdown Guide', title: 'Markdown Guide',
default: true, default: true,
@ -1646,14 +1674,14 @@ var toolbarBuiltInButtons = {
'undo': { 'undo': {
name: 'undo', name: 'undo',
action: undo, action: undo,
className: 'fa fa-undo', className: iconClassMap['undo'],
noDisable: true, noDisable: true,
title: 'Undo', title: 'Undo',
}, },
'redo': { 'redo': {
name: 'redo', name: 'redo',
action: redo, action: redo,
className: 'fa fa-repeat fa-redo', className: iconClassMap['redo'],
noDisable: true, noDisable: true,
title: 'Redo', title: 'Redo',
}, },
@ -1826,6 +1854,7 @@ function EasyMDE(options) {
options.autosave.timeFormat = extend({}, timeFormat, options.autosave.timeFormat || {}); options.autosave.timeFormat = extend({}, timeFormat, options.autosave.timeFormat || {});
} }
options.iconClassMap = extend({}, iconClassMap, options.iconClassMap || {});
// Merging the shortcuts, with the given options // Merging the shortcuts, with the given options
options.shortcuts = extend({}, shortcuts, options.shortcuts || {}); options.shortcuts = extend({}, shortcuts, options.shortcuts || {});

Loading…
Cancel
Save