Skip to content

Commit f32e103

Browse files
committed
Merge pull request sparksuite#114 from NextStepWebs/development
Intelligently download Font Awesome, New options, Bug fixes
2 parents 57fcf52 + 8d07c5e commit f32e103

File tree

10 files changed

+263
-186
lines changed

10 files changed

+263
-186
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ SimpleMDE is also available on [jsDelivr](http://www.jsdelivr.com/#!simplemde).
2121
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
2222
```
2323

24-
SimpleMDE depends on Font Awesome (load via MaxCDN for best performance).
25-
26-
```HTML
27-
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
28-
```
29-
3024
And then load SimpleMDE on the first textarea on a page
3125

3226
```HTML
@@ -65,28 +59,30 @@ simplemde.value("This text will appear in the editor");
6559

6660
## Configuration
6761

62+
- **autoDownloadFontAwesome**: If set to `true`, force downloads Font Awesome (used for icons). If set to false, prevents downloading. Defaults to `undefined`, which will intelligently check whether Font Awesome has already been included, then download accordingly.
6863
- **autofocus**: If set to `true`, autofocuses the editor. Defaults to `false`.
6964
- **autosave**: *Saves the text that's being written. It will forget the text when the form is submitted.*
7065
- **enabled**: If set to `true`, autosave the text. Defaults to `false`.
7166
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
7267
- **unique_id**: You must set a unique identifier so that SimpleMDE can autosave. Something that separates this from other textareas.
7368
- **element**: The DOM element for the textarea to use. Defaults to the first textarea on the page.
69+
- **hideIcons**: An array of icon names to hide. Can be used to hide specific icons without completely customizing the toolbar.
7470
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
7571
- **initialValue**: If set, will customize the initial value of the editor.
7672
- **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`.
7773
- **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing).
7874
- **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`.
79-
- **fencedCodeBlocks**: If set to `false`, will not process GFM fenced code blocks syntax. Defaults to `true`.
8075
- **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`.
8176
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
8277
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
83-
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
78+
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
79+
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
80+
- **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page. For example, include the script and the CSS files like:<br>`<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>`<br>`<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">`
8481
- **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`.
8582
- **status**: If set to `false`, hide the status bar. Defaults to `true`.
8683
- Optionally, you can set an array of status bar elements to include, and in what order.
8784
- **tabSize**: If set, customize the tab size. Defaults to `2`.
8885
- **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons).
89-
- **toolbarGuideIcon**: If set to `false`, disable guide icon in the toolbar. Defaults to `true`.
9086
- **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`.
9187

9288
```JavaScript
@@ -98,12 +94,12 @@ var simplemde = new SimpleMDE({
9894
delay: 1000,
9995
},
10096
element: document.getElementById("MyID"),
97+
hideIcons: ["guide", "heading"],
10198
indentWithTabs: false,
10299
initialValue: "Hello world!",
103100
lineWrapping: false,
104101
parsingConfig: {
105102
allowAtxHeaderWithoutSpace: true,
106-
fencedCodeBlocks: false,
107103
strikethrough: false,
108104
underscoresBreakWords: true,
109105
},
@@ -117,13 +113,15 @@ var simplemde = new SimpleMDE({
117113

118114
return "Loading...";
119115
}
120-
singleLineBreaks: false,
116+
renderingConfig: {
117+
singleLineBreaks: false,
118+
codeSyntaxHighlighting: true,
119+
},
121120
spellChecker: false,
122121
status: false,
123122
status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
124123
tabSize: 4,
125124
toolbar: false,
126-
toolbarGuideIcon: false,
127125
toolbarTips: false,
128126
});
129127
```
@@ -150,9 +148,9 @@ ordered-list | toggleOrderedList | Numbered List (Ctrl+Alt+L)<br>fa fa-list-ol
150148
link | drawLink | Create Link (Ctrl+K)<br>fa fa-link
151149
image | drawImage | Insert Image (Ctrl+Alt+I)<br>fa fa-picture-o
152150
horizontal-rule | drawHorizontalRule | Insert Horizontal Line<br>fa fa-minus
153-
preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye
154-
side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns
155-
fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt
151+
preview | togglePreview | Toggle Preview (Ctrl+P)<br>fa fa-eye no-disable
152+
side-by-side | toggleSideBySide | Toggle Side by Side (F9)<br>fa fa-columns no-disable no-mobile
153+
fullscreen | toggleFullScreen | Toggle Fullscreen (F11)<br>fa fa-arrows-alt no-disable no-mobile
156154
guide | [This link](http://nextstepwebs.github.io/simplemde-markdown-editor/markdown-guide) | Markdown Guide<br>fa fa-question-circle
157155

158156
Customize the toolbar using the `toolbar` option like:

dist/simplemde.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/simplemde.min.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ gulp.task("downloads-codemirror", function(callback) {
1919
var download_urls = [
2020
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/lib/codemirror.js",
2121
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/edit/continuelist.js",
22-
//"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/edit/tablist.js", //waiting for PRs
2322
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/display/fullscreen.js",
2423
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/addon/mode/overlay.js",
25-
//"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/gfm/gfm.js", //waiting for PRs
24+
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/gfm/gfm.js",
2625
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/markdown/markdown.js",
2726
"https://raw.githubusercontent.com/codemirror/CodeMirror/master/mode/xml/xml.js"];
2827

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simplemde",
3-
"version": "1.7.1",
3+
"version": "1.7.2",
44
"description": "A simple, beautiful, and embeddable JavaScript markdown editor. Features autosaving and spell checking.",
55
"keywords": [
66
"embeddable",

src/css/simplemde.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@
177177
content: "▼";
178178
}
179179

180-
.editor-toolbar.disabled-for-preview a:not(.fa-eye):not(.fa-arrows-alt):not(.fa-columns) {
180+
.editor-toolbar.disabled-for-preview a:not(.no-disable) {
181181
pointer-events: none;
182182
background: #fff;
183183
border-color: transparent;
184184
text-shadow: inherit;
185185
}
186186

187187
@media only screen and (max-width: 700px) {
188-
.editor-toolbar a.fa-columns {
188+
.editor-toolbar a.no-mobile {
189189
display: none;
190190
}
191191
}

src/js/codemirror/codemirror.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,10 @@
15341534
}
15351535
},
15361536

1537+
readOnlyChanged: function(val) {
1538+
if (!val) this.reset();
1539+
},
1540+
15371541
setUneditable: nothing,
15381542

15391543
needsContentAttribute: false
@@ -1552,7 +1556,6 @@
15521556
init: function(display) {
15531557
var input = this, cm = input.cm;
15541558
var div = input.div = display.lineDiv;
1555-
div.contentEditable = "true";
15561559
disableBrowserMagic(div);
15571560

15581561
on(div, "paste", function(e) { handlePaste(e, cm); })
@@ -1593,7 +1596,7 @@
15931596

15941597
on(div, "input", function() {
15951598
if (input.composing) return;
1596-
if (!input.pollContent())
1599+
if (isReadOnly(cm) || !input.pollContent())
15971600
runInOp(input.cm, function() {regChange(cm);});
15981601
});
15991602

@@ -1818,17 +1821,24 @@
18181821
this.div.focus();
18191822
},
18201823
applyComposition: function(composing) {
1821-
if (composing.data && composing.data != composing.startData)
1824+
if (isReadOnly(this.cm))
1825+
operation(this.cm, regChange)(this.cm)
1826+
else if (composing.data && composing.data != composing.startData)
18221827
operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel);
18231828
},
18241829

18251830
setUneditable: function(node) {
1826-
node.setAttribute("contenteditable", "false");
1831+
node.contentEditable = "false"
18271832
},
18281833

18291834
onKeyPress: function(e) {
18301835
e.preventDefault();
1831-
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
1836+
if (!isReadOnly(this.cm))
1837+
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
1838+
},
1839+
1840+
readOnlyChanged: function(val) {
1841+
this.div.contentEditable = String(val != "nocursor")
18321842
},
18331843

18341844
onContextMenu: nothing,
@@ -5389,8 +5399,8 @@
53895399
cm.display.disabled = true;
53905400
} else {
53915401
cm.display.disabled = false;
5392-
if (!val) cm.display.input.reset();
53935402
}
5403+
cm.display.input.readOnlyChanged(val)
53945404
});
53955405
option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true);
53965406
option("dragDrop", true, dragDropChanged);
@@ -8093,24 +8103,30 @@
80938103
}
80948104
};
80958105

