diff --git a/css/base.css b/css/base.css
index 5799214..b451fea 100644
--- a/css/base.css
+++ b/css/base.css
@@ -1,47 +1,47 @@
-@charset "UTF-8";
-/**
- *
- * @authors yutent (yutent@doui.cc)
- * @date 2014-10-10 00:45:09
- *
- * doui的CSS规范
- *
- * 不能出现大写,以连字符风格命名
- * 表示状态的应该用do-st-*命名
- * 表示功能的应该用do-fn-*命名
- * 表示页面模块的应该用do-mod-modname 命名
- * 表示UI组件的应该用do-uiname命名, 它的子元素应该全部包在 .do-uiname这个根类下
- * 如 .do-layer .body { ... }
- *
- * 样式规则的出现顺序
- * 1 display float position overflow z-index 表示定位/布局的属性
- * 2 width height margin padding border 表示盒子模型的属性
- * 3 line-height font-size vertical-align text-align user-select outline ....排版相关的属性
- * 4 color background opacity cursor ...表示装饰相关的属性
- * 5 content list-style quotes ... 内容生成相关的属性
- *
- */
-* {margin: 0;padding: 0;vertical-align: baseline;box-sizing:border-box;}
-
-/* HTML5 display-role reset for older browsers */
-article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {display: block;}
-img {border:0;display:block;}
-ol, ul {list-style: none;}
-blockquote, q {quotes: none;}
-blockquote:before, blockquote:after,
-q:before, q:after {content: '';content: none;}
-table {border-collapse: collapse;border-spacing: 0;}
-
-.do-fn-cl { *zoom: 1; }
-.do-fn-cl:after {visibility: hidden;overflow:hidden; display: block;height: 0;content: "."; clear: both;}
-.do-fn-clear {clear:both;display:inline;}
-
-.do-fn-show{display:block;}
-.do-fn-hide{display:none;}
-.do-fn-fl{float:left;}
-.do-fn-fr{float:right;}
-.do-fn-noselect {-webkit-touch-callout: none;-webkit-user-select: none;-moz-user-select: none;user-select: none;}
-.do-fn-noselect img, .do-fn-noselect a {-webkit-user-drag:none;}
-.do-fn-ell {overflow:hidden; white-space:nowrap; text-overflow:ellipsis }
-.do-st-thin {-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}
-.do-st-hand {cursor:pointer;}
+@charset "UTF-8";
+/**
+ *
+ * @authors yutent (yutent@doui.cc)
+ * @date 2014-10-10 00:45:09
+ *
+ * doui的CSS规范
+ *
+ * 不能出现大写,以连字符风格命名
+ * 表示状态的应该用do-st-*命名
+ * 表示功能的应该用do-fn-*命名
+ * 表示页面模块的应该用do-mod-modname 命名
+ * 表示UI组件的应该用do-uiname命名, 它的子元素应该全部包在 .do-uiname这个根类下
+ * 如 .do-layer .body { ... }
+ *
+ * 样式规则的出现顺序
+ * 1 display float position overflow z-index 表示定位/布局的属性
+ * 2 width height margin padding border 表示盒子模型的属性
+ * 3 line-height font-size vertical-align text-align user-select outline ....排版相关的属性
+ * 4 color background opacity cursor ...表示装饰相关的属性
+ * 5 content list-style quotes ... 内容生成相关的属性
+ *
+ */
+* {margin: 0;padding: 0;vertical-align: baseline;box-sizing:border-box;}
+
+/* HTML5 display-role reset for older browsers */
+article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section,content {display: block;}
+img {border:0;display:inline-block;}
+ol, ul {list-style: none;}
+blockquote, q {quotes: none;}
+blockquote:before, blockquote:after,
+q:before, q:after {content: '';content: none;}
+table {border-collapse: collapse;border-spacing: 0;}
+
+.do-fn-cl { *zoom: 1; }
+.do-fn-cl:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; overflow:hidden;}
+.do-fn-clear {clear:both;display:inline;}
+
+.do-fn-show{display:block;}
+.do-fn-hide{display:none;}
+.do-fn-fl{float:left;}
+.do-fn-fr{float:right;}
+.do-fn-noselect {-webkit-touch-callout: none;-webkit-user-select: none;-moz-user-select: none;user-select: none;}
+.do-fn-noselect img, .do-fn-noselect a {-webkit-user-drag:none;}
+.do-fn-ell {overflow:hidden; white-space:nowrap; text-overflow:ellipsis }
+.do-st-thin {-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}
+.do-st-hand {cursor:pointer;}
diff --git a/css/base.min.css b/css/base.min.css
index 4e3642e..e69de29 100644
--- a/css/base.min.css
+++ b/css/base.min.css
@@ -1 +0,0 @@
-@charset "UTF-8";*{margin:0;padding:0;vertical-align:baseline;box-sizing:border-box}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}img{border:0;display:block}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}table{border-collapse:collapse;border-spacing:0}.do-fn-cl{*zoom:1}.do-fn-cl:after{content:".";display:block;height:0;clear:both;visibility:hidden;overflow:hidden}.do-fn-clear{clear:both;display:inline}.do-fn-show{display:block}.do-fn-hide{display:none}.do-fn-fl{float:left}.do-fn-fr{float:right}.do-fn-noselect{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}.do-fn-noselect a,.do-fn-noselect img{-webkit-user-drag:none}.do-fn-ell{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.do-st-thin{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.do-st-hand{cursor:pointer}
\ No newline at end of file
diff --git a/css/basic-elem.css b/css/basic-elem.css
new file mode 100644
index 0000000..367a068
--- /dev/null
+++ b/css/basic-elem.css
@@ -0,0 +1 @@
+.do-ui-button{display:inline-block;padding:0 5px;text-align:center;font-size:12px;transition:all .1s ease-in-out}.do-ui-button.medium{min-width:100px;height:35px;line-height:35px;font-size:15px}.do-ui-button.large{min-width:150px;height:50px;line-height:50px;font-size:18px}.do-ui-button.radius-3{border-radius:3px}.do-ui-button.radius-5{border-radius:5px}.do-ui-button.green{background:#1abc9c;color:#fff}.do-ui-button.green:hover{background:#48c9b0}.do-ui-button.green:active{background:#16a085}.do-ui-button.blue{background:#3498db;color:#fff}.do-ui-button.blue:hover{background:#5dade2}.do-ui-button.blue:active{background:#2c81ba}.do-ui-button.red{background:#e74c3c;color:#fff}.do-ui-button.red:hover{background:#ec7063}.do-ui-button.red:active{background:#c54133}.do-ui-button.orange{background:#f39c12;color:#fff}.do-ui-button.orange:hover{background:#f1c40f}.do-ui-button.orange:active{background:#e67e22}.do-ui-button.plain{background:#e7e8eb;color:#34495e}.do-ui-button.plain:hover{background:#ecf0f1}.do-ui-button.plain:active{background:#bdc3c7}.do-ui-button.grey{background:#34495e;color:#fff}.do-ui-button.grey:hover{background:#5d6d7e}.do-ui-button.grey:active{background:#2c3e50}.do-ui-input{display:inline-block;min-height:30px;padding:0 5px;border:1px solid #bdc3c7;background:#fff;color:#34495e;outline:none;transition:all .1s ease-in-out}.do-ui-input::-webkit-input-placeholder{color:#bdc3c7}.do-ui-input.radius-3{border-radius:3px}.do-ui-input.radius-5{border-radius:5px}.do-ui-input:focus{border-color:#1abc9c}.do-ui-input.alert{border-color:#e74c3c;color:#e74c3c}.do-ui-input.disabled{border-color:transparent;background:#e7e8eb;color:#bdc3c7}.do-ui-select{display:inline-block;min-height:30px;padding:0 5px;border:1px solid #bdc3c7;background:#fff;color:#34495e;outline:none;-moz-appearance:none;transition:all .1s ease-in-out}.do-ui-select::-ms-expand{display:none}.do-ui-select.radius-3{border-radius:3px}.do-ui-select.radius-5{border-radius:5px}.do-ui-select:focus{border-color:#1abc9c}.do-ui-select.alert{border-color:#e74c3c;color:#e74c3c}.do-ui-select.disabled{border-color:transparent;background:#e7e8eb;color:#bdc3c7}.do-ui-radio,.do-ui-checkbox{display:inline-block;position:relative;width:auto;height:auto;min-height:30px;padding-left:50px;background:#fff}.do-ui-radio>input,.do-ui-checkbox>input{position:absolute;left:25px;top:5px;width:20px;height:20px;outline:none;-webkit-appearance:none;background:#fff;border:2px solid #1abc9c;border-radius:3px}.do-ui-radio>input:checked,.do-ui-checkbox>input:checked{background:#1abc9c}.do-ui-checkbox>input:checked{box-shadow:inset 0 0 0 2px #fff}.do-ui-radio>input{left:10px;width:35px;border-radius:10px;border-color:#bdc3c7;background:#bdc3c7}.do-ui-radio>input::after{float:left;display:block;width:16px;height:16px;border-radius:50%;content:"";background:#fff}.do-ui-radio>input:checked{border-color:#1abc9c}.do-ui-radio>input:checked::after{float:right}
diff --git a/css/basic-elem.scss b/css/basic-elem.scss
new file mode 100644
index 0000000..03b34fa
--- /dev/null
+++ b/css/basic-elem.scss
@@ -0,0 +1,98 @@
+@charset "UTF-8";
+/**
+ *
+ * @authors yutent (yutent@doui.cc)
+ * @date 2017-05-20 21:35:30
+ * @version $Id$
+ */
+
+$cg: #1abc9c #48c9b0 #16a085;
+$cb: #3498db #5dade2 #2c81ba;
+$cr: #e74c3c #ec7063 #c54133;
+$co: #f39c12 #f1c40f #e67e22;
+$cp: #e7e8eb #ecf0f1 #bdc3c7;
+$cgr: #34495e #5d6d7e #2c3e50;
+
+@mixin ts($c: all, $t: .1s, $m: ease-in-out){
+ transition:$c $t $m;
+}
+/*--------各种按钮---------*/
+.do-ui-button {display:inline-block;padding:0 5px;text-align:center;font-size:12px;@include ts;
+
+ &.medium {min-width:100px;height:35px;line-height:35px;font-size:15px}
+ &.large {min-width:150px;height:50px;line-height:50px;font-size:18px;}
+ &.radius-3 {border-radius:3px;}
+ &.radius-5 {border-radius:5px;}
+
+ &.green {background:nth($cg, 1);color:#fff;}
+ &.green:hover {background:nth($cg, 2);}
+ &.green:active {background:nth($cg, 3);}
+ &.blue {background:nth($cb, 1);color:#fff;}
+ &.blue:hover {background:nth($cb, 2);}
+ &.blue:active {background:nth($cb, 3);}
+ &.red {background:nth($cr, 1);color:#fff;}
+ &.red:hover {background:nth($cr, 2);}
+ &.red:active {background:nth($cr, 3);}
+ &.orange {background:nth($co, 1);color:#fff;}
+ &.orange:hover {background:nth($co, 2);}
+ &.orange:active {background:nth($co, 3);}
+ &.plain {background:nth($cp, 1);color:nth($cgr, 1);}
+ &.plain:hover {background:nth($cp, 2);}
+ &.plain:active {background:nth($cp, 3);}
+ &.grey {background:nth($cgr, 1);color:#fff;}
+ &.grey:hover {background:nth($cgr, 2);}
+ &.grey:active {background:nth($cgr, 3);}
+}
+
+
+
+
+/*--------各种input---------*/
+
+
+.do-ui-input {display:inline-block;min-height:30px;padding:0 5px;border:1px solid nth($cp, 3);background:#fff;color:nth($cgr, 1);outline:none;@include ts;
+
+ &::-webkit-input-placeholder {color:nth($cp, 3);}
+
+ &.radius-3 {border-radius:3px;}
+ &.radius-5 {border-radius:5px;}
+
+ &:focus {border-color:nth($cg, 1);}
+ &.alert {border-color:nth($cr, 1);color:nth($cr, 1)}
+ &.disabled {border-color:transparent;background:nth($cp, 1);color:nth($cp, 3)}
+
+}
+
+
+
+.do-ui-select {display:inline-block;min-height:30px;padding:0 5px;border:1px solid nth($cp, 3);background:#fff;color:nth($cgr, 1);outline:none;-moz-appearance: none;@include ts;
+
+ &::-ms-expand {display:none;}
+ &.radius-3 {border-radius:3px;}
+ &.radius-5 {border-radius:5px;}
+
+ &:focus {border-color:nth($cg, 1);}
+ &.alert {border-color:nth($cr, 1);color:nth($cr, 1)}
+ &.disabled {border-color:transparent;background:nth($cp, 1);color:nth($cp, 3)}
+}
+
+
+.do-ui-radio,
+.do-ui-checkbox {display:inline-block;position:relative;width:auto;height:auto;min-height:30px;padding-left:50px;background:#fff;
+
+ >input {position:absolute;left:25px;top:5px;width:20px;height:20px;outline:none;-webkit-appearance:none;background:#fff;border:2px solid nth($cg, 1);border-radius:3px;
+
+ &:checked {background:nth($cg, 1);}
+ }
+}
+.do-ui-checkbox {
+ >input:checked {box-shadow:inset 0 0 0 2px #fff;}
+}
+.do-ui-radio {
+ >input {left:10px;width:35px;border-radius:10px;border-color:nth($cp, 3);background:nth($cp, 3);
+
+ &::after {float:left;display:block;width:16px;height:16px;border-radius:50%;content:"";background:#fff;}
+ &:checked {border-color:nth($cg, 1);}
+ &:checked::after {float: right;}
+ }
+}
diff --git a/js/lib/layer/base.js b/js/lib/layer/base.js
index 7639ca3..dee9872 100644
--- a/js/lib/layer/base.js
+++ b/js/lib/layer/base.js
@@ -188,9 +188,9 @@ define(['yua', 'lib/drag', 'css!./skin/def'], function(yua){
conf.menubar = false;
return __layer.open(conf)
},
- prompt: function(msg, callback){
- if(typeof callback !== 'function'){
- return console.error('argument [callback] requires a function, but ' + (typeof callback) + ' given')
+ prompt: function(msg, yescb, nocb){
+ if(typeof yescb !== 'function'){
+ return console.error('argument [callback] requires a function, but ' + (typeof yescb) + ' given')
}
var conf = {
type: 3,
@@ -199,9 +199,12 @@ define(['yua', 'lib/drag', 'css!./skin/def'], function(yua){
title: msg,
content: '',
yes: function(id){
- callback(id, yua.vmodels[id].prompt)
+ yescb(id, yua.vmodels[id].prompt)
}
}
+ if(typeof nocb === 'function'){
+ conf.no = nocb
+ }
return __layer.open(conf)
},
use: function(skin, callback){
@@ -486,7 +489,7 @@ define(['yua', 'lib/drag', 'css!./skin/def'], function(yua){
this.init.$id = uuid();
}
if(this.init.icon > 17){
- this.icon.icon = 17
+ this.init.icon = 17
}
//base版没有iframe类型
if(this.init.type === 4){
diff --git a/js/lib/marked/marked.js b/js/lib/marked/marked.js
index e03745a..b11e151 100644
--- a/js/lib/marked/marked.js
+++ b/js/lib/marked/marked.js
@@ -762,7 +762,8 @@ function Renderer(options) {
}
Renderer.prototype.code = function(code, lang, escaped) {
-
+ code = code.replace(/<script>/g, '')
if (this.options.highlight) {
var out = this.options.highlight(code, lang);
if (out != null && out !== code) {
@@ -798,15 +799,15 @@ Renderer.prototype.code = function(code, lang, escaped) {
}
}
- output += ''
+ codes[idx - 1]
+ '\n
' //加\n为了避免空行时无法显示
- + '
' @@ -886,6 +887,7 @@ Renderer.prototype.em = function(text) { }; Renderer.prototype.codespan = function(txt) { + txt = txt.replace(/&/g, '&') return '' + txt + '
'; }; diff --git a/js/lib/meditor/addon/attach.css b/js/lib/meditor/addon/attach.css index 17c60c7..bb9adf3 100644 --- a/js/lib/meditor/addon/attach.css +++ b/js/lib/meditor/addon/attach.css @@ -36,22 +36,24 @@ .do-meditor-attach .cont-box .select-file {width:100%;height:35px;line-height:33px} .do-meditor-attach .cont-box .select-file span.file {float:left;width:100px;height:35px;border:1px solid #ddd;background:#f7f7f7;color:#666;text-align:center;cursor:pointer;} +.do-meditor-attach .cont-box .select-file span.tips {display:inline-block;padding:0 10px;line-height:35px;color:#666;} .do-meditor-attach .cont-box .upload-box {width:100%;height:auto;min-height:190px;margin:10px 0;border:1px solid #e2e2e2;} .do-meditor-attach .cont-box .upload-box .tr {width:100%;height:35px;line-height:35px;text-align:center;} .do-meditor-attach .cont-box .upload-box .tr:hover {background:#fafafa} .do-meditor-attach .cont-box .upload-box .thead {line-height:34px;border-bottom:1px solid #e2e2e2;background:#f7f7f7;} .do-meditor-attach .cont-box .upload-box .td {float:left;} -.do-meditor-attach .cont-box .upload-box .td.name {width:50%;} -.do-meditor-attach .cont-box .upload-box .td.progress {width:20%;} -.do-meditor-attach .cont-box .upload-box .td.option {width:30%;} +.do-meditor-attach .cont-box .upload-box .td.name {width:45%;} +.do-meditor-attach .cont-box .upload-box .td.progress {width:40%;} +.do-meditor-attach .cont-box .upload-box .td.option {width:15%;} .do-meditor-attach .cont-box .upload-box .td.option a {display:inline-block;padding:3px 5px;line-height:13px;border:1px solid #e2e2e2;background:#f7f7f7;color:#666;} +.do-meditor-attach .cont-box .upload-box .td .red {color:#f30;} .do-meditor-attach .cont-box .manager {overflow:hidden;overflow-y:auto;width:100%;height:320px;padding:10px;} -.do-meditor-attach .cont-box .manager .item {float:left;width:22%;height:130px;margin:10px 1.5%;} +.do-meditor-attach .cont-box .manager .item {float:left;width:22%;height:130px;margin:10px 1.5%;padding:5px;} .do-meditor-attach .cont-box .manager .item:hover {background:#f7f7f7;} .do-meditor-attach .cont-box .manager .thumb {display:block;width:100%;height:100px;} -.do-meditor-attach .cont-box .manager .name {overflow:hidden;line-height:30px;text-align:center;} +.do-meditor-attach .cont-box .manager .name {overflow:hidden;height:20px;line-height:30px;text-align:center;} .do-meditor-attach .cont-box .manager img {width:100%;height:100%;} .do-meditor-attach .cont-box .manager .attac-icon {display:inline-block;width:100%;height:100px;text-align:center;font:50px/100px "edicon" !important;-webkit-font-smoothing: antialiased;-webkit-text-stroke-width: 0.2px;-moz-osx-font-smoothing: grayscale;} diff --git a/js/lib/meditor/addon/attach.js b/js/lib/meditor/addon/attach.js index 211d110..81aa30a 100644 --- a/js/lib/meditor/addon/attach.js +++ b/js/lib/meditor/addon/attach.js @@ -78,6 +78,28 @@ define([ } + function uploadScreenshot(vm, blob){ + var upload = new Uploader(vm.uploadUrl || ME.uploadUrl) + if(ME.beforeUpload){ + ME.beforeUpload(Date.now().toString(16) + '.jpg', function(qn){ + upload.field('file', blob) + .field('token', qn.token) + .field('key', qn.key) + .onEnd(function(json){ + ME.insert(vm.$editor, '![截图](' + qn.url + ')') + }) + .start() + }) + }else{ + upload.field('file', blob) + .onEnd(function(json){ + ME.insert(vm.$editor, '![截图](' + json.data.url + ')') + }) + .start() + } + } + + var $init = function(vm){ if(!vm.uploadUrl && !ME.uploadUrl){ console.error('使用附件上传,必须先设置uploadUrl;\n可以给vm增加uploadUrl属性,也可以通过ME.uploadUrl设置') @@ -85,7 +107,9 @@ define([ if(!vm.manageUrl && !ME.manageUrl){ console.error('使用附件管理功能,必须先设置manageUrl;\n可以给vm增加manageUrl属性,也可以通过ME.manageUrl设置') } - // ME.addon.image() + if(!ME.maxSize){ + ME.maxSize = 4194304 + } vm.$editor.addEventListener('paste', function(ev){ var txt = ev.clipboardData.getData('text/plain').trim(), @@ -107,12 +131,45 @@ define([ } if(blob !== null) { - var upload = new Uploader(vm.uploadUrl || ME.uploadUrl) - - upload.field('image', blob) - .onEnd(function(json){ - ME.insert(vm.$editor, '![截图](' + json.data.url + ')') - }).start() + layer.msg('截图处理中...') + // 压缩截图,避免文件过大 + var reader = new FileReader() + reader.onload = function(){ + var img = document.createElement('img'), + canvas = document.createElement('canvas') + + img.onload = function(){ + canvas.width = img.width + canvas.height = img.height + + var ctx = canvas.getContext('2d') + ctx.clearRect(0,0, canvas.width, canvas.height) + ctx.drawImage(this, 0, 0, canvas.width, canvas.height) + + + if(canvas.toBlob){ + canvas.toBlob(function(obj){ + uploadScreenshot(vm, obj) + }, 'image/jpeg', 0.8) + }else{ + var base64 = canvas.toDataURL('image/jpeg', 0.8), + buf = atob(base64.split(',')[1]), + arrBuf = new ArrayBuffer(buf.length), + intArr = new Uint8Array(arrBuf), + obj = null; + + for(var i = 0; i < buf.length; i++){ + intArr[i] = buf.charCodeAt(i) + } + obj = new Blob([intArr], {type: 'image/jpeg'}) + uploadScreenshot(vm, obj) + } + + + } + img.src = this.result + } + reader.readAsDataURL(blob) } } ev.preventDefault() @@ -131,7 +188,7 @@ define([ fixCont = function(){ return '' + '' + '' - + '
- ' + + '
- ' + '' + lang[openType][0] +'' + '本地上传' + '' + lang[openType][1] + '' @@ -150,12 +207,14 @@ define([ + '' + '
' - + '选择文件' + + '选择文件(上传大小限制:单文件最大' + + (ME.maxSize/1048576).toFixed(2) + + 'MB)' + '' + '
' @@ -163,7 +222,7 @@ define([ + '- 文件名上传进度操作
' + '- ' + '' - + '' + + '' + '插入' + '
' + '' + '
' + '' @@ -179,20 +238,42 @@ define([ */ function uploadFile(files, vm){ for(var i = 0, it; it = files[i++];){ - if(openType === 'image' && !/image/.test(it.type)){ + + if(openType === 'image' && !/\.(jpg|jpeg|png|gif|bmp|webp|ico)$/.test(it.name)){ + vm.uploadFile.push({name: it.name, progress: '0%(失败,不允许的文件类型)', url: ''}) continue } + if(it.size > ME.maxSize){ + vm.uploadFile.push({name: it.name, progress: '0%(文件体积过大)', url: ''}) + continue + } + var fixName = Date.now().toString(16) + it.name.slice(it.name.lastIndexOf('.')) + var idx = vm.uploadFile.length, upload = new Uploader(vm.uploadUrl || ME.uploadUrl) - vm.uploadFile.push({name: it.name, progress: '0%', url: ''}) - upload.field(openType, it) - .onProgress(function(val){ - vm.uploadFile[idx].progress = val + '%' - }).onEnd(function(json){ - vm.uploadFile[idx].url = json.data.url - }).start() + + upload.field('file', it) + + if(ME.beforeUpload){ + ME.beforeUpload(fixName, function(qn){ + + upload.field('token', qn.token) + .field('key', qn.key) + .onProgress(function(val){ + vm.uploadFile[idx].progress = val + '%' + }).onEnd(function(json){ + vm.uploadFile[idx].url = qn.url + }).start() + }) + }else{ + upload.onProgress(function(val){ + vm.uploadFile[idx].progress = val + '%' + }).onEnd(function(json){ + vm.uploadFile[idx].url = json.data.url + }).start() + } } } @@ -232,7 +313,8 @@ define([ type: 7, menubar: false, shade: false, - offset: [offset.top + 37], + fixed: true, + offset: [offset.top + 37 - document.body.scrollTop], tab: 2, attach: '', attachAlt: '', @@ -264,6 +346,9 @@ define([ $select: yua.noop, $change: yua.noop, $insert: function(it){ + if(!it.url){ + return + } var val = (openType === 'image' ? '!' : '') + '[' + it.name + '](' + it.url + ')' ME.insert(vm.$editor, val) diff --git a/js/lib/meditor/addon/base.js b/js/lib/meditor/addon/base.js index 49863ed..122c92d 100644 --- a/js/lib/meditor/addon/base.js +++ b/js/lib/meditor/addon/base.js @@ -42,7 +42,7 @@ define(['lib/layer/base'], function(){ ME.insert(vm.$editor, wrap) layer.close(h1Obj) }, - offset: [offset.top + 37, 'auto', 'auto', offset.left], + offset: [offset.top + 37 - document.body.scrollTop, 'auto', 'auto', offset.left - document.body.scrollLeft], content: '- ' + '' - + '' + + '' + '
' + '' + '
- 一级标题
' + '- 二级标题
' @@ -121,7 +121,7 @@ define(['lib/layer/base'], function(){ ME.insert(vm.$editor, val) layer.close(layid) }, - offset: [offset.top + 37, 'auto', 'auto', offset.left], + offset: [offset.top + 37 - document.body.scrollTop, 'auto', 'auto', offset.left - document.body.scrollLeft], content: '' + '链接文字' + '' @@ -151,7 +151,7 @@ define(['lib/layer/base'], function(){ fixed: true, shadeClose: true, arr: getOrderArr(36), - offset: [offset.top + 37, 'auto', 'auto', offset.left], + offset: [offset.top + 37 - document.body.scrollTop, 'auto', 'auto', offset.left - document.body.scrollLeft], content: ' ' + '' + '
', @@ -168,7 +168,7 @@ define(['lib/layer/base'], function(){ title: '0行 x 0列', fixed: true, shadeClose: true, - offset: [offset.top + 37, 'auto', 'auto', offset.left], + offset: [offset.top + 37 - document.body.scrollTop, 'auto', 'auto', offset.left - document.body.scrollLeft], matrix: objArr(10).map(function(){return objArr(10)}), content: '' + '
- ' @@ -239,7 +239,7 @@ define(['lib/layer/base'], function(){ ME.insert(vm.$editor, val) layer.close(layid) }, - offset: [offset.top + 37, 'auto', 'auto', offset.left], + offset: [offset.top + 37 - document.body.scrollTop, 'auto', 'auto', offset.left - document.body.scrollLeft], content: '
' + '图片描述' + '' @@ -313,7 +313,7 @@ define(['lib/layer/base'], function(){ content: ' ' + '语言类型' + '' + ' ' + '' @@ -333,19 +333,14 @@ define(['lib/layer/base'], function(){ }, fullscreen: function(elem, vm){ vm.fullscreen = !vm.fullscreen - if(vm.fullscreen){ - vm.preview = true - vm.htmlTxt = vm.$htmlTxt - }else{ - vm.preview = false - } + vm.$onFullscreen(vm.fullscreen) }, about: function(elem){ var offset = yua(elem).offset() layer.open({ type: 7, title: '关于编辑器', - offset: [offset.top + 37], + offset: [offset.top + 37 - document.body.scrollTop], content: ' ' + '' + ' __ __ _____ _ _ _\n' diff --git a/js/lib/meditor/main.js b/js/lib/meditor/main.js index e83f068..0aeef8e 100644 --- a/js/lib/meditor/main.js +++ b/js/lib/meditor/main.js @@ -21,6 +21,7 @@ define([ } }) + var editorVM = [] yua.ui.meditor = '0.0.1' //存放编辑器公共静态资源 window.ME = { @@ -28,11 +29,13 @@ define([ toolbar: { //工具栏title pipe: '', h1: '标题', + quote: '引用文本', bold: '粗体', italic: '斜体', through: '删除线', unordered: '无序列表', ordered: '有序列表', + link: '超链接', hr: '横线', time: '插入当前时间', face: '表情', @@ -47,7 +50,7 @@ define([ }, addon: {}, //已有插件 //往文本框中插入内容 - insert: function(dom, val){ + insert: function(dom, val, isSelect){ if(document.selection){ dom.focus() var range = document.selection.createRange() @@ -64,8 +67,7 @@ define([ + val + dom.value.slice(endPos, dom.value.length); - - dom.selectionStart = startPos + dom.selectionStart = isSelect ? startPos : (startPos + val.length) dom.selectionEnd = startPos + val.length dom.scrollTop = scrollTop dom.focus() @@ -123,6 +125,33 @@ define([ } return result } + }, + get: function(id){ + if(id === void 0){ + id = editorVM.length - 1 + } + var vm = editorVM[id] + if(vm){ + return { + id: vm.$id, + getVal: function(){ + return vm.plainTxt.trim() + }, + getHtml: function(){ + return vm.$htmlTxt + }, + setVal: function(txt){ + vm.plainTxt = txt + }, + show: function(){ + vm.editorVisible = true + }, + hide: function(){ + vm.editorVisible = false + } + } + } + return null } } //获取真实的引用路径,避免因为不同的目录结构导致加载失败的情况 @@ -274,14 +303,14 @@ define([ yua.component('meditor', { - $template: '' + $template: '' + '', $$template: function(txt){ @@ -300,6 +329,10 @@ define([ }) delete base.$addons } + if(base.hasOwnProperty('$show')){ + base.editorVisible = base.$show + delete base.$show + } return base }, $init: function(vm){ @@ -324,6 +357,7 @@ define([ $ready: function(vm){ vm.$editor = document.querySelector('#' + vm.$id) + editorVM.push(vm) //自动加载额外的插件 require(extraAddons, function(){ var args = Array.prototype.slice.call(arguments, 0) @@ -334,17 +368,27 @@ define([ yua(vm.$editor).bind('keydown', function(ev){ - //tab键改为插入4个空格,阻止默认事件,防止焦点失去 + var wrap = ME.selection(vm.$editor) || '', + select = !!wrap; + //tab键改为插入2个空格,阻止默认事件,防止焦点失去 if(ev.keyCode === 9){ - var wrap = ME.selection(vm.$editor) || '' wrap = wrap.split('\n').map(function(it){ return ev.shiftKey ? it.replace(/^\s\s/, '') : ' ' + it }).join('\n') - ME.insert(this, wrap) + ME.insert(this, wrap, select) ev.preventDefault() } + //修复按退格键删除选中文本时,选中的状态不更新的bug + if(ev.keyCode === 8){ + if(select){ + ME.insert(this, '', select) + ev.preventDefault() + } + } }) + //编辑器成功加载的回调 + vm.$onSuccess(ME.get(), vm) }, $paste: function(ev){ var txt = ev.clipboardData.getData('text/plain').trim(), @@ -360,15 +404,22 @@ define([ ev.preventDefault() }, $compile: function(){ + var txt = this.plainTxt.trim() + txt = txt.replace(/ ' + '' + '' + '' - + '' - + '' + + '' - + ' ' + '