Skip to content

Commit 8618543

Browse files
committed
Merge pull request sparksuite#242 from moczolaszlo/development
Optional prompt windows to Link and Image
2 parents 047c0ef + 5a53199 commit 8618543

File tree

7 files changed

+1044
-312
lines changed

7 files changed

+1044
-312
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ simplemde.value("This text will appear in the editor");
9393
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
9494
- **placeholder**: Custom placeholder that should be displayed
9595
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
96+
- **promptURLs**: If set to `true`, a prompt window come if you insert link or image. Defaults to `false`.
9697
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
9798
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
9899
- **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">`
@@ -145,6 +146,7 @@ var simplemde = new SimpleMDE({
145146

146147
return "Loading...";
147148
},
149+
promptURLs: true, // Show a prompt window to insert URL for link or image
148150
renderingConfig: {
149151
singleLineBreaks: false,
150152
codeSyntaxHighlighting: true,

debug/simplemde.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
171171
}
172172

173173
/* The fake, visible scrollbars. Used to force redraw during scrolling
174-
before actuall scrolling happens, thus preventing shaking and
174+
before actual scrolling happens, thus preventing shaking and
175175
flickering artifacts. */
176176
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
177177
position: absolute;

debug/simplemde.debug.js

Lines changed: 501 additions & 149 deletions
Large diffs are not rendered by default.

debug/simplemde.js

Lines changed: 500 additions & 148 deletions
Large diffs are not rendered by default.

dist/simplemde.min.css

Lines changed: 1 addition & 1 deletion
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.

src/js/simplemde.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,14 @@ function drawLink(editor) {
616616
var cm = editor.codemirror;
617617
var stat = getState(cm);
618618
var options = editor.options;
619-
_replaceSelection(cm, stat.link, options.insertTexts.link);
619+
var url = "http://";
620+
if(options.promptURLs) {
621+
url = prompt(options.promptTexts.link);
622+
if(!url) {
623+
return false;
624+
}
625+
}
626+
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
620627
}
621628

622629
/**
@@ -626,7 +633,14 @@ function drawImage(editor) {
626633
var cm = editor.codemirror;
627634
var stat = getState(cm);
628635
var options = editor.options;
629-
_replaceSelection(cm, stat.image, options.insertTexts.image);
636+
var url = "http://";
637+
if(options.promptURLs) {
638+
url = prompt(options.promptTexts.image);
639+
if(!url) {
640+
return false;
641+
}
642+
}
643+
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
630644
}
631645

632646
/**
@@ -770,7 +784,7 @@ function togglePreview(editor) {
770784
toggleSideBySide(editor);
771785
}
772786

773-
function _replaceSelection(cm, active, startEnd) {
787+
function _replaceSelection(cm, active, startEnd, url) {
774788
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
775789
return;
776790

@@ -779,6 +793,9 @@ function _replaceSelection(cm, active, startEnd) {
779793
var end = startEnd[1];
780794
var startPoint = cm.getCursor("start");
781795
var endPoint = cm.getCursor("end");
796+
if(url) {
797+
end = end.replace("#url#", url);
798+
}
782799
if(active) {
783800
text = cm.getLine(startPoint.line);
784801
start = text.slice(0, startPoint.ch);
@@ -1220,12 +1237,17 @@ var toolbarBuiltInButtons = {
12201237
};
12211238

12221239
var insertTexts = {
1223-
link: ["[", "](http://)"],
1224-
image: ["![](http://", ")"],
1240+
link: ["[", "](#url#)"],
1241+
image: ["![", "](#url#)"],
12251242
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
12261243
horizontalRule: ["", "\n\n-----\n\n"]
12271244
};
12281245

1246+
var promptTexts = {
1247+
link: "URL for the link:",
1248+
image: "URL of the image:"
1249+
};
1250+
12291251
var blockStyles = {
12301252
"bold": "**",
12311253
"code": "```",
@@ -1327,6 +1349,10 @@ function SimpleMDE(options) {
13271349
options.insertTexts = extend({}, insertTexts, options.insertTexts || {});
13281350

13291351

1352+
// Merging the promptTexts, with the given options
1353+
options.promptTexts = promptTexts;
1354+
1355+
13301356
// Merging the blockStyles, with the given options
13311357
options.blockStyles = extend({}, blockStyles, options.blockStyles || {});
13321358

0 commit comments

Comments
 (0)