diff --git a/build.dev.js b/build.dev.js index 4017223..e72453b 100644 --- a/build.dev.js +++ b/build.dev.js @@ -19,7 +19,12 @@ const prefixer = postcss().use( ) const jsOpt = { presets: ['es2015'], - plugins: ['transform-es2015-modules-amd'] + plugins: [ + 'transform-es2015-modules-amd', + 'transform-decorators-legacy', + 'transform-class-properties', + 'transform-object-rest-spread' + ] } const cssOpt = { includePaths: ['src/css/'], diff --git a/build.prod.js b/build.prod.js index 8f79a3a..334caa7 100644 --- a/build.prod.js +++ b/build.prod.js @@ -18,7 +18,12 @@ const prefixer = postcss().use( ) const jsOpt = { presets: ['es2015', 'minify'], - plugins: ['transform-es2015-modules-amd'] + plugins: [ + 'transform-es2015-modules-amd', + 'transform-decorators-legacy', + 'transform-class-properties', + 'transform-object-rest-spread' + ] } const cssOpt = { includePaths: ['src/css/'], diff --git a/package-lock.json b/package-lock.json index 2b5f5fc..e90d0ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "doui-yua", + "name": "doui-anot", "version": "0.0.1", "lockfileVersion": 1, "requires": true, @@ -463,6 +463,47 @@ "babel-helper-is-void-0": "0.2.0" } }, + "babel-plugin-syntax-class-properties": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz", + "integrity": "sha1-1+sjt5oxf4VDlixQW4J8fWysJ94=", + "dev": true + }, + "babel-plugin-syntax-decorators": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz", + "integrity": "sha1-MSVjtNvePMgGzuPkFszurd0RrAs=", + "dev": true + }, + "babel-plugin-syntax-object-rest-spread": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", + "integrity": "sha1-/WU28rzhODb/o6VFjEkDpZe7O/U=", + "dev": true + }, + "babel-plugin-transform-class-properties": { + "version": "6.24.1", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.24.1.tgz", + "integrity": "sha1-anl2PqYdM9NvN7YRqp3vgagbRqw=", + "dev": true, + "requires": { + "babel-helper-function-name": "6.24.1", + "babel-plugin-syntax-class-properties": "6.13.0", + "babel-runtime": "6.26.0", + "babel-template": "6.26.0" + } + }, + "babel-plugin-transform-decorators-legacy": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-decorators-legacy/-/babel-plugin-transform-decorators-legacy-1.3.4.tgz", + "integrity": "sha1-dBtY9sW86eYCfgiC2cmU8E82aSU=", + "dev": true, + "requires": { + "babel-plugin-syntax-decorators": "6.13.0", + "babel-runtime": "6.26.0", + "babel-template": "6.26.0" + } + }, "babel-plugin-transform-es2015-arrow-functions": { "version": "6.22.0", "resolved": "https://registry.npmjs.org/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz", @@ -721,6 +762,16 @@ "integrity": "sha512-bPbUhkeN2Nc0KH0/A19GwQGj8w+CvdJzyu8t59VoEDgsNMQ9Bopzi5DrVkrSsVjbYUaZpzq/DYLrH+wD5K2Tig==", "dev": true }, + "babel-plugin-transform-object-rest-spread": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz", + "integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=", + "dev": true, + "requires": { + "babel-plugin-syntax-object-rest-spread": "6.13.0", + "babel-runtime": "6.26.0" + } + }, "babel-plugin-transform-property-literals": { "version": "6.8.5", "resolved": "https://registry.npmjs.org/babel-plugin-transform-property-literals/-/babel-plugin-transform-property-literals-6.8.5.tgz", diff --git a/package.json b/package.json index 8aaf582..66403d5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "doui-yua", + "name": "doui-anot", "version": "0.0.1", "description": "基于Anot框架的doUI组件库。支持IE10+,及现代浏览器。", "main": "index.js", @@ -13,13 +13,16 @@ }, "keywords": [ "doui", - "yua" + "Anot" ], "author": "yutent", "license": "MIT", "devDependencies": { "autoprefixer": "^7.2.5", "babel-core": "^6.26.0", + "babel-plugin-transform-class-properties": "^6.24.1", + "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-minify": "^0.2.0", "chalk": "^2.3.0", diff --git a/src/font/ui-font.eot b/src/font/ui-font.eot index b4d3763..fb01476 100644 Binary files a/src/font/ui-font.eot and b/src/font/ui-font.eot differ diff --git a/src/font/ui-font.js b/src/font/ui-font.js index 7dc9667..95f34ca 100644 --- a/src/font/ui-font.js +++ b/src/font/ui-font.js @@ -1 +1 @@ -(function(window){var svgSprite='';var script=function(){var scripts=document.getElementsByTagName("script");return scripts[scripts.length-1]}();var shouldInjectCss=script.getAttribute("data-injectcss");var ready=function(fn){if(document.addEventListener){if(~["complete","loaded","interactive"].indexOf(document.readyState)){setTimeout(fn,0)}else{var loadFn=function(){document.removeEventListener("DOMContentLoaded",loadFn,false);fn()};document.addEventListener("DOMContentLoaded",loadFn,false)}}else if(document.attachEvent){IEContentLoaded(window,fn)}function IEContentLoaded(w,fn){var d=w.document,done=false,init=function(){if(!done){done=true;fn()}};var polling=function(){try{d.documentElement.doScroll("left")}catch(e){setTimeout(polling,50);return}init()};polling();d.onreadystatechange=function(){if(d.readyState=="complete"){d.onreadystatechange=null;init()}}}};var before=function(el,target){target.parentNode.insertBefore(el,target)};var prepend=function(el,target){if(target.firstChild){before(el,target.firstChild)}else{target.appendChild(el)}};function appendSvg(){var div,svg;div=document.createElement("div");div.innerHTML=svgSprite;svgSprite=null;svg=div.getElementsByTagName("svg")[0];if(svg){svg.setAttribute("aria-hidden","true");svg.style.position="absolute";svg.style.width=0;svg.style.height=0;svg.style.overflow="hidden";prepend(svg,document.body)}}if(shouldInjectCss&&!window.__iconfont__svg__cssinject__){window.__iconfont__svg__cssinject__=true;try{document.write("")}catch(e){console&&console.log(e)}}ready(appendSvg)})(window) \ No newline at end of file +(function(window){var svgSprite='';var script=function(){var scripts=document.getElementsByTagName("script");return scripts[scripts.length-1]}();var shouldInjectCss=script.getAttribute("data-injectcss");var ready=function(fn){if(document.addEventListener){if(~["complete","loaded","interactive"].indexOf(document.readyState)){setTimeout(fn,0)}else{var loadFn=function(){document.removeEventListener("DOMContentLoaded",loadFn,false);fn()};document.addEventListener("DOMContentLoaded",loadFn,false)}}else if(document.attachEvent){IEContentLoaded(window,fn)}function IEContentLoaded(w,fn){var d=w.document,done=false,init=function(){if(!done){done=true;fn()}};var polling=function(){try{d.documentElement.doScroll("left")}catch(e){setTimeout(polling,50);return}init()};polling();d.onreadystatechange=function(){if(d.readyState=="complete"){d.onreadystatechange=null;init()}}}};var before=function(el,target){target.parentNode.insertBefore(el,target)};var prepend=function(el,target){if(target.firstChild){before(el,target.firstChild)}else{target.appendChild(el)}};function appendSvg(){var div,svg;div=document.createElement("div");div.innerHTML=svgSprite;svgSprite=null;svg=div.getElementsByTagName("svg")[0];if(svg){svg.setAttribute("aria-hidden","true");svg.style.position="absolute";svg.style.width=0;svg.style.height=0;svg.style.overflow="hidden";prepend(svg,document.body)}}if(shouldInjectCss&&!window.__iconfont__svg__cssinject__){window.__iconfont__svg__cssinject__=true;try{document.write("")}catch(e){console&&console.log(e)}}ready(appendSvg)})(window) \ No newline at end of file diff --git a/src/font/ui-font.ttf b/src/font/ui-font.ttf index 8568230..70e12c1 100644 Binary files a/src/font/ui-font.ttf and b/src/font/ui-font.ttf differ diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index d4baa6e..d9cf270 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -3297,11 +3297,12 @@ if (/^:/.test(attr.name)) { var name = attr.name.match(rmsAttr)[1] var value = null - if (!name || Anot.directives[name]) { + if (!name || Anot.directives[name] || events[name]) { return } try { value = parseExpr(attr.value, vmodels, {}).apply(0, vmodels) + value = toJson(value) elem.removeAttribute(attr.name) if (!value) { return @@ -4092,7 +4093,7 @@ elem.addEventListener(type, callback, false) var old = binding.rollback binding.rollback = function() { - elem.anotStter = null + elem.anotSetter = null Anot.unbind(elem, type, callback) old && old() } @@ -4196,7 +4197,7 @@ elem.msFocus = false }) } - elem.anotStter = updateVModel //#765 + elem.anotSetter = updateVModel //#765 watchValueInTimer(function() { if (root.contains(elem)) { if (!elem.msFocus) { @@ -4346,8 +4347,8 @@ function newSetter(value) { // jshint ignore:line setters[this.tagName].call(this, value) - if (!this.msFocus && this.anotStter) { - this.anotStter() + if (!this.msFocus && this.anotSetter) { + this.anotSetter() } } var inputProto = HTMLInputElement.prototype diff --git a/src/js/datepicker/style.scss b/src/js/datepicker/style.scss index 53863d9..ddc45d3 100644 --- a/src/js/datepicker/style.scss +++ b/src/js/datepicker/style.scss @@ -42,16 +42,16 @@ &:active {font-weight:bold; &::before {animation:ripple .3s cubic-bezier(0.23, 1, 0.32, 1);} } - &::after {content:"\e652";} + &::after {content:"\e692";} &.prev-month {left:35px; - &::after {content:"\e659"} + &::after {content:"\e67c"} } &.next-month {left:auto; right:35px; - &::after {content:"\e658"} + &::after {content:"\e66e"} } &.next-year {left:auto; right:0; - &::after {content:"\e653"} + &::after {content:"\e694"} } } diff --git a/src/js/drag/index.js b/src/js/drag/index.js new file mode 100644 index 0000000..60c355e --- /dev/null +++ b/src/js/drag/index.js @@ -0,0 +1,219 @@ +/** + * + * @authors yutent (yutent@doui.cc) + * @date 2017-03-29 18:39:35 + * + */ + +'use strict' + +function getBindingCallback(elem, name, vmodels) { + var callback = elem.getAttribute(name) + if (callback) { + for (var i = 0, vm; (vm = vmodels[i++]); ) { + if (vm.hasOwnProperty(callback) && typeof vm[callback] === 'function') { + return vm[callback] + } + } + } +} +Anot.ui.drag = '1.0.0' +// 元素拖动 +Anot.directive('drag', { + priority: 1500, + init: function(binding) { + binding.expr = '"' + binding.expr + '"' + Anot(binding.element).css('cursor', 'move') + + //取得拖动的3种状态回调 + //按下,且拖拽之前 + binding.beforedrag = getBindingCallback( + binding.element, + 'data-beforedrag', + binding.vmodels + ) + //拖拽过程 + binding.dragging = getBindingCallback( + binding.element, + 'data-dragging', + binding.vmodels + ) + // 拖拽结束,且释放鼠标 + binding.dragged = getBindingCallback( + binding.element, + 'data-dragged', + binding.vmodels + ) + + //默认允许溢出可视区 + binding.overflow = true + + //方向,x轴, y轴, xy轴 + binding.axis = 'xy' + if (!!binding.element.dataset.axis) { + binding.axis = binding.element.dataset.axis + delete binding.element.dataset.axis + } + + //默认不限制拖拽区域 + binding.limit = false + if (!!binding.element.dataset.limit) { + binding.limit = binding.element.dataset.limit + //这里,只要不为空,除parent外,其他值都默认为window, 故"可溢出"为false + binding.overflow = false + delete binding.element.dataset.limit + } + + delete binding.element.dataset.beforedrag + delete binding.element.dataset.dragging + delete binding.element.dataset.dragged + }, + update: function(val) { + var _this = this, + target = val ? this.element.parentNode : this.element, + $drag = Anot(this.element), + $doc = Anot(document), + $target = null, + parentElem = null + + // val值不为空时, 获取真正的拖动元素 + // 仅从父级上找 + while (val && target) { + if (target.classList.contains(val) || target.id === val) { + break + } else { + target = target.parentNode + } + } + $target = Anot(target) + // 限制范围为parent时,获取父级元素 + if (this.limit === 'parent') { + parentElem = target.parentNode + } + + var dx, dy, mx, my, ox, oy, fox, foy, tw, th, ww, wh, bst, bsl + $drag.bind('mousedown', function(ev) { + var gcs = getComputedStyle(target), + cst = gcs.transform.replace(/matrix\((.*)\)/, '$1'), + offset = $target.offset() + + cst = cst !== 'none' ? cst.split(', ') : [1, 0, 0, 1, 0, 0] + cst[4] -= 0 + cst[5] -= 0 + + //记录初始的transform位移 + dx = cst[4] + dy = cst[5] + + //滚动条的偏移 + bst = $doc.scrollTop() + bsl = $doc.scrollLeft() + + // 计算元素的offset值, 需要修正 + ox = offset.left - dx - bsl + oy = offset.top - dy - bst + + mx = ev.pageX //按下鼠标的的坐标值 + my = ev.pageY //按下鼠标的的坐标值 + + // 在按下时才获取窗口大小, 是为了防止人为的改变窗口大小,导致计算不准备 + // 同时减少不必要的事件监听(页面上可能会很多可拖动元素) + ww = window.innerWidth + wh = window.innerHeight + + // 同样,在点击之后获取元素的宽高,可保证获取到的是真实的值 + tw = target.clientWidth + th = target.clientHeight + + //拖拽前回调 + if (_this.beforedrag) { + var result = _this.beforedrag.call(_this.vmodels, target, ox, oy) + if (result === false) { + return + } + } + + //限制区域, 4个值依次是: 上, 下, 左, 右 + var limit = [0, wh - th, 0, ww - tw] + + if (_this.limit === 'parent') { + var pgcs = getComputedStyle(parentElem), + pcst = pgcs.transform.replace(/matrix\((.*)\)/, '$1'), + poffset = Anot(parentElem).offset() + + pcst = pcst !== 'none' ? pcst.split(', ') : [1, 0, 0, 1, 0, 0] + + var pox = poffset.left - pcst[4] - bsl, + poy = poffset.top - pcst[5] - bst + + limit = [ + poy, + poy + parentElem.clientHeight - th, + pox, + pox + parentElem.clientWidth - tw + ] + } + + var mvfn = $doc.bind('mousemove', function(ev) { + //坐标轴限制 + if (_this.axis !== 'y') { + cst[4] = ev.pageX - mx + dx + } + if (_this.axis !== 'x') { + cst[5] = ev.pageY - my + dy + } + + ;(fox = ox + cst[4]), //修正的offset + (foy = oy + cst[5]) //修正的offset + + //如果不允许溢出可视区 + if (!_this.overflow) { + if (_this.axis !== 'y') { + if (fox <= limit[2]) { + fox = limit[2] + //修正矩阵 + cst[4] = fox - ox + } + if (fox >= limit[3]) { + fox = limit[3] + //修正矩阵 + cst[4] = fox - ox + } + } + + if (_this.axis !== 'x') { + if (foy <= limit[0]) { + foy = limit[0] + //修正矩阵 + cst[5] = foy - oy + } + if (foy >= limit[1]) { + foy = limit[1] + //修正矩阵 + cst[5] = foy - oy + } + } + } + + $target.css({ + transform: 'matrix(' + cst.join(', ') + ')' + }) + + //拖拽过程的回调 + if (_this.dragging) { + _this.dragging.call(_this.vmodels, target, fox, foy) + } + // 防止拖动到边缘时导致页面滚动 + ev.preventDefault() + }), + upfn = $doc.bind('mouseup', function(ev) { + $doc.unbind('mousemove', mvfn) + $doc.unbind('mouseup', upfn) + //结束回调 + if (_this.dragged) { + _this.dragged.call(_this.vmodels, target, fox, foy) + } + }) + }) + } +}) diff --git a/src/js/drag/main.js b/src/js/drag/main.js deleted file mode 100644 index 5d4a5ca..0000000 --- a/src/js/drag/main.js +++ /dev/null @@ -1,216 +0,0 @@ -/** - * - * @authors yutent (yutent@doui.cc) - * @date 2017-03-29 18:39:35 - * - */ - -"use strict"; - -define(['yua'], function(){ - - function getBindingCallback(elem, name, vmodels) { - var callback = elem.getAttribute(name) - if (callback) { - for (var i = 0, vm; vm = vmodels[i++]; ) { - if (vm.hasOwnProperty(callback) && typeof vm[callback] === "function") { - return vm[callback] - } - } - } - } - yua.ui.drag = '1.0.0' - // 元素拖动 - yua.directive('drag', { - priority: 1500, - init: function(binding){ - binding.expr = '"' + binding.expr + '"' - yua(binding.element).css('cursor', 'move') - - //取得拖动的3种状态回调 - //按下,且拖拽之前 - binding.beforedrag = getBindingCallback(binding.element, 'data-beforedrag', binding.vmodels) - //拖拽过程 - binding.dragging = getBindingCallback(binding.element, 'data-dragging', binding.vmodels) - // 拖拽结束,且释放鼠标 - binding.dragged = getBindingCallback(binding.element, 'data-dragged', binding.vmodels) - - //默认允许溢出可视区 - binding.overflow = true - - //方向,x轴, y轴, xy轴 - binding.axis = 'xy' - if(!!binding.element.dataset.axis){ - binding.axis = binding.element.dataset.axis - delete binding.element.dataset.axis - } - - //默认不限制拖拽区域 - binding.limit = false - if(!!binding.element.dataset.limit) { - binding.limit = binding.element.dataset.limit - //这里,只要不为空,除parent外,其他值都默认为window, 故"可溢出"为false - binding.overflow = false - delete binding.element.dataset.limit - } - - delete binding.element.dataset.beforedrag - delete binding.element.dataset.dragging - delete binding.element.dataset.dragged - }, - update: function(val){ - var _this = this, - target = val ? this.element.parentNode : this.element, - $drag = yua(this.element), - $doc = yua(document), - $target = null, - parentElem = null; - - // val值不为空时, 获取真正的拖动元素 - // 仅从父级上找 - while(val && target){ - if(target.classList.contains(val) || target.id === val){ - break - }else{ - target = target.parentNode - } - } - $target = yua(target); - // 限制范围为parent时,获取父级元素 - if(this.limit === 'parent'){ - parentElem = target.parentNode - } - - - var dx,dy,mx,my,ox,oy,fox,foy,tw,th,ww,wh,bst,bsl; - $drag.bind('mousedown', function(ev){ - var gcs = getComputedStyle(target), - cst = gcs.transform.replace(/matrix\((.*)\)/, '$1'), - offset = $target.offset(); - - cst = cst !== 'none' ? cst.split(', ') : [1,0,0,1,0,0] - cst[4] -= 0 - cst[5] -= 0 - - //记录初始的transform位移 - dx = cst[4] - dy = cst[5] - - //滚动条的偏移 - bst = $doc.scrollTop() - bsl = $doc.scrollLeft() - - // 计算元素的offset值, 需要修正 - ox = offset.left - dx - bsl - oy = offset.top - dy - bst - - mx = ev.pageX //按下鼠标的的坐标值 - my = ev.pageY //按下鼠标的的坐标值 - - // 在按下时才获取窗口大小, 是为了防止人为的改变窗口大小,导致计算不准备 - // 同时减少不必要的事件监听(页面上可能会很多可拖动元素) - ww = window.innerWidth; - wh = window.innerHeight; - - // 同样,在点击之后获取元素的宽高,可保证获取到的是真实的值 - tw = target.clientWidth; - th = target.clientHeight; - - //拖拽前回调 - if(_this.beforedrag){ - var result = _this.beforedrag.call(_this.vmodels, target, ox, oy) - if(result === false){ - return - } - } - - //限制区域, 4个值依次是: 上, 下, 左, 右 - var limit = [0, wh - th, 0, ww - tw] - - if(_this.limit === 'parent') { - var pgcs = getComputedStyle(parentElem), - pcst = pgcs.transform.replace(/matrix\((.*)\)/, '$1'), - poffset = yua(parentElem).offset(); - - pcst = pcst !== 'none' ? pcst.split(', ') : [1,0,0,1,0,0] - - var pox = poffset.left - pcst[4] - bsl, - poy = poffset.top - pcst[5] - bst; - - limit = [poy, poy + parentElem.clientHeight - th, pox, pox + parentElem.clientWidth - tw] - } - - var mvfn = $doc.bind('mousemove', function(ev){ - - //坐标轴限制 - if(_this.axis !== 'y'){ - cst[4] = ev.pageX - mx + dx - } - if(_this.axis !== 'x'){ - cst[5] = ev.pageY - my + dy - } - - - fox = ox + cst[4], //修正的offset - foy = oy + cst[5]; //修正的offset - - - //如果不允许溢出可视区 - if(!_this.overflow){ - if(_this.axis !== 'y'){ - if(fox <= limit[2]) { - fox = limit[2] - //修正矩阵 - cst[4] = fox - ox - } - if(fox >= limit[3]){ - fox = limit[3] - //修正矩阵 - cst[4] = fox - ox - } - } - - if(_this.axis !== 'x'){ - if(foy <= limit[0]) { - foy = limit[0] - //修正矩阵 - cst[5] = foy - oy - } - if(foy >= limit[1]){ - foy = limit[1] - //修正矩阵 - cst[5] = foy - oy - } - } - - } - - $target.css({ - transform: 'matrix(' + cst.join(', ') + ')' - }) - - //拖拽过程的回调 - if(_this.dragging){ - _this.dragging.call(_this.vmodels, target, fox, foy) - } - // 防止拖动到边缘时导致页面滚动 - ev.preventDefault() - }), - upfn = $doc.bind('mouseup', function(ev){ - $doc.unbind('mousemove', mvfn) - $doc.unbind('mouseup', upfn) - //结束回调 - if(_this.dragged){ - _this.dragged.call(_this.vmodels, target, fox, foy) - } - }); - - }) - - } - }) - - - - -}) diff --git a/src/js/layer/base.js b/src/js/layer/base.js index c1608a5..29cc150 100644 --- a/src/js/layer/base.js +++ b/src/js/layer/base.js @@ -1,243 +1,257 @@ /** - * + * * @authors yutent (yutent@doui.cc) * @date 2016-09-21 01:36:29 * */ -"use strict"; +'use strict' +import 'drag/index' +import './skin/def.scss' -define(['yua', 'lib/drag/main', 'css!./skin/def'], function(yua){ +Anot.ui.layer = '1.0.0-base' +let layerDom = {} +let layerObj = {} +let unique = null //储存当前打开的1/2/3类型的弹窗 +let lid = 0 +let defconf = { + type: 1, // 弹窗类型 + skin: 'def', //默认主题 + icon: 1, //图标类型 + background: '#fff', + mask: true, //遮罩 + maskClose: false, //遮罩点击关闭弹窗 + radius: '0px', //弹窗圆角半径 + area: ['auto', 'auto'], + title: '提示', //弹窗主标题(在工具栏上的) + menubar: true, //是否显示菜单栏 + content: '', // 弹窗的内容 + fixed: false, //是否固定不可拖拽 + offset: null, //弹窗出来时的坐标, 为数组,可有4个值,依次是 上右下左 + btns: ['确定', '取消'] //弹窗的2个按钮的文字 +} +const uuid = function() { + return 'layer-' + ++lid +} +const close = function(id) { + if (typeof id !== 'string' && typeof id !== 'number') { + return Anot.error('要关闭的layer实例不存在') + } + if (/^\$wrap\-/.test(id) || layerObj['$wrap-' + id]) { + try { + id = (layerObj['$wrap-' + id] ? '$wrap-' : '') + id + //未显示过,忽略 + if (!layerObj[id].show) { + return + } + layerObj[id].parentElem.replaceChild(layerObj[id].wrap, layerDom[id][0]) + layerObj[id].wrap.style.display = 'none' + layerObj[id].show = false + } catch (err) {} + } else { + try { + // document.body.removeChild(layerDom[id][1]) + document.body.removeChild(layerDom[id][0]) + unique = null + } catch (err) {} - if(window.layer){ - return window.layer + delete layerDom[id] + delete Anot.vmodels[id] + } +} + +const reapeat = function(str, num) { + var idx = 0, + result = '' + while (idx < num) { + result += str + idx++ + } + return result +} +const fixOffset = function(val) { + if (!val && val !== 0) { + return 'auto' + } else { + return val + } +} +const __layer__ = function(conf) { + if (conf) { + let { yes, no, success } = conf + delete conf.yes + delete conf.no + delete conf.success + + this.construct({ + state: { ...conf }, + props: { yes, no, success } + }) + .append() + .show() + } +} + +const _layer = { + alert: function(msg, conf) { + if (typeof conf === 'function') { + conf = { methods: { yes: conf, no: conf } } + } else if (typeof conf === 'object') { + conf = conf + } else { + conf = {} + } + conf.icon = 5 + conf.content = msg + conf.fixed = true + return _layer.open(conf) + }, + confirm: function(msg, yescb, nocb) { + var conf = {} + if (typeof yescb === 'function') { + conf = { yes: yescb } + } else if (typeof yescb === 'object') { + conf = yescb + } + conf.type = 2 + conf.icon = 0 + conf.content = msg + if (typeof nocb === 'function') { + conf.no = nocb + } + conf.fixed = true + return _layer.open(conf) + }, + msg: function(msg, conf) { + if (typeof conf !== 'object') { + var tmp = conf + conf = { timeout: 2500 } + if (typeof tmp === 'number') { + conf.icon = tmp + } } - yua.ui.layer = '1.0.0-base' - var layerDom = {}, - layerObj = {}, - unique = null, //储存当前打开的1/2/3类型的弹窗 - lid = 0, - defconf = { - type: 1, // 弹窗类型 - skin: 'def', //默认主题 - icon: 1, //图标类型 - background: '#fff', - shade: true, //遮罩 - shadeClose: false, //遮罩点击关闭弹窗 - radius: '0px', //弹窗圆角半径 - area: ['auto', 'auto'], - title: '提示', //弹窗主标题(在工具栏上的) - menubar: true, //是否显示菜单栏 - content: '', // 弹窗的内容 - fixed: false, //是否固定不可拖拽 - offset: null, //弹窗出来时的坐标, 为数组,可有4个值,依次是 上右下左 - btns: ['确定', '取消'], //弹窗的2个按钮的文字 - yes: yua.noop, //确定按钮对应的回调 - no: yua.noop, //取消按钮对应的回调 - success: null //弹窗初始化完成时的回调 - }, - uuid = function(){ - return 'layer-' + (++lid) - }, - close = function(id){ - if(typeof id !== 'string' && typeof id !== 'number'){ - return yua.error('要关闭的layer实例不存在') - } - if(/^\$wrap\-/.test(id) || layerObj['$wrap-' + id]){ + if (!conf.hasOwnProperty('timeout')) { + conf.timeout = 2500 + } - try { - id = (layerObj['$wrap-' + id] ? '$wrap-' : '') + id; - //未显示过,忽略 - if(!layerObj[id].show){ - return - } - layerObj[id].parentElem.replaceChild(layerObj[id].wrap, layerDom[id][1]) - layerObj[id].wrap.style.display = 'none' - layerObj[id].show = false + conf.specialMode = true //特殊模式 + conf.content = '
' + msg + '
' + conf.type = 7 + conf.fixed = true + conf.shade = false + conf.menubar = false + conf.radius = '5px' + return _layer.open(conf) + }, + loading: function(style, time, cb) { + style = style >>> 0 - }catch(err){} - }else{ - try { - document.body.removeChild(layerDom[id][1]) - document.body.removeChild(layerDom[id][0]) - unique = null - }catch(err){} + if (typeof time === 'function') { + cb = time + time = 0 + } else { + time = time >>> 0 + if (typeof cb !== 'function') { + cb = Anot.noop + } + } + return _layer.open({ + type: 6, + load: style, + yes: cb, + timeout: time, + menubar: false, + background: 'none', + fixed: true + }) + }, + tips: function(msg, elem, conf) { + if (!(elem instanceof HTMLElement)) { + return Anot.error('tips类型必须指定一个目标容器') + } + if (typeof conf !== 'object') { + var tmp = conf + conf = { timeout: 2500 } + if (typeof tmp === 'number') { + conf.icon = tmp + } + } + if (!conf.hasOwnProperty('timeout')) { + conf.timeout = 2500 + } + if (!conf.background) { + conf.background = 'rgba(0,0,0,.5)' + } + if (!conf.color) { + conf.color = '#fff' + } + conf.$elem = elem + conf.content = msg + conf.type = 5 + conf.icon = 0 + conf.fixed = true + conf.shade = false + conf.menubar = false + return _layer.open(conf) + }, + prompt: function(msg, yescb) { + if (typeof yescb !== 'function') { + return console.error( + 'argument [callback] requires a function, but ' + + typeof yescb + + ' given' + ) + } + var conf = { + type: 3, + prompt: '', + title: msg, + content: + '', + fixed: true, + yes: yescb + } + return _layer.open(conf) + }, + use: function(skin, callback) { + require(['css!./skin/' + skin], callback) + }, + close: close, + open: function(conf) { + if (typeof conf === 'string') { + /*conf = '$wrap-' + conf + if (!layerObj[conf]) { + throw new Error('layer实例不存在') + } else { + //只能显示一个实例 + if (layerObj[conf].show) { + return conf + } + layerObj[conf].show = true - delete layerDom[id] - delete yua.vmodels[id] - } - }, - reapeat = function(str, num){ - var idx = 0, - result = '' - while(idx < num){ - result += str - idx++ - } - return result - }, - fixOffset = function (val){ - if(!val && val !== 0){ - return 'auto' - }else{ - return val - } - }, - __constructor = function(conf){ - if(conf){ - this.ready(conf).append().show() - } - }, - __layer = { - alert: function(msg, conf){ - if(typeof conf === 'function'){ - conf = {yes: conf, no: conf} - }else if(typeof conf === 'object'){ - conf = conf - }else{ - conf = {} - } - conf.icon = 5 - conf.content = msg - return __layer.open(conf) - }, - confirm: function(msg, yescb, nocb){ - var conf = {} - if(typeof yescb === 'function'){ - conf = {yes: yescb} - }else if(typeof yescb === 'object'){ - conf = yescb - } - conf.type = 2 - conf.icon = 0 - conf.content = msg - if(typeof nocb === 'function'){ - conf.no = nocb - } - return __layer.open(conf) - }, - msg: function(msg, conf){ - if(typeof conf !== 'object'){ - var tmp = conf - conf = {timeout: 2500} - if(typeof tmp === 'number'){ - conf.icon = tmp - } - } + if (!Anot.vmodels[conf]) { + Anot(layerObj[conf].obj.init) + } - if(!conf.hasOwnProperty('timeout')){ - conf.timeout = 2500 - } + layerObj[conf].parentElem.appendChild(layerDom[conf][1]) + layerDom[conf][1] + .querySelector('.detail') + .appendChild(layerObj[conf].wrap) + layerObj[conf].wrap.style.display = '' + // Anot.scan(layerDom[conf][1]) + layerObj[conf].obj.show() + return conf + }*/ + } else { + return new __layer__(conf).init.$id + } + }, + version: Anot.ui.layer +} - conf.specialMode = true;//特殊模式 - conf.content = '' + msg + '
' - conf.type = 7 - conf.fixed = true - conf.shade = false - conf.menubar = false - conf.radius = '5px' - return __layer.open(conf) - }, - loading: function(style, time, cb){ - style = style >>> 0 - - if(typeof time === 'function'){ - cb = time; - time = 0 - } else{ - time = time >>> 0 - if(typeof cb !== 'function'){ - cb = yua.noop - } - } - return __layer.open({type: 6, load: style, yes: cb, timeout: time, menubar: false, background: 'none', fixed: true}) - }, - tips: function(msg, elem, conf){ - if(!(elem instanceof HTMLElement)){ - return yua.error('tips类型必须指定一个目标容器') - } - if(typeof conf !== 'object'){ - var tmp = conf - conf = {timeout: 2500} - if(typeof tmp === 'number'){ - conf.icon = tmp - } - } - if(!conf.hasOwnProperty('timeout')){ - conf.timeout = 2500 - } - if(!conf.background){ - conf.background = 'rgba(0,0,0,.5)' - } - if(!conf.color){ - conf.color = '#fff' - } - conf.$elem = elem - conf.content = msg - conf.type = 5; - conf.icon = 0; - conf.fixed = true; - conf.shade = false; - conf.menubar = false; - return __layer.open(conf) - }, - prompt: function(msg, yescb){ - if(typeof yescb !== 'function'){ - return console.error('argument [callback] requires a function, but ' + (typeof yescb) + ' given') - } - var conf = { - type: 3, - prompt: '', - title: msg, - content: '', - yes: function(id){ - if(!yua.vmodels[id].prompt){ - return - } - yescb(id, yua.vmodels[id].prompt) - } - } - return __layer.open(conf) - }, - use: function(skin, callback){ - require(['css!./skin/' + skin], callback) - }, - close: close, - open: function(conf){ - if(typeof conf === 'string'){ - conf = '$wrap-' + conf - if(!layerObj[conf]){ - throw new Error('layer实例不存在') - }else{ - //只能显示一个实例 - if(layerObj[conf].show){ - return conf - } - layerObj[conf].show = true - - if(!yua.vmodels[conf]){ - yua(layerObj[conf].obj.init) - } - - layerObj[conf].parentElem.appendChild(layerDom[conf][1]) - layerDom[conf][1].querySelector('.detail').appendChild(layerObj[conf].wrap) - layerObj[conf].wrap.style.display = '' - yua.scan(layerDom[conf][1]) - layerObj[conf].obj.show() - return conf - } - }else{ - return new __constructor(conf).init.$id - } - }, - version: yua.ui.layer - }; - - - defconf.yes = defconf.no = close - /*type: { // 弹窗类型对应的id值 +/*type: { // 弹窗类型对应的id值 1: 'alert', 2: 'confirm', 3: 'prompt', @@ -246,364 +260,423 @@ define(['yua', 'lib/drag/main', 'css!./skin/def'], function(yua){ 6: 'loading', 7: 'msg', }*/ - __constructor.prototype = { - dot: { //loading的子元素数量 - 1: 0, - 2: 0, - 3: 5, - 4: 5, - 5: 9 +__layer__.prototype = { + dot: { + //loading的子元素数量 + 1: 0, + 2: 0, + 3: 5, + 4: 5, + 5: 9 + }, + timeout: null, + construct: function(conf) { + let _id = conf.$id || uuid() + this.init = { + $id: _id, + state: { + ...defconf, + ...conf.state + }, + props: conf.props, + methods: { + onMaskClick: function() { + if (this.type < 4) { + this.$refs.layer.classList.add('scale') + setTimeout(() => { + this.$refs.layer.classList.remove('scale') + }, 100) + } }, - timeout: null, - create: function(){ - var layBox = document.createElement('div'), - coverBox = document.createElement('div'); - - coverBox.className = 'do-layer-cover type-' + this.init.type - // 允许点击遮罩关闭弹层时, 添加控制器 - if(this.init.shadeClose){ - coverBox.setAttribute(':controller', this.cInit.$id) - coverBox.setAttribute(':click', 'close(\'' + this.init.$id + '\')') + handleConfirm: function() { + if (this.type === 3) { + if (!this.prompt) { + return } - - layBox.className = 'do-layer skin-' - + this.init.skin - + (this.init.type === 5 && ' active' || '') - + ' type-' - + ((!this.init.specialMode && this.init.type === 7) ? 'unspecial' : this.init.type); - - //暂时隐藏,避免修正定位时,能看到闪一下 - layBox.style.visibility = 'hidden' - layBox.style.borderRadius = this.init.radius - - layBox.setAttribute(':controller', this.init.$id) - - //没有菜单栏, 且未禁止拖拽,则加上可拖拽属性 - if(!this.init.menubar && !this.init.fixed){ - layBox.setAttribute(':drag', '') - layBox.setAttribute('data-limit', 'window') - } - - //弹窗的宽高 - var boxcss = '' - if(this.init.area[0] !== 'auto'){ - boxcss += 'width: ' + this.init.area[0] + ';' - } - if(this.init.area[1] !== 'auto'){ - boxcss += 'height: ' + this.init.area[1] + ';' - } - - layBox.innerHTML = this.getMenubar() - + ' ' - + this.getBtns() - + (this.init.type === 5 && '' || '') - delete this.init.wrap - return [this.init.shade ? coverBox : null, layBox] + } + if (typeof this.props.yes === 'function') { + this.props.yes.call(this, this.prompt, this.$id) + } else { + this.close() + } }, - getCont: function(){ - if(this.init.type === 6){ - return this.getLoading(this.init.load) - }else{ - return this.getIcon() - + '' - } + handleCancel: function() { + if (typeof this.props.no === 'function') { + this.props.no.call(this, this.$id) + } else { + this.close() + } }, - getLoading: function(style){ - return '' + msg + '
' - conf.type = 7 - conf.fixed = true - conf.shade = false - conf.menubar = false - conf.radius = '5px' - return __layer.open(conf) - }, - loading: function(style, time, cb){ - style = style >>> 0 - - if(typeof time === 'function'){ - cb = time; - time = 0 - } else{ - time = time >>> 0 - if(typeof cb !== 'function'){ - cb = yua.noop - } - } - return __layer.open({type: 6, load: style, yes: cb, timeout: time, menubar: false, background: 'none', fixed: true}) - }, - tips: function(msg, elem, conf){ - if(!(elem instanceof HTMLElement)){ - return console.error(new Error('tips类型必须指定一个目标容器')) - } - if(typeof conf !== 'object'){ - var tmp = conf - conf = {timeout: 2500} - if(typeof tmp === 'number'){ - conf.icon = tmp - } - } - if(!conf.hasOwnProperty('timeout')){ - conf.timeout = 2500 - } - if(!conf.background){ - conf.background = 'rgba(0,0,0,.5)' - } - if(!conf.color){ - conf.color = '#fff' - } - conf.$elem = elem - conf.content = msg - conf.type = 5; - conf.icon = 0; - conf.fixed = true; - conf.shade = false; - 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') - } - var conf = { - type: 3, - icon: 7, - prompt: '', - title: msg, - content: '', - yes: function(id){ - callback(id, yua.vmodels[id].prompt) - } - } - return __layer.open(conf) - }, - use: function(skin, callback){ - require(['css!./skin/' + skin], callback) - }, - close: close, - open: function(conf){ - if(typeof conf === 'string'){ - conf = '$wrap-' + conf - if(!layerObj[conf]){ - throw new Error('layer实例不存在') - }else{ - //只能显示一个实例 - if(layerObj[conf].show){ - return - } - layerObj[conf].show = true - - if(!yua.vmodels[conf]){ - yua.define(layerObj[conf].obj.init) - } - - yua.scan(layerDom[conf][1]) - layerObj[conf].obj.show() - - layerObj[conf].parentElem.appendChild(layerDom[conf][1]) - layerObj[conf].parentElem.replaceChild(layerDom[conf][1], layerObj[conf].wrap) - } - }else{ - return new __constructor(conf).init.$id - } - }, - version: '0.0.1-base' - }; - - /*type: { // 弹窗类型对应的id值 - 1: 'alert', - 2: 'confirm', - 3: 'prompt', - 4: 'iframe', - 5: 'tips', - 6: 'loading', - 7: 'msg', - }*/ - __constructor.prototype = { - dot: { //loading的子元素数量 - 0: 4, - 1: 9, - 2: 2, - 3: 3, - 4: 2, - 5: 5, - 6: 5, - 7: 5 - }, - timeout: null, - create: function(){ - var layBox = document.createElement('div'), - coverBox = document.createElement('div'); - - coverBox.className = 'do-layer-cover type-' + this.init.type - // 允许点击遮罩关闭弹层时, 添加控制器 - if(this.init.shadeClose){ - coverBox.setAttribute(':controller', this.cInit.$id) - coverBox.setAttribute(':click', 'close(\'' + this.init.$id + '\')') - } - - layBox.className = 'do-layer skin-' - + this.init.skin - + (this.init.type === 5 && ' active' || '') - + ' type-' - + ((!this.init.specialMode && this.init.type === 7) ? 'unspecial' : this.init.type); - - //暂时隐藏,避免修正定位时,能看到闪一下 - layBox.style.visibility = 'hidden' - layBox.style.borderRadius = this.init.radius - - layBox.setAttribute(':controller', this.init.$id) - - //没有菜单栏, 且未禁止拖拽,则加上可拖拽属性 - if(!this.init.menubar && !this.init.fixed){ - layBox.setAttribute(':drag', '') - layBox.setAttribute('data-limit', 'window') - } - - //弹窗的宽高 - var boxcss = '' - if(this.init.area[0] !== 'auto'){ - boxcss += 'width: ' + this.init.area[0] + ';' - } - if(this.init.area[1] !== 'auto'){ - boxcss += 'height: ' + this.init.area[1] + ';' - } - - layBox.innerHTML = this.getMenubar() - + ' ' - + this.getBtns() - + (this.init.type === 5 && '' || '') - - return [this.init.shade ? coverBox : null, layBox] - }, - getCont: function(){ - if(this.init.type === 6){ - return this.getLoading(this.init.load) - }else{ - return this.getIcon() - + '' - } - }, - getLoading: function(style){ - return '' + msg + '
' - conf.type = 7 - conf.fixed = true - conf.shade = false - conf.menubar = false - conf.radius = '5px' - return __layer.open(conf) - }, - loading: function(style, time, cb){ - style = style >>> 0 - - if(typeof time === 'function'){ - cb = time; - time = 0 - } else{ - time = time >>> 0 - if(typeof cb !== 'function'){ - cb = yua.noop - } - } - return __layer.open({type: 6, load: style, yes: cb, timeout: time, menubar: false, background: 'none', fixed: true}) - }, - tips: function(msg, elem, conf){ - if(!(elem instanceof HTMLElement)){ - return console.error(new Error('tips类型必须指定一个目标容器')) - } - if(typeof conf !== 'object'){ - var tmp = conf - conf = {timeout: 2500} - if(typeof tmp === 'number'){ - conf.icon = tmp - } - } - if(!conf.hasOwnProperty('timeout')){ - conf.timeout = 2500 - } - if(!conf.background){ - conf.background = 'rgba(0,0,0,.5)' - } - if(!conf.color){ - conf.color = '#fff' - } - conf.$elem = elem - conf.content = msg - conf.type = 5; - conf.icon = 0; - conf.fixed = true; - conf.shade = false; - 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') - } - var conf = { - type: 3, - icon: 7, - prompt: '', - title: msg, - content: '', - yes: function(id){ - callback(id, yua.vmodels[id].prompt) - } - } - return __layer.open(conf) - }, - use: function(skin, callback){ - require(['css!./skin/' + skin], callback) - }, - close: close, - open: function(conf){ - if(typeof conf === 'string'){ - conf = '$wrap-' + conf - if(!layerObj[conf]){ - throw new Error('layer实例不存在') - }else{ - //只能显示一个实例 - if(layerObj[conf].show){ - return - } - layerObj[conf].show = true - - if(!yua.vmodels[conf]){ - yua.define(layerObj[conf].obj.init) - } - - yua.scan(layerDom[conf][1]) - layerObj[conf].obj.show() - - layerObj[conf].parentElem.appendChild(layerDom[conf][1]) - layerObj[conf].parentElem.replaceChild(layerDom[conf][1], layerObj[conf].wrap) - } - }else{ - return new __constructor(conf).init.$id - } - }, - version: '0.0.1-base' - }; - - /*type: { // 弹窗类型对应的id值 - 1: 'alert', - 2: 'confirm', - 3: 'prompt', - 4: 'iframe', - 5: 'tips', - 6: 'loading', - 7: 'msg', - }*/ - __constructor.prototype = { - dot: { //loading的子元素数量 - 0: 4, - 1: 9, - 2: 2, - 3: 3, - 4: 2, - 5: 5, - 6: 5, - 7: 5 - }, - timeout: null, - create: function(){ - var layBox = document.createElement('div'), - coverBox = document.createElement('div'); - - coverBox.className = 'do-layer-cover type-' + this.init.type - // 允许点击遮罩关闭弹层时, 添加控制器 - if(this.init.shadeClose){ - coverBox.setAttribute(':controller', this.cInit.$id) - coverBox.setAttribute(':click', 'close(\'' + this.init.$id + '\')') - } - - layBox.className = 'do-layer skin-' - + this.init.skin - + (this.init.type === 5 && ' active' || '') - + ' type-' - + ((!this.init.specialMode && this.init.type === 7) ? 'unspecial' : this.init.type); - - //暂时隐藏,避免修正定位时,能看到闪一下 - layBox.style.visibility = 'hidden' - layBox.style.borderRadius = this.init.radius - - layBox.setAttribute(':controller', this.init.$id) - - //没有菜单栏, 且未禁止拖拽,则加上可拖拽属性 - if(!this.init.menubar && !this.init.fixed){ - layBox.setAttribute(':drag', '') - layBox.setAttribute('data-limit', 'window') - } - - //弹窗的宽高 - var boxcss = '' - if(this.init.area[0] !== 'auto'){ - boxcss += 'width: ' + this.init.area[0] + ';' - } - if(this.init.area[1] !== 'auto'){ - boxcss += 'height: ' + this.init.area[1] + ';' - } - - layBox.innerHTML = this.getMenubar() - + ' ' - + this.getBtns() - + (this.init.type === 5 && '' || '') - - return [this.init.shade ? coverBox : null, layBox] - }, - getCont: function(){ - if(this.init.type === 6){ - return this.getLoading(this.init.load) - }else{ - return this.getIcon() - + '' - } - }, - getLoading: function(style){ - return '' + codes[idx - 1] + '\n
' //加\n为了避免空行时无法显示
+ }
+
+ return '' + output + '' +} + +Renderer.prototype.blockquote = function(quote) { + return '
\n' + quote + '\n' +} +Renderer.prototype.mark = function(mark, t) { + return ( + '
' + text + '
\n' +} + +Renderer.prototype.table = function(header, body) { + return ( + '' + txt + '
'
+}
+
+Renderer.prototype.br = function() {
+ return this.options.xhtml ? 'An error occured:
' + + escape(e.message + '', true) + + '' + ) + } + throw e + } +} + +/** + * Options + */ + +marked.options = marked.setOptions = function(opt) { + merge(marked.defaults, opt) + return marked +} +if (window.Anot) { + Anot.ui.marked = '1.0.0' +} + +marked.defaults = { + gfm: true, + tables: true, + breaks: true, + pedantic: false, + sanitize: false, + sanitizer: null, + mangle: true, + smartLists: false, + silent: false, + highlight: null, + langPrefix: 'lang-', + smartypants: false, + headerPrefix: '', + renderer: new Renderer(), + xhtml: false +} + +/** + * Expose + */ + +marked.Parser = Parser +marked.parser = Parser.parse + +marked.Renderer = Renderer + +marked.Lexer = Lexer +marked.lexer = Lexer.lex + +marked.InlineLexer = InlineLexer +marked.inlineLexer = InlineLexer.output + +marked.parse = marked + +window.marked = marked + +export default marked diff --git a/src/js/marked/main.js b/src/js/marked/main.js deleted file mode 100644 index 69d11a1..0000000 --- a/src/js/marked/main.js +++ /dev/null @@ -1,1377 +0,0 @@ -/** - * marked - a markdown parser - * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed) - * https://github.com/chjj/marked - */ - -;(function() { - -/** - * Block-Level Grammar - */ - -var block = { - newline: /^\n+/, - code: /^( {4}[^\n]+\n*)+/, - fences: noop, - hr: /^( *[-*_]){3,} *(?:\n+|$)/, - heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, - nptable: noop, - lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/, - blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/, - mark: /^ *;;;([\!]?) ([^\n]+)/, - task: /^ *- *\[([ x]?)\] *([^\n]*)/, - list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/, - html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/, - def: /^ *\[([^\]]+)\]: *([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/, - table: noop, - paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/, - text: /^[^\n]+/ -}; - -block.bullet = /(?:[*+-]|\d+\.)/; -block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/; -block.item = replace(block.item, 'gm') - (/bull/g, block.bullet) - (); - -block.list = replace(block.list) - (/bull/g, block.bullet) - ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))') - ('def', '\\n+(?=' + block.def.source + ')') - (); - -block.blockquote = replace(block.blockquote) - ('def', block.def) - (); - - -block._tag = '(?!(?:' - + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code' - + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo' - + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b'; - -block.html = replace(block.html) - ('comment', //) - ('closed', /<(tag)[\s\S]+?<\/\1>/) - ('closing', /
'
- + codes[idx - 1]
- + '\n
' //加\n为了避免空行时无法显示
- }
-
- return '' - + output - + ''; -}; - -Renderer.prototype.blockquote = function(quote) { - return '
\n' + quote + '\n'; -}; -Renderer.prototype.mark = function(mark, t) { - return '
' + text + '
\n'; -}; - -Renderer.prototype.table = function(header, body) { - return '' + txt + '
';
-};
-
-Renderer.prototype.br = function() {
- return this.options.xhtml ? 'An error occured:
' - + escape(e.message + '', true) - + ''; - } - throw e; - } -} - -/** - * Options - */ - -marked.options = -marked.setOptions = function(opt) { - merge(marked.defaults, opt); - return marked; -}; -if (window.yua) {yua.ui.marked = '1.0.0'} - -marked.defaults = { - gfm: true, - tables: true, - breaks: true, - pedantic: false, - sanitize: false, - sanitizer: null, - mangle: true, - smartLists: false, - silent: false, - highlight: null, - langPrefix: 'lang-', - smartypants: false, - headerPrefix: '', - renderer: new Renderer, - xhtml: false -}; - -/** - * Expose - */ - -marked.Parser = Parser; -marked.parser = Parser.parse; - -marked.Renderer = Renderer; - -marked.Lexer = Lexer; -marked.lexer = Lexer.lex; - -marked.InlineLexer = InlineLexer; -marked.inlineLexer = InlineLexer.output; - -marked.parse = marked; - -this.marked = marked; -if (typeof module !== 'undefined' && typeof exports === 'object') { - module.exports = marked; -} else if (typeof define === 'function' && define.amd) { - define(['css!./theme'], function() { return marked; }); -} - -}).call(function() { - return this || (typeof window !== 'undefined' ? window : global); -}()); diff --git a/src/js/meditor/addon/base.js b/src/js/meditor/addon/base.js index f53baec..128a1cd 100644 --- a/src/js/meditor/addon/base.js +++ b/src/js/meditor/addon/base.js @@ -1,363 +1,407 @@ /** - * + * * @authors yutent (yutent@doui.cc) * @date 2017-04-17 21:41:48 * */ -"use strict"; +'use strict' +import 'layer/base' -define(['lib/layer/base'], function(){ +function objArr(num) { + var arr = [] + while (num > 0) { + arr.push({ v: 0 }) + num-- + } + return arr +} +function trim(str, sign) { + return str.replace(new RegExp('^' + sign + '|' + sign + '$', 'g'), '') +} +function getOrderArr(len) { + var arr = [], + i = 0 + while (i < len) { + arr.push(i++) + } + return arr +} +const addon = { + h1: function(elem, vm) { + var offset = Anot(elem).offset(), + wrap = ME.selection(vm.$editor, true) || '在此输入文本', + h1ID = layer.open({ + type: 7, + menubar: false, + shadeClose: true, + fixed: true, + $insert: function(level) { + wrap = wrap.replace(/^#{1,6} /, '') + wrap = ME.repeat('#', level) + ' ' + wrap + ME.insert(vm.$editor, wrap, true) + layer.close(h1ID) + }, + offset: [ + offset.top + 37 - ME.doc.scrollTop(), + 'auto', + 'auto', + offset.left - ME.doc.scrollLeft() + ], + content: + '
' - + ' __ __ _____ _ _ _\n' - + '| \\/ | ____|__| (_) |_ ___ _ __\n' - + '| |\\/| | _| / _` | | __/ _ \\| \'__|\n' - + '| | | | |__| (_| | | || (_) | |\n' - + '|_| |_|_____\\__,_|_|\\__\\___/|_| ' - + 'v' + ME.version + '' - + '
开源在线Markdown编辑器
' - + 'https://doui.cc/product/meditor
' - + 'Copyright © 2017 Yutent, The MIT License.
' - + '' + + ' __ __ _____ _ _ _\n' + + '| \\/ | ____|__| (_) |_ ___ _ __\n' + + "| |\\/| | _| / _` | | __/ _ \\| '__|\n" + + '| | | | |__| (_| | | || (_) | |\n' + + '|_| |_|_____\\__,_|_|\\__\\___/|_| ' + + 'v' + + ME.version + + '' + + '
开源在线Markdown编辑器
' + + 'https://doui.cc/product/meditor
' + + 'Copyright © 2017 Yutent, The MIT License.
' + + '