mdui.editor
Version:
Material Design 样式的富文本编辑器
6 lines • 51.3 kB
JavaScript
/*!
* mdui.editor 1.0.2 (https://github.com/zdhxiong/mdui.editor#readme)
* Copyright 2019-2020 zdhxiong
* Licensed under MIT
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Editor=e()}(this,function(){"use strict";function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),n}function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}!function(){try{return new MouseEvent("test")}catch(t){}function t(t,e){e=e||{bubbles:!1,cancelable:!1};var n=document.createEvent("MouseEvent");return n.initMouseEvent(t,e.bubbles,e.cancelable,window,0,e.screenX||0,e.screenY||0,e.clientX||0,e.clientY||0,e.ctrlKey||!1,e.altKey||!1,e.shiftKey||!1,e.metaKey||!1,e.button||0,e.relatedTarget||null),n}t.prototype=Event.prototype,window.MouseEvent=t}(),"function"!=typeof window.CustomEvent&&(t.prototype=window.Event.prototype,window.CustomEvent=t);var n=setTimeout;function s(t){return Boolean(t&&void 0!==t.length)}function o(){}function r(t){if(!(this instanceof r))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],d(t,this)}function i(n,o){for(;3===n._state;)n=n._value;0!==n._state?(n._handled=!0,r._immediateFn(function(){var t=1===n._state?o.onFulfilled:o.onRejected;if(null!==t){var e;try{e=t(n._value)}catch(t){return void c(o.promise,t)}a(o.promise,e)}else(1===n._state?a:c)(o.promise,n._value)})):n._deferreds.push(o)}function a(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof r)return e._state=3,e._value=t,void u(e);if("function"==typeof n)return void d(function(t,e){return function(){t.apply(e,arguments)}}(n,t),e)}e._state=1,e._value=t,u(e)}catch(t){c(e,t)}}function c(t,e){t._state=2,t._value=e,u(t)}function u(t){2===t._state&&0===t._deferreds.length&&r._immediateFn(function(){t._handled||r._unhandledRejectionFn(t._value)});for(var e=0,n=t._deferreds.length;e<n;e++)i(t,t._deferreds[e]);t._deferreds=null}function l(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function d(t,e){var n=!1;try{t(function(t){n||(n=!0,a(e,t))},function(t){n||(n=!0,c(e,t))})}catch(t){if(n)return;n=!0,c(e,t)}}r.prototype.catch=function(t){return this.then(null,t)},r.prototype.then=function(t,e){var n=new this.constructor(o);return i(this,new l(t,e,n)),n},r.prototype.finally=e,r.all=function(e){return new r(function(o,i){if(!s(e))return i(new TypeError("Promise.all accepts an array"));var r=Array.prototype.slice.call(e);if(0===r.length)return o([]);var a=r.length;function c(e,t){try{if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if("function"==typeof n)return void n.call(t,function(t){c(e,t)},i)}r[e]=t,0==--a&&o(r)}catch(t){i(t)}}for(var t=0;t<r.length;t++)c(t,r[t])})},r.resolve=function(e){return e&&"object"==typeof e&&e.constructor===r?e:new r(function(t){t(e)})},r.reject=function(n){return new r(function(t,e){e(n)})},r.race=function(i){return new r(function(t,e){if(!s(i))return e(new TypeError("Promise.race accepts an array"));for(var n=0,o=i.length;n<o;n++)r.resolve(i[n]).then(t,e)})},r._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){n(t,0)},r._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var f=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();function p(t){return"function"==typeof t}function E(t){return"string"==typeof t}function h(t){return"number"==typeof t}function w(t){return void 0===t}function m(t){return null===t}function v(t){return t instanceof Window}function g(t){return t instanceof Document}function y(t){return t instanceof Element}function b(t){return!p(t)&&!v(t)&&h(t.length)}function T(t){return"object"==typeof t&&null!==t}function x(t){return g(t)?t.documentElement:t}function C(t){return t.replace(/^-ms-/,"ms-").replace(/-([a-z])/g,function(t,e){return e.toUpperCase()})}function _(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})}function R(t,e){return window.getComputedStyle(t).getPropertyValue(_(e))}function O(t){return"border-box"===R(t,"box-sizing")}function k(i,t,r){var a="width"===t?["Left","Right"]:["Top","Bottom"];return[0,1].reduce(function(t,e,n){var o=r+a[n];return"border"===r&&(o+="Width"),t+parseFloat(R(i,o)||"0")},0)}function $(t,e){if("width"!==e&&"height"!==e)return R(t,e);var n=t.getBoundingClientRect()[e];return O(t)?n+"px":n-k(t,e,"border")-k(t,e,"padding")+"px"}function S(t,e){var n=document.createElement(e);return n.innerHTML=t,[].slice.call(n.childNodes)}function L(){return!1}"Promise"in f?f.Promise.prototype.finally||(f.Promise.prototype.finally=e):f.Promise=r;var H=["animationIterationCount","columnCount","fillOpacity","flexGrow","flexShrink","fontWeight","gridArea","gridColumn","gridColumnEnd","gridColumnStart","gridRow","gridRowEnd","gridRowStart","lineHeight","opacity","order","orphans","widows","zIndex","zoom"];function j(t,e){if(b(t)){for(var n=0;n<t.length;n+=1)if(!1===e.call(t[n],n,t[n]))return t}else for(var o=Object.keys(t),i=0;i<o.length;i+=1)if(!1===e.call(t[o[i]],o[i],t[o[i]]))return t;return t}function A(t){var n=this;return this.length=0,t&&(j(t,function(t,e){n[t]=e}),this.length=t.length),this}var M,N=((M=function(t){if(!t)return new A;if(t instanceof A)return t;if(p(t))return/complete|loaded|interactive/.test(document.readyState)&&document.body?t.call(document,M):document.addEventListener("DOMContentLoaded",function(){return t.call(document,M)},!1),new A([document]);if(E(t)){var n=t.trim();if("<"===n[0]&&">"===n[n.length-1]){var o="div";return j({li:"ul",tr:"tbody",td:"tr",th:"tr",tbody:"table",option:"select"},function(t,e){if(0===n.indexOf("<"+t))return o=e,!1}),new A(S(n,o))}if(!("#"===t[0]&&!t.match(/[ .<>:~]/)))return new A(document.querySelectorAll(t));var e=document.getElementById(t.slice(1));return e?new A([e]):new A}return b(t)&&!function(t){return t instanceof Node}(t)?new A(t):new A([t])}).fn=A.prototype,M);function D(n,t){for(var e=[],o=arguments.length-2;0<o--;)e[o]=arguments[o+2];return e.unshift(t),j(e,function(t,e){j(e,function(t,e){w(e)||(n[t]=e)})}),n}function B(t,n){var e,o,i=[];return j(t,function(t,e){null!=(o=n.call(window,e,t))&&i.push(o)}),(e=[]).concat.apply(e,i)}function U(t){var n=[];return j(t,function(t,e){-1===n.indexOf(e)&&n.push(e)}),n}function I(t,e){return t!==e&&x(t).contains(e)}function P(n,t){return j(t,function(t,e){n.push(e)}),n}N.fn.each=function(t){return j(this,t)},j(["add","remove","toggle"],function(t,o){N.fn[o+"Class"]=function(e){return"remove"!==o||arguments.length?this.each(function(t,n){y(n)&&j((p(e)?e.call(n,t,n.getAttribute("class")||""):e).split(" ").filter(function(t){return t}),function(t,e){n.classList[o](e)})}):this.each(function(t,e){e.setAttribute("class","")})}}),j(["insertBefore","insertAfter"],function(c,t){N.fn[t]=function(t){var e=c?N(this.get().reverse()):this,n=N(t),a=[];return n.each(function(i,r){r.parentNode&&e.each(function(t,e){var n=i?e.cloneNode(!0):e,o=c?r.nextSibling:r;a.push(n),r.parentNode.insertBefore(n,o)})}),N(c?a.reverse():a)}}),j(["before","after"],function(i,t){N.fn[t]=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return 1===i&&(t=t.reverse()),this.each(function(n,o){j(p(t[0])?[t[0].call(o,n,o.innerHTML)]:t,function(t,e){(function(t){return E(t)&&("<"!==t[0]||">"!==t[t.length-1])}(e)?N(S(e,"div")):n&&y(e)?N(e.cloneNode(!0)):N(e))[i?"insertAfter":"insertBefore"](o)})})}}),N.fn.map=function(n){return new A(B(this,function(t,e){return n.call(t,e,t)}))},N.fn.clone=function(){return this.map(function(){return this.cloneNode(!0)})},N.fn.is=function(n){var o=!1;if(p(n))return this.each(function(t,e){n.call(e,t,e)&&(o=!0)}),o;if(E(n))return this.each(function(t,e){g(e)||v(e)||(e.matches||e.msMatchesSelector).call(e,n)&&(o=!0)}),o;var e=N(n);return this.each(function(t,n){e.each(function(t,e){n===e&&(o=!0)})}),o},N.fn.remove=function(n){return this.each(function(t,e){!e.parentNode||n&&!N(e).is(n)||e.parentNode.removeChild(e)})},j(["prepend","append"],function(s,t){N.fn[t]=function(){for(var c=[],t=arguments.length;t--;)c[t]=arguments[t];return this.each(function(t,e){var n,o=e.childNodes,i=o.length,r=i?o[s?i-1:0]:document.createElement("div");i||e.appendChild(r);var a=p(c[0])?[c[0].call(e,t,e.innerHTML)]:c;t&&(a=a.map(function(t){return E(t)?t:N(t).clone()})),(n=N(r))[s?"after":"before"].apply(n,a),i||e.removeChild(r)})}}),j(["attr","prop","css"],function(r,a){function c(t,e){switch(r){case 0:var n=t.getAttribute(e);return m(n)?void 0:n;case 1:return t[e];default:return $(t,e)}}N.fn[a]=function(n,o){var i=this;if(T(n))return j(n,function(t,e){i[a](t,e)}),this;if(1!==arguments.length)return this.each(function(t,e){!function(t,e,n){if(!w(n))switch(r){case 0:m(n)?t.removeAttribute(e):t.setAttribute(e,n);break;case 1:t[e]=n;break;default:e=C(e),t.style[e]=h(n)?n+(-1<H.indexOf(e)?"":"px"):n}}(e,n,p(o)?o.call(e,t,c(e,n)):o)});var t=this[0];return y(t)?c(t,n):void 0}}),N.fn.children=function(n){var o=[];return this.each(function(t,e){j(e.childNodes,function(t,e){y(e)&&(n&&!N(e).is(n)||o.push(e))})}),new A(U(o))},N.fn.slice=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return new A([].slice.apply(this,t))},N.fn.eq=function(t){var e=-1===t?this.slice(t):this.slice(t,+t+1);return new A(e)},N.fn.first=function(){return this.eq(0)},j(["val","html","text"],function(i,t){var r={0:"value",1:"innerHTML",2:"textContent"}[i];function a(t){if(2===i)return B(t,function(t){return x(t)[r]}).join("");if(t.length){var e=t[0];return 0===i&&N(e).is("select[multiple]")?B(N(e).find("option:checked"),function(t){return t.value}):e[r]}}N.fn[t]=function(o){return arguments.length?this.each(function(t,e){var n=p(o)?o.call(e,t,a(N(e))):o;0===i&&Array.isArray(n)?N(e).is("select[multiple]")?B(N(e).find("option"),function(t){return t.selected=-1<n.indexOf(t.value)}):e.checked=-1<n.indexOf(e.value):function(t,e){if(w(e)){if(0!==i)return;e=""}1===i&&y(e)&&(e=e.outerHTML),t[r]=e}(e,n)}):a(this)}}),N.fn.last=function(){return this.eq(-1)},N.fn.get=function(t){return void 0===t?[].slice.call(this):this[0<=t?t:t+this.length]},N.fn.find=function(n){var o=[];return this.each(function(t,e){P(o,N(e.querySelectorAll(n)).get())}),new A(o)};var F={},q=1;function z(t){var e="_mduiEventId";return t[e]||(t[e]=++q),t[e]}function K(t){var e=t.split(".");return{type:e[0],ns:e.slice(1).sort().join(" ")}}function W(t){return new RegExp("(?:^| )"+t.replace(" "," .* ?")+"(?: |$)")}function V(e,t,n,o){function i(t){delete r[t.id],e.removeEventListener(t.type,t.proxy,!1)}var r=F[z(e)]||[];t?t.split(" ").forEach(function(t){t&&function(t,e,n,o){var i=K(e);return(F[z(t)]||[]).filter(function(t){return t&&(!i.type||t.type===i.type)&&(!i.ns||W(i.ns).test(t.ns))&&(!n||z(t.func)===z(n))&&(!o||t.selector===o)})}(e,t,n,o).forEach(function(t){return i(t)})}):r.forEach(function(t){return i(t)})}N.fn.off=function(t,n,e){var o=this;return T(t)?(j(t,function(t,e){o.off(t,n,e)}),this):(!1!==n&&!p(n)||(e=n,n=void 0),!1===e&&(e=L),this.each(function(){V(this,t,e,n)}))},N.fn.on=function(t,n,o,e,i){var r=this;if(T(t))return E(n)||(o=o||n,n=void 0),j(t,function(t,e){r.on(t,n,o,e,i)}),this;if(null==o&&null==e?(e=n,o=n=void 0):null==e&&(E(n)?(e=o,o=void 0):(e=o,o=n,n=void 0)),!1===e)e=L;else if(!e)return this;if(i){var a=this,c=e;e=function(t){return a.off(t.type,n,e),c.apply(this,arguments)}}return this.each(function(){!function(r,t,a,c,s){var u=z(r);F[u]||(F[u]=[]);var l=!1;T(c)&&c.useCapture&&(l=!0),t.split(" ").forEach(function(t){if(t){var n=K(t),e={type:n.type,ns:n.ns,func:a,selector:s,id:F[u].length,proxy:i};F[u].push(e),r.addEventListener(e.type,i,l)}function o(t,e){!1===a.apply(e,void 0===t._detail?[t]:[t].concat(t._detail))&&(t.preventDefault(),t.stopPropagation())}function i(e){e._ns&&!W(e._ns).test(n.ns)||(e._data=c,s?N(r).find(s).get().reverse().forEach(function(t){t!==e.target&&!I(t,e.target)||o(e,t)}):o(e,r))}})}(this,t,e,o,n)})},j(["appendTo","prependTo"],function(a,t){N.fn[t]=function(t){var r=[],e=N(t).map(function(t,e){var n=e.childNodes,o=n.length;if(o)return n[a?0:o-1];var i=document.createElement("div");return e.appendChild(i),r.push(i),i}),n=this[a?"insertBefore":"insertAfter"](e);return N(r).remove(),n}});function G(t){this.editor=t}var X={$toolbar:{configurable:!0},$container:{configurable:!0},selection:{configurable:!0},command:{configurable:!0}};X.$toolbar.get=function(){return this.editor.$toolbar},X.$container.get=function(){return this.editor.$container},X.selection.get=function(){return this.editor.selection},X.command.get=function(){return this.editor.command},Object.defineProperties(G.prototype,X);var J=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.do=function(t,e){if(this.selection.getRange()){this.selection.restore();var n=t;this[n]?this[n](e):document.execCommand(t,!1,e),this.editor.menus.changeStatus(),this.selection.saveRange(),this.selection.restore(),this.editor.change&&this.editor.change()}},e.prototype.insertHTML=function(t){if(document.queryCommandSupported("insertHTML"))document.execCommand("insertHTML",!1,t);else{var e=this.selection.getRange();e.insertNode?(e.deleteContents(),e.insertNode(N(t)[0])):e.pasteHTML&&e.pasteHTML(t)}},e.prototype.replaceRoot=function(t){var e=this.selection.getRootElem(),n=N(t).insertAfter(e);e.remove(),this.selection.createRangeByElem(n,!1,!0),this.selection.restore()},e.prototype.insertAfterRoot=function(t){var e=this.selection.getRootElem(),n=N(t).insertAfter(e);this.selection.createRangeByElem(n,!1,!0),this.selection.restore()},e.prototype.appendHTML=function(t){var e=N(t).appendTo(this.$container);this.selection.createRangeByElem(e,!1,!0),this.selection.restore()},e.prototype.insertElem=function(t){var e=this.selection.getRange();e.insertNode&&(e.deleteContents(),e.insertNode(t[0]))},e}(G),Q=function(n){function t(t,e){n.call(this,t),this.$button=e}return n&&(t.__proto__=n),((t.prototype=Object.create(n&&n.prototype)).constructor=t).prototype.isActive=function(){return!1},t}(G);Q.icon="",Q.title="",Q.disable=[];var Y=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.onclick=function(){var t=this.selection.isEmpty();t&&this.selection.createEmptyRange(this.getElementName()),this.command.do(this.getCommandName()),t&&(this.selection.collapseRange(),this.selection.restore())},e.prototype.isActive=function(){return document.queryCommandState(this.getCommandName())},e}(Q),Z=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.getCommandName=function(){return"bold"},e.prototype.getElementName=function(){return"strong"},e}(Y);Z.icon="format_bold",Z.title="粗体",Z.disable=["image"];var tt=N(document),et=N(window),nt=N("body");setTimeout(function(){return nt.addClass("mdui-loaded")});var ot={$:N};function it(e,n,t,o,i,r){function a(t){return k(e,n.toLowerCase(),t)*r}return 2===o&&i&&(t+=a("margin")),O(e)?(window.document.documentMode&&1===r&&(t+=a("border"),t+=a("padding")),0===o&&(t-=a("border")),1===o&&(t-=a("border"),t-=a("padding"))):(0===o&&(t+=a("padding")),2===o&&(t+=a("border"),t+=a("padding"))),t}function rt(t,e,n,o){var i="client"+e,r="scroll"+e,a="offset"+e,c="inner"+e;if(v(t))return 2===n?t[c]:x(document)[i];if(g(t)){var s=x(t);return Math.max(t.body[r],s[r],t.body[a],s[a],s[i])}var u=parseFloat(R(t,e.toLowerCase())||"0");return it(t,e,u,n,o,1)}N.fn.hasClass=function(t){return this[0].classList.contains(t)},j(["Width","Height"],function(t,r){j(["inner"+r,r.toLowerCase(),"outer"+r],function(i,t){N.fn[t]=function(n,t){var e=arguments.length&&(i<2||!function(t){return"boolean"==typeof t}(n)),o=!0===n||!0===t;return e?this.each(function(t,e){return function(t,e,n,o,i,r){var a=p(r)?r.call(t,e,rt(t,n,o,i)):r;if(null!=a){var c=N(t),s=n.toLowerCase();if(-1<["auto","inherit",""].indexOf(a))c.css(s,a);else{var u=a.toString().replace(/\b[0-9.]*/,"");a=it(t,n,parseFloat(a),o,i,-1)+(u||"px"),c.css(s,a)}}}(e,t,r,i,o,n)}):this.length?rt(this[0],r,i,o):void 0}})}),N.fn.hide=function(){return this.each(function(){this.style.display="none"})};var at={};N.fn.show=function(){return this.each(function(){"none"===this.style.display&&(this.style.display=""),"none"===$(this,"display")&&(this.style.display=function(t){var e,n;return at[t]||(e=document.createElement(t),document.body.appendChild(e),n=$(e,"display"),e.parentNode.removeChild(e),"none"===n&&(n="block"),at[t]=n),at[t]}(this.nodeName))})},N.fn.transitionEnd=function(e){var n=this,o=["webkitTransitionEnd","transitionend"];function i(t){t.target===this&&(e.call(this,t),j(o,function(t,e){n.off(e,i)}))}return j(o,function(t,e){n.on(e,i)}),this};var ct="_mduiElementDataStorage";function st(n,t){n[ct]||(n[ct]={}),j(t,function(t,e){n[ct][C(t)]=e})}function ut(t,e,n){var o;return T(e)?(st(t,e),e):w(n)?w(e)?t[ct]?t[ct]:{}:(e=C(e),t[ct]&&e in t[ct]?t[ct][e]:void 0):(st(t,((o={})[e]=n,o)),n)}var lt=/^(?:{[\w\W]*\}|\[[\w\W]*\])$/;function dt(t,e,n){if(w(n)&&1===t.nodeType){var o="data-"+_(e);if(E(n=t.getAttribute(o)))try{n=function(t){return"true"===t||"false"!==t&&("null"===t?null:t===+t+""?+t:lt.test(t)?JSON.parse(t):t)}(n)}catch(t){}else n=void 0}return n}N.fn.data=function(t,e){if(w(t)){if(!this.length)return;var n=this[0],o=ut(n);if(1!==n.nodeType)return o;for(var i=n.attributes,r=i.length;r--;)if(i[r]){var a=i[r].name;0===a.indexOf("data-")&&(o[a=C(a.slice(5))]=dt(n,a,o[a]))}return o}return T(t)?this.each(function(){ut(this,t)}):2===arguments.length&&w(e)?this:w(e)?this.length?dt(this[0],t,ut(this[0],t)):void 0:this.each(function(){ut(this,t,e)})},N.hideOverlay=function(t){void 0===t&&(t=!1);var e=N(".mdui-overlay");if(e.length){var n=t?1:e.data("_overlay_level");1<n?e.data("_overlay_level",--n):e.data("_overlay_level",0).removeClass("mdui-overlay-show").data("_overlay_is_deleted",!0).transitionEnd(function(){e.data("_overlay_is_deleted")&&e.remove()})}},N.lockScreen=function(){var t=nt.width(),e=nt.data("_lockscreen_level")||0;nt.addClass("mdui-locked").width(t).data("_lockscreen_level",++e)},N.fn.reflow=function(){return this.each(function(){return this.clientLeft})},N.showOverlay=function(t){var e=N(".mdui-overlay");e.length?(e.data("_overlay_is_deleted",!1),w(t)||e.css("z-index",t)):(w(t)&&(t=2e3),e=N('<div class="mdui-overlay">').appendTo(document.body).reflow().css("z-index",t));var n=e.data("_overlay_level")||0;return e.data("_overlay_level",++n).addClass("mdui-overlay-show")},N.throttle=function(o,i){void 0===i&&(i=16);var r=null;return function(){for(var t=this,e=[],n=arguments.length;n--;)e[n]=arguments[n];m(r)&&(r=setTimeout(function(){o.apply(t,e),r=null},i))}},N.unlockScreen=function(t){void 0===t&&(t=!1);var e=t?1:nt.data("_lockscreen_level");1<e?nt.data("_lockscreen_level",--e):nt.data("_lockscreen_level",0).removeClass("mdui-locked").width("")},N.fn.trigger=function(t,e){var n,o=K(t),i={bubbles:!0,cancelable:!0},r=-1<["click","mousedown","mouseup","mousemove"].indexOf(o.type);return(n=r?new MouseEvent(o.type,i):(i.detail=e,new CustomEvent(o.type,i)))._detail=e,n._ns=o.ns,this.each(function(){this.dispatchEvent(n)})};var ft={};function pt(t,e){if(w(ft[t])&&(ft[t]=[]),w(e))return ft[t];ft[t].push(e)}function ht(t,e){var n=this;void 0===e&&(e={}),this.options=D({},vt),this.state="closed",this.append=!1,this.$element=N(t).first(),I(document.body,this.$element[0])||(this.append=!0,nt.append(this.$element)),D(this.options,e),this.$element.find("[mdui-dialog-cancel]").each(function(t,e){N(e).on("click",function(){n.triggerEvent("cancel"),n.options.closeOnCancel&&n.close()})}),this.$element.find("[mdui-dialog-confirm]").each(function(t,e){N(e).on("click",function(){n.triggerEvent("confirm"),n.options.closeOnConfirm&&n.close()})}),this.$element.find("[mdui-dialog-close]").each(function(t,e){N(e).on("click",function(){return n.close()})})}var mt,vt={history:!0,overlay:!0,modal:!1,closeOnEsc:!0,closeOnCancel:!0,closeOnConfirm:!0,destroyOnClosed:!1},gt=null,yt="_mdui_dialog",bt=!1;ht.prototype.triggerEvent=function(t){!function(t,e,n,o,i){(i=i||{}).inst=o;var r=t+".mdui."+e;"undefined"!=typeof jQuery&&jQuery(n).trigger(r,i);var a=N(n);a.trigger(r,i);var c=new CustomEvent(r,{bubbles:!0,cancelable:!0,detail:i});c._detail=i,a[0].dispatchEvent(c)}(t,"dialog",this.$element,this)},ht.prototype.readjust=function(){if(gt){var t=gt.$element,e=t.children(".mdui-dialog-title"),n=t.children(".mdui-dialog-content"),o=t.children(".mdui-dialog-actions");t.height(""),n.height("");var i=t.height();t.css({top:(et.height()-i)/2+"px",height:i+"px"}),n.innerHeight(i-(e.innerHeight()||0)-(o.innerHeight()||0))}},ht.prototype.hashchangeEvent=function(){window.location.hash.substring(1).indexOf("mdui-dialog")<0&>.close(!0)},ht.prototype.overlayClick=function(t){N(t.target).hasClass("mdui-overlay")&>&>.close()},ht.prototype.transitionEnd=function(){this.$element.hasClass("mdui-dialog-open")?(this.state="opened",this.triggerEvent("opened")):(this.state="closed",this.triggerEvent("closed"),this.$element.hide(),pt(yt).length||gt||!bt||(N.unlockScreen(),bt=!1),et.off("resize",N.throttle(this.readjust,100)),this.options.destroyOnClosed&&this.destroy())},ht.prototype.doOpen=function(){var t=this;if(gt=this,bt||(N.lockScreen(),bt=!0),this.$element.show(),this.readjust(),et.on("resize",N.throttle(this.readjust,100)),this.state="opening",this.triggerEvent("open"),this.$element.addClass("mdui-dialog-open").transitionEnd(function(){return t.transitionEnd()}),mt=mt||N.showOverlay(5100),this.options.modal?mt.off("click",this.overlayClick):mt.on("click",this.overlayClick),mt.css("opacity",this.options.overlay?"":0),this.options.history){var e=window.location.hash.substring(1);-1<e.indexOf("mdui-dialog")&&(e=e.replace(/[&?]?mdui-dialog/g,"")),window.location.hash=e?e+(-1<e.indexOf("?")?"&":"?")+"mdui-dialog":"mdui-dialog",et.on("hashchange",this.hashchangeEvent)}},ht.prototype.isOpen=function(){return"opening"===this.state||"opened"===this.state},ht.prototype.open=function(){var t=this;this.isOpen()||(gt&&("opening"===gt.state||"opened"===gt.state)||pt(yt).length?pt(yt,function(){return t.doOpen()}):this.doOpen())},ht.prototype.close=function(t){var e=this;void 0===t&&(t=!1),setTimeout(function(){e.isOpen()&&(gt=null,e.state="closing",e.triggerEvent("close"),!pt(yt).length&&mt&&(N.hideOverlay(),mt=null,N(".mdui-overlay").css("z-index",2e3)),e.$element.removeClass("mdui-dialog-open").transitionEnd(function(){return e.transitionEnd()}),e.options.history&&!pt(yt).length&&(t||window.history.back(),et.off("hashchange",e.hashchangeEvent)),setTimeout(function(){!function(t){w(ft[t])||ft[t].length&&ft[t].shift()()}(yt)},100))})},ht.prototype.toggle=function(){this.isOpen()?this.close():this.open()},ht.prototype.getState=function(){return this.state},ht.prototype.destroy=function(){this.append&&this.$element.remove(),pt(yt).length||gt||(mt&&(N.hideOverlay(),mt=null),bt&&(N.unlockScreen(),bt=!1))},ht.prototype.handleUpdate=function(){this.readjust()},tt.on("keydown",function(t){gt&>.options.closeOnEsc&&"opened"===gt.state&&27===t.keyCode&>.close()}),ot.Dialog=ht;var xt={text:"",bold:!1,close:!0,onClick:function(){}},Ct={title:"",content:"",buttons:[],stackedButtons:!1,cssClass:"",history:!0,overlay:!0,modal:!1,closeOnEsc:!0,destroyOnClosed:!0,onOpen:function(){},onOpened:function(){},onClose:function(){},onClosed:function(){}},_t={confirmText:"ok",cancelText:"cancel",history:!0,modal:!(ot.dialog=function(n){var t,e;j((n=D({},Ct,n)).buttons,function(t,e){n.buttons[t]=D({},xt,e)});var o="";(null===(t=n.buttons)||void 0===t?void 0:t.length)&&(o='<div class="mdui-dialog-actions'+(n.stackedButtons?" mdui-dialog-actions-stacked":"")+'">',j(n.buttons,function(t,e){o+='<a href="javascript:void(0)" class="mdui-btn mdui-ripple mdui-text-color-primary '+(e.bold?"mdui-btn-bold":"")+'">'+e.text+"</a>"}),o+="</div>");var i='<div class="mdui-dialog '+n.cssClass+'">'+(n.title?'<div class="mdui-dialog-title">'+n.title+"</div>":"")+(n.content?'<div class="mdui-dialog-content">'+n.content+"</div>":"")+o+"</div>",r=new ot.Dialog(i,{history:n.history,overlay:n.overlay,modal:n.modal,closeOnEsc:n.closeOnEsc,destroyOnClosed:n.destroyOnClosed});return(null===(e=n.buttons)||void 0===e?void 0:e.length)&&r.$element.find(".mdui-dialog-actions .mdui-btn").each(function(t,e){N(e).on("click",function(){n.buttons[t].onClick(r),n.buttons[t].close&&r.close()})}),r.$element.on("open.mdui.dialog",function(){n.onOpen(r)}).on("opened.mdui.dialog",function(){n.onOpened(r)}).on("close.mdui.dialog",function(){n.onClose(r)}).on("closed.mdui.dialog",function(){n.onClosed(r)}),r.open(),r}),closeOnEsc:!0,closeOnCancel:!0,closeOnConfirm:!0};ot.confirm=function(t,e,n,o,i){return p(e)&&(i=o,o=n,n=e,e=""),w(n)&&(n=function(){}),w(o)&&(o=function(){}),w(i)&&(i={}),i=D({},_t,i),ot.dialog({title:e,content:t,buttons:[{text:i.cancelText,bold:!1,close:i.closeOnCancel,onClick:o},{text:i.confirmText,bold:!1,close:i.closeOnConfirm,onClick:n}],cssClass:"mdui-dialog-confirm",history:i.history,modal:i.modal,closeOnEsc:i.closeOnEsc})};var Et=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.onclick=function(){var e=this;ot.confirm("确定要清空内容?",function(){var t=e.editor.options;e.editor.setHTML(""),t.autoSave&&(window.localStorage.removeItem(t.autoSaveKey),t.onClearDrafts())},L,{confirmText:"确定",cancelText:"取消"})},e}(Q);function wt(t){return void 0===t&&(t=""),t.replace(/</gm,"<").replace(/>/gm,">").replace(/"/gm,""")}Et.icon="delete",Et.title="舍弃草稿",N.fn.add=function(t){return new A(U(P(this.get(),N(t).get())))};var Tt=function(n){function t(t,e){n.call(this,t,e),this.active=!1,this.init()}return n&&(t.__proto__=n),((t.prototype=Object.create(n&&n.prototype)).constructor=t).prototype.init=function(){var n=this;this.$container.on("keydown",function(t){if(13===t.keyCode&&n.active){t.preventDefault();var e=n.selection.getRange().startOffset;n.command.do("insertHTML","\n"),n.selection.saveRange(),n.selection.getRange().startOffset===e&&n.command.do("insertHTML","\n"),n.selection.getContainerElem()[0].scrollLeft=0}9===t.keyCode&&n.active&&(t.preventDefault(),n.command.do("insertHTML"," "))})},t.prototype.onclick=function(){var o=this,t=this.selection.getRootElem();if(this.active){var e=t.text().split("\n"),n="";return e.forEach(function(t){t=wt(t),n=t?"<p>"+t+"</p>"+n:"<p><br></p>"+n}),void this.command.do("replaceRoot",n)}if(t.length){var i=wt(t.text());this.command.do("replaceRoot",i?"<pre><code>"+i+"</code></pre>":"<pre><code><br></code></pre>")}else{var r=this.selection.getRange();if(r.collapsed)this.command.do("appendHTML","<pre><code><br></code></pre>");else{var a="",c=!1,s=N();this.$container.children().each(function(t,e){var n=N(e);return c||(n.is(r.startContainer)||n[0].contains(r.startContainer)||o.$container.is(r.startContainer))&&(c=!0),!(c&&(a+=wt(n.text())+"\n",s=s.add(n),n.is(r.endContainer)||n[0].contains(r.endContainer)))}),s.each(function(t,e){var n=N(e);t<s.length-1&&n.remove()}),this.selection.createRangeByElem(s.last(),!1,!0),this.command.do("replaceRoot","<pre><code>"+a+"</code></pre>")}}},t.prototype.isActive=function(){return this.active=this.selection.getRootElem().is("pre"),this.active},t}(Q);Tt.icon="code",Tt.title="代码块",Tt.disable=["bold","italic","head","ol","ul","link","image"];var Rt=function(t){function e(){t.apply(this,arguments),this.active=!1}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.onclick=function(){var t=this.selection.getRootElem();if(this.active){var e=t.text();this.command.do("replaceRoot",e?"<p>"+e+"</p>":"<p><br></p>")}else{if(t.length)this.command.do("replaceRoot","<h2>"+wt(t.text())+"</h2>");else this.selection.getRange().collapsed&&this.command.do("appendHTML","<h2><br></h2>")}},e.prototype.isActive=function(){return this.active=this.selection.getRootElem().is("h2"),this.active},e}(Q);Rt.icon="title",Rt.title="标题",Rt.disable=["bold","italic","image"];var Ot={},kt="start.mdui.ajax",$t="success.mdui.ajax",St="error.mdui.ajax",Lt="complete.mdui.ajax";function Ht(t){return 0<=["GET","HEAD"].indexOf(t)}function jt(t,e){return(t+"&"+e).replace(/[&?]{1,2}/,"?")}function At(t){var a,c=!1,s={},u=function(t){var n={url:"",method:"GET",data:"",processData:!0,async:!0,cache:!0,username:"",password:"",headers:{},xhrFields:{},statusCode:{},dataType:"text",contentType:"application/x-www-form-urlencoded",timeout:0,global:!0};return j(Ot,function(t,e){["beforeSend","success","error","complete","statusCode"].indexOf(t)<0&&!w(e)&&(n[t]=e)}),D({},n,t)}(t),n=u.url||window.location.toString(),l=u.method.toUpperCase(),o=u.data,e=u.processData,d=u.async,f=u.cache,p=u.username,h=u.password,m=u.headers,v=u.xhrFields,g=u.statusCode,y=u.dataType,b=u.contentType,x=u.timeout,C=u.global;function _(t,e,n){for(var o,i,r=[],a=arguments.length-3;0<a--;)r[a]=arguments[a+3];C&&N(document).trigger(t,e),n&&(n in Ot&&(o=Ot[n].apply(Ot,r)),u[n]&&(i=u[n].apply(u,r)),"beforeSend"!==n||!1!==o&&!1!==i||(c=!0))}return!o||!Ht(l)&&!e||E(o)||o instanceof ArrayBuffer||o instanceof Blob||o instanceof Document||o instanceof FormData||(o=function(t){if(!T(t)&&!Array.isArray(t))return"";var e=[];function r(n,o){var i;T(o)?j(o,function(t,e){i=Array.isArray(o)&&!T(e)?"":t,r(n+"["+i+"]",e)}):(i=null==o||""===o?"=":"="+encodeURIComponent(o),e.push(encodeURIComponent(n)+i))}return Array.isArray(t)?j(t,function(){r(this.name,this.value)}):j(t,r),e.join("&")}(o)),o&&Ht(l)&&(n=jt(n,o),o=null),new Promise(function(t,e){Ht(l)&&!f&&(n=jt(n,"_="+Date.now()));var i,r=new XMLHttpRequest;r.open(l,n,d,p,h),(b||o&&!Ht(l)&&!1!==b)&&r.setRequestHeader("Content-Type",b),"json"===y&&r.setRequestHeader("Accept","application/json, text/javascript"),m&&j(m,function(t,e){w(e)||r.setRequestHeader(t,e+"")}),/^([\w-]+:)?\/\/([^/]+)/.test(n)&&RegExp.$2!==window.location.host||r.setRequestHeader("X-Requested-With","XMLHttpRequest"),v&&j(v,function(t,e){r[t]=e}),s.xhr=r,s.options=u,r.onload=function(){i&&clearTimeout(i);var n,o=200<=r.status&&r.status<300||304===r.status||0===r.status;if(o)if(a=204===r.status||"HEAD"===l?"nocontent":304===r.status?"notmodified":"success","json"===y){try{n="HEAD"===l?void 0:JSON.parse(r.responseText),s.data=n}catch(t){_(St,s,"error",r,a="parsererror"),e(new Error(a))}"parsererror"!==a&&(_($t,s,"success",n,a,r),t(n))}else n="HEAD"===l?void 0:"text"===r.responseType||""===r.responseType?r.responseText:r.response,s.data=n,_($t,s,"success",n,a,r),t(n);else _(St,s,a="error",r,a),e(new Error(a));j([Ot.statusCode,g],function(t,e){e&&e[r.status]&&(o?e[r.status](n,a,r):e[r.status](r,a))}),_(Lt,s,"complete",r,a)},r.onerror=function(){i&&clearTimeout(i),_(St,s,"error",r,r.statusText),_(Lt,s,"complete",r,"error"),e(new Error(r.statusText))},r.onabort=function(){var t="abort";i&&(t="timeout",clearTimeout(i)),_(St,s,"error",r,t),_(Lt,s,"complete",r,t),e(new Error(t))},_(kt,s,"beforeSend",r),c?e(new Error("cancel")):(0<x&&(i=setTimeout(function(){r.abort()},x)),r.send(o))})}function Mt(t,n,o,i,r){var a,c=[];return t.each(function(t,e){for(a=e[o];a&&y(a);){if(2===n){if(i&&N(a).is(i))break;r&&!N(a).is(r)||c.push(a)}else{if(0===n){i&&!N(a).is(i)||c.push(a);break}i&&!N(a).is(i)||c.push(a)}a=a[o]}}),new A(U(c))}j(["","All","Until"],function(n,t){N.fn["next"+t]=function(t,e){return Mt(this,n,"nextElementSibling",t,e)}});var Nt={confirmText:"ok",history:!0,modal:!1,closeOnEsc:!0,closeOnConfirm:!0};ot.alert=function(t,e,n,o){return p(e)&&(o=n,n=e,e=""),w(n)&&(n=function(){}),w(o)&&(o={}),o=D({},Nt,o),ot.dialog({title:e,content:t,buttons:[{text:o.confirmText,bold:!1,close:o.closeOnConfirm,onClick:n}],cssClass:"mdui-dialog-alert",history:o.history,modal:o.modal,closeOnEsc:o.closeOnEsc})};var Dt={};N.guid=function(t){if(!w(t)&&!w(Dt[t]))return Dt[t];function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}var n="_"+e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e();return w(t)||(Dt[t]=n),n};var Bt=function(n){function t(t,e){n.call(this,t,e),this.$input=N(),this.inputID=N.guid(),this.suffixs=[],this.accepts=[],this.setAccepts(),this.setInput(),this.bindInputChange(),this.bindKeyboardEvent()}return n&&(t.__proto__=n),((t.prototype=Object.create(n&&n.prototype)).constructor=t).prototype.bindKeyboardEvent=function(){var r=this;this.$container.on("keydown",function(t){var e=t.keyCode;r.selection.saveRange();var n=r.selection.getContainerElem();if((8===e||46===e)&&n.is("figcaption")){var o=n.html().toLowerCase().trim();o&&"<br>"!==o&&"<br/>"!==o||(n.html(""),t.preventDefault())}if(n.is("figure")&&(8!==e&&46!==e||(r.selection.createRangeByElem(n.next()),n.remove(),r.selection.restore()),t.preventDefault()),13===e&&n.is("figcaption")){var i=r.selection.getRootElem().next();i.length?(r.selection.createRangeByElem(i),r.selection.restore()):r.command.do("insertAfterRoot","<p><br></p>"),t.preventDefault()}}),this.$container.on("keyup",function(t){var e=t.keyCode,n=r.selection.getContainerElem();if((8===e||46===e)&&n.is("figcaption")){var o=n.html().toLowerCase().trim();o&&"<br>"!==o&&"<br/>"!==o||n.html("")}})},t.prototype.setAccepts=function(){this.suffixs=this.editor.options.imageUploadSuffix;var e={png:"image/png",jpg:"image/jpeg",gif:"image/gif"};this.accepts=this.suffixs.map(function(t){return e[t]})},t.prototype.setInput=function(){this.$input=N('<input type="file" id="'+this.inputID+'" name="'+this.editor.options.imageUploadName+'" accept="'+this.accepts.join(", ")+'"/>').insertAfter(this.$button)},t.prototype.bindInputChange=function(){var n=this;this.$input.on("change",function(t){var e=t.target.files;e.length&&(n.upload(e[0]),n.$input.val(""))})},t.prototype.upload=function(t){var i=this;if(this.accepts.indexOf(t.type)<0)ot.alert("仅允许上传 "+this.suffixs.join(", ")+" 格式的图片");else if(this.editor.options.imageUploadMaxSize&&t.size>this.editor.options.imageUploadMaxSize)ot.alert("图片体积不能超过 "+function(t){for(var e=0;1024<=t;)t/=1024,e++;return t.toFixed(2)+["B","KB","MB","GB","TB"][e]}(this.editor.options.imageUploadMaxSize));else{var n,o,r,e=new FormData;e.append(this.editor.options.imageUploadName,t),At({url:this.editor.options.imageUploadUrl,method:"POST",data:e,processData:!1,dataType:"json",contentType:!1,global:!1,beforeSend:function(t){o=0,r=setInterval(function(){return o+=100},100);var e=(n=ot.dialog({title:"上传中…",content:'<p class="mdui_editor-upload-progress">0%</p>',history:!1,modal:!0,cssClass:"mdui_editor-upload-progress-dialog"})).$element.find(".mdui_editor-upload-progress");t.upload.onprogress=function(t){e.html((t.loaded/t.total*100).toFixed(0)+"%")}},complete:function(){clearInterval(r),o<500?setTimeout(function(){n.close()},500-o):n.close()}}).then(function(t){if(i.editor.options.imageUploadResponseTransform&&(t=i.editor.options.imageUploadResponseTransform(t)),t.code)ot.alert(t.message);else{var e=i.selection.getRootElem(),n=e.html().toLowerCase().trim(),o='<figure><img src="'+t.data.url+'"/><figcaption placeholder="图片描述(选填)"></figcaption></figure>';"P"!==e[0].nodeName||"<br>"!==n&&"<br/>"!==n?i.command.do("insertAfterRoot",o):i.command.do("replaceRoot",o),i.command.do("insertAfterRoot","<p><br></p>")}}).catch(function(){return ot.alert("图片上传失败")})}},t.prototype.onclick=function(){N("#"+this.inputID).trigger("click")},t}(Q);Bt.icon="image",Bt.title="插入图片";var Ut=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.getCommandName=function(){return"italic"},e.prototype.getElementName=function(){return"em"},e}(Y);Ut.icon="format_italic",Ut.title="斜体",Ut.disable=["image"],j(["","s","sUntil"],function(n,t){N.fn["parent"+t]=function(t,e){return Mt(n?N(this.get().reverse()):this,n,"parentNode",t,e)}});var It={};function Pt(t,e,n,o){var i=ut(o,"_mdui_mutation");i||ut(o,"_mdui_mutation",i=[]),-1===i.indexOf(t)&&(i.push(t),e.call(o,n,o))}N.fn.mutation=function(){return this.each(function(t,e){var i=N(e);j(It,function(n,o){i.is(n)&&Pt(n,o,t,e),i.find(n).each(function(t,e){Pt(n,o,t,e)})})})};var Ft={reInit:!(ot.mutation=function(n,o){w(n)||w(o)?N(document).mutation():(It[n]=o,N(n).each(function(t,e){return Pt(n,o,t,e)}))}),domLoadedEvent:!1};function qt(t,e){void 0===e&&(e={}),e=D({},Ft,e);var n=t.target,o=N(n),i=t.type,r=o.val(),a=o.attr("type")||"";if(!(-1<["checkbox","button","submit","range","radio","image"].indexOf(a))){var c=o.parent(".mdui-textfield");if("focus"===i&&c.addClass("mdui-textfield-focus"),"blur"===i&&c.removeClass("mdui-textfield-focus"),"blur"!==i&&"input"!==i||(r?c.addClass("mdui-textfield-not-empty"):c.removeClass("mdui-textfield-not-empty")),n.disabled?c.addClass("mdui-textfield-disabled"):c.removeClass("mdui-textfield-disabled"),"input"!==i&&"blur"!==i||e.domLoadedEvent||!n.validity||(n.validity.valid?c.removeClass("mdui-textfield-invalid-html5"):c.addClass("mdui-textfield-invalid-html5")),o.is("textarea")){var s=r,u=!1;""===s.replace(/[\r\n]/g,"")&&(o.val(" "+s),u=!0),o.outerHeight("");var l=o.outerHeight(),d=n.scrollHeight;l<d&&o.outerHeight(d),u&&o.val(s)}e.reInit&&c.find(".mdui-textfield-counter").remove();var f=o.attr("maxlength");f&&((e.reInit||e.domLoadedEvent)&&N('<div class="mdui-textfield-counter"><span class="mdui-textfield-counter-inputed"></span> / '+f+"</div>").appendTo(c),c.find(".mdui-textfield-counter-inputed").text(r.length.toString())),(c.find(".mdui-textfield-helper").length||c.find(".mdui-textfield-error").length||f)&&c.addClass("mdui-textfield-has-bottom")}}N(function(){tt.on("input focus blur",".mdui-textfield-input",{useCapture:!0},qt),tt.on("click",".mdui-textfield-expandable .mdui-textfield-icon",function(){N(this).parents(".mdui-textfield").addClass("mdui-textfield-expanded").find(".mdui-textfield-input")[0].focus()}),tt.on("click",".mdui-textfield-expanded .mdui-textfield-close",function(){N(this).parents(".mdui-textfield").removeClass("mdui-textfield-expanded").find(".mdui-textfield-input").val("")}),ot.mutation(".mdui-textfield",function(){N(this).find(".mdui-textfield-input").trigger("input",{domLoadedEvent:!0})})});var zt={confirmText:"ok",cancelText:"cancel",history:!0,modal:!(ot.updateTextFields=function(t){(w(t)?N(".mdui-textfield"):N(t)).each(function(t,e){N(e).find(".mdui-textfield-input").trigger("input",{reInit:!0})})}),closeOnEsc:!0,closeOnCancel:!0,closeOnConfirm:!0,type:"text",maxlength:0,defaultValue:"",confirmOnEnter:!1};ot.prompt=function(t,e,o,n,i){p(e)&&(i=n,n=o,o=e,e=""),w(o)&&(o=function(){}),w(n)&&(n=function(){}),w(i)&&(i={});var r='<div class="mdui-textfield">'+(t?'<label class="mdui-textfield-label">'+t+"</label>":"")+("text"===(i=D({},zt,i)).type?'<input class="mdui-textfield-input" type="text" value="'+i.defaultValue+'" '+(i.maxlength?'maxlength="'+i.maxlength+'"':"")+"/>":"")+("textarea"===i.type?'<textarea class="mdui-textfield-input" '+(i.maxlength?'maxlength="'+i.maxlength+'"':"")+">"+i.defaultValue+"</textarea>":"")+"</div>";return ot.dialog({title:e,content:r,buttons:[{text:i.cancelText,bold:!1,close:i.closeOnCancel,onClick:function(t){var e=t.$element.find(".mdui-textfield-input").val();n(e,t)}},{text:i.confirmText,bold:!1,close:i.closeOnConfirm,onClick:function(t){var e=t.$element.find(".mdui-textfield-input").val();o(e,t)}}],cssClass:"mdui-dialog-prompt",history:i.history,modal:i.modal,closeOnEsc:i.closeOnEsc,onOpen:function(n){var t=n.$element.find(".mdui-textfield-input");ot.updateTextFields(t),t[0].focus(),"textarea"!==i.type&&!0===i.confirmOnEnter&&t.on("keydown",function(t){if(13===t.keyCode){var e=n.$element.find(".mdui-textfield-input").val();return o(e,n),i.closeOnConfirm&&n.close(),!1}}),"textarea"===i.type&&t.on("input",function(){return n.handleUpdate()}),i.maxlength&&n.handleUpdate()}})};var Kt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.onclick=function(){var o=this,t=this.selection.getContainerElem(),e="";t.is("a")&&(this.selection.createRangeByElem(t,!1,!0),e=t.attr("href")||"");var n=ot.prompt("请输入链接地址",function(t,e){if(!t)return o.command.do("unlink"),void e.close();var n=e.$element.find(".mdui-textfield-input")[0];return n.validity&&n.validity.valid?(o.command.do("createLink",t),void e.close()):void 0},L,{confirmText:"确认",cancelText:"取消",defaultValue:e,confirmOnEnter:!0,closeOnConfirm:!1});n.$element.find(".mdui-textfield-input").attr("type","text").attr("pattern","^(https?|ftp|file)://[\\S]+\\.[\\S]+$").after('<div class="mdui-textfield-error">链接格式错误</div>'),ot.updateTextFields(n.$element.find(".mdui-textfield")),n.handleUpdate()},e.prototype.isActive=function(){return this.selection.getContainerElem().is("a")},e}(Q);Kt.icon="link",Kt.title="插入链接",Kt.disable=["image"],j(["","All","Until"],function(n,t){N.fn["prev"+t]=function(t,e){return Mt(n?N(this.get().reverse()):this,n,"previousElementSibling",t,e)}});var Wt=function(t){function e(){t.apply(this,arguments),this.disable=["head","code","image"]}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.getCommandName=function(){return"ol"===this.getName()?"insertOrderedList":"insertUnorderedList"},e.prototype.moveListToRoot=function(t){var o=this;t.each(function(t,e){var n=N(e).parent();n.is(o.$container)||(o.selection.createRangeByElem(n,!1,!0),o.command.do("replaceRoot",e))})},e.prototype.moveElemToP=function(){var c=this;N(this.$container[0].childNodes).each(function(t,e){var n=N(e),o=e.nodeType,i=e.nodeName,r=e.nodeValue,a=e.outerHTML;return 3===o?(c.selection.createRangeByElem(n.prev(),!1,!0),c.command.do("insertAfterRoot",r?"<p>"+r+"</p>":"<p><br></p>"),void n.remove()):1===o?-1<["B","STRONG","I","EM","A"].indexOf(i)?(c.selection.createRangeByElem(n,!1,!0),void c.command.do("replaceRoot",a?"<p>"+a+"</p>":"<p><br></p>")):void("BR"===i&&n.remove()):void 0})},e.prototype.onclick=function(){this.command.do(this.getCommandName()),this.moveListToRoot(this.$container.find(this.getName())),this.moveElemToP()},e.prototype.isActive=function(){return document.queryCommandState(this.getCommandName())},e}(Q),Vt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.getName=function(){return"ol"},e}(Wt);Vt.icon="format_list_numbered",Vt.title="有序列表";var Gt=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.getName=function(){return"ul"},e}(Wt);Gt.icon="format_list_bulleted",Gt.title="无序列表";var Xt={bold:Z,clear_drafts:Et,code:Tt,head:Rt,image:Bt,italic:Ut,link:Kt,ol:Vt,ul:Gt},Jt=function(e){function t(t){e.call(this,t),this.menus={},this.init()}return e&&(t.__proto__=e),((t.prototype=Object.create(e&&e.prototype)).constructor=t).prototype.init=function(){var i=this;this.editor.options.menus.forEach(function(t){if("|"!==t)if(" "!==t){var e=Xt[t];if(e&&"function"==typeof e){var n=N('<button class="mdui-btn mdui_editor-toolbar-menu mdui_editor-toolbar-menu-'+t+'" type="button" title="'+e.title+'"><i class="mdui-icon material-icons">'+e.icon+"</i></button>").appendTo(i.$toolbar),o=new e(i.editor,n);i.menus[t]=o;n.on("click",function(){null!==i.selection.getRange()&&o.onclick()})}}else i.$toolbar.append('<div class="mdui-toolbar-spacer"></div>');else i.$toolbar.append('<div class="mdui_editor-toolbar-divider"></div>')})},t.prototype.changeStatus=function(){var n=this,o=[];j(this.menus,function(t,e){setTimeout(function(){e.isActive()?(e.$button.addClass("mdui_editor-toolbar-menu-active"),Xt[t].disable&&(o=o.concat(Xt[t].disable))):e.$button.removeClass("mdui_editor-toolbar-menu-active"),t===n.editor.options.menus[n.editor.options.menus.length-1]&&(o=U(o),j(n.menus,function(t,e){e.$button.prop("disabled",-1<o.indexOf(t))}))},0)})},t}(G);var Qt=function(t){function e(){t.apply(this,arguments),this.currentRange=void 0}return t&&(e.__proto__=t),((e.prototype=Object.create(t&&t.prototype)).constructor=e).prototype.getRange=function(){return this.currentRange},e.prototype.saveRange=function(t){if(t)this.currentRange=t;else{var e=window.getSelection();if(0!==e.rangeCount){var n=e.getRangeAt(0),o=this.getContainerElem(n);o.length&&this.$container[0].contains(o[0])&&(this.currentRange=n)}}},e.prototype.collapseRange=function(t){void 0===t&&(t=!1);var e=this.currentRange;e&&e.collapse(t)},e.prototype.getText=function(){return this.currentRange?this.currentRange.toString():""},e.prototype.getContainerElem=function(t){if(t=t||this.currentRange){var e=t.commonAncestorContainer;return N(1===e.nodeType?e:e.parentNode)}return N()},e.prototype.getRootElem=function(t){var e=this.getContainerElem(t);return this.$container.is(e)?N():e.parent().is(this.$container)?e:e.parentsUntil(this.$container).last()},e.prototype.isEmpty=function(){var t=this.currentRange;return!(!t||!t.startContainer)&&(t.startContainer===t.endContainer&&t.startOffset===t.endOffset)},e.prototype.restore=function(){var t=window.getSelection();t.removeAllRanges(),t.addRange(this.currentRange)},e.prototype.createEmptyRange=function(t){void 0===t&&(t="strong");var e,n=this.getRange();if(n&&this.isEmpty())try{/webkit/i.test(navigator.userAgent)?(this.command.do("insertHTML","​"),n.setEnd(n.endContainer,n.endOffset+1),this.saveRange(n)):(e=N("<"+t+">​</"+t+">"),this.command.do("insertElem",e),this.createRangeByElem(e,!0))}catch(t){}},e.prototype.createRangeByElem=function(t,e,n){if(void 0===e&&(e=!1),void 0===n&&(n=!1),t.length){var o=t[0],i=document.createRange();n?i.selectNodeContents(o):i.selectNode(o),i.collapse(e),this.saveRange(i)}},e}(G);function Yt(t){return wt(function(t){var e=t.clipboardData||t.originalEvent&&t.originalEvent.clipboardData,n="",o="";return null===e?n=window.clipboardData&&window.clipboardData.getData("text"):(n=e.getData("text/plain"),o=e.getData("text/html")),{pasteText:n,pasteHtml:o}}(t).pasteText)}function Zt(t,e,n){void 0===n&&(n={}),this.options=D({},te),this.change=null,D(this.options,n),this.$toolbar=N(t).first().addClass("mdui_editor-toolbar"),this.$container=N(e).first().addClass("mdui_editor-content mdui-typo").attr({contenteditable:"",placeholder:this.options.placeholder}),this.command=new J(this),this.selection=new Qt(this),this.menus=new Jt(this),this.options.autoSave&&this.setHTML(window.localStorage.getItem(this.options.autoSaveKey)||""),this.initSelection(!0),this.bindEvent(),this.command.do("defaultParagraphSeparator","p");try{this.command.do("AutoUrlDetect",!1)}catch(t){}}var te={onchange:function(){},onClearDrafts:function(){},onchangeTimeout:200,placeholder:"说点什么",menus:["bold","italic","head","code","ol","ul","link","image"," ","clear_drafts"],tagsWhiteList:["p","strong","b","em","i","h2","pre","code","ol","ul","li","a","img","figure","figcaption"],autoSave:!1,autoSaveKey:"mdui-editor-content",imageUploadUrl:"",imageUploadMaxSize:2097152,imageUploadSuffix:["png","jpg","gif"],imageUploadName:"file",imageUploadResponseTransform:!1};return Zt.prototype.initSelection=function(t){void 0===t&&(t=!1);var e=this.$container.children();if(!e.length)return this.$container.append("<p><br></p>"),this.initSelection();var n=e.last();if(t){var o=n.html().toLowerCase(),i=n[0].nodeName;if("<br>"!==o&&"<br/>"!==o||"P"!==i)return this.$container.append("<p><br></p>"),this.initSelection()}this.updatePlaceholder(),this.selection.createRangeByElem(n,!1,!0),this.selection.restore()},Zt.prototype.getHTML=function(){return this.$container.html().replace(/\u200b/gm,"")},Zt.prototype.setHTML=function(t){this.$container.html(t),this.initSelection()},Zt.prototype.getText=function(){return this.$container.text().replace(/\u200b/gm,"")},Zt.prototype.setText=function(t){this.setHTML(t?"<p>"+t+"</p>":"<p><br></p>")},Zt.prototype.clear=function(){this.setHTML("<p><br></p>")},Zt.prototype.focus=function(){this.initSelection()},Zt.prototype.bindEvent=function(){var t=this,e=!0;this.$container.on("compositionstart",function(){e=!1}).on("compositionend",function(){e=!0}).on("click keyup",function(){e&&t.change&&t.change()}),this.$toolbar.on("click",function(){t.change&&t.change()}),this.bindChange(),this.saveRangeRealTime(),this.pasteHandler(),this.deleteHandler(),this.containerClickHandler(),this.dragHandler(),this.undoHandler()},Zt.prototype.updatePlaceholder=function(){var t="mdui_editor-content-empty";"<p><br></p>"===this.$container.html()?this.$container.addClass(t):this.$container.removeClass(t)},Zt.prototype.bindChange=function(){var e=this,n=this.options,o=n.onchangeTimeout,i=0,r=this.getHTML();this.change=function(){var t=e.getHTML();t!==r&&(i&&clearTimeout(i),i=setTimeout(function(){n.onchange(e),r=t,n.autoSave&&window.localStorage.setItem(n.autoSaveKey,e.getHTML()),e.updatePlaceholder()},o))}},Zt.prototype.saveRangeRealTime=function(){function t(){e.selection.saveRange(),e.menus.changeStatus()}var e=this;this.$container.on("keyup",t).on("mousedown",function(){e.$container.on("mouseleave",t)}).on("mouseup",function(){t(),e.$container.off("mouseleave",t)})},Zt.prototype.pasteHandler=function(){var r=this;this.$container.on("paste",function(t){t.preventDefault();var e=function(t){var e="";return t.split("\n").forEach(function(t){t=t.replace(/[\r\n]/gm,""),e+=t?"<p>"+t+"</p>":"<p><br></p>"}),e}(