Browse Source

Fixed some bugs

develop
pandao 6 years ago
parent
commit
6704d47869
  1. 5
      css/editormd.css
  2. 6
      css/editormd.logo.css
  3. 4
      css/editormd.logo.min.css
  4. 6
      css/editormd.min.css
  5. 6
      css/editormd.preview.css
  6. 4
      css/editormd.preview.min.css
  7. 182
      editormd.amd.js
  8. 6
      editormd.amd.min.js
  9. 181
      editormd.js
  10. 5
      editormd.min.js
  11. 8
      examples/dynamic-create-editormd.html
  12. 2
      examples/form-get-value.html
  13. 10
      examples/katex.html
  14. 25
      examples/multi-editormd.html
  15. 2
      examples/test.md
  16. 4
      languages/zh-tw.js
  17. 6
      lib/codemirror/addons.min.js
  18. 12
      lib/codemirror/modes.min.js
  19. 11
      lib/marked.min.js
  20. 2
      package.json
  21. 4
      plugins/code-block-dialog/code-block-dialog.js
  22. 4
      plugins/emoji-dialog/emoji-dialog.js
  23. 4
      plugins/goto-line-dialog/goto-line-dialog.js
  24. 2
      plugins/help-dialog/help-dialog.js
  25. 4
      plugins/html-entities-dialog/html-entities-dialog.js
  26. 2
      plugins/image-dialog/image-dialog.js
  27. 4
      plugins/link-dialog/link-dialog.js
  28. 2
      plugins/preformatted-text-dialog/preformatted-text-dialog.js
  29. 4
      plugins/reference-link-dialog/reference-link-dialog.js
  30. 4
      plugins/table-dialog/table-dialog.js
  31. 231
      src/editormd.js

5
css/editormd.css

