Browse Source

fixed & improve image upload, etc.

develop
pandao 6 years ago
parent
commit
5b730587bd
  1. 83
      README.md
  2. 2
      css/editormd.css
  3. 2
      css/editormd.logo.css
  4. 2
      css/editormd.logo.min.css
  5. 2
      css/editormd.min.css
  6. 2
      css/editormd.preview.css
  7. 2
      css/editormd.preview.min.css
  8. 29
      editormd.amd.js
  9. 4
      editormd.amd.min.js
  10. 29
      editormd.js
  11. 4
      editormd.min.js
  12. 22
      examples/image-cross-domain-upload.html
  13. 12
      examples/image-upload.html
  14. 7
      examples/php/cross-domain-upload.php
  15. 25
      examples/php/editormd.uploader.class.php
  16. 4
      examples/php/upload.php
  17. 16
      examples/php/upload_callback.html
  18. 4
      lib/codemirror/addons.min.js
  19. 4
      lib/codemirror/modes.min.js
  20. 2
      package.json
  21. 51
      plugins/image-dialog/image-dialog.js
  22. 27
      src/editormd.js

83
README.md

@ -40,8 +40,8 @@
- 支持 AMD / CMD 模块化加载(支持 [Require.js](https://pandao.github.io/editor.md/examples/use-requirejs.html) & [Sea.js](https://pandao.github.io/editor.md/examples/use-seajs.html)),并且支持[自定义扩展插件](https://pandao.github.io/editor.md/examples/define-plugin.html);
- 兼容主流的浏览器(IE8+)和 [Zepto.js](https://pandao.github.io/editor.md/examples/use-zepto.html),且支持 iPad 等平板设备;
#### Download & install
#### Download & install
Download:
[Github download](https://github.com/pandao/editor.md/archive/master.zip)
@ -58,13 +58,13 @@ Bower install :
bower install editor.md
```
#### Usages
#### Usages
##### Create a Markdown editor
```html
<link rel="stylesheet" href="editor.md/css/editormd.min.css" />
<div id="editor">
<div id="editor">
<!-- Tips: Editor.md can auto append a `<textarea>` tag -->
<textarea style="display:none;">### Hello Editor.md !</textarea>
</div>
@ -72,9 +72,9 @@ bower install editor.md
<script src="editor.md/editormd.min.js"></script>
<script type="text/javascript">
$(function() {
var editor = editormd("editor", {
// width: "100%",
// height: "100%",
var editor = editormd("editor", {
// width: "100%",
// height: "100%",
// markdown: "xxxx", // dynamic set Markdown text
path : "editor.md/lib/" // Autoload modules mode, codemirror, marked... dependents libs path
});
@ -85,13 +85,13 @@ bower install editor.md
If you using modular script loader:
- [Using Require.js](https://github.com/pandao/editor.md/tree/master/examples/use-requirejs.html)
- [Using Sea.js](https://github.com/pandao/editor.md/tree/master/examples/use-seajs.html)
##### Markdown to HTML
- [Using Sea.js](https://github.com/pandao/editor.md/tree/master/examples/use-seajs.html)
##### Markdown to HTML
```html
<link rel="stylesheet" href="editormd/css/editormd.preview.css" />
<div id="test-markdown-view">
<div id="test-markdown-view">
<!-- Server-side output Markdown text -->
<textarea style="display:none;">### Hello world!</textarea>
</div>
@ -105,26 +105,26 @@ If you using modular script loader:
// markdown : "[TOC]\n### Hello world!\n## Heading 2", // Also, you can dynamic set Markdown text
// htmlDecode : true, // Enable / disable HTML tag encode.
// htmlDecode : "style,script,iframe", // Note: If enabled, you should filter some dangerous HTML tags for website security.
});
});
</script>
```
> See the full example: [http://editor.md.ipandao.com/examples/html-preview-markdown-to-html.html](http://editor.md.ipandao.com/examples/html-preview-markdown-to-html.html)
##### HTML to Markdown?
});
});
</script>
```
> See the full example: [http://editor.md.ipandao.com/examples/html-preview-markdown-to-html.html](http://editor.md.ipandao.com/examples/html-preview-markdown-to-html.html)
##### HTML to Markdown?
Sorry, Editor.md not support HTML to Markdown parsing, Maybe In the future.
#### Examples
[https://pandao.github.io/editor.md/examples/index.html](https://pandao.github.io/editor.md/examples/index.html)
#### Options
Editor.md options and default values:
```javascript
[https://pandao.github.io/editor.md/examples/index.html](https://pandao.github.io/editor.md/examples/index.html)
#### Options
Editor.md options and default values:
```javascript
{
mode : "gfm", // gfm or markdown
name : "", // Form element name for post
@ -185,6 +185,9 @@ Editor.md options and default values:
imageUpload : false, // Enable/disable upload
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "", // Upload url
imageUploadFields : "", // append upload form fields for CRSF etc. Server-side receives the POST parameters. v1.5.1+
imageUploadCallback : function() {}, // set image upload finish (success or failure) callback handler v1.5.1+
imageUploadCallbackName : '__Editor_md_ImageUploadCallback', // upload callback name for cross-domain upload v1.5.1+
crossDomainUpload : false, // Enable/disable Cross-domain upload
uploadCallbackURL : "", // Cross-domain upload callback url
@ -229,18 +232,18 @@ Editor.md options and default values:
name : "zh-cn",
description : "开源在线Markdown编辑器<br/>Open source online Markdown editor.",
tocTitle : "目录",
toolbar : {
//...
},
button: {
//...
toolbar : {
//...
},
button: {
//...
},
dialog : {
//...
}
//...
}
}
dialog : {
//...
}
//...
}
}
```
#### Dependents

2
css/editormd.css

@ -2,7 +2,7 @@
* Editor.md
*
* @file /editormd.css
* @version v1.5.0
* @version v1.5.1
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao

2
css/editormd.logo.css

@ -2,7 +2,7 @@
* Editor.md
*
* @file /editormd.logo.css
* @version v1.5.0
* @version v1.5.1
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao

2
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 | 2019-05-11 */
/*! Editor.md v1.5.1 | /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}

2
css/editormd.min.css

File diff suppressed because one or more lines are too long

2
css/editormd.preview.css

@ -2,7 +2,7 @@
* Editor.md
*
* @file /editormd.preview.css
* @version v1.5.0
* @version v1.5.1
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao

2
css/editormd.preview.min.css

@ -1,4 +1,4 @@
/*! Editor.md v1.5.0 | /editormd.preview.min.css | Open source online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2019-05-11 */
/*! Editor.md v1.5.1 | /editormd.preview.min.css | Open source online markdown editor. | MIT License | By: Pandao | https://github.com/pandao/editor.md | 2019-05-11 */
@charset "UTF-8";/*! prefixes.scss v0.1.0 | Author: Pandao | https://github.com/pandao/prefixes.scss | MIT license | Copyright (c) 2015 *//*!
* Font Awesome 4.3.0 by @davegandy - http://fontawesome.io - @fontawesome
* License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)

29
editormd.amd.js

@ -2,7 +2,7 @@
* Editor.md
*
* @file editormd.amd.js
* @version v1.5.0
* @version v1.5.1
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao
@ -129,7 +129,7 @@
};
editormd.title = editormd.$name = "Editor.md";
editormd.version = "1.5.0";
editormd.version = "1.5.1";
editormd.homePage = "https://pandao.github.io/editor.md/";
editormd.classPrefix = "editormd-";
@ -218,6 +218,9 @@
imageUpload : false,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "",
imageUploadFields : "", // append upload form fields for CRSF etc. Server-side receives the POST parameters. v1.5.1+
imageUploadCallback : function() {}, // set image upload finish (success or failure) callback handler v1.5.1+
imageUploadCallbackName : '__Editor_md_ImageUploadCallback', // upload callback name for cross-domain upload v1.5.1+
crossDomainUpload : false,
uploadCallbackURL : "",
@ -298,7 +301,7 @@
lang : {
name : "zh-cn",
description : "开源在线Markdown编辑器<br/>Open source online Markdown editor.",
description : "开源在线 Markdown 编辑器<br/>Open source online Markdown editor.",
tocTitle : "目录",
toolbar : {
undo : "撤销(Ctrl+Z)",
@ -436,8 +439,14 @@
}
var classPrefix = this.classPrefix = editormd.classPrefix;
var settings = this.settings = $.extend(true, {}, editormd.defaults, options);
var settings = $.extend(true, {}, editormd.defaults, options);
if (options.imageFormats) {
settings.imageFormats = options.imageFormats;
}
this.settings = settings;
id = (typeof id === "object") ? settings.id : id;
var editor = this.editor = $("#" + id);
@ -1384,7 +1393,7 @@
"<h1><i class=\"editormd-logo editormd-logo-lg editormd-logo-color\"></i> " + editormd.title + "<small>v" + editormd.version + "</small></h1>",
"<p>" + this.lang.description + "</p>",
"<p style=\"margin: 10px 0 20px 0;\"><a href=\"" + editormd.homePage + "\" target=\"_blank\">" + editormd.homePage + " <i class=\"fa fa-external-link\"></i></a></p>",
"<p style=\"font-size: 0.85em;\">Copyright &copy; 2015 <a href=\"https://github.com/pandao\" target=\"_blank\" class=\"hover-link\">Pandao</a>, The <a href=\"https://github.com/pandao/editor.md/blob/master/LICENSE\" target=\"_blank\" class=\"hover-link\">MIT</a> License.</p>",
"<p style=\"font-size: 0.85em;\">Copyright &copy; 2015-" + editormd.dateFormat('yyyy') + " <a href=\"https://github.com/pandao\" target=\"_blank\" class=\"hover-link\">Pandao</a>, The <a href=\"https://github.com/pandao/editor.md/blob/master/LICENSE\" target=\"_blank\" class=\"hover-link\">MIT</a> License.</p>",
"</div>",
"<a href=\"javascript:;\" class=\"fa fa-close " + classPrefix + "dialog-close\"></a>",
"</div>"
@ -1542,9 +1551,9 @@
{
previewContainer.find("pre").addClass("prettyprint linenums");
if (typeof prettyPrint !== "undefined")
if (typeof window.prettyPrint !== "undefined")
{
prettyPrint();
window.prettyPrint();
}
}
@ -2524,7 +2533,7 @@
},
/**
* 消毁并移除编辑器实例
* 消毁并移除编辑器实例 v1.5.1+
*
* destroy & remove editor
*
@ -4065,7 +4074,7 @@
if (settings.previewCodeHighlight)
{
div.find("pre").addClass("prettyprint linenums");
prettyPrint();
window.prettyPrint();
}
if (!editormd.isIE8)

4
editormd.amd.min.js

File diff suppressed because one or more lines are too long

29
editormd.js

@ -2,7 +2,7 @@
* Editor.md
*
* @file editormd.js
* @version v1.5.0
* @version v1.5.1
* @description Open source online markdown editor.
* @license MIT License
* @author Pandao
@ -59,7 +59,7 @@
};
editormd.title = editormd.$name = "Editor.md";
editormd.version = "1.5.0";
editormd.version = "1.5.1";
editormd.homePage = "https://pandao.github.io/editor.md/";
editormd.classPrefix = "editormd-";
@ -148,6 +148,9 @@
imageUpload : false,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "",
imageUploadFields : "", // append upload form fields for CRSF etc. Server-side receives the POST parameters. v1.5.1+
imageUploadCallback : function() {}, // set image upload finish (success or failure) callback handler v1.5.1+
imageUploadCallbackName : '__Editor_md_ImageUploadCallback', // upload callback name for cross-domain upload v1.5.1+
crossDomainUpload : false,
uploadCallbackURL : "",
@ -228,7 +231,7 @@
lang : {
name : "zh-cn",
description : "开源在线Markdown编辑器<br/>Open source online Markdown editor.",
description : "开源在线 Markdown 编辑器<br/>Open source online Markdown editor.",
tocTitle : "目录",
toolbar : {
undo : "撤销(Ctrl+Z)",
@ -366,8 +369,14 @@
}
var classPrefix = this.classPrefix = editormd.classPrefix;
var settings = this.settings = $.extend(true, {}, editormd.defaults, options);
var settings = $.extend(true, {}, editormd.defaults, options);
if (options.imageFormats) {
settings.imageFormats = options.imageFormats;
}
this.settings = settings;
id = (typeof id === "object") ? settings.id : id;
var editor = this.editor = $("#" + id);
@ -1314,7 +1323,7 @@
"<h1><i class=\"editormd-logo editormd-logo-lg editormd-logo-color\"></i> " + editormd.title + "<small>v" + editormd.version + "</small></h1>",
"<p>" + this.lang.description + "</p>",
"<p style=\"margin: 10px 0 20px 0;\"><a href=\"" + editormd.homePage + "\" target=\"_blank\">" + editormd.homePage + " <i class=\"fa fa-external-link\"></i></a></p>",
"<p style=\"font-size: 0.85em;\">Copyright &copy; 2015 <a href=\"https://github.com/pandao\" target=\"_blank\" class=\"hover-link\">Pandao</a>, The <a href=\"https://github.com/pandao/editor.md/blob/master/LICENSE\" target=\"_blank\" class=\"hover-link\">MIT</a> License.</p>",
"<p style=\"font-size: 0.85em;\">Copyright &copy; 2015-" + editormd.dateFormat('yyyy') + " <a href=\"https://github.com/pandao\" target=\"_blank\" class=\"hover-link\">Pandao</a>, The <a href=\"https://github.com/pandao/editor.md/blob/master/LICENSE\" target=\"_blank\" class=\"hover-link\">MIT</a> License.</p>",
"</div>",
"<a href=\"javascript:;\" class=\"fa fa-close " + classPrefix + "dialog-close\"></a>",
"</div>"
@ -1472,9 +1481,9 @@
{
previewContainer.find("pre").addClass("prettyprint linenums");
if (typeof prettyPrint !== "undefined")
if (typeof window.prettyPrint !== "undefined")
{
prettyPrint();
window.prettyPrint();
}
}
@ -2454,7 +2463,7 @@
},
/**
* 消毁并移除编辑器实例
* 消毁并移除编辑器实例 v1.5.1+
*
* destroy & remove editor
*
@ -3995,7 +4004,7 @@
if (settings.previewCodeHighlight)
{
div.find("pre").addClass("prettyprint linenums");
prettyPrint();
window.prettyPrint();
}
if (!editormd.isIE8)

4
editormd.min.js

File diff suppressed because one or more lines are too long

22
examples/image-cross-domain-upload.html

@ -21,8 +21,12 @@
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "http://xxxxxxx/editor.md/examples/php/cross-domain-upload.php?test=dfdf",
imageUploadFields : "&lt;input type=\"hidden\" name=\"token\" value=\"d3sE3fc87\"/&gt;", // v1.5.1+
crossDomainUpload : true,
uploadCallbackURL : "http://xxxxxx/upload_callback.html?test=dfdf"
uploadCallbackURL : "http://xxxxxx/upload_callback.html?test=dfdf",
imageUploadCallback : function (result, dialog) { // v1.5.1+
console.log('imageUploadCallback: ', this, result, dialog);
}
}
```
@ -74,6 +78,14 @@ exit;
var imageDialog = window.parent.document.getElementById(query['dialog_id']);
//console.log(imageDialog, window.parent.document, window.parent, query);
if (query['callback_handler']) {
try {
window.parent[query['callback_handler']](query, imageDialog);
} catch (e) {
console.error('upload_callback: callback_handler =>', e);
}
}
&lt;/script&gt;
```</textarea>
</div>
@ -89,9 +101,13 @@ exit;
path : '../lib/',
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "http://www.ipandao.com/editor.md/examples/php/cross-domain-upload.php?test=dfdf",
imageUploadURL : "http://127.0.0.1/editor.md/examples/php/cross-domain-upload.php?test=dfdf",
imageUploadFields : "<input type=\"hidden\" name=\"token\" value=\"d3sE3fc87\"/>", // append upload form fields for CRSF etc. Server-side receives the POST parameters. v1.5.1+
crossDomainUpload : true,
uploadCallbackURL : "http://localhost/editor.md/examples/php/upload_callback.html?test=dfdf"
uploadCallbackURL : "http://localhost/editor.md/examples/php/upload_callback.html?test=dfdf",
imageUploadCallback : function (result, dialog) { // v1.5.1+
console.log('imageUploadCallback: ', this, result, dialog);
}
/*
跨域时,上传的图片服务器后台只需要返回一个跳转 URL 并跳转到原页面同域下的 callback 页面,结构如下:

12
examples/image-upload.html

@ -21,6 +21,10 @@
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "./php/upload.php",
imageUploadFields: "&lt;input type=\"hidden\" name=\"token\" value=\"d3sE3fc87\"/&gt;", // append upload form fields for CRSF etc. v1.5.1+
imageUploadCallback : function (result, dialog) { // v1.5.1+
console.log('imageUploadCallback: ', this, result, dialog);
}
}
```
@ -44,7 +48,7 @@
height: 640,
markdown : "",
path : '../lib/',
//dialogLockScreen : false, // 设置弹出层对话框不锁屏,全局通用,默认为 true
//dialogLockScreen : false, // 设置弹出层对话框不锁屏,全局通用,默认为 false
//dialogShowMask : false, // 设置弹出层对话框显示透明遮罩层,全局通用,默认为 true
//dialogDraggable : false, // 设置弹出层对话框不可拖动,全局通用,默认为 true
//dialogMaskOpacity : 0.4, // 设置透明遮罩层的透明度,全局通用,默认值为 0.1
@ -52,7 +56,11 @@
imageUpload : true,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "./php/upload.php?test=dfdf",
imageUploadFields: "<input type=\"hidden\" name=\"token\" value=\"d3sE3fc87\"/>", // append upload form fields for CRSF etc. Server-side receives the POST parameters. v1.5.1+
imageUploadCallback : function (result, dialog) { // v1.5.1+
console.log('imageUploadCallback: ', this, result, dialog);
}
/*
上传的后台只需要返回一个 JSON 数据,结构如下:
{

7
examples/php/cross-domain-upload.php

@ -38,7 +38,12 @@
'maxSize' => 1024, // 允许上传的最大文件大小,以KB为单位,默认值为1024
'cover' => true // 是否覆盖同名文件,默认为true
));
$imageUploader->appendResult = array(
'callback_handler' => $_GET['callback_handler'],
'meta' => $_POST
);
$imageUploader->redirect = true;
$imageUploader->redirectURL = $callbackUrl . (empty(parse_url($callbackUrl)['query']) ? '?' : '&') . 'dialog_id=' . $_GET['dialog_id'] . '&temp=' . date('ymdhis');

25
examples/php/editormd.uploader.class.php

@ -19,6 +19,7 @@
public $saveName; // 最终保存的文件名
public $saveURL; // 最终保存URL地址
public $savePath; // 保存本地文件路径
public $appendResult = []; // 追加到输出结果的数据
public $randomLength = ''; // 生成随机文件名的长度,当为日期时为日期的格式
public $randomNameType = 1; // 生成随机的形式, NULL为保留原文件名, 1生成随机字符串, 2生成日期文件名
public $formats = array( // 允许上传的文件格式
@ -252,7 +253,7 @@
private function setSeveName()
{
$this->saveName = $this->randomFileName().".".$this->fileExt;
$this->saveName = $this->randomFileName();
if($this->saveName == '') //如果没生成随机文件名,就保留原文件名
{
@ -307,21 +308,29 @@
public function message($message, $success = 0)
{
$array = array(
'success' => $success
'success' => $success,
'message' => $message
);
$url = $this->saveURL . $this->saveName;
$array = array_merge($array, $this->appendResult);
$url = $this->saveURL . $this->saveName;
// 适用于跨域上传时,跳转到中介页面等
if ($this->redirect)
{
$this->redirectURL .= "&success=" . $success . "&message=" . $message;
foreach ($array as $key => $value) {
if (is_array($value)) {
$this->redirectURL .= '&' . $key . '=' . urlencode(json_encode($value));
} else {
$this->redirectURL .= '&' . $key . '=' . $value;
}
}
if ($success == 1)
{
$this->redirectURL .= '&url=' . $url;
}
$this->redirect();
}
else
@ -330,10 +339,6 @@
{
$array['url'] = $url;
}
else
{
$array['message'] = $message;
}
echo json_encode($array);
}

4
examples/php/upload.php

@ -38,6 +38,10 @@
'maxSize' => 1024, // 允许上传的最大文件大小,以KB为单位,默认值为1024
'cover' => true // 是否覆盖同名文件,默认为true
));
$imageUploader->appendResult = array(
'meta' => $_POST
);
if ($imageUploader->upload($name))
{

16
examples/php/upload_callback.html

@ -15,9 +15,11 @@
for (var i = 0; i< urlParams.length; i++)
{
var param = urlParams[i].split("=");
query[param[0]] = param[1];
query[param[0]] = param[0] === "meta" ? JSON.parse(decodeURIComponent(param[1])) : param[1];
}
console.log('upload_callback: result =>', JSON.stringify(query, null, ' '));
var imageDialog = window.parent.document.getElementById(query['dialog_id']);
if (parseInt(query['success']) === 1)
@ -26,10 +28,18 @@
}
else
{
alert(query['message']);
alert(decodeURIComponent(query['message']));
}
if (query['callback_handler']) {
try {
window.parent[query['callback_handler']](query, imageDialog);
} catch (e) {
console.error('upload_callback: callback_handler =>', e);
}
}
location.href = "about:blank";
location.replace("about:blank");
</script>
</body>
</html>

4
lib/codemirror/addons.min.js

File diff suppressed because one or more lines are too long

4
lib/codemirror/modes.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,6 +1,6 @@
{
"name": "editor.md",
"version": "1.5.0",
"version": "1.5.1",
"description": "Open source online markdown editor.",
"directories": {
"doc": "docs",

51
plugins/image-dialog/image-dialog.js

@ -41,18 +41,43 @@
var guid = (new Date).getTime();
var action = settings.imageUploadURL + (settings.imageUploadURL.indexOf("?") >= 0 ? "&" : "?") + "guid=" + guid;
var imageUploadCallback = function (json, dialog) {
if (typeof settings.imageUploadCallback === 'function') {
$.proxy(settings.imageUploadCallback, _this)(json, dialog);
}
};
if (settings.crossDomainUpload)
{
var callbackName = settings.imageUploadCallbackName;
window[callbackName] = imageUploadCallback;
action += "&callback_handler=" + callbackName;
action += "&callback=" + settings.uploadCallbackURL + "&dialog_id=editormd-image-dialog-" + guid;
settings.imageUploadFields += "<input type=\"hidden\" name=\"callback\" value=\"" + settings.uploadCallbackURL + "\" />";
settings.imageUploadFields += "<input type=\"hidden\" name=\"callback_handler\" value=\"" + callbackName + "\" />";
settings.imageUploadFields += "<input type=\"hidden\" name=\"dialog_id\" value=\"editormd-image-dialog-" + guid + "\" />";
}
var dialogContent = ( (settings.imageUpload) ? "<form action=\"" + action +"\" target=\"" + iframeName + "\" method=\"post\" enctype=\"multipart/form-data\" class=\"" + classPrefix + "form\">" : "<div class=\"" + classPrefix + "form\">" ) +
var imageUploadAccept = [];
settings.imageFormats.forEach(function (format) {
imageUploadAccept.push("image/" + format);
});
imageUploadAccept.join(",");
var dialogContent = ( (settings.imageUpload) ? "<form action=\"" + action + "\" target=\"" + iframeName + "\" method=\"post\" enctype=\"multipart/form-data\" class=\"" + classPrefix + "form\">" : "<div class=\"" + classPrefix + "form\">" ) +
( (settings.imageUpload) ? "<iframe name=\"" + iframeName + "\" id=\"" + iframeName + "\" guid=\"" + guid + "\"></iframe>" : "" ) +
"<label>" + imageLang.url + "</label>" +
"<input type=\"text\" data-url />" + (function(){
return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" +
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/*\" />" +
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"" + imageUploadAccept + "\" />" +
"<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" +
"<input type=\"hidden\" name=\"guid\" value=\"" + guid + "\" />" +
settings.imageUploadFields +
"</div>" : "";
})() +
"<br/>" +
@ -166,21 +191,25 @@
if(!settings.crossDomainUpload)
{
if (json.success === 1)
{
dialog.find("[data-url]").val(json.url);
}
else
{
alert(json.message);
}
if (json.success === 1)
{
dialog.find("[data-url]").val(json.url);
}
else
{
alert(json.message);
}
if (typeof settings.imageUploadCallback === 'function') {
$.proxy(settings.imageUploadCallback, _this)(json, dialog);
}
}
return false;
};
};
dialog.find("[type=\"submit\"]").bind("click", submitHandler).trigger("click");
dialog.find('form').on("submit", submitHandler).trigger("submit");
});
}

27
src/editormd.js

@ -47,7 +47,7 @@
};
editormd.title = editormd.$name = "Editor.md";
editormd.version = "1.5.0";
editormd.version = "1.5.1";
editormd.homePage = "https://pandao.github.io/editor.md/";
editormd.classPrefix = "editormd-";
@ -136,6 +136,9 @@
imageUpload : false,
imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
imageUploadURL : "",
imageUploadFields : "", // append upload form fields for CRSF etc. Server-side receives the POST parameters. v1.5.1+
imageUploadCallback : function() {}, // set image upload finish (success or failure) callback handler v1.5.1+
imageUploadCallbackName : '__Editor_md_ImageUploadCallback', // upload callback name for cross-domain upload v1.5.1+
crossDomainUpload : false,
uploadCallbackURL : "",
@ -216,7 +219,7 @@
lang : {
name : "zh-cn",
description : "开源在线Markdown编辑器<br/>Open source online Markdown editor.",
description : "开源在线 Markdown 编辑器<br/>Open source online Markdown editor.",
tocTitle : "目录",
toolbar : {
undo : "撤销(Ctrl+Z)",
@ -354,8 +357,14 @@
}
var classPrefix = this.classPrefix = editormd.classPrefix;
var settings = this.settings = $.extend(true, {}, editormd.defaults, options);
var settings = $.extend(true, {}, editormd.defaults, options);
if (options.imageFormats) {
settings.imageFormats = options.imageFormats;
}
this.settings = settings;
id = (typeof id === "object") ? settings.id : id;
var editor = this.editor = $("#" + id);
@ -1302,7 +1311,7 @@
"<h1><i class=\"editormd-logo editormd-logo-lg editormd-logo-color\"></i> " + editormd.title + "<small>v" + editormd.version + "</small></h1>",
"<p>" + this.lang.description + "</p>",
"<p style=\"margin: 10px 0 20px 0;\"><a href=\"" + editormd.homePage + "\" target=\"_blank\">" + editormd.homePage + " <i class=\"fa fa-external-link\"></i></a></p>",
"<p style=\"font-size: 0.85em;\">Copyright &copy; 2015 <a href=\"https://github.com/pandao\" target=\"_blank\" class=\"hover-link\">Pandao</a>, The <a href=\"https://github.com/pandao/editor.md/blob/master/LICENSE\" target=\"_blank\" class=\"hover-link\">MIT</a> License.</p>",
"<p style=\"font-size: 0.85em;\">Copyright &copy; 2015-" + editormd.dateFormat('yyyy') + " <a href=\"https://github.com/pandao\" target=\"_blank\" class=\"hover-link\">Pandao</a>, The <a href=\"https://github.com/pandao/editor.md/blob/master/LICENSE\" target=\"_blank\" class=\"hover-link\">MIT</a> License.</p>",
"</div>",
"<a href=\"javascript:;\" class=\"fa fa-close " + classPrefix + "dialog-close\"></a>",
"</div>"
@ -1460,9 +1469,9 @@
{
previewContainer.find("pre").addClass("prettyprint linenums");
if (typeof prettyPrint !== "undefined")
if (typeof window.prettyPrint !== "undefined")
{
prettyPrint();
window.prettyPrint();
}
}
@ -2442,7 +2451,7 @@
},
/**
* 消毁并移除编辑器实例
* 消毁并移除编辑器实例 v1.5.1+
*
* destroy & remove editor
*
@ -3983,7 +3992,7 @@
if (settings.previewCodeHighlight)
{
div.find("pre").addClass("prettyprint linenums");
prettyPrint();
window.prettyPrint();
}
if (!editormd.isIE8)

Loading…
Cancel
Save