From 2877d9563dd5c4e9ce2e57d83d8bfbf34d35351e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E7=8F=BD?= Date: Wed, 10 May 2017 16:44:30 +0800 Subject: [PATCH] add onDrawImage --- src/js/simplemde.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/js/simplemde.js b/src/js/simplemde.js index 2de43f3..e230ef3 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -632,17 +632,22 @@ function drawLink(editor) { /** * Action for drawing an img. */ -function drawImage(editor) { +function drawImage(editor,imageUrl) { var cm = editor.codemirror; var stat = getState(cm); var options = editor.options; var url = "http://"; - if(options.promptURLs) { + if(options.onDrawImage && !imageUrl) { + options.onDrawImage(); + return; + } + if(options.promptURLs) { url = prompt(options.promptTexts.image); if(!url) { return false; } } + url = imageUrl || url; _replaceSelection(cm, stat.image, options.insertTexts.image, url); } @@ -2004,8 +2009,8 @@ SimpleMDE.prototype.cleanBlock = function() { SimpleMDE.prototype.drawLink = function() { drawLink(this); }; -SimpleMDE.prototype.drawImage = function() { - drawImage(this); +SimpleMDE.prototype.drawImage = function(url) { + drawImage(this,url); }; SimpleMDE.prototype.drawTable = function() { drawTable(this);