allow drawImage to take an optional description argument

This commit is contained in:
Elliot Fosong 2017-07-06 15:16:07 +01:00
parent 0c63959382
commit 85ecc582b4
4 changed files with 29 additions and 20 deletions

File diff suppressed because one or more lines are too long

View File

@ -16360,8 +16360,9 @@ function drawLink(editor) {
/** /**
* Action for drawing an img. * Action for drawing an img.
*/ */
function drawImage(editor, url) { function drawImage(editor, url, desc) {
url = (typeof url != "undefined") ? url : "http://"; url = (typeof url != "undefined") ? url : "http://";
desc = (typeof desc != "undefined") ? desc : "";
var cm = editor.codemirror; var cm = editor.codemirror;
var stat = getState(cm); var stat = getState(cm);
var options = editor.options; var options = editor.options;
@ -16371,7 +16372,7 @@ function drawImage(editor, url) {
return false; return false;
} }
} }
_replaceSelection(cm, stat.image, options.insertTexts.image, url); _replaceSelection(cm, stat.image, options.insertTexts.image, url, desc);
} }
/** /**
@ -16518,7 +16519,8 @@ function togglePreview(editor) {
toggleSideBySide(editor); toggleSideBySide(editor);
} }
function _replaceSelection(cm, active, startEnd, url) { function _replaceSelection(cm, active, startEnd, url, desc) {
desc = (typeof desc != "undefined") ? desc : "";
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
return; return;
@ -16528,6 +16530,7 @@ function _replaceSelection(cm, active, startEnd, url) {
var startPoint = cm.getCursor("start"); var startPoint = cm.getCursor("start");
var endPoint = cm.getCursor("end"); var endPoint = cm.getCursor("end");
if(url) { if(url) {
start = start.replace("#desc#", desc);
end = end.replace("#url#", url); end = end.replace("#url#", url);
} }
if(active) { if(active) {
@ -16972,7 +16975,7 @@ var toolbarBuiltInButtons = {
var insertTexts = { var insertTexts = {
link: ["[", "](#url#)"], link: ["[", "](#url#)"],
image: ["![](", "#url#)"], image: ["![#desc#](", "#url#)"],
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"], table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
horizontalRule: ["", "\n\n-----\n\n"] horizontalRule: ["", "\n\n-----\n\n"]
}; };
@ -17677,8 +17680,8 @@ SimpleMDE.prototype.cleanBlock = function() {
SimpleMDE.prototype.drawLink = function() { SimpleMDE.prototype.drawLink = function() {
drawLink(this); drawLink(this);
}; };
SimpleMDE.prototype.drawImage = function(url) { SimpleMDE.prototype.drawImage = function(url, desc) {
drawImage(this, url); drawImage(this, url, desc);
}; };
SimpleMDE.prototype.drawTable = function() { SimpleMDE.prototype.drawTable = function() {
drawTable(this); drawTable(this);

File diff suppressed because one or more lines are too long

View File

@ -630,8 +630,9 @@ function drawLink(editor) {
/** /**
* Action for drawing an img. * Action for drawing an img.
*/ */
function drawImage(editor, url) { function drawImage(editor, url, desc) {
url = (typeof url != "undefined") ? url : "http://"; url = (typeof url != "undefined") ? url : "http://";
desc = (typeof desc != "undefined") ? desc : "";
var cm = editor.codemirror; var cm = editor.codemirror;
var stat = getState(cm); var stat = getState(cm);
var options = editor.options; var options = editor.options;
@ -641,7 +642,7 @@ function drawImage(editor, url) {
return false; return false;
} }
} }
_replaceSelection(cm, stat.image, options.insertTexts.image, url); _replaceSelection(cm, stat.image, options.insertTexts.image, url, desc);
} }
/** /**
@ -788,7 +789,8 @@ function togglePreview(editor) {
toggleSideBySide(editor); toggleSideBySide(editor);
} }
function _replaceSelection(cm, active, startEnd, url) { function _replaceSelection(cm, active, startEnd, url, desc) {
desc = (typeof desc != "undefined") ? desc : "";
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className)) if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
return; return;
@ -798,6 +800,7 @@ function _replaceSelection(cm, active, startEnd, url) {
var startPoint = cm.getCursor("start"); var startPoint = cm.getCursor("start");
var endPoint = cm.getCursor("end"); var endPoint = cm.getCursor("end");
if(url) { if(url) {
start = start.replace("#desc#", desc);
end = end.replace("#url#", url); end = end.replace("#url#", url);
} }
if(active) { if(active) {
@ -1242,7 +1245,7 @@ var toolbarBuiltInButtons = {
var insertTexts = { var insertTexts = {
link: ["[", "](#url#)"], link: ["[", "](#url#)"],
image: ["![](", "#url#)"], image: ["![#desc#](", "#url#)"],
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"], table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
horizontalRule: ["", "\n\n-----\n\n"] horizontalRule: ["", "\n\n-----\n\n"]
}; };
@ -1947,8 +1950,8 @@ SimpleMDE.prototype.cleanBlock = function() {
SimpleMDE.prototype.drawLink = function() { SimpleMDE.prototype.drawLink = function() {
drawLink(this); drawLink(this);
}; };
SimpleMDE.prototype.drawImage = function(url) { SimpleMDE.prototype.drawImage = function(url, desc) {
drawImage(this, url); drawImage(this, url, desc);
}; };
SimpleMDE.prototype.drawTable = function() { SimpleMDE.prototype.drawTable = function() {
drawTable(this); drawTable(this);