" ) +
+ ( (settings.imageUpload) ? "
" + (function(){
return (settings.imageUpload) ? "
" +
@@ -931,9 +941,11 @@
}]
}
});
+
+ imageDialog.attr("id", classPrefix + "image-dialog-" + guid);
}
-
- var fileInput = imageDialog.find("[name=\"" + classPrefix + "image-file\"]");
+
+ var fileInput = imageDialog.find("[name=\"" + classPrefix + "image-file\"]");
fileInput.bind("change", function() {
var fileName = fileInput.val();
@@ -952,11 +964,16 @@
imageDialog.loading(true);
var submitHandler = function() {
+ if (settings.crossDomainUpload) {
+ imageDialog.loading(false);
+ return ;
+ }
+
var uploadIframe = document.getElementById(iframeName);
-
+
uploadIframe.onload = function() {
imageDialog.loading(false);
-
+
var json = uploadIframe.contentWindow.document.body.innerHTML;
json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")");
@@ -974,6 +991,7 @@
};
imageDialog.find("[type=\"submit\"]").bind(editormd.mouseOrTouch("click", "touchend"), submitHandler).trigger("click");
+
}
return false;
diff --git a/dist/js/editormd.min.js b/dist/js/editormd.min.js
index 641f586..b6edef7 100644
--- a/dist/js/editormd.min.js
+++ b/dist/js/editormd.min.js
@@ -1,3 +1,3 @@
/*! Editor.md v1.1.0 | editormd.min.js | A simple online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2015-02-15 */
-!function(e){"use strict";"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define?define(["jquery"],e):window.editormd=e()}(function(){"use strict";var $="undefined"!=typeof jQuery?jQuery:Zepto;if("undefined"!=typeof $){var editormd=function(e,t){return new editormd.fn.init(e,t)};return editormd.title=editormd.$name="Editor.md",editormd.version="1.1.0",editormd.homePage="https://pandao.github.io/editor.md/",editormd.classPrefix="editormd-",editormd.defaults={mode:"gfm",markdown:"",width:"100%",height:"100%",path:"./lib/",watch:!0,placeholder:"now coding markdown...",readOnly:!1,lineNumbers:!0,styleActiveLine:!0,dialogLockScreen:!0,dialogShowMask:!0,dialogDraggable:!0,dialogMaskBgColor:"#fff",dialogMaskOpacity:.1,onload:function(){},onchange:function(){},onfullscreen:function(){},onfullscreenExit:function(){},imageUpload:!1,imageFormats:["jpg","jpeg","gif","png","bmp","webp"],imageUploadURL:"",saveHTMLToTextarea:!1,toc:!0,tocStartLevel:1,fontSize:"13px",htmlDecode:!1,tex:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0,inRequirejs:!1,toolbar:!0,toolbarIcons:function(){return["undo","redo","|","bold","del","italic","quote","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","anchor","image","code","code-block-tab","code-block","datetime","|","watch","preview","fullscreen","clear","|","info"]},toolbarTitles:{},toolbarHandlers:{},toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",h1:editormd.classPrefix+"bold",h2:editormd.classPrefix+"bold",h3:editormd.classPrefix+"bold",h4:editormd.classPrefix+"bold",h5:editormd.classPrefix+"bold",h6:editormd.classPrefix+"bold","list-ul":"fa-list-ul","list-ol":"fa-list-ol",hr:"fa-minus",link:"fa-link",anchor:"fa-anchor",image:"fa-picture-o",code:"fa-code","code-block-tab":"fa-file-code-o","code-block":"fa-file-code-o",datetime:"fa-clock-o",watch:"fa-eye-slash",unwatch:"fa-eye",preview:"fa-search",fullscreen:"fa-arrows-alt",clear:"fa-eraser",info:"fa-info-circle"},toolbarIconTexts:{},lang:{name:"zh-cn",description:"开源在线Markdown编辑器
A simple markdown doucment online editor.",toolbar:{undo:"撤销(Ctrl+Z)",redo:"重做(Ctrl+Y)",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接",anchor:"锚点",image:"图片",code:"行内代码","code-block-tab":"预格式文本 / 代码块(缩进风格)","code-block":"代码块(多语言风格)",datetime:"日期时间",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"全窗口预览HTML(可按ESC还原)",fullscreen:"全屏(按ESC还原)",clear:"清空",info:"关于"+editormd.title},buttons:{enter:"确定",cancel:"取消"},dialog:{link:{title:"添加链接",url:"链接地址",urlTitle:"链接标题",urlEmpty:"错误:请填写链接地址。",titleEmpty:"错误:请填写链接标题。"},anchor:{title:"添加锚点链接",name:"锚点名称",url:"链接地址",urlTitle:"链接标题",nameEmpty:"错误:锚点名称不能为空。",titleEmpty:"错误:请填写锚点链接标题。",urlEmpty:"错误:请填写锚点链接地址。"},image:{title:"添加图片",url:"图片地址",link:"图片链接",alt:"图片描述",uploadButton:"本地上传",imageURLEmpty:"错误:图片地址不能为空。",uploadFileEmpty:"错误:上传的图片不能为空。",formatNotAllowed:"错误:只允许上传图片文件,允许上传的图片文件格式有:"},tabCodeBlock:{title:"添加预格式文本或代码块",codeEmptyAlert:"错误:请填写预格式文本或代码的内容。"},codeBlock:{title:"添加代码块",selectLabel:"代码语言:",selectDefaultText:"请选择代码语言",otherLanguage:"其他语言",unselectedLanguageAlert:"错误:请选择代码所属的语言类型。",codeEmptyAlert:"错误:请填写代码内容。"}}}},editormd.classNames={tex:editormd.classPrefix+"tex"},editormd.dialogZindex=99999,editormd.$katex=null,editormd.$marked=null,editormd.$CodeMirror=null,editormd.$prettyPrint=null,editormd.prototype=editormd.fn={state:{preview:!1,fullscreen:!1},init:function(e,t){t=t||{};var i=this,o=this.classPrefix=editormd.classPrefix,a=this.editor=$("#"+e),r=this.settings=$.extend(!0,editormd.defaults,t);this.id=e,this.lang=r.lang;var n=this.classNames={textarea:{html:this.classPrefix+"html-textarea",markdown:this.classPrefix+"markdown-textarea"}};a.hasClass("editormd")||a.addClass("editormd"),a.css({width:"number"==typeof r.width?r.width+"px":r.width,height:"number"==typeof r.height?r.height+"px":r.height});var s=this.markdownTextarea=a.children("textarea");s.length<1&&(a.append("
"),s=this.markdownTextarea=a.children("textarea")),s.addClass(n.textarea.markdown).attr("name",e+"-markdown-doc").attr("placeholder",r.placeholder);var d=[r.readOnly?"":'
',r.saveHTMLToTextarea?'
':"",'
','
','
'].join("\n");return a.append(d).addClass(o+"vertical"),""!==r.markdown&&s.val(r.markdown),this.htmlTextarea=a.find("."+n.textarea.html),this.preview=a.find("."+o+"preview"),this.previewContainer=this.preview.children("."+o+"preview-container"),this.toolbarIconHandlers={},r.inRequirejs?(i.setCodeMirror(),i.setToolbar(),i.setMarked().loadedDisplay()):this.loadQueues(),this},loadQueues:function(){var e=this,t=this.settings,i=t.path,o=function(){return editormd.isIE8?void e.setMarked().loadedDisplay():void(t.flowChart||t.sequenceDiagram?editormd.loadScript(i+"raphael.min",function(){editormd.loadScript(i+"underscore.min",function(){!t.flowChart&&t.sequenceDiagram?editormd.loadScript(i+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()}):t.flowChart&&!t.sequenceDiagram?editormd.loadScript(i+"flowchart.min",function(){editormd.loadScript(i+"jquery.flowchart.min",function(){e.setMarked().loadedDisplay()})}):t.flowChart&&t.sequenceDiagram&&editormd.loadScript(i+"flowchart.min",function(){editormd.loadScript(i+"jquery.flowchart.min",function(){editormd.loadScript(i+"sequence-diagram.min",function(){e.setMarked().loadedDisplay()})})})})}):e.setMarked().loadedDisplay())};return editormd.loadCSS(i+"codemirror/codemirror.min"),editormd.loadScript(i+"codemirror/codemirror.min",function(){editormd.$CodeMirror=CodeMirror,editormd.loadScript(i+"codemirror/modes.min",function(){editormd.loadScript(i+"codemirror/addons.min",function(){e.setCodeMirror(),e.setToolbar(),editormd.loadScript(i+"marked.min",function(){editormd.$marked=marked,t.previewCodeHighlight?editormd.loadScript(i+"prettify.min",function(){o()}):o()})})})}),this},setCodeMirror:function(){var e=this.settings,t={mode:e.mode,theme:"default",tabSize:4,dragDrop:!1,autofocus:!0,readOnly:e.readOnly?"nocursor":!1,indentUnit:4,lineNumbers:e.lineNumbers,lineWrapping:!0,matchBrackets:!0,indentWithTabs:!0,styleActiveLine:e.styleActiveLine,styleSelectedText:!0,autoCloseBrackets:!0,showTrailingSpace:!0,highlightSelectionMatches:{showToken:/\w/}};return this.codeEditor=editormd.$CodeMirror.fromTextArea(this.markdownTextarea[0],t),this.codeMirror=this.editor.find(".CodeMirror"),this.codeMirror.css({fontSize:this.settings.fontSize,width:e.watch?"50%":"100%"}),this},showToolbar:function(){var e=this.settings;if(!e.readOnly)return e.toolbar=!0,this.toolbar.show(),this.resize(),this},hideToolbar:function(){var e=this.settings;return e.toolbar=!1,this.toolbar.hide(),this.resize(),this},setToolbar:function(){var e=this.settings;if(!e.readOnly){var t=this.editor,i=(this.preview,this.classPrefix);t.append('
');var o=this.toolbar=t.find("."+i+"toolbar");if(!e.toolbar)return void o.hide();o.show();for(var a=e.toolbarIcons(),r=o.find("."+this.classPrefix+"menu"),n="",s=0,d=a.length;d>s;s++){var l=a[s];if("|"!==l){var c=/h(\d)/.test(l),h=l;"watch"!==l||e.watch||(h="unwatch");var u=e.lang.toolbar[h],m=e.toolbarIconTexts[h],g=e.toolbarIconsClass[h];u="undefined"==typeof u?"":u,m="undefined"==typeof m?"":m,g="undefined"==typeof g?"":g,n+='
'+(c?l:""===g?m:"")+""}else n+='
|'}return r.html(n),this.setToolbarHandler(),this}},getToolbarHandles:function(name){var _this=this,settings=this.settings,lang=settings.lang,editor=this.editor,codeEditor=this.codeEditor,cursor=codeEditor.getCursor(),selection=codeEditor.getSelection(),classPrefix=this.classPrefix,dialogLockScreen=function(){settings.dialogLockScreen&&$("html,body").css("overflow","hidden")},dialogShowMask=function(e){e.css({top:($(window).height()-e.height())/2+"px",left:($(window).width()-e.width())/2+"px"}),settings.dialogShowMask&&editor.find("."+classPrefix+"mask").css("z-index",parseInt(e.css("z-index"))-1).show()},toolbarHandlers=this.toolbarHandlers={undo:function(){codeEditor.undo()},redo:function(){codeEditor.redo()},bold:function(){codeEditor.replaceSelection("**"+selection+"**"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+2)},del:function(){codeEditor.replaceSelection("~~"+selection+"~~"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+2)},italic:function(){codeEditor.replaceSelection("*"+selection+"*"),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1)},quote:function(){codeEditor.replaceSelection(""===selection?["> "+selection,""].join("\n"):"> "+selection),codeEditor.setCursor(cursor.line,""===selection?cursor.ch+2:cursor.ch+selection.length+2)},h1:function(){codeEditor.replaceSelection("#"+selection)},h2:function(){codeEditor.replaceSelection("##"+selection)},h3:function(){codeEditor.replaceSelection("###"+selection)},h4:function(){codeEditor.replaceSelection("####"+selection)},h5:function(){codeEditor.replaceSelection("#####"+selection)},h6:function(){codeEditor.replaceSelection("######"+selection)},"list-ul":function(){if(""===selection)codeEditor.replaceSelection("- "+selection);else{for(var e=selection.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":"- "+e[t];codeEditor.replaceSelection(e.join("\n"))}},"list-ol":function(){if(""===selection)codeEditor.replaceSelection("1. "+selection);else{for(var e=selection.split("\n"),t=0,i=e.length;i>t;t++)e[t]=""===e[t]?"":t+1+". "+e[t];codeEditor.replaceSelection(e.join("\n"))}},hr:function(){codeEditor.replaceSelection("------------")},link:function(){var e,t=lang.dialog.link,i=classPrefix+"link-dialog";if(editor.find("."+i).length>0)e=editor.find("."+i),e.find("[data-url]").val("http://"),e.find("[data-title]").val(selection),dialogShowMask(e),dialogLockScreen(),e.show();else{var o='
';e=_this.createDialog({title:t.title,width:380,height:210,content:o,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-url]").val(),i=this.find("[data-title]").val();return"http://"===e||""===e?(alert(t.urlEmpty),!1):""===i?(alert(t.titleEmpty),!1):(codeEditor.replaceSelection("["+i+"]("+e+' "'+i+'")'),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},anchor:function(){var e,t=lang.dialog.anchor,i=classPrefix+"anchor-dialog";if(editor.find("."+i).length>0)e=editor.find("."+i),e.find("[data-name]").val(""),e.find("[data-url]").val("http://"),e.find("[data-title]").val(selection),dialogShowMask(e),dialogLockScreen(),e.show();else{var o='
';e=_this.createDialog({name:i,title:t.title,width:380,height:250,content:o,mask:settings.dialogShowMask,drag:settings.dialogDraggable,lockScreen:settings.dialogLockScreen,maskStyle:{opacity:settings.dialogMaskOpacity,backgroundColor:settings.dialogMaskBgColor},buttons:{enter:[lang.buttons.enter,function(){var e=this.find("[data-name]").val(),i=this.find("[data-url]").val(),o=this.find("[data-title]").val();return""===e?(alert(t.nameEmpty),!1):"http://"===i||""===i?(alert(t.urlEmpty),!1):""===o?(alert(t.titleEmpty),!1):(codeEditor.replaceSelection("["+o+"]["+e+"]\n["+e+"]: "+i),""===selection&&codeEditor.setCursor(cursor.line,cursor.ch+1),this.hide().lockScreen(!1).hideMask(),!1)}],cancel:[lang.buttons.cancel,function(){return this.hide().lockScreen(!1).hideMask(),!1}]}})}},image:function(){var imageLang=lang.dialog.image,iframeName=classPrefix+"image-iframe",imageDialogName=classPrefix+"image-dialog",imageDialog;if(editor.find("."+imageDialogName).length>0)imageDialog=editor.find("."+imageDialogName),imageDialog.find('[type="text"]').val(""),imageDialog.find('[type="file"]').val(""),imageDialog.find("[data-link]").val("http://"),dialogShowMask(imageDialog),dialogLockScreen(),imageDialog.show();else{var imageDialogHTML=(settings.imageUpload?'