@ -1,13 +1,13 @@
/*
* Editor.md
*
* @file editormd.css
* @file /editormd.css
* @version v1.5.0
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-06-09
* @updateTime 2019-05-11
*/
@charset "UTF-8";
@ -675,6 +675,7 @@
line-height: 1.6;
display: none;
background: #fff;
z-index: 10;
}
.editormd .CodeMirror {

6
css/editormd.logo.css

@ -1,20 +1,20 @@
/*
* Editor.md
*
* @file editormd.logo.css
* @file /editormd.logo.css
* @version v1.5.0
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-06-09
* @updateTime 2019-05-11
*/
/*! prefixes.scss v0.1.0 | Author: Pandao | https://github.com/pandao/prefixes.scss | MIT license | Copyright (c) 2015 */
@font-face {
font-family: 'editormd-logo';
src: url("../fonts/editormd-logo.eot?-5y8q6h");
src: url(".../fonts/editormd-logo.eot?#iefix-5y8q6h") format("embedded-opentype"), url("../fonts/editormd-logo.woff?-5y8q6h") format("woff"), url("../fonts/editormd-logo.ttf?-5y8q6h") format("truetype"), url("../fonts/editormd-logo.svg?-5y8q6h#icomoon") format("svg");
src: url("../fonts/editormd-logo.eot?#iefix-5y8q6h") format("embedded-opentype"), url("../fonts/editormd-logo.woff?-5y8q6h") format("woff"), url("../fonts/editormd-logo.ttf?-5y8q6h") format("truetype"), url("../fonts/editormd-logo.svg?-5y8q6h#icomoon") format("svg");
font-weight: normal;
font-style: normal;
}

4
css/editormd.logo.min.css

@ -1,2 +1,2 @@
/*! Editor.md v1.5.0 | editormd.logo.min.css | Open source online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2015-06-09 */
/*! prefixes.scss v0.1.0 | Author: Pandao | https://github.com/pandao/prefixes.scss | MIT license | Copyright (c) 2015 */@font-face{font-family:editormd-logo;src:url(../fonts/editormd-logo.eot?-5y8q6h);src:url(.../fonts/editormd-logo.eot?#iefix-5y8q6h)format("embedded-opentype"),url(../fonts/editormd-logo.woff?-5y8q6h)format("woff"),url(../fonts/editormd-logo.ttf?-5y8q6h)format("truetype"),url(../fonts/editormd-logo.svg?-5y8q6h#icomoon)format("svg");font-weight:400;font-style:normal}.editormd-logo,.editormd-logo-1x,.editormd-logo-2x,.editormd-logo-3x,.editormd-logo-4x,.editormd-logo-5x,.editormd-logo-6x,.editormd-logo-7x,.editormd-logo-8x{font-family:editormd-logo;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;font-size:inherit;line-height:1;display:inline-block;text-rendering:auto;vertical-align:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.editormd-logo-1x:before,.editormd-logo-2x:before,.editormd-logo-3x:before,.editormd-logo-4x:before,.editormd-logo-5x:before,.editormd-logo-6x:before,.editormd-logo-7x:before,.editormd-logo-8x:before,.editormd-logo:before{content:"\e1987"}.editormd-logo-1x{font-size:1em}.editormd-logo-lg{font-size:1.2em}.editormd-logo-2x{font-size:2em}.editormd-logo-3x{font-size:3em}.editormd-logo-4x{font-size:4em}.editormd-logo-5x{font-size:5em}.editormd-logo-6x{font-size:6em}.editormd-logo-7x{font-size:7em}.editormd-logo-8x{font-size:8em}.editormd-logo-color{color:#2196F3}
/*! Editor.md v1.5.0 | /editormd.logo.min.css | Open source online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2019-05-11 */
/*! prefixes.scss v0.1.0 | Author: Pandao | https://github.com/pandao/prefixes.scss | MIT license | Copyright (c) 2015 */@font-face{font-family:editormd-logo;src:url(../fonts/editormd-logo.eot?-5y8q6h);src:url(../fonts/editormd-logo.eot?#iefix-5y8q6h) format("embedded-opentype"),url(../fonts/editormd-logo.woff?-5y8q6h) format("woff"),url(../fonts/editormd-logo.ttf?-5y8q6h) format("truetype"),url(../fonts/editormd-logo.svg?-5y8q6h#icomoon) format("svg");font-weight:400;font-style:normal}.editormd-logo,.editormd-logo-1x,.editormd-logo-2x,.editormd-logo-3x,.editormd-logo-4x,.editormd-logo-5x,.editormd-logo-6x,.editormd-logo-7x,.editormd-logo-8x{font-family:editormd-logo;speak:none;font-style:normal;font-weight:400;font-variant:normal;text-transform:none;font-size:inherit;line-height:1;display:inline-block;text-rendering:auto;vertical-align:inherit;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.editormd-logo-1x:before,.editormd-logo-2x:before,.editormd-logo-3x:before,.editormd-logo-4x:before,.editormd-logo-5x:before,.editormd-logo-6x:before,.editormd-logo-7x:before,.editormd-logo-8x:before,.editormd-logo:before{content:"\e1987"}.editormd-logo-1x{font-size:1em}.editormd-logo-lg{font-size:1.2em}.editormd-logo-2x{font-size:2em}.editormd-logo-3x{font-size:3em}.editormd-logo-4x{font-size:4em}.editormd-logo-5x{font-size:5em}.editormd-logo-6x{font-size:6em}.editormd-logo-7x{font-size:7em}.editormd-logo-8x{font-size:8em}.editormd-logo-color{color:#2196F3}

6
css/editormd.min.css

File diff suppressed because one or more lines are too long

6
css/editormd.preview.css

@ -1,13 +1,13 @@
/*
* Editor.md
*
* @file editormd.preview.css
* @file /editormd.preview.css
* @version v1.5.0
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-06-09
* @updateTime 2019-05-11
*/
@charset "UTF-8";
@ -2365,7 +2365,7 @@
@font-face {
font-family: 'editormd-logo';
src: url("../fonts/editormd-logo.eot?-5y8q6h");
src: url(".../fonts/editormd-logo.eot?#iefix-5y8q6h") format("embedded-opentype"), url("../fonts/editormd-logo.woff?-5y8q6h") format("woff"), url("../fonts/editormd-logo.ttf?-5y8q6h") format("truetype"), url("../fonts/editormd-logo.svg?-5y8q6h#icomoon") format("svg");
src: url("../fonts/editormd-logo.eot?#iefix-5y8q6h") format("embedded-opentype"), url("../fonts/editormd-logo.woff?-5y8q6h") format("woff"), url("../fonts/editormd-logo.ttf?-5y8q6h") format("truetype"), url("../fonts/editormd-logo.svg?-5y8q6h#icomoon") format("svg");
font-weight: normal;
font-style: normal;
}

4
css/editormd.preview.min.css

File diff suppressed because one or more lines are too long

182
editormd.amd.js

@ -7,7 +7,7 @@
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-06-09
* @updateTime 2019-05-11
*/
;(function(factory) {
@ -16,20 +16,20 @@
// CommonJS/Node.js
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
{
module.exports = factory;
module.exports = factory();
}
else if (typeof define === "function") // AMD/CMD/Sea.js
{
if (define.amd) // for Require.js
{
var cmModePath = "./lib/codemirror/mode/";
var cmAddonPath = "./lib/codemirror/addon/";
var cmModePath = "codemirror/mode/";
var cmAddonPath = "codemirror/addon/";
var codeMirrorModules = [
"jquery", "marked", "prettify",
"katex", "raphael", "underscore", "flowchart", "jqueryflowchart", "sequenceDiagram",
"./lib/codemirror/lib/codemirror",
"codemirror/lib/codemirror",
cmModePath + "css/css",
cmModePath + "sass/sass",
cmModePath + "shell/shell",
@ -110,7 +110,7 @@
"use strict";
var $ = (typeof (jQuery) !== "undefined") ? jQuery : Zepto;
var $ = (typeof (window.jQuery) !== "undefined") ? window.jQuery : window.Zepto;
if (typeof ($) === "undefined") {
return ;
@ -194,7 +194,7 @@
styleSelectedText : true,
matchWordHighlight : true, // options: true, false, "onselected"
styleActiveLine : true, // Highlight the current line
dialogLockScreen : true,
dialogLockScreen : false,
dialogShowMask : true,
dialogDraggable : true,
dialogMaskBgColor : "#fff",
@ -374,7 +374,8 @@
},
preformattedText : {
title : "添加预格式文本或代码块",
emptyAlert : "错误:请填写预格式文本或代码的内容。"
emptyAlert : "错误:请填写预格式文本或代码的内容。",
placeholder : "Coding now...."
},
codeBlock : {
title : "添加代码块",
@ -382,7 +383,8 @@
selectDefaultText : "请选择代码语言",
otherLanguage : "其他语言",
unselectedLanguageAlert : "错误:请选择代码所属的语言类型。",
codeEmptyAlert : "错误:请填写代码内容。"
codeEmptyAlert : "错误:请填写代码内容。",
placeholder : "Coding now...."
},
htmlEntities : {
title : "HTML 实体字符"
@ -433,9 +435,8 @@
options = id;
}
var _this = this;
var classPrefix = this.classPrefix = editormd.classPrefix;
var settings = this.settings = $.extend(true, editormd.defaults, options);
var settings = this.settings = $.extend(true, {}, editormd.defaults, options);
id = (typeof id === "object") ? settings.id : id;
@ -523,9 +524,9 @@
if (typeof define === "function" && define.amd)
{
if (typeof katex !== "undefined")
if (typeof window.katex !== "undefined")
{
editormd.$katex = katex;
editormd.$katex = window.katex;
}
if (settings.searchReplace && !settings.readOnly)
@ -537,12 +538,12 @@
if ((typeof define === "function" && define.amd) || !settings.autoLoadModules)
{
if (typeof CodeMirror !== "undefined") {
editormd.$CodeMirror = CodeMirror;
if (typeof window.CodeMirror !== "undefined") {
editormd.$CodeMirror = window.CodeMirror;
}
if (typeof marked !== "undefined") {
editormd.$marked = marked;
if (typeof window.marked !== "undefined") {
editormd.$marked = window.marked;
}
this.setCodeMirror().setToolbar().loadedDisplay();
@ -883,7 +884,6 @@
}
var cm = this.cm;
var editor = this.editor;
var count = cm.lineCount();
var preview = this.preview;
@ -1182,7 +1182,6 @@
}
var editor = this.editor;
var preview = this.preview;
var classPrefix = this.classPrefix;
var toolbar = this.toolbar = editor.children("." + classPrefix + "toolbar");
@ -1317,7 +1316,7 @@
var toolbarIcons = this.toolbarIcons = toolbar.find("." + classPrefix + "menu > li > a");
var toolbarIconHandlers = this.getToolbarHandles();
toolbarIcons.bind(editormd.mouseOrTouch("click", "touchend"), function(event) {
toolbarIcons.bind("click", function() {
var icon = $(this).children(".fa");
var name = icon.attr("name");
@ -1395,7 +1394,7 @@
var infoDialog = this.infoDialog = editor.children("." + classPrefix + "dialog-info");
infoDialog.find("." + classPrefix + "dialog-close").bind(editormd.mouseOrTouch("click", "touchend"), function() {
infoDialog.find("." + classPrefix + "dialog-close").bind("click", function() {
_this.hideInfoDialog();
});
@ -1441,7 +1440,6 @@
$("html,body").css("overflow-x", "hidden");
var _this = this;
var editor = this.editor;
var settings = this.settings;
var infoDialog = this.infoDialog = editor.children("." + this.classPrefix + "dialog-info");
@ -1504,7 +1502,6 @@
*/
recreate : function() {
var _this = this;
var editor = this.editor;
var settings = this.settings;
@ -1699,17 +1696,17 @@
{
case 120:
$.proxy(toolbarHandlers["watch"], _this)();
return false;
event.stopPropagation();
break;
case 121:
$.proxy(toolbarHandlers["preview"], _this)();
return false;
event.stopPropagation();
break;
case 122:
$.proxy(toolbarHandlers["fullscreen"], _this)();
return false;
event.stopPropagation();
break;
default:
@ -1837,8 +1834,7 @@
return this;
}
cm.on("change", function(_cm, changeObj) {
cm.on("change", function() {
if (settings.watch)
{
_this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
@ -1987,7 +1983,7 @@
if(settings.watch)
{
codeMirror.width(editor.width() / 2);
codeMirror.width((editor.width() / 2) - 1);
preview.width((!state.preview) ? editor.width() / 2 : editor.width());
this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
@ -2085,13 +2081,8 @@
marked.setOptions(markedOptions);
var newMarkdownDoc = editormd.$marked(cmValue, markedOptions);
//console.info("cmValue", cmValue, newMarkdownDoc);
newMarkdownDoc = editormd.filterHTMLTags(newMarkdownDoc, settings.htmlDecode);
//console.error("cmValue", cmValue, newMarkdownDoc);
this.markdownTextarea.text(cmValue);
cm.save();
@ -2297,7 +2288,6 @@
*/
appendMarkdown : function(md) {
var settings = this.settings;
var cm = this.cm;
cm.setValue(cm.getValue() + md);
@ -2533,6 +2523,19 @@
return this;
},
/**
* 消毁并移除编辑器实例
*
* destroy & remove editor
*
* @returns {void} void 无返回值
*/
destroy : function () {
this.hide();
this.editor.remove();
},
/**
* 隐藏编辑器部分只预览HTML
* Enter preview html state
@ -2554,6 +2557,8 @@
return this;
}
var editorHeight = this.editor.outerHeight();
if (settings.toolbar && toolbar) {
toolbar.toggle();
toolbar.find(".fa[name=preview]").toggleClass("active");
@ -2571,11 +2576,15 @@
{
this.state.preview = true;
if (this.settings.autoHeight) {
this.editor.css("height", editorHeight);
}
if (this.state.fullscreen) {
preview.css("background", "#fff");
}
editor.find("." + this.classPrefix + "preview-close-btn").show().bind(editormd.mouseOrTouch("click", "touchend"), function(){
editor.find("." + this.classPrefix + "preview-close-btn").show().bind("click", function(){
_this.previewed();
});
@ -2637,7 +2646,7 @@
preview[(settings.watch) ? "show" : "hide"]();
previewCloseBtn.hide().unbind(editormd.mouseOrTouch("click", "touchend"));
previewCloseBtn.hide().unbind("click");
previewContainer.removeClass(this.classPrefix + "preview-active");
@ -2646,6 +2655,10 @@
previewContainer.css("padding", "20px");
}
if (this.settings.autoHeight) {
this.editor.css("height", "auto");
}
preview.css({
background : null,
position : "absolute",
@ -2674,7 +2687,6 @@
var _this = this;
var state = this.state;
var editor = this.editor;
var preview = this.preview;
var toolbar = this.toolbar;
var settings = this.settings;
var fullscreenClass = this.classPrefix + "fullscreen";
@ -2972,7 +2984,6 @@
lowercase : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var selections = cm.listSelections();
@ -3084,7 +3095,6 @@
"list-ul" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
if (selection === "")
@ -3106,7 +3116,6 @@
"list-ol" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
if(selection === "")
@ -3129,7 +3138,6 @@
hr : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
cm.replaceSelection(((cursor.ch !== 0) ? "\n\n" : "\n") + "------------\n\n");
},
@ -3168,7 +3176,6 @@
}
var cm = this.cm;
var selection = cm.getSelection();
cm.replaceSelection("\r\n[========]\r\n");
},
@ -3203,8 +3210,6 @@
datetime : function() {
var cm = this.cm;
var selection = cm.getSelection();
var date = new Date();
var langName = this.settings.lang.name;
var datefmt = editormd.dateFormat() + " " + editormd.dateFormat((langName === "zh-cn" || langName === "zh-tw") ? "cn-week-day" : "week-day");
@ -3252,6 +3257,9 @@
}
};
// var isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
// var key = isMac ? "Cmd" : "Ctrl";
editormd.keyMaps = {
"Ctrl-1" : "h1",
"Ctrl-2" : "h2",
@ -3261,7 +3269,6 @@
"Ctrl-6" : "h6",
"Ctrl-B" : "bold", // if this is string == editormd.toolbarHandlers.xxxx
"Ctrl-D" : "datetime",
"Ctrl-E" : function() { // emoji
var cm = this.cm;
var cursor = cm.getCursor();
@ -3283,7 +3290,6 @@
"Ctrl-H" : "hr",
"Ctrl-I" : "italic",
"Ctrl-K" : "code",
"Ctrl-L" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3298,7 +3304,6 @@
}
},
"Ctrl-U" : "list-ul",
"Shift-Ctrl-A" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3316,12 +3321,10 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
"Shift-Ctrl-C" : "code",
"Shift-Ctrl-Q" : "quote",
"Shift-Ctrl-S" : "del",
"Shift-Ctrl-K" : "tex", // KaTeX
"Shift-Alt-C" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3333,7 +3336,6 @@
cm.setCursor(cursor.line, cursor.ch + 3);
}
},
"Shift-Ctrl-Alt-C" : "code-block",
"Shift-Ctrl-H" : "html-entities",
"Shift-Alt-H" : "help",
@ -3342,21 +3344,19 @@
"Shift-Alt-U" : "ucwords",
"Shift-Ctrl-Alt-U" : "ucfirst",
"Shift-Alt-L" : "lowercase",
"Shift-Ctrl-I" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var title = (selection === "") ? "" : " \""+selection+"\"";
var title = (selection === "") ? "" : " \"" + selection + "\"";
cm.replaceSelection("![" + selection + "]("+title+")");
cm.replaceSelection("![" + selection + "](" + title + ")");
if (selection === "") {
cm.setCursor(cursor.line, cursor.ch + 4);
}
},
"Shift-Ctrl-Alt-I" : "image",
"Shift-Ctrl-L" : "link",
"Shift-Ctrl-O" : "list-ol",
@ -3412,8 +3412,6 @@
});
};
var ucfirst = firstUpperCase;
editormd.firstUpperCase = editormd.ucfirst = firstUpperCase;
editormd.urls = {
@ -3425,7 +3423,7 @@
email : /(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,
emailLink : /(mailto:)?([\w\.\_]+)@(\w+)\.(\w+)\.?(\w+)?/g,
emoji : /:([\w\+-]+):/g,
emojiDatetime : /(\d{2}:\d{2}:\d{2})/g,
emojiDatetime : /(\d{1,2}:\d{1,2}:\d{1,2})/g,
twemoji : /:(tw-([\w]+)-?(\w+)?):/g,
fontAwesome : /:(fa-([\w]+)(-(\w+)){0,}):/g,
editormdLogo : /:(editormd-logo-?(\w+)?):/g,
@ -3434,7 +3432,7 @@
// Emoji graphics files url path
editormd.emoji = {
path : "http://www.emoji-cheat-sheet.com/graphics/emojis/",
path : "https://www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/",
ext : ".png"
};
@ -3500,7 +3498,7 @@
matchs[i] = ":\\+1:";
}
text = text.replace(new RegExp(matchs[i]), function($1, $2){
text = text.replace(new RegExp(matchs[i]), function($1) {
var faMatchs = $1.match(faIconReg);
var name = $1.replace(/:/g, "");
@ -3581,14 +3579,14 @@
if (this.options.sanitize) {
try {
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g,"").toLowerCase();
} catch(e) {
return "";
}
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, "").toLowerCase();
if (prot.indexOf("javascript:") === 0) {
return "";
}
} catch(e) {
return "";
}
}
var out = "<a href=\"" + href + "\"";
@ -3612,11 +3610,11 @@
return out;
};
markedRenderer.heading = function(text, level, raw) {
markedRenderer.heading = function(text, level) {
var linkText = text;
var hasLinkReg = /\s*\<a\s*href\=\"(.*)\"\s*([^\>]*)\>(.*)\<\/a\>\s*/;
var getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
// var getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
if (hasLinkReg.test(text))
{
@ -3688,7 +3686,7 @@
: ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "<p" + isTeXAddClass + ">" + this.atLink(this.emoji(text)) + "</p>\n" );
};
markedRenderer.code = function (code, lang, escaped) {
markedRenderer.code = function (code, lang) {
if (lang === "seq" || lang === "sequence")
{
@ -3879,7 +3877,7 @@
editormd.filterHTMLTags = function(html, filters) {
if (typeof html !== "string") {
html = new String(html);
html = html.toString();
}
if (typeof filters !== "string") {
@ -3917,7 +3915,9 @@
var $attrs = {};
$.each(_attrs, function(i, e) {
if (e.nodeName !== '"') $attrs[e.nodeName] = e.nodeValue;
if (e.nodeName !== "\"") {
$attrs[e.nodeName] = e.nodeValue;
}
});
$.each($attrs, function(i) {
@ -3988,7 +3988,7 @@
editormd.$marked = marked;
var div = $("#" + id);
var settings = div.settings = $.extend(true, defaults, options || {});
var settings = div.settings = $.extend(true, {}, defaults, options || {});
var saveTo = div.find("textarea");
if (saveTo.length < 1)
@ -4026,7 +4026,7 @@
smartypants : true
};
markdownDoc = new String(markdownDoc);
markdownDoc = markdownDoc.toString();
var markdownParsed = marked(markdownDoc, markedOptions);
@ -4193,8 +4193,8 @@
}
};
editormd.isIE = (navigator.appName == "Microsoft Internet Explorer");
editormd.isIE8 = (editormd.isIE && navigator.appVersion.match(/8./i) == "8.");
editormd.isIE = (navigator.appName === "Microsoft Internet Explorer");
editormd.isIE8 = (editormd.isIE && navigator.appVersion.match(/8./i) === "8.");
/**
* 动态加载JS文件的方法
@ -4248,8 +4248,8 @@
// 使用国外的CDN,加载速度有时会很慢,或者自定义URL
// You can custom KaTeX load url.
editormd.katexURL = {
css : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min",
js : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min"
css : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min",
js : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min"
};
editormd.kaTeXLoaded = false;
@ -4295,6 +4295,7 @@
title : "",
drag : true,
closed : true,
cached : false,
content : "",
mask : true,
maskStyle : {
@ -4313,8 +4314,6 @@
var classPrefix = editormd.classPrefix;
var guid = (new Date()).getTime();
var dialogName = ( (options.name === "") ? classPrefix + "dialog-" + guid : options.name);
var mouseOrTouch = editormd.mouseOrTouch;
var html = "<div class=\"" + classPrefix + "dialog " + dialogName + "\">";
if (options.title !== "")
@ -4337,7 +4336,6 @@
}
html += "</div>";
html += "<div class=\"" + classPrefix + "dialog-mask " + classPrefix + "dialog-mask-bg\"></div>";
html += "<div class=\"" + classPrefix + "dialog-mask " + classPrefix + "dialog-mask-con\"></div>";
html += "</div>";
@ -4400,8 +4398,12 @@
$(window).resize(dialogPosition);
dialog.children("." + classPrefix + "dialog-close").bind(mouseOrTouch("click", "touchend"), function() {
dialog.children("." + classPrefix + "dialog-close").bind("click", function() {
dialog.hide().lockScreen(false).hideMask();
if (!options.cached) {
dialog.remove();
}
});
if (typeof options.buttons === "object")
@ -4415,7 +4417,7 @@
footer.append("<button class=\"" + classPrefix + "btn " + btnClassName + "\">" + btn[0] + "</button>");
btn[1] = $.proxy(btn[1], dialog);
footer.children("." + btnClassName).bind(mouseOrTouch("click", "touchend"), btn[1]);
footer.children("." + btnClassName).bind("click", btn[1]);
}
}
@ -4425,26 +4427,18 @@
var dialogHeader = dialog.children("." + classPrefix + "dialog-header");
if (!options.mask) {
dialogHeader.bind(mouseOrTouch("click", "touchend"), function(){
dialogHeader.bind("click", function(){
editormd.dialogZindex += 2;
dialog.css("z-index", editormd.dialogZindex);
});
}
dialogHeader.mousedown(function(e) {
e = e || window.event; //IE
posX = e.clientX - parseInt(dialog[0].style.left);
posY = e.clientY - parseInt(dialog[0].style.top);
document.onmousemove = moveAction;
});
var userCanSelect = function (obj) {
obj.removeClass(classPrefix + "user-unselect").off("selectstart");
};
var userUnselect = function (obj) {
obj.addClass(classPrefix + "user-unselect").on("selectstart", function(event) { // selectstart for IE
obj.addClass(classPrefix + "user-unselect").on("selectstart", function() { // selectstart for IE
return false;
});
};
@ -4484,6 +4478,14 @@
dialog[0].style.top = top + "px";
};
dialogHeader.mousedown(function(e) {
e = e || window.event; //IE
posX = e.clientX - parseInt(dialog[0].style.left);
posY = e.clientY - parseInt(dialog[0].style.top);
document.onmousemove = moveAction;
});
document.onmouseup = function() {
userCanSelect($("body"));
userCanSelect(dialog);

6
editormd.amd.min.js

File diff suppressed because one or more lines are too long

181
editormd.js

@ -7,7 +7,7 @@
* @license MIT License
* @author Pandao
* {@link https://github.com/pandao/editor.md}
* @updateTime 2015-06-09
* @updateTime 2019-05-11
*/
;(function(factory) {
@ -16,7 +16,7 @@
// CommonJS/Node.js
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
{
module.exports = factory;
module.exports = factory();
}
else if (typeof define === "function") // AMD/CMD/Sea.js
{
@ -40,7 +40,7 @@
"use strict";
var $ = (typeof (jQuery) !== "undefined") ? jQuery : Zepto;
var $ = (typeof (window.jQuery) !== "undefined") ? window.jQuery : window.Zepto;
if (typeof ($) === "undefined") {
return ;
@ -124,7 +124,7 @@
styleSelectedText : true,
matchWordHighlight : true, // options: true, false, "onselected"
styleActiveLine : true, // Highlight the current line
dialogLockScreen : true,
dialogLockScreen : false,
dialogShowMask : true,
dialogDraggable : true,
dialogMaskBgColor : "#fff",
@ -304,7 +304,8 @@
},
preformattedText : {
title : "添加预格式文本或代码块",
emptyAlert : "错误:请填写预格式文本或代码的内容。"
emptyAlert : "错误:请填写预格式文本或代码的内容。",
placeholder : "Coding now...."
},
codeBlock : {
title : "添加代码块",
@ -312,7 +313,8 @@
selectDefaultText : "请选择代码语言",
otherLanguage : "其他语言",
unselectedLanguageAlert : "错误:请选择代码所属的语言类型。",
codeEmptyAlert : "错误:请填写代码内容。"
codeEmptyAlert : "错误:请填写代码内容。",
placeholder : "Coding now...."
},
htmlEntities : {
title : "HTML 实体字符"
@ -363,7 +365,6 @@
options = id;
}
var _this = this;
var classPrefix = this.classPrefix = editormd.classPrefix;
var settings = this.settings = $.extend(true, {}, editormd.defaults, options);
@ -453,9 +454,9 @@
if (typeof define === "function" && define.amd)
{
if (typeof katex !== "undefined")
if (typeof window.katex !== "undefined")
{
editormd.$katex = katex;
editormd.$katex = window.katex;
}
if (settings.searchReplace && !settings.readOnly)
@ -467,12 +468,12 @@
if ((typeof define === "function" && define.amd) || !settings.autoLoadModules)
{
if (typeof CodeMirror !== "undefined") {
editormd.$CodeMirror = CodeMirror;
if (typeof window.CodeMirror !== "undefined") {
editormd.$CodeMirror = window.CodeMirror;
}
if (typeof marked !== "undefined") {
editormd.$marked = marked;
if (typeof window.marked !== "undefined") {
editormd.$marked = window.marked;
}
this.setCodeMirror().setToolbar().loadedDisplay();
@ -813,7 +814,6 @@
}
var cm = this.cm;
var editor = this.editor;
var count = cm.lineCount();
var preview = this.preview;
@ -1112,7 +1112,6 @@
}
var editor = this.editor;
var preview = this.preview;
var classPrefix = this.classPrefix;
var toolbar = this.toolbar = editor.children("." + classPrefix + "toolbar");
@ -1247,7 +1246,7 @@
var toolbarIcons = this.toolbarIcons = toolbar.find("." + classPrefix + "menu > li > a");
var toolbarIconHandlers = this.getToolbarHandles();
toolbarIcons.bind(editormd.mouseOrTouch("click", "touchend"), function(event) {
toolbarIcons.bind("click", function() {
var icon = $(this).children(".fa");
var name = icon.attr("name");
@ -1325,7 +1324,7 @@
var infoDialog = this.infoDialog = editor.children("." + classPrefix + "dialog-info");
infoDialog.find("." + classPrefix + "dialog-close").bind(editormd.mouseOrTouch("click", "touchend"), function() {
infoDialog.find("." + classPrefix + "dialog-close").bind("click", function() {
_this.hideInfoDialog();
});
@ -1371,7 +1370,6 @@
$("html,body").css("overflow-x", "hidden");
var _this = this;
var editor = this.editor;
var settings = this.settings;
var infoDialog = this.infoDialog = editor.children("." + this.classPrefix + "dialog-info");
@ -1434,7 +1432,6 @@
*/
recreate : function() {
var _this = this;
var editor = this.editor;
var settings = this.settings;
@ -1629,17 +1626,17 @@
{
case 120:
$.proxy(toolbarHandlers["watch"], _this)();
return false;
event.stopPropagation();
break;
case 121:
$.proxy(toolbarHandlers["preview"], _this)();
return false;
event.stopPropagation();
break;
case 122:
$.proxy(toolbarHandlers["fullscreen"], _this)();
return false;
event.stopPropagation();
break;
default:
@ -1767,8 +1764,7 @@
return this;
}
cm.on("change", function(_cm, changeObj) {
cm.on("change", function() {
if (settings.watch)
{
_this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
@ -1917,7 +1913,7 @@
if(settings.watch)
{
codeMirror.width(editor.width() / 2);
codeMirror.width((editor.width() / 2) - 1);
preview.width((!state.preview) ? editor.width() / 2 : editor.width());
this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
@ -1965,15 +1961,14 @@
save : function() {
var _this = this;
var state = this.state;
var settings = this.settings;
if (timer === null && !(!settings.watch && state.preview))
if (timer === null)
{
return this;
}
var _this = this;
var state = this.state;
var settings = this.settings;
var cm = this.cm;
var cmValue = cm.getValue();
var previewContainer = this.previewContainer;
@ -2016,13 +2011,8 @@
marked.setOptions(markedOptions);
var newMarkdownDoc = editormd.$marked(cmValue, markedOptions);
//console.info("cmValue", cmValue, newMarkdownDoc);
newMarkdownDoc = editormd.filterHTMLTags(newMarkdownDoc, settings.htmlDecode);
//console.error("cmValue", cmValue, newMarkdownDoc);
this.markdownTextarea.text(cmValue);
cm.save();
@ -2228,7 +2218,6 @@
*/
appendMarkdown : function(md) {
var settings = this.settings;
var cm = this.cm;
cm.setValue(cm.getValue() + md);
@ -2464,6 +2453,19 @@
return this;
},
/**
* 消毁并移除编辑器实例
*
* destroy & remove editor
*
* @returns {void} void 无返回值
*/
destroy : function () {
this.hide();
this.editor.remove();
},
/**
* 隐藏编辑器部分只预览HTML
* Enter preview html state
@ -2485,6 +2487,8 @@
return this;
}
var editorHeight = this.editor.outerHeight();
if (settings.toolbar && toolbar) {
toolbar.toggle();
toolbar.find(".fa[name=preview]").toggleClass("active");
@ -2502,11 +2506,15 @@
{
this.state.preview = true;
if (this.settings.autoHeight) {
this.editor.css("height", editorHeight);
}
if (this.state.fullscreen) {
preview.css("background", "#fff");
}
editor.find("." + this.classPrefix + "preview-close-btn").show().bind(editormd.mouseOrTouch("click", "touchend"), function(){
editor.find("." + this.classPrefix + "preview-close-btn").show().bind("click", function(){
_this.previewed();
});
@ -2568,7 +2576,7 @@
preview[(settings.watch) ? "show" : "hide"]();
previewCloseBtn.hide().unbind(editormd.mouseOrTouch("click", "touchend"));
previewCloseBtn.hide().unbind("click");
previewContainer.removeClass(this.classPrefix + "preview-active");
@ -2577,6 +2585,10 @@
previewContainer.css("padding", "20px");
}
if (this.settings.autoHeight) {
this.editor.css("height", "auto");
}
preview.css({
background : null,
position : "absolute",
@ -2605,7 +2617,6 @@
var _this = this;
var state = this.state;
var editor = this.editor;
var preview = this.preview;
var toolbar = this.toolbar;
var settings = this.settings;
var fullscreenClass = this.classPrefix + "fullscreen";
@ -2903,7 +2914,6 @@
lowercase : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var selections = cm.listSelections();
@ -3015,7 +3025,6 @@
"list-ul" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
if (selection === "")
@ -3037,7 +3046,6 @@
"list-ol" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
if(selection === "")
@ -3060,7 +3068,6 @@
hr : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
cm.replaceSelection(((cursor.ch !== 0) ? "\n\n" : "\n") + "------------\n\n");
},
@ -3099,7 +3106,6 @@
}
var cm = this.cm;
var selection = cm.getSelection();
cm.replaceSelection("\r\n[========]\r\n");
},
@ -3134,8 +3140,6 @@
datetime : function() {
var cm = this.cm;
var selection = cm.getSelection();
var date = new Date();
var langName = this.settings.lang.name;
var datefmt = editormd.dateFormat() + " " + editormd.dateFormat((langName === "zh-cn" || langName === "zh-tw") ? "cn-week-day" : "week-day");
@ -3183,6 +3187,9 @@
}
};
// var isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
// var key = isMac ? "Cmd" : "Ctrl";
editormd.keyMaps = {
"Ctrl-1" : "h1",
"Ctrl-2" : "h2",
@ -3192,7 +3199,6 @@
"Ctrl-6" : "h6",
"Ctrl-B" : "bold", // if this is string == editormd.toolbarHandlers.xxxx
"Ctrl-D" : "datetime",
"Ctrl-E" : function() { // emoji
var cm = this.cm;
var cursor = cm.getCursor();
@ -3214,7 +3220,6 @@
"Ctrl-H" : "hr",
"Ctrl-I" : "italic",
"Ctrl-K" : "code",
"Ctrl-L" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3229,7 +3234,6 @@
}
},
"Ctrl-U" : "list-ul",
"Shift-Ctrl-A" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3247,12 +3251,10 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
"Shift-Ctrl-C" : "code",
"Shift-Ctrl-Q" : "quote",
"Shift-Ctrl-S" : "del",
"Shift-Ctrl-K" : "tex", // KaTeX
"Shift-Alt-C" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3264,7 +3266,6 @@
cm.setCursor(cursor.line, cursor.ch + 3);
}
},
"Shift-Ctrl-Alt-C" : "code-block",
"Shift-Ctrl-H" : "html-entities",
"Shift-Alt-H" : "help",
@ -3273,21 +3274,19 @@
"Shift-Alt-U" : "ucwords",
"Shift-Ctrl-Alt-U" : "ucfirst",
"Shift-Alt-L" : "lowercase",
"Shift-Ctrl-I" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var title = (selection === "") ? "" : " \""+selection+"\"";
var title = (selection === "") ? "" : " \"" + selection + "\"";
cm.replaceSelection("![" + selection + "]("+title+")");
cm.replaceSelection("![" + selection + "](" + title + ")");
if (selection === "") {
cm.setCursor(cursor.line, cursor.ch + 4);
}
},
"Shift-Ctrl-Alt-I" : "image",
"Shift-Ctrl-L" : "link",
"Shift-Ctrl-O" : "list-ol",
@ -3343,8 +3342,6 @@
});
};
var ucfirst = firstUpperCase;
editormd.firstUpperCase = editormd.ucfirst = firstUpperCase;
editormd.urls = {
@ -3356,7 +3353,7 @@
email : /(\w+)@(\w+)\.(\w+)\.?(\w+)?/g,
emailLink : /(mailto:)?([\w\.\_]+)@(\w+)\.(\w+)\.?(\w+)?/g,
emoji : /:([\w\+-]+):/g,
emojiDatetime : /(\d{2}:\d{2}:\d{2})/g,
emojiDatetime : /(\d{1,2}:\d{1,2}:\d{1,2})/g,
twemoji : /:(tw-([\w]+)-?(\w+)?):/g,
fontAwesome : /:(fa-([\w]+)(-(\w+)){0,}):/g,
editormdLogo : /:(editormd-logo-?(\w+)?):/g,
@ -3431,7 +3428,7 @@
matchs[i] = ":\\+1:";
}
text = text.replace(new RegExp(matchs[i]), function($1, $2){
text = text.replace(new RegExp(matchs[i]), function($1) {
var faMatchs = $1.match(faIconReg);
var name = $1.replace(/:/g, "");
@ -3512,14 +3509,14 @@
if (this.options.sanitize) {
try {
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g,"").toLowerCase();
} catch(e) {
return "";
}
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, "").toLowerCase();
if (prot.indexOf("javascript:") === 0) {
return "";
}
} catch(e) {
return "";
}
}
var out = "<a href=\"" + href + "\"";
@ -3543,11 +3540,11 @@
return out;
};
markedRenderer.heading = function(text, level, raw) {
markedRenderer.heading = function(text, level) {
var linkText = text;
var hasLinkReg = /\s*\<a\s*href\=\"(.*)\"\s*([^\>]*)\>(.*)\<\/a\>\s*/;
var getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
// var getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
if (hasLinkReg.test(text))
{
@ -3619,7 +3616,7 @@
: ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "<p" + isTeXAddClass + ">" + this.atLink(this.emoji(text)) + "</p>\n" );
};
markedRenderer.code = function (code, lang, escaped) {
markedRenderer.code = function (code, lang) {
if (lang === "seq" || lang === "sequence")
{
@ -3810,7 +3807,7 @@
editormd.filterHTMLTags = function(html, filters) {
if (typeof html !== "string") {
html = new String(html);
html = html.toString();
}
if (typeof filters !== "string") {
@ -3848,7 +3845,9 @@
var $attrs = {};
$.each(_attrs, function(i, e) {
if (e.nodeName !== '"') $attrs[e.nodeName] = e.nodeValue;
if (e.nodeName !== "\"") {
$attrs[e.nodeName] = e.nodeValue;
}
});
$.each($attrs, function(i) {
@ -3919,7 +3918,7 @@
editormd.$marked = marked;
var div = $("#" + id);
var settings = div.settings = $.extend(true, defaults, options || {});
var settings = div.settings = $.extend(true, {}, defaults, options || {});
var saveTo = div.find("textarea");
if (saveTo.length < 1)
@ -3957,7 +3956,7 @@
smartypants : true
};
markdownDoc = new String(markdownDoc);
markdownDoc = markdownDoc.toString();
var markdownParsed = marked(markdownDoc, markedOptions);
@ -4124,8 +4123,8 @@
}
};
editormd.isIE = (navigator.appName == "Microsoft Internet Explorer");
editormd.isIE8 = (editormd.isIE && navigator.appVersion.match(/8./i) == "8.");
editormd.isIE = (navigator.appName === "Microsoft Internet Explorer");
editormd.isIE8 = (editormd.isIE && navigator.appVersion.match(/8./i) === "8.");
/**
* 动态加载JS文件的方法
@ -4179,8 +4178,8 @@
// 使用国外的CDN,加载速度有时会很慢,或者自定义URL
// You can custom KaTeX load url.
editormd.katexURL = {
css : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min",
js : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min"
css : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min",
js : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min"
};
editormd.kaTeXLoaded = false;
@ -4226,6 +4225,7 @@
title : "",
drag : true,
closed : true,
cached : false,
content : "",
mask : true,
maskStyle : {
@ -4244,8 +4244,6 @@
var classPrefix = editormd.classPrefix;
var guid = (new Date()).getTime();
var dialogName = ( (options.name === "") ? classPrefix + "dialog-" + guid : options.name);
var mouseOrTouch = editormd.mouseOrTouch;
var html = "<div class=\"" + classPrefix + "dialog " + dialogName + "\">";
if (options.title !== "")
@ -4268,7 +4266,6 @@
}
html += "</div>";
html += "<div class=\"" + classPrefix + "dialog-mask " + classPrefix + "dialog-mask-bg\"></div>";
html += "<div class=\"" + classPrefix + "dialog-mask " + classPrefix + "dialog-mask-con\"></div>";
html += "</div>";
@ -4331,8 +4328,12 @@
$(window).resize(dialogPosition);
dialog.children("." + classPrefix + "dialog-close").bind(mouseOrTouch("click", "touchend"), function() {
dialog.children("." + classPrefix + "dialog-close").bind("click", function() {
dialog.hide().lockScreen(false).hideMask();
if (!options.cached) {
dialog.remove();
}
});
if (typeof options.buttons === "object")
@ -4346,7 +4347,7 @@
footer.append("<button class=\"" + classPrefix + "btn " + btnClassName + "\">" + btn[0] + "</button>");
btn[1] = $.proxy(btn[1], dialog);
footer.children("." + btnClassName).bind(mouseOrTouch("click", "touchend"), btn[1]);
footer.children("." + btnClassName).bind("click", btn[1]);
}
}
@ -4356,26 +4357,18 @@
var dialogHeader = dialog.children("." + classPrefix + "dialog-header");
if (!options.mask) {
dialogHeader.bind(mouseOrTouch("click", "touchend"), function(){
dialogHeader.bind("click", function(){
editormd.dialogZindex += 2;
dialog.css("z-index", editormd.dialogZindex);
});
}
dialogHeader.mousedown(function(e) {
e = e || window.event; //IE
posX = e.clientX - parseInt(dialog[0].style.left);
posY = e.clientY - parseInt(dialog[0].style.top);
document.onmousemove = moveAction;
});
var userCanSelect = function (obj) {
obj.removeClass(classPrefix + "user-unselect").off("selectstart");
};
var userUnselect = function (obj) {
obj.addClass(classPrefix + "user-unselect").on("selectstart", function(event) { // selectstart for IE
obj.addClass(classPrefix + "user-unselect").on("selectstart", function() { // selectstart for IE
return false;
});
};
@ -4415,6 +4408,14 @@
dialog[0].style.top = top + "px";
};
dialogHeader.mousedown(function(e) {
e = e || window.event; //IE
posX = e.clientX - parseInt(dialog[0].style.left);
posY = e.clientY - parseInt(dialog[0].style.top);
document.onmousemove = moveAction;
});
document.onmouseup = function() {
userCanSelect($("body"));
userCanSelect(dialog);

5
editormd.min.js

File diff suppressed because one or more lines are too long

8
examples/dynamic-create-editormd.html

@ -16,6 +16,7 @@
<div class="btns" style="margin:0;">
<button id="create-btn">动态创建一个 Editor.md</button>
<button id="remove-btn">移除 Editor.md</button>
<button id="destroy-btn">消毁 Editor.md</button>
</div>
</header>
</div>
@ -26,7 +27,7 @@
$(function() {
$("#create-btn").click(function(){
$.getScript("../editormd.js", function() {
$.getScript("../editormd.js?v=20190511", function() {
$("#layout").append("<div id=\"test-editormd\"></div>");
testEditormd = editormd("test-editormd", {
@ -41,6 +42,11 @@
$("#remove-btn").click(function() {
testEditormd.editor.remove();
});
$("#destroy-btn").click(function() {
testEditormd.destroy();
testEditormd = null;
});
});
</script>
</body>

2
examples/form-get-value.html

@ -13,7 +13,7 @@
<h1>表单取值</h1>
<p>Form get textarea value.</p>
</header>
<form method="post" action="http://editormd.ipandao.com/php/post.php">
<form method="post" action="./php/post.php">
<div id="test-editormd">
<!-- Custom textarea name attribute <textarea style="display:none;" name="test-textarea-name"> -->
<textarea style="display:none;">#### Get value

10
examples/katex.html

@ -31,8 +31,8 @@
// Default using CloudFlare KaTeX's CDN
// You can custom url
editormd.katexURL = {
js : "your url", // default: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min
css : "your url" // default: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min
js : "your url", // default: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min
css : "your url" // default: //cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min
};
```
@ -180,6 +180,12 @@ f(x) = \int_{-\infty}^\infty
<script src="../editormd.js"></script>
<script type="text/javascript">
$(function() {
// custom Katex version
// editormd.katexURL = {
// css : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min",
// js : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min"
// };
var testEditor = editormd("test-editormd", {
width: "90%",
height: 640,

25
examples/multi-editormd.html

@ -35,28 +35,29 @@
<script src="js/jquery.min.js"></script>
<script src="../editormd.js"></script>
<script type="text/javascript">
var testEditormd, testEditormd2;
$(function() {
testEditormd = editormd("test-editormd", {
var testEditormd = editormd("test-editormd", {
width: "90%",
height: 480,
markdown : "#### Editor.md A",
path : '../lib/'
});
testEditormd2 = editormd("test-editormd2", {
width: "90%",
height: 480,
markdown : "#### Editor.md B",
path : '../lib/'
var testEditormd2 = editormd("test-editormd2", {
width: "50%",
height: 280,
markdown : "#### Editor.md B\n\n多个 Editor.md 并存",
path : '../lib/',
toolbarIcons: 'mini'
});
testEditormd3 = editormd("test-editormd3", {
width: "90%",
height: 480,
var testEditormd3 = editormd("test-editormd3", {
width: "60%",
height: 380,
markdown : "#### Editor.md C",
path : '../lib/'
path : '../lib/',
toolbarIcons: 'simple',
watch: false
});
});
</script>

2
examples/test.md

@ -95,7 +95,7 @@ GFM a-tail link @pandao 邮箱地址自动链接 test.test@gmail.com www@vip.q
| Content Cell | Content Cell |
| Content Cell | Content Cell |
#### JS代码 
#### JS代码
```javascript
function test() {

4
languages/zh-tw.js

@ -78,7 +78,7 @@
preformattedText : {
title : "添加預格式文本或代碼塊",
emptyAlert : "錯誤:請填寫預格式文本或代碼的內容。",
placeholder : "coding now...."
placeholder : "Coding now...."
},
codeBlock : {
title : "添加代碼塊",
@ -87,7 +87,7 @@
otherLanguage : "其他語言",
unselectedLanguageAlert : "錯誤:請選擇代碼所屬的語言類型。",
codeEmptyAlert : "錯誤:請填寫代碼內容。",
placeholder: : "coding now...."
placeholder : "Coding now...."
},
htmlEntities : {
title : "HTML實體字符"

6
lib/codemirror/addons.min.js

File diff suppressed because one or more lines are too long

12
lib/codemirror/modes.min.js

File diff suppressed because one or more lines are too long

11
lib/marked.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -8,6 +8,8 @@
"test": "tests"
},
"scripts": {
"dev": "gulp watch",
"build": "gulp",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {

4
plugins/code-block-dialog/code-block-dialog.js

@ -127,11 +127,15 @@
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

4
plugins/emoji-dialog/emoji-dialog.js

@ -128,11 +128,15 @@
cm.replaceSelection(selecteds.join(" "));
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

4
plugins/goto-line-dialog/goto-line-dialog.js

@ -108,12 +108,16 @@
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

2
plugins/help-dialog/help-dialog.js

@ -47,6 +47,8 @@
close : [lang.buttons.close, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

4
plugins/html-entities-dialog/html-entities-dialog.js

@ -72,11 +72,15 @@
cm.replaceSelection(selecteds.join(" "));
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

2
plugins/image-dialog/image-dialog.js

@ -108,7 +108,6 @@
this.hide().lockScreen(false).hideMask();
//删除对话框
this.remove();
return false;
@ -117,7 +116,6 @@
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
//删除对话框
this.remove();
return false;

4
plugins/link-dialog/link-dialog.js

@ -90,12 +90,16 @@
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

2
plugins/preformatted-text-dialog/preformatted-text-dialog.js

@ -82,11 +82,13 @@
cm.replaceSelection(codeTexts);
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]

4
plugins/reference-link-dialog/reference-link-dialog.js

@ -99,11 +99,15 @@
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

4
plugins/table-dialog/table-dialog.js

@ -155,12 +155,16 @@
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}],
cancel : [lang.buttons.cancel, function() {
this.hide().lockScreen(false).hideMask();
this.remove();
return false;
}]
}

231
src/editormd.js

@ -4,7 +4,7 @@
// CommonJS/Node.js
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
{
module.exports = factory;
module.exports = factory();
}
else if (typeof define === "function") // AMD/CMD/Sea.js
{
@ -28,7 +28,7 @@
"use strict";
var $ = (typeof (jQuery) !== "undefined") ? jQuery : Zepto;
var $ = (typeof (window.jQuery) !== "undefined") ? window.jQuery : window.Zepto;
if (typeof ($) === "undefined") {
return ;
@ -112,7 +112,7 @@
styleSelectedText : true,
matchWordHighlight : true, // options: true, false, "onselected"
styleActiveLine : true, // Highlight the current line
dialogLockScreen : true,
dialogLockScreen : false,
dialogShowMask : true,
dialogDraggable : true,
dialogMaskBgColor : "#fff",
@ -292,7 +292,8 @@
},
preformattedText : {
title : "添加预格式文本或代码块",
emptyAlert : "错误:请填写预格式文本或代码的内容。"
emptyAlert : "错误:请填写预格式文本或代码的内容。",
placeholder : "Coding now...."
},
codeBlock : {
title : "添加代码块",
@ -300,7 +301,8 @@
selectDefaultText : "请选择代码语言",
otherLanguage : "其他语言",
unselectedLanguageAlert : "错误:请选择代码所属的语言类型。",
codeEmptyAlert : "错误:请填写代码内容。"
codeEmptyAlert : "错误:请填写代码内容。",
placeholder : "Coding now...."
},
htmlEntities : {
title : "HTML 实体字符"
@ -351,9 +353,8 @@
options = id;
}
var _this = this;
var classPrefix = this.classPrefix = editormd.classPrefix;
var settings = this.settings = $.extend(true, editormd.defaults, options);
var settings = this.settings = $.extend(true, {}, editormd.defaults, options);
id = (typeof id === "object") ? settings.id : id;
@ -441,9 +442,9 @@
if (typeof define === "function" && define.amd)
{
if (typeof katex !== "undefined")
if (typeof window.katex !== "undefined")
{
editormd.$katex = katex;
editormd.$katex = window.katex;
}
if (settings.searchReplace && !settings.readOnly)
@ -455,12 +456,12 @@
if ((typeof define === "function" && define.amd) || !settings.autoLoadModules)
{
if (typeof CodeMirror !== "undefined") {
editormd.$CodeMirror = CodeMirror;
if (typeof window.CodeMirror !== "undefined") {
editormd.$CodeMirror = window.CodeMirror;
}
if (typeof marked !== "undefined") {
editormd.$marked = marked;
if (typeof window.marked !== "undefined") {
editormd.$marked = window.marked;
}
this.setCodeMirror().setToolbar().loadedDisplay();
@ -801,7 +802,6 @@
}
var cm = this.cm;
var editor = this.editor;
var count = cm.lineCount();
var preview = this.preview;
@ -1100,7 +1100,6 @@
}
var editor = this.editor;
var preview = this.preview;
var classPrefix = this.classPrefix;
var toolbar = this.toolbar = editor.children("." + classPrefix + "toolbar");
@ -1235,7 +1234,7 @@
var toolbarIcons = this.toolbarIcons = toolbar.find("." + classPrefix + "menu > li > a");
var toolbarIconHandlers = this.getToolbarHandles();
toolbarIcons.bind(editormd.mouseOrTouch("click", "touchend"), function(event) {
toolbarIcons.bind("click", function() {
var icon = $(this).children(".fa");
var name = icon.attr("name");
@ -1313,7 +1312,7 @@
var infoDialog = this.infoDialog = editor.children("." + classPrefix + "dialog-info");
infoDialog.find("." + classPrefix + "dialog-close").bind(editormd.mouseOrTouch("click", "touchend"), function() {
infoDialog.find("." + classPrefix + "dialog-close").bind("click", function() {
_this.hideInfoDialog();
});
@ -1359,7 +1358,6 @@
$("html,body").css("overflow-x", "hidden");
var _this = this;
var editor = this.editor;
var settings = this.settings;
var infoDialog = this.infoDialog = editor.children("." + this.classPrefix + "dialog-info");
@ -1422,7 +1420,6 @@
*/
recreate : function() {
var _this = this;
var editor = this.editor;
var settings = this.settings;
@ -1617,17 +1614,17 @@
{
case 120:
$.proxy(toolbarHandlers["watch"], _this)();
return false;
event.stopPropagation();
break;
case 121:
$.proxy(toolbarHandlers["preview"], _this)();
return false;
event.stopPropagation();
break;
case 122:
$.proxy(toolbarHandlers["fullscreen"], _this)();
return false;
event.stopPropagation();
break;
default:
@ -1755,8 +1752,7 @@
return this;
}
cm.on("change", function(_cm, changeObj) {
cm.on("change", function() {
if (settings.watch)
{
_this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
@ -1905,7 +1901,7 @@
if(settings.watch)
{
codeMirror.width(editor.width() / 2);
codeMirror.width((editor.width() / 2) - 1);
preview.width((!state.preview) ? editor.width() / 2 : editor.width());
this.previewContainer.css("padding", settings.autoHeight ? "20px 20px 50px 40px" : "20px");
@ -2003,13 +1999,8 @@
marked.setOptions(markedOptions);
var newMarkdownDoc = editormd.$marked(cmValue, markedOptions);
//console.info("cmValue", cmValue, newMarkdownDoc);
newMarkdownDoc = editormd.filterHTMLTags(newMarkdownDoc, settings.htmlDecode);
//console.error("cmValue", cmValue, newMarkdownDoc);
this.markdownTextarea.text(cmValue);
cm.save();
@ -2215,7 +2206,6 @@
*/
appendMarkdown : function(md) {
var settings = this.settings;
var cm = this.cm;
cm.setValue(cm.getValue() + md);
@ -2451,6 +2441,19 @@
return this;
},
/**
* 消毁并移除编辑器实例
*
* destroy & remove editor
*
* @returns {void} void 无返回值
*/
destroy : function () {
this.hide();
this.editor.remove();
},
/**
* 隐藏编辑器部分只预览HTML
* Enter preview html state
@ -2472,6 +2475,8 @@
return this;
}
var editorHeight = this.editor.outerHeight();
if (settings.toolbar && toolbar) {
toolbar.toggle();
toolbar.find(".fa[name=preview]").toggleClass("active");
@ -2489,11 +2494,15 @@
{
this.state.preview = true;
if (this.settings.autoHeight) {
this.editor.css("height", editorHeight);
}
if (this.state.fullscreen) {
preview.css("background", "#fff");
}
editor.find("." + this.classPrefix + "preview-close-btn").show().bind(editormd.mouseOrTouch("click", "touchend"), function(){
editor.find("." + this.classPrefix + "preview-close-btn").show().bind("click", function(){
_this.previewed();
});
@ -2555,7 +2564,7 @@
preview[(settings.watch) ? "show" : "hide"]();
previewCloseBtn.hide().unbind(editormd.mouseOrTouch("click", "touchend"));
previewCloseBtn.hide().unbind("click");
previewContainer.removeClass(this.classPrefix + "preview-active");
@ -2564,6 +2573,10 @@
previewContainer.css("padding", "20px");
}
if (this.settings.autoHeight) {
this.editor.css("height", "auto");
}
preview.css({
background : null,
position : "absolute",
@ -2592,7 +2605,6 @@
var _this = this;
var state = this.state;
var editor = this.editor;
var preview = this.preview;
var toolbar = this.toolbar;
var settings = this.settings;
var fullscreenClass = this.classPrefix + "fullscreen";
@ -2890,7 +2902,6 @@
lowercase : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var selections = cm.listSelections();
@ -3002,7 +3013,6 @@
"list-ul" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
if (selection === "")
@ -3024,7 +3034,6 @@
"list-ol" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
if(selection === "")
@ -3047,7 +3056,6 @@
hr : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
cm.replaceSelection(((cursor.ch !== 0) ? "\n\n" : "\n") + "------------\n\n");
},
@ -3086,7 +3094,6 @@
}
var cm = this.cm;
var selection = cm.getSelection();
cm.replaceSelection("\r\n[========]\r\n");
},
@ -3121,8 +3128,6 @@
datetime : function() {
var cm = this.cm;
var selection = cm.getSelection();
var date = new Date();
var langName = this.settings.lang.name;
var datefmt = editormd.dateFormat() + " " + editormd.dateFormat((langName === "zh-cn" || langName === "zh-tw") ? "cn-week-day" : "week-day");
@ -3170,20 +3175,19 @@
}
};
var isMac = navigator.platform.toUpperCase().indexOf('MAC')>=0;
var key = isMac ? "Cmd" : "Ctrl";
// var isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0;
// var key = isMac ? "Cmd" : "Ctrl";
editormd.keyMaps = {
[key + "-1"] : "h1",
[key + "-2"] : "h2",
[key + "-3"] : "h3",
[key + "-4"] : "h4",
[key + "-5"] : "h5",
[key + "-6"] : "h6",
[key + "-B"] : "bold", // if this is string == editormd.toolbarHandlers.xxxx
[key + "-D"] : "datetime",
[key + "Ctrl-E"] : function() { // emoji
"Ctrl-1" : "h1",
"Ctrl-2" : "h2",
"Ctrl-3" : "h3",
"Ctrl-4" : "h4",
"Ctrl-5" : "h5",
"Ctrl-6" : "h6",
"Ctrl-B" : "bold", // if this is string == editormd.toolbarHandlers.xxxx
"Ctrl-D" : "datetime",
"Ctrl-E" : function() { // emoji
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
@ -3200,11 +3204,10 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
[key + "-Alt-G"] : "goto-line",
[key + "-H"] : "hr",
[key + "-I"] : "italic",
[key + "-K"] : "code",
"Ctrl-Alt-G" : "goto-line",
"Ctrl-H" : "hr",
"Ctrl-I" : "italic",
"Ctrl-K" : "code",
"Ctrl-L" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3218,8 +3221,7 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
[key + "-U"] : "list-ul",
"Ctrl-U" : "list-ul",
"Shift-Ctrl-A" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3237,12 +3239,10 @@
cm.setCursor(cursor.line, cursor.ch + 1);
}
},
["Shift" + key + "-C"] : "code",
["Shift" + key + "Q"] : "quote",
["Shift" + key + "S"] : "del",
["Shift" + key + "K"] : "tex", // KaTeX
"Shift-Ctrl-C" : "code",
"Shift-Ctrl-Q" : "quote",
"Shift-Ctrl-S" : "del",
"Shift-Ctrl-K" : "tex", // KaTeX
"Shift-Alt-C" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
@ -3254,35 +3254,32 @@
cm.setCursor(cursor.line, cursor.ch + 3);
}
},
["Shift-" + key + "-Alt-C"] : "code-block",
["Shift-" + key + "-H"] : "html-entities",
"Shift-Ctrl-Alt-C" : "code-block",
"Shift-Ctrl-H" : "html-entities",
"Shift-Alt-H" : "help",
["Shift-" + key + "-E"] : "emoji",
["Shift-" + key + "-U"] : "uppercase",
"Shift-Ctrl-E" : "emoji",
"Shift-Ctrl-U" : "uppercase",
"Shift-Alt-U" : "ucwords",
["Shift-" + key + "-Alt-U"] : "ucfirst",
"Shift-Ctrl-Alt-U" : "ucfirst",
"Shift-Alt-L" : "lowercase",
["Shift-" + key + "-I"] : function() {
"Shift-Ctrl-I" : function() {
var cm = this.cm;
var cursor = cm.getCursor();
var selection = cm.getSelection();
var title = (selection === "") ? "" : " \""+selection+"\"";
var title = (selection === "") ? "" : " \"" + selection + "\"";
cm.replaceSelection("![" + selection + "]("+title+")");
cm.replaceSelection("![" + selection + "](" + title + ")");
if (selection === "") {
cm.setCursor(cursor.line, cursor.ch + 4);
}
},
["Shift-" + key + "-Alt-I"] : "image",
["Shift-" + key + "-L"] : "link",
["Shift-" + key + "-O"] : "list-ol",
["Shift-" + key + "-P"] : "preformatted-text",
["Shift-" + key + "-T"] : "table",
"Shift-Ctrl-Alt-I" : "image",
"Shift-Ctrl-L" : "link",
"Shift-Ctrl-O" : "list-ol",
"Shift-Ctrl-P" : "preformatted-text",
"Shift-Ctrl-T" : "table",
"Shift-Alt-P" : "pagebreak",
"F9" : "watch",
"F10" : "preview",
@ -3333,8 +3330,6 @@
});
};
var ucfirst = firstUpperCase;
editormd.firstUpperCase = editormd.ucfirst = firstUpperCase;
editormd.urls = {
@ -3355,7 +3350,7 @@
// Emoji graphics files url path
editormd.emoji = {
path : "http://www.emoji-cheat-sheet.com/graphics/emojis/",
path : "https://www.webpagefx.com/tools/emoji-cheat-sheet/graphics/emojis/",
ext : ".png"
};
@ -3421,7 +3416,7 @@
matchs[i] = ":\\+1:";
}
text = text.replace(new RegExp(matchs[i]), function($1, $2){
text = text.replace(new RegExp(matchs[i]), function($1) {
var faMatchs = $1.match(faIconReg);
var name = $1.replace(/:/g, "");
@ -3502,14 +3497,14 @@
if (this.options.sanitize) {
try {
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g,"").toLowerCase();
} catch(e) {
return "";
}
var prot = decodeURIComponent(unescape(href)).replace(/[^\w:]/g, "").toLowerCase();
if (prot.indexOf("javascript:") === 0) {
return "";
}
} catch(e) {
return "";
}
}
var out = "<a href=\"" + href + "\"";
@ -3533,11 +3528,11 @@
return out;
};
markedRenderer.heading = function(text, level, raw) {
markedRenderer.heading = function(text, level) {
var linkText = text;
var hasLinkReg = /\s*\<a\s*href\=\"(.*)\"\s*([^\>]*)\>(.*)\<\/a\>\s*/;
var getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
// var getLinkTextReg = /\s*\<a\s*([^\>]+)\>([^\>]*)\<\/a\>\s*/g;
if (hasLinkReg.test(text))
{
@ -3609,7 +3604,7 @@
: ( (pageBreakReg.test(text)) ? this.pageBreak(text) : "<p" + isTeXAddClass + ">" + this.atLink(this.emoji(text)) + "</p>\n" );
};
markedRenderer.code = function (code, lang, escaped) {
markedRenderer.code = function (code, lang) {
if (lang === "seq" || lang === "sequence")
{
@ -3800,7 +3795,7 @@
editormd.filterHTMLTags = function(html, filters) {
if (typeof html !== "string") {
html = new String(html);
html = html.toString();
}
if (typeof filters !== "string") {
@ -3838,7 +3833,9 @@
var $attrs = {};
$.each(_attrs, function(i, e) {
if (e.nodeName !== '"') $attrs[e.nodeName] = e.nodeValue;
if (e.nodeName !== "\"") {
$attrs[e.nodeName] = e.nodeValue;
}
});
$.each($attrs, function(i) {
@ -3909,7 +3906,7 @@
editormd.$marked = marked;
var div = $("#" + id);
var settings = div.settings = $.extend(true, defaults, options || {});
var settings = div.settings = $.extend(true, {}, defaults, options || {});
var saveTo = div.find("textarea");
if (saveTo.length < 1)
@ -3947,7 +3944,7 @@
smartypants : true
};
markdownDoc = new String(markdownDoc);
markdownDoc = markdownDoc.toString();
var markdownParsed = marked(markdownDoc, markedOptions);
@ -4114,8 +4111,8 @@
}
};
editormd.isIE = (navigator.appName == "Microsoft Internet Explorer");
editormd.isIE8 = (editormd.isIE && navigator.appVersion.match(/8./i) == "8.");
editormd.isIE = (navigator.appName === "Microsoft Internet Explorer");
editormd.isIE8 = (editormd.isIE && navigator.appVersion.match(/8./i) === "8.");
/**
* 动态加载JS文件的方法
@ -4169,8 +4166,8 @@
// 使用国外的CDN,加载速度有时会很慢,或者自定义URL
// You can custom KaTeX load url.
editormd.katexURL = {
css : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min",
js : "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min"
css : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min",
js : "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.1/katex.min"
};
editormd.kaTeXLoaded = false;
@ -4216,6 +4213,7 @@
title : "",
drag : true,
closed : true,
cached : false,
content : "",
mask : true,
maskStyle : {
@ -4234,8 +4232,6 @@
var classPrefix = editormd.classPrefix;
var guid = (new Date()).getTime();
var dialogName = ( (options.name === "") ? classPrefix + "dialog-" + guid : options.name);
var mouseOrTouch = editormd.mouseOrTouch;
var html = "<div class=\"" + classPrefix + "dialog " + dialogName + "\">";
if (options.title !== "")
@ -4258,7 +4254,6 @@
}
html += "</div>";
html += "<div class=\"" + classPrefix + "dialog-mask " + classPrefix + "dialog-mask-bg\"></div>";
html += "<div class=\"" + classPrefix + "dialog-mask " + classPrefix + "dialog-mask-con\"></div>";
html += "</div>";
@ -4321,8 +4316,12 @@
$(window).resize(dialogPosition);
dialog.children("." + classPrefix + "dialog-close").bind(mouseOrTouch("click", "touchend"), function() {
dialog.children("." + classPrefix + "dialog-close").bind("click", function() {
dialog.hide().lockScreen(false).hideMask();
if (!options.cached) {
dialog.remove();
}
});
if (typeof options.buttons === "object")
@ -4336,7 +4335,7 @@
footer.append("<button class=\"" + classPrefix + "btn " + btnClassName + "\">" + btn[0] + "</button>");
btn[1] = $.proxy(btn[1], dialog);
footer.children("." + btnClassName).bind(mouseOrTouch("click", "touchend"), btn[1]);
footer.children("." + btnClassName).bind("click", btn[1]);
}
}
@ -4346,26 +4345,18 @@
var dialogHeader = dialog.children("." + classPrefix + "dialog-header");
if (!options.mask) {
dialogHeader.bind(mouseOrTouch("click", "touchend"), function(){
dialogHeader.bind("click", function(){
editormd.dialogZindex += 2;
dialog.css("z-index", editormd.dialogZindex);
});
}
dialogHeader.mousedown(function(e) {
e = e || window.event; //IE
posX = e.clientX - parseInt(dialog[0].style.left);
posY = e.clientY - parseInt(dialog[0].style.top);
document.onmousemove = moveAction;
});
var userCanSelect = function (obj) {
obj.removeClass(classPrefix + "user-unselect").off("selectstart");
};
var userUnselect = function (obj) {
obj.addClass(classPrefix + "user-unselect").on("selectstart", function(event) { // selectstart for IE
obj.addClass(classPrefix + "user-unselect").on("selectstart", function() { // selectstart for IE
return false;
});
};
@ -4405,6 +4396,14 @@
dialog[0].style.top = top + "px";
};
dialogHeader.mousedown(function(e) {
e = e || window.event; //IE
posX = e.clientX - parseInt(dialog[0].style.left);
posY = e.clientY - parseInt(dialog[0].style.top);
document.onmousemove = moveAction;
});
document.onmouseup = function() {
userCanSelect($("body"));
userCanSelect(dialog);

Loading…
Cancel
Save