8106+
var noHandlers = []
8107+
function getHandlers(emitter, type, copy) {
8108+
var arr = emitter._handlers && emitter._handlers[type]
8109+
if (copy) return arr && arr.length > 0 ? arr.slice() : noHandlers
8110+
else return arr || noHandlers
8111+
}
8112+
80968113
var off = CodeMirror.off = function(emitter, type, f) {
80978114
if (emitter.removeEventListener)
80988115
emitter.removeEventListener(type, f, false);
80998116
else if (emitter.detachEvent)
81008117
emitter.detachEvent("on" + type, f);
81018118
else {
8102-
var arr = emitter._handlers && emitter._handlers[type];
8103-
if (!arr) return;
8104-
for (var i = 0; i < arr.length; ++i)
8105-
if (arr[i] == f) { arr.splice(i, 1); break; }
8119+
var handlers = getHandlers(emitter, type, false)
8120+
for (var i = 0; i < handlers.length; ++i)
8121+
if (handlers[i] == f) { handlers.splice(i, 1); break; }
81068122
}
81078123
};
81088124

81098125
var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
8110-
var arr = emitter._handlers && emitter._handlers[type];
8111-
if (!arr) return;
8126+
var handlers = getHandlers(emitter, type, true)
8127+
if (!handlers.length) return;
81128128
var args = Array.prototype.slice.call(arguments, 2);
8113-
for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
8129+
for (var i = 0; i < handlers.length; ++i) handlers[i].apply(null, args);
81148130
};
81158131

81168132
var orphanDelayedCallbacks = null;
@@ -8123,8 +8139,8 @@
81238139
// them to be executed when the last operation ends, or, if no
81248140
// operation is active, when a timeout fires.
81258141
function signalLater(emitter, type /*, values...*/) {
8126-
var arr = emitter._handlers && emitter._handlers[type];
8127-
if (!arr) return;
8142+
var arr = getHandlers(emitter, type, false)
8143+
if (!arr.length) return;
81288144
var args = Array.prototype.slice.call(arguments, 2), list;
81298145
if (operationGroup) {
81308146
list = operationGroup.delayedCallbacks;
@@ -8164,8 +8180,7 @@
81648180
}
81658181

81668182
function hasHandler(emitter, type) {
8167-
var arr = emitter._handlers && emitter._handlers[type];
8168-
return arr && arr.length > 0;
8183+
return getHandlers(emitter, type).length > 0
81698184
}
81708185

81718186
// Add on and off methods to a constructor's prototype, to make
@@ -8819,7 +8834,7 @@
88198834

88208835
// THE END
88218836

8822-
CodeMirror.version = "5.6.1";
8837+
CodeMirror.version = "5.7.1";
88238838

88248839
return CodeMirror;
88258840
});

0 commit comments

Comments
 (0)