Skip to content

Commit 4d065c3

Browse files
authored
Merge pull request #454 from vanillajonathan/patch-8
Refactor into using a map for icon classes
2 parents c84af4c + 78fcda5 commit 4d065c3

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ easyMDE.value('New input for **EasyMDE**');
159159
- **promptTexts**: Customize the text used to prompt for URLs.
160160
- **image**: The text to use when prompting for an image's URL. Defaults to `URL of the image:`.
161161
- **link**: The text to use when prompting for a link's URL. Defaults to `URL for the link:`.
162+
- **iconClassMap**: Used to specify the icon class names for the various toolbar buttons.
162163
- **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`.
163164
- **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).
164165
- **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`.

src/js/easymde.js

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,62 +1471,90 @@ function wordCount(data) {
14711471
return count;
14721472
}
14731473

1474+
var iconClassMap = {
1475+
'bold': 'fa fa-bold',
1476+
'italic': 'fa fa-italic',
1477+
'strikethrough': 'fa fa-strikethrough',
1478+
'heading': 'fa fa-header fa-heading',
1479+
'heading-smaller': 'fa fa-header fa-heading header-smaller',
1480+
'heading-bigger': 'fa fa-header fa-heading header-bigger',
1481+
'heading-1': 'fa fa-header fa-heading header-1',
1482+
'heading-2': 'fa fa-header fa-heading header-2',
1483+
'heading-3': 'fa fa-header fa-heading header-3',
1484+
'code': 'fa fa-code',
1485+
'quote': 'fa fa-quote-left',
1486+
'ordered-list': 'fa fa-list-ol',
1487+
'unordered-list': 'fa fa-list-ul',
1488+
'clean-block': 'fa fa-eraser',
1489+
'link': 'fa fa-link',
1490+
'image': 'fa fa-image',
1491+
'upload-image': 'fa fa-image',
1492+
'table': 'fa fa-table',
1493+
'horizontal-rule': 'fa fa-minus',
1494+
'preview': 'fa fa-eye',
1495+
'side-by-side': 'fa fa-columns',
1496+
'fullscreen': 'fa fa-arrows-alt',
1497+
'guide': 'fa fa-question-circle',
1498+
'undo': 'fa fa-undo',
1499+
'redo': 'fa fa-repeat fa-redo',
1500+
};
1501+
14741502
var toolbarBuiltInButtons = {
14751503
'bold': {
14761504
name: 'bold',
14771505
action: toggleBold,
1478-
className: 'fa fa-bold',
1506+
className: iconClassMap['bold'],
14791507
title: 'Bold',
14801508
default: true,
14811509
},
14821510
'italic': {
14831511
name: 'italic',
14841512
action: toggleItalic,
1485-
className: 'fa fa-italic',
1513+
className: iconClassMap['italic'],
14861514
title: 'Italic',
14871515
default: true,
14881516
},
14891517
'strikethrough': {
14901518
name: 'strikethrough',
14911519
action: toggleStrikethrough,
1492-
className: 'fa fa-strikethrough',
1520+
className: iconClassMap['strikethrough'],
14931521
title: 'Strikethrough',
14941522
},
14951523
'heading': {
14961524
name: 'heading',
14971525
action: toggleHeadingSmaller,
1498-
className: 'fa fa-header fa-heading',
1526+
className: iconClassMap['heading'],
14991527
title: 'Heading',
15001528
default: true,
15011529
},
15021530
'heading-smaller': {
15031531
name: 'heading-smaller',
15041532
action: toggleHeadingSmaller,
1505-
className: 'fa fa-header fa-heading header-smaller',
1533+
className: iconClassMap['heading-smaller'],
15061534
title: 'Smaller Heading',
15071535
},
15081536
'heading-bigger': {
15091537
name: 'heading-bigger',
15101538
action: toggleHeadingBigger,
1511-
className: 'fa fa-header fa-heading header-bigger',
1539+
className: iconClassMap['heading-bigger'],
15121540
title: 'Bigger Heading',
15131541
},
15141542
'heading-1': {
15151543
name: 'heading-1',
15161544
action: toggleHeading1,
1517-
className: 'fa fa-header fa-heading header-1',
1545+
className: iconClassMap['heading-1'],
15181546
title: 'Big Heading',
15191547
},
15201548
'heading-2': {
15211549
name: 'heading-2',
15221550
action: toggleHeading2,
1523-
className: 'fa fa-header fa-heading header-2',
1551+
className: iconClassMap['heading-2'],
15241552
title: 'Medium Heading',
15251553
},
15261554
'heading-3': {
15271555
name: 'heading-3',
15281556
action: toggleHeading3,
1529-
className: 'fa fa-header fa-heading header-3',
1557+
className: iconClassMap['heading-3'],
15301558
title: 'Small Heading',
15311559
},
15321560
'separator-1': {
@@ -1535,34 +1563,34 @@ var toolbarBuiltInButtons = {
15351563
'code': {
15361564
name: 'code',
15371565
action: toggleCodeBlock,
1538-
className: 'fa fa-code',
1566+
className: iconClassMap['code'],
15391567
title: 'Code',
15401568
},
15411569
'quote': {
15421570
name: 'quote',
15431571
action: toggleBlockquote,
1544-
className: 'fa fa-quote-left',
1572+
className: iconClassMap['quote'],
15451573
title: 'Quote',
15461574
default: true,
15471575
},
15481576
'unordered-list': {
15491577
name: 'unordered-list',
15501578
action: toggleUnorderedList,
1551-
className: 'fa fa-list-ul',
1579+
className: iconClassMap['ordered-list'],
15521580
title: 'Generic List',
15531581
default: true,
15541582
},
15551583
'ordered-list': {
15561584
name: 'ordered-list',
15571585
action: toggleOrderedList,
1558-
className: 'fa fa-list-ol',
1586+
className: iconClassMap['unordered-list'],
15591587
title: 'Numbered List',
15601588
default: true,
15611589
},
15621590
'clean-block': {
15631591
name: 'clean-block',
15641592
action: cleanBlock,
1565-
className: 'fa fa-eraser',
1593+
className: iconClassMap['clean-block'],
15661594
title: 'Clean block',
15671595
},
15681596
'separator-2': {
@@ -1571,33 +1599,33 @@ var toolbarBuiltInButtons = {
15711599
'link': {
15721600
name: 'link',
15731601
action: drawLink,
1574-
className: 'fa fa-link',
1602+
className: iconClassMap['link'],
15751603
title: 'Create Link',
15761604
default: true,
15771605
},
15781606
'image': {
15791607
name: 'image',
15801608
action: drawImage,
1581-
className: 'fa fa-image',
1609+
className: iconClassMap['image'],
15821610
title: 'Insert Image',
15831611
default: true,
15841612
},
15851613
'upload-image': {
15861614
name: 'upload-image',
15871615
action: drawUploadedImage,
1588-
className: 'fa fa-image',
1616+
className: iconClassMap['upload-image'],
15891617
title: 'Import an image',
15901618
},
15911619
'table': {
15921620
name: 'table',
15931621
action: drawTable,
1594-
className: 'fa fa-table',
1622+
className: iconClassMap['table'],
15951623
title: 'Insert Table',
15961624
},
15971625
'horizontal-rule': {
15981626
name: 'horizontal-rule',
15991627
action: drawHorizontalRule,
1600-
className: 'fa fa-minus',
1628+
className: iconClassMap['horizontal-rule'],
16011629
title: 'Insert Horizontal Line',
16021630
},
16031631
'separator-3': {
@@ -1606,15 +1634,15 @@ var toolbarBuiltInButtons = {
16061634
'preview': {
16071635
name: 'preview',
16081636
action: togglePreview,
1609-
className: 'fa fa-eye',
1637+
className: iconClassMap['preview'],
16101638
noDisable: true,
16111639
title: 'Toggle Preview',
16121640
default: true,
16131641
},
16141642
'side-by-side': {
16151643
name: 'side-by-side',
16161644
action: toggleSideBySide,
1617-
className: 'fa fa-columns',
1645+
className: iconClassMap['side-by-side'],
16181646
noDisable: true,
16191647
noMobile: true,
16201648
title: 'Toggle Side by Side',
@@ -1623,7 +1651,7 @@ var toolbarBuiltInButtons = {
16231651
'fullscreen': {
16241652
name: 'fullscreen',
16251653
action: toggleFullScreen,
1626-
className: 'fa fa-arrows-alt',
1654+
className: iconClassMap['fullscreen'],
16271655
noDisable: true,
16281656
noMobile: true,
16291657
title: 'Toggle Fullscreen',
@@ -1635,7 +1663,7 @@ var toolbarBuiltInButtons = {
16351663
'guide': {
16361664
name: 'guide',
16371665
action: 'https://www.markdownguide.org/basic-syntax/',
1638-
className: 'fa fa-question-circle',
1666+
className: iconClassMap['guide'],
16391667
noDisable: true,
16401668
title: 'Markdown Guide',
16411669
default: true,
@@ -1646,14 +1674,14 @@ var toolbarBuiltInButtons = {
16461674
'undo': {
16471675
name: 'undo',
16481676
action: undo,
1649-
className: 'fa fa-undo',
1677+
className: iconClassMap['undo'],
16501678
noDisable: true,
16511679
title: 'Undo',
16521680
},
16531681
'redo': {
16541682
name: 'redo',
16551683
action: redo,
1656-
className: 'fa fa-repeat fa-redo',
1684+
className: iconClassMap['redo'],
16571685
noDisable: true,
16581686
title: 'Redo',
16591687
},
@@ -1826,6 +1854,7 @@ function EasyMDE(options) {
18261854
options.autosave.timeFormat = extend({}, timeFormat, options.autosave.timeFormat || {});
18271855
}
18281856

1857+
options.iconClassMap = extend({}, iconClassMap, options.iconClassMap || {});
18291858

18301859
// Merging the shortcuts, with the given options
18311860
options.shortcuts = extend({}, shortcuts, options.shortcuts || {});

0 commit comments

Comments
 (0)