text: !function(t,e){"function"==typeof define&&define.amd?define("simditor",["jquery","simple-module","simple-hotkeys","simple-uploader"],function(i,n,r,o){return t.Simditor=e(i,n,r,o)}):"object"==typeof exports?module.exports=e(require("jquery"),require("simple-module"),require("simple-hotkeys"),require("simple-uploader")):t.Simditor=e(jQuery,SimpleModule,simple.hotkeys,simple.uploader)}(this,function(t,e,i,n){var r,o,s,a,l,d,u,h,p,c,f,g,m,v,y,_,b,w,x,C,T,k,N,S,A,E,B,R,I,M,O,P,L,W,z=function(t,e){for(var i in e)D.call(e,i)&&(t[i]=e[i]);function n(){this.constructor=t}return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t},D={}.hasOwnProperty,H=[].indexOf||function(t){for(var e=0,i=this.length;e<i;e++)if(e in this&&this[e]===t)return e;return-1},q=[].slice;return A=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="Selection",n.prototype._range=null,n.prototype._startNodes=null,n.prototype._endNodes=null,n.prototype._containerNode=null,n.prototype._nodes=null,n.prototype._blockNodes=null,n.prototype._rootNodes=null,n.prototype._init=function(){var t;return this.editor=this._module,this._selection=document.getSelection(),this.editor.on("selectionchanged",(t=this,function(e){return t.reset(),t._range=t._selection.getRangeAt(0)})),this.editor.on("blur",function(t){return function(e){return t.reset()}}(this))},n.prototype.reset=function(){return this._range=null,this._startNodes=null,this._endNodes=null,this._containerNode=null,this._nodes=null,this._blockNodes=null,this._rootNodes=null},n.prototype.clear=function(){try{this._selection.removeAllRanges()}catch(t){t}return this.reset()},n.prototype.range=function(t){var e;return t?(this.clear(),this._selection.addRange(t),this._range=t,e=this.editor.util.browser.firefox||this.editor.util.browser.msie,!this.editor.inputManager.focused&&e&&this.editor.body.focus()):!this._range&&this.editor.inputManager.focused&&this._selection.rangeCount&&(this._range=this._selection.getRangeAt(0)),this._range},n.prototype.startNodes=function(){var e;return this._range&&(this._startNodes||(this._startNodes=(e=this,function(){var i;return(i=t(e._range.startContainer).parentsUntil(e.editor.body).get()).unshift(e._range.startContainer),t(i)})())),this._startNodes},n.prototype.endNodes=function(){var e;return this._range&&(this._endNodes||(this._endNodes=this._range.collapsed?this.startNodes():((e=t(this._range.endContainer).parentsUntil(this.editor.body).get()).unshift(this._range.endContainer),t(e)))),this._endNodes},n.prototype.containerNode=function(){return this._range&&(this._containerNode||(this._containerNode=t(this._range.commonAncestorContainer))),this._containerNode},n.prototype.nodes=function(){var e;return this._range&&(this._nodes||(this._nodes=(e=this,function(){var i;return i=[],e.startNodes().first().is(e.endNodes().first())?i=e.startNodes().get():(e.startNodes().each(function(n,r){var o,s,a,l,d,u,h;return s=t(r),e.endNodes().index(s)>-1?i.push(r):s.parent().is(e.editor.body)||(u=e.endNodes().index(s.parent()))>-1?(o=u&&u>-1?e.endNodes().eq(u-1):e.endNodes().last(),h=(a=s.parent().contents()).index(s),l=a.index(o),t.merge(i,a.slice(h,l).get())):(d=(a=s.parent().contents()).index(s),t.merge(i,a.slice(d).get()))}),e.endNodes().each(function(n,r){var o,s,a;return(o=t(r)).parent().is(e.editor.body)||e.startNodes().index(o.parent())>-1?(i.push(r),!1):(a=(s=o.parent().contents()).index(o),t.merge(i,s.slice(0,a+1)))})),t(t.unique(i))})())),this._nodes},n.prototype.blockNodes=function(){var t;if(this._range)return this._blockNodes||(this._blockNodes=(t=this,function(){return t.nodes().filter(function(e,i){return t.editor.util.isBlockNode(i)})})()),this._blockNodes},n.prototype.rootNodes=function(){var e;if(this._range)return this._rootNodes||(this._rootNodes=(e=this,function(){return e.nodes().filter(function(i,n){var r;return(r=t(n).parent()).is(e.editor.body)||r.is("blockquote")})})()),this._rootNodes},n.prototype.rangeAtEndOf=function(e,i){var n,r,o,s,a,l;if(null==i&&(i=this.range()),i&&i.collapsed)return e=t(e)[0],o=i.endContainer,s=this.editor.util.getNodeLength(o),r=i.endOffset===s-1,a=t(o).contents().last().is("br"),n=i.endOffset===s,!!(r&&a||n)&&(e===o||!!t.contains(e,o)&&(l=!0,t(o).parentsUntil(e).addBack().each(function(e,i){var n,r,o;if(o=(n=t(i).parent().contents().filter(function(){return!(this!==i&&3===this.nodeType&&!this.nodeValue)}).last()).get(0)===i,r=n.is("br")&&n.prev().get(0)===i,!o&&!r)return l=!1,!1}),l))},n.prototype.rangeAtStartOf=function(e,i){var n,r;if(null==i&&(i=this.range()),i&&i.collapsed)return e=t(e)[0],r=i.startContainer,0===i.startOffset&&(e===r||!!t.contains(e,r)&&(n=!0,t(r).parentsUntil(e).addBack().each(function(e,i){if(t(i).parent().contents().filter(function(){return!(this!==i&&3===this.nodeType&&!this.nodeValue)}).first().get(0)!==i)return n=!1}),n))},n.prototype.insertNode=function(e,i){if(null==i&&(i=this.range()),i)return e=t(e)[0],i.insertNode(e),this.setRangeAfter(e,i)},n.prototype.setRangeAfter=function(e,i){if(null==i&&(i=this.range()),null!=i)return e=t(e)[0],i.setEndAfter(e),i.collapse(!1),this.range(i)},n.prototype.setRangeBefore=function(e,i){if(null==i&&(i=this.range()),null!=i)return e=t(e)[0],i.setEndBefore(e),i.collapse(!1),this.range(i)},n.prototype.setRangeAtStartOf=function(e,i){return null==i&&(i=this.range()),e=t(e).get(0),i.setEnd(e,0),i.collapse(!1),this.range(i)},n.prototype.setRangeAtEndOf=function(e,i){var n,r,o,s,a,l,d;return null==i&&(i=this.range()),e=(r=t(e))[0],r.is("pre")?(o=r.contents()).length>0?(l=(s=o.last()).text(),a=this.editor.util.getNodeLength(s[0]),"\n"===l.charAt(l.length-1)?i.setEnd(s[0],a-1):i.setEnd(s[0],a)):i.setEnd(e,0):(d=this.editor.util.getNodeLength(e),3!==e.nodeType&&d>0&&((n=t(e).contents().last()).is("br")?d-=1:3!==n[0].nodeType&&this.editor.util.isEmptyNode(n)&&(n.append(this.editor.util.phBr),e=n[0],d=0)),i.setEnd(e,d)),i.collapse(!1),this.range(i)},n.prototype.deleteRangeContents=function(t){var e,i,n,r;return null==t&&(t=this.range()),r=t.cloneRange(),n=t.cloneRange(),r.collapse(!0),n.collapse(!1),i=this.rangeAtStartOf(this.editor.body,r),e=this.rangeAtEndOf(this.editor.body,n),!t.collapsed&&i&&e?(this.editor.body.empty(),t.setStart(this.editor.body[0],0),t.collapse(!0),this.range(t)):t.deleteContents(),t},n.prototype.breakBlockEl=function(e,i){var n;return null==i&&(i=this.range()),n=t(e),i.collapsed?(i.setStartBefore(n.get(0)),i.collapsed?n:n.before(i.extractContents())):n},n.prototype.save=function(e){var i,n,r;if(null==e&&(e=this.range()),!this._selectionSaved)return(n=e.cloneRange()).collapse(!1),r=t("<span/>").addClass("simditor-caret-start"),i=t("<span/>").addClass("simditor-caret-end"),n.insertNode(i[0]),e.insertNode(r[0]),this.clear(),this._selectionSaved=!0},n.prototype.restore=function(){var t,e,i,n,r,o,s;return!!this._selectionSaved&&(r=this.editor.body.find(".simditor-caret-start"),t=this.editor.body.find(".simditor-caret-end"),r.length&&t.length?(s=(o=r.parent()).contents().index(r),i=(e=t.parent()).contents().index(t),o[0]===e[0]&&(i-=1),(n=document.createRange()).setStart(o.get(0),s),n.setEnd(e.get(0),i),r.remove(),t.remove(),this.range(n)):(r.remove(),t.remove()),this._selectionSaved=!1,n)},n}(),c=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="Formatter",n.prototype.opts={allowedTags:[],allowedAttributes:{},allowedStyles:{}},n.prototype._init=function(){return this.editor=this._module,this._allowedTags=t.merge(["br","span","a","img","b","strong","i","strike","u","font","p","ul","ol","li","blockquote","pre","code","h1","h2","h3","h4","hr"],this.opts.allowedTags),this._allowedAttributes=t.extend({img:["src","alt","width","height","data-non-image"],a:["href","target"],font:["color"],code:["class"]},this.opts.allowedAttributes),this._allowedStyles=t.extend({span:["color","font-size"],b:["color"],i:["color"],strong:["color"],strike:["color"],u:["color"],p:["margin-left","text-align"],h1:["margin-left","text-align"],h2:["margin-left","text-align"],h3:["margin-left","text-align"],h4:["margin-left","text-align"]},this.opts.allowedStyles),this.editor.body.on("click","a",function(t){return!1})},n.prototype.decorate=function(t){return null==t&&(t=this.editor.body),this.editor.trigger("decorate",[t]),t},n.prototype.undecorate=function(t){return null==t&&(t=this.editor.body.clone()),this.editor.trigger("undecorate",[t]),t},n.prototype.autolink=function(e){var i,n,r,o,s,a,l,d,u,h,p,c,f;for(null==e&&(e=this.editor.body),l=[],(r=function(i){return i.contents().each(function(i,n){var o,s;if(!(o=t(n)).is("a")&&!o.closest("a, pre",e).length)return!o.is("iframe")&&o.contents().length?r(o):(s=o.text())&&/https?:\/\/|www\./gi.test(s)?l.push(o):void 0})})(e),u=/(https?:\/\/|www\.)[\w\-\.\?&=\/#%:,@\!\+]+/gi,o=0,a=l.length;o<a;o++){for(c=(n=l[o]).text(),h=[],d=null,s=0;null!==(d=u.exec(c));)p=c.substring(s,d.index),h.push(document.createTextNode(p)),s=u.lastIndex,f=/^(http(s)?:\/\/|\/)/.test(d[0])?d[0]:"http://"+d[0],i=t('<a href="'+f+'" rel="nofollow"></a>').text(d[0]),h.push(i[0]);h.push(document.createTextNode(c.substring(s))),n.replaceWith(t(h))}return e},n.prototype.format=function(e){var i,n,r,o,s,a,l,d,u,h;if(null==e&&(e=this.editor.body),e.is(":empty"))return e.append("<p>"+this.editor.util.phBr+"</p>"),e;for(r=0,s=(u=e.contents()).length;r<s;r++)l=u[r],this.cleanNode(l,!0);for(o=0,a=(h=e.contents()).length;o<a;o++)d=h[o],(i=t(d)).is("br")?(null!=n&&(n=null),i.remove()):this.editor.util.isBlockNode(d)?i.is("li")?n&&n.is("ul, ol")?n.append(d):(n=t("<ul/>").insertBefore(d)).append(d):n=null:(n&&!n.is("ul, ol")||(n=t("<p/>").insertBefore(d)),n.append(d),this.editor.util.isEmptyNode(n)&&n.append(this.editor.util.phBr));return e},n.prototype.cleanNode=function(e,i){var n,r,o,s,a,l,d,u,h,p,c,f,g,m,v,y,_,b;if((o=t(e)).length>0){if(3!==o[0].nodeType){if(u=o.is("iframe")?null:o.contents(),h=this.editor.util.isDecoratedNode(o),o.is(this._allowedTags.join(","))||h){if(o.is("a")&&(r=o.find("img")).length>0&&(o.replaceWith(r),o=r,u=null),o.is("td")&&(n=o.find(this.editor.util.blockNodes.join(","))).length>0&&(n.each(function(e,i){return t(i).contents().unwrap()}),u=o.contents()),o.is("img")&&o.hasClass("uploading")&&o.remove(),!h){for(l=this._allowedAttributes[o[0].tagName.toLowerCase()],p=0,f=(v=t.makeArray(o[0].attributes)).length;p<f;p++)"style"!==(d=v[p]).name&&(null!=l&&(y=d.name,H.call(l,y)>=0)||o.removeAttr(d.name));this._cleanNodeStyles(o),o.is("span")&&0===o[0].attributes.length&&o.contents().first().unwrap()}}else 1!==o[0].nodeType||o.is(":empty")?(o.remove(),u=null):o.is("div, article, dl, header, footer, tr")?(o.append("<br/>"),u.first().unwrap()):o.is("table")?(s=t("<p/>"),o.find("tr").each(function(e,i){return s.append(t(i).text()+"<br/>")}),o.replaceWith(s),u=null):o.is("thead, tfoot")?(o.remove(),u=null):o.is("th")?(a=t("<td/>").append(o.contents()),o.replaceWith(a)):u.first().unwrap();if(i&&null!=u&&!o.is("pre"))for(c=0,g=u.length;c<g;c++)m=u[c],this.cleanNode(m,!0);return null}(_=o.text().replace(/(\r\n|\n|\r)/gm,""))?(b=document.createTextNode(_),o.replaceWith(b)):o.remove()}},n.prototype._cleanNodeStyles=function(e){var i,n,r,o,s,a,l,d,u;if(d=e.attr("style")){if(e.removeAttr("style"),!((i=this._allowedStyles[e[0].tagName.toLowerCase()])&&i.length>0))return e;for(u={},n=0,r=(s=d.split(";")).length;n<r;n++)l=s[n],((o=(l=t.trim(l)).split(":")).length=2)&&(a=o[0],H.call(i,a)>=0&&(u[t.trim(o[0])]=t.trim(o[1])));return Object.keys(u).length>0&&e.css(u),e}},n.prototype.clearHtml=function(e,i){var n,r,o,s;return null==i&&(i=!0),n=t("<div/>").append(e),r=n.contents(),o="",r.each((s=this,function(e,n){var a,l;return 3===n.nodeType?o+=n.nodeValue:1===n.nodeType&&((l=(a=t(n)).is("iframe")?null:a.contents())&&l.length>0&&(o+=s.clearHtml(l)),i&&e<r.length-1&&a.is("br, p, div, li,tr, pre, address, artticle, aside, dl, figcaption, footer, h1, h2,h3, h4, header"))?o+="\n":void 0})),o},n.prototype.beautify=function(e){var i;return i=function(t){return!!(t.is("p")&&!t.text()&&t.children(":not(br)").length<1)},e.each(function(e,n){var r;return((r=t(n)).is(':not(img, br, col, td, hr, [class^="simditor-"]):empty')||i(r))&&r.remove(),r.find(':not(img, br, col, td, hr, [class^="simditor-"]):empty').remove()})},n}(),_=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="InputManager",n.prototype._modifierKeys=[16,17,18,91,93,224],n.prototype._arrowKeys=[37,38,39,40],n.prototype._init=function(){var e,i,n;return this.editor=this._module,this.throttledValueChanged=this.editor.util.throttle((n=this,function(t){return setTimeout(function(){return n.editor.trigger("valuechanged",t)},10)}),300),this.throttledSelectionChanged=this.editor.util.throttle(function(t){return function(){return t.editor.trigger("selectionchanged")}}(this),50),t(document).on("selectionchange.simditor"+this.editor.id,function(t){return function(e){var i;if(t.focused&&!t.editor.clipboard.pasting)return(i=function(){return t._selectionTimer&&(clearTimeout(t._selectionTimer),t._selectionTimer=null),t.editor.selection._selection.rangeCount>0?t.throttledSelectionChanged():t._selectionTimer=setTimeout(function(){if(t._selectionTimer=null,t.focused)return i()},10)})()}}(this)),this.editor.on("valuechanged",function(e){return function(){var i;if(e.lastCaretPosition=null,i=e.editor.body.children().filter(function(t,i){return e.editor.util.isBlockNode(i)}),e.focused&&0===i.length&&(e.editor.selection.save(),e.editor.formatter.format(),e.editor.selection.restore()),e.editor.body.find("hr, pre, .simditor-table").each(function(i,n){var r,o;if(((r=t(n)).parent().is("blockquote")||r.parent()[0]===e.editor.body[0])&&(o=!1,0===r.next().length&&(t("<p/>").append(e.editor.util.phBr).insertAfter(r),o=!0),0===r.prev().length&&(t("<p/>").append(e.editor.util.phBr).insertBefore(r),o=!0),o))return e.throttledValueChanged()}),e.editor.body.find("pre:empty").append(e.editor.util.phBr),!e.editor.util.support.onselectionchange&&e.focused)return e.throttledSelectionChanged()}}(this)),this.editor.body.on("keydown",t.proxy(this._onKeyDown,this)).on("keypress",t.proxy(this._onKeyPress,this)).on("keyup",t.proxy(this._onKeyUp,this)).on("mouseup",t.proxy(this._onMouseUp,this)).on("focus",t.proxy(this._onFocus,this)).on("blur",t.proxy(this._onBlur,this)).on("drop",t.proxy(this._onDrop,this)).on("input",t.proxy(this._onInput,this)),this.editor.util.browser.firefox&&(this.editor.hotkeys.add("cmd+left",function(t){return function(e){return e.preventDefault(),t.editor.selection._selection.modify("move","backward","lineboundary"),!1}}(this)),this.editor.hotkeys.add("cmd+right",function(t){return function(e){return e.preventDefault(),t.editor.selection._selection.modify("move","forward","lineboundary"),!1}}(this)),e=this.editor.util.os.mac?"cmd+a":"ctrl+a",this.editor.hotkeys.add(e,function(t){return function(e){var i,n,r,o;if((i=t.editor.body.children()).length>0)return n=i.first().get(0),r=i.last().get(0),(o=document.createRange()).setStart(n,0),o.setEnd(r,t.editor.util.getNodeLength(r)),t.editor.selection.range(o),!1}}(this))),i=this.editor.util.os.mac?"cmd+enter":"ctrl+enter",this.editor.hotkeys.add(i,function(t){return function(e){return t.editor.el.closest("form").find("button:submit").click(),!1}}(this))},n.prototype._onFocus=function(t){var e;if(!this.editor.clipboard.pasting)return this.editor.el.addClass("focus").removeClass("error"),this.focused=!0,setTimeout((e=this,function(){var t,i;if((i=e.editor.selection._selection.getRangeAt(0)).startContainer===e.editor.body[0]&&(e.lastCaretPosition?e.editor.undoManager.caretPosition(e.lastCaretPosition):(t=e.editor.body.children().first(),i=document.createRange(),e.editor.selection.setRangeAtStartOf(t,i))),e.lastCaretPosition=null,e.editor.triggerHandler("focus"),!e.editor.util.support.onselectionchange)return e.throttledSelectionChanged()}),0)},n.prototype._onBlur=function(t){var e;if(!this.editor.clipboard.pasting)return this.editor.el.removeClass("focus"),this.editor.sync(),this.focused=!1,this.lastCaretPosition=null!=(e=this.editor.undoManager.currentState())?e.caret:void 0,this.editor.triggerHandler("blur")},n.prototype._onMouseUp=function(t){if(!this.editor.util.support.onselectionchange)return this.throttledSelectionChanged()},n.prototype._onKeyDown=function(t){var e,i;if(!1===this.editor.triggerHandler(t))return!1;if(!this.editor.hotkeys.respondTo(t)){if(this.editor.keystroke.respondTo(t))return this.throttledValueChanged(),!1;if(!(e=t.which,H.call(this._modifierKeys,e)>=0||(i=t.which,H.call(this._arrowKeys,i)>=0)||this.editor.util.metaKey(t)&&86===t.which))return this.editor.util.support.oninput||this.throttledValueChanged(["typing"]),null}},n.prototype._onKeyPress=function(t){if(!1===this.editor.triggerHandler(t))return!1},n.prototype._onKeyUp=function(e){var i,n;if(!1===this.editor.triggerHandler(e))return!1;!this.editor.util.support.onselectionchange&&(n=e.which,H.call(this._arrowKeys,n)>=0)?this.throttledValueChanged():8!==e.which&&46!==e.which||!this.editor.util.isEmptyNode(this.editor.body)||(this.editor.body.empty(),i=t("<p/>").append(this.editor.util.phBr).appendTo(this.editor.body),this.editor.selection.setRangeAtStartOf(i))},n.prototype._onDrop=function(t){return!1!==this.editor.triggerHandler(t)&&this.throttledValueChanged()},n.prototype._onInput=function(t){return this.throttledValueChanged(["oninput"])},n}(),w=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="Keystroke",n.prototype._init=function(){return this.editor=this._module,this._keystrokeHandlers={},this._initKeystrokeHandlers()},n.prototype.add=function(t,e,i){return t=t.toLowerCase(),t=this.editor.hotkeys.constructor.aliases[t]||t,this._keystrokeHandlers[t]||(this._keystrokeHandlers[t]={}),this._keystrokeHandlers[t][e]=i},n.prototype.respondTo=function(e){var i,n,r,o,s;if(n=null!=(r=this.editor.hotkeys.constructor.keyNameMap[e.which])?r.toLowerCase():void 0)return!!(n in this._keystrokeHandlers&&((o="function"==typeof(i=this._keystrokeHandlers[n])["*"]?i["*"](e):void 0)||this.editor.selection.startNodes().each((s=this,function(i,r){var a,l;if(r.nodeType===Node.ELEMENT_NODE)return a=null!=(l=s._keystrokeHandlers[n])?l[r.tagName.toLowerCase()]:void 0,!0!==(o="function"==typeof a?a(e,t(r)):void 0)&&!1!==o&&void 0})),o))||void 0},n.prototype._initKeystrokeHandlers=function(){var e,i;return this.editor.util.browser.safari&&this.add("enter","*",(i=this,function(e){var n,r;if(e.shiftKey&&!(n=i.editor.selection.blockNodes().last()).is("pre"))return r=t("<br/>"),i.editor.selection.rangeAtEndOf(n)?(i.editor.selection.insertNode(r),i.editor.selection.insertNode(t("<br/>")),i.editor.selection.setRangeBefore(r)):i.editor.selection.insertNode(r),!0})),(this.editor.util.browser.webkit||this.editor.util.browser.msie)&&(e=function(e){return function(i,n){var r;if(e.editor.selection.rangeAtEndOf(n))return r=t("<p/>").append(e.editor.util.phBr).insertAfter(n),e.editor.selection.setRangeAtStartOf(r),!0}}(this),this.add("enter","h1",e),this.add("enter","h2",e),this.add("enter","h3",e),this.add("enter","h4",e),this.add("enter","h5",e),this.add("enter","h6",e)),this.add("backspace","*",function(t){return function(e){var i,n,r;return(n=(r=t.editor.selection.rootNodes().first()).prev()).is("hr")&&t.editor.selection.rangeAtStartOf(r)?(t.editor.selection.save(),n.remove(),t.editor.selection.restore(),!0):(i=t.editor.selection.blockNodes().last(),t.editor.util.browser.webkit&&t.editor.selection.rangeAtStartOf(i)?(t.editor.selection.save(),t.editor.formatter.cleanNode(i,!0),t.editor.selection.restore(),null):void 0)}}(this)),this.add("enter","li",function(e){return function(i,n){var r,o,s,a;if((r=n.clone()).find("ul, ol").remove(),e.editor.util.isEmptyNode(r)&&n.is(e.editor.selection.blockNodes().last())){if(o=n.parent(),n.next("li").length>0){if(!e.editor.util.isEmptyNode(n))return;o.parent("li").length>0?(s=t("<li/>").append(e.editor.util.phBr).insertAfter(o.parent("li")),a=t("<"+o[0].tagName+"/>").append(n.nextAll("li")),s.append(a)):(s=t("<p/>").append(e.editor.util.phBr).insertAfter(o),a=t("<"+o[0].tagName+"/>").append(n.nextAll("li")),s.after(a))}else o.parent("li").length>0?(s=t("<li/>").insertAfter(o.parent("li")),n.contents().length>0?s.append(n.contents()):s.append(e.editor.util.phBr)):(s=t("<p/>").append(e.editor.util.phBr).insertAfter(o),n.children("ul, ol").length>0&&s.after(n.children("ul, ol")));return n.prev("li").length?n.remove():o.remove(),e.editor.selection.setRangeAtStartOf(s),!0}}}(this)),this.add("enter","pre",function(e){return function(i,n){var r,o,s;return i.preventDefault(),i.shiftKey?(r=t("<p/>").append(e.editor.util.phBr).insertAfter(n),e.editor.selection.setRangeAtStartOf(r),!0):(o=null,(s=e.editor.selection.range()).deleteContents(),!e.editor.util.browser.msie&&e.editor.selection.rangeAtEndOf(n)?(o=document.createTextNode("\n\n"),s.insertNode(o),s.setEnd(o,1)):(o=document.createTextNode("\n"),s.insertNode(o),s.setStartAfter(o)),s.collapse(!1),e.editor.selection.range(s),!0)}}(this)),this.add("enter","blockquote",function(t){return function(e,i){var n,r;if((n=t.editor.selection.blockNodes().last()).is("p")&&!n.next().length&&t.editor.util.isEmptyNode(n))return i.after(n),r=document.createRange(),t.editor.selection.setRangeAtStartOf(n,r),!0}}(this)),this.add("backspace","li",function(e){return function(i,n){var r,o,s,a,l,d,u,h,p;return o=n.children("ul, ol"),l=n.prev("li"),o.length>0&&l.length>0&&(p="",d=null,n.contents().each(function(e,i){return(1!==i.nodeType||!/UL|OL/.test(i.nodeName))&&(1===i.nodeType&&/BR/.test(i.nodeName)?void 0:(3===i.nodeType&&i.nodeValue?p+=i.nodeValue:1===i.nodeType&&(p+=t(i).text()),d=t(i)))}),u=e.editor.util.browser.firefox&&!d.next("br").length,d&&1===p.length&&u?(r=t(e.editor.util.phBr).insertAfter(d),d.remove(),e.editor.selection.setRangeBefore(r),!0):!(p.length>0)&&(h=document.createRange(),(a=l.children("ul, ol")).length>0?(s=t("<li/>").append(e.editor.util.phBr).appendTo(a),a.append(o.children("li")),n.remove(),e.editor.selection.setRangeAtEndOf(s,h)):(e.editor.selection.setRangeAtEndOf(l,h),l.append(o),n.remove(),e.editor.selection.range(h)),!0))}}(this)),this.add("backspace","pre",function(e){return function(i,n){var r,o,s;if(e.editor.selection.rangeAtStartOf(n))return o=n.html().replace("\n","<br/>")||e.editor.util.phBr,r=t("<p/>").append(o).insertAfter(n),n.remove(),s=document.createRange(),e.editor.selection.setRangeAtStartOf(r,s),!0}}(this)),this.add("backspace","blockquote",function(t){return function(e,i){var n,r;if(t.editor.selection.rangeAtStartOf(i))return n=i.children().first().unwrap(),r=document.createRange(),t.editor.selection.setRangeAtStartOf(n,r),!0}}(this))},n}(),P=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="UndoManager",n.prototype._index=-1,n.prototype._capacity=20,n.prototype._startPosition=null,n.prototype._endPosition=null,n.prototype._init=function(){var t,e,i;return this.editor=this._module,this._stack=[],this.editor.util.os.mac?(e="cmd+z",t="shift+cmd+z"):this.editor.util.os.win?(e="ctrl+z",t="ctrl+y"):(e="ctrl+z",t="shift+ctrl+z"),this.editor.hotkeys.add(e,(i=this,function(t){return t.preventDefault(),i.undo(),!1})),this.editor.hotkeys.add(t,function(t){return function(e){return e.preventDefault(),t.redo(),!1}}(this)),this.throttledPushState=this.editor.util.throttle(function(t){return function(){return t._pushUndoState()}}(this),2e3),this.editor.on("valuechanged",function(t){return function(e,i){if("undo"!==i&&"redo"!==i)return t.throttledPushState()}}(this)),this.editor.on("selectionchanged",function(t){return function(e){return t.resetCaretPosition(),t.update()}}(this)),this.editor.on("focus",function(t){return function(e){if(0===t._stack.length)return t._pushUndoState()}}(this)),this.editor.on("blur",function(t){return function(e){return t.resetCaretPosition()}}(this))},n.prototype.resetCaretPosition=function(){return this._startPosition=null,this._endPosition=null},n.prototype.startPosition=function(){return this.editor.selection._range&&(this._startPosition||(this._startPosition=this._getPosition("start"))),this._startPosition},n.prototype.endPosition=function(){var t;return this.editor.selection._range&&(this._endPosition||(this._endPosition=(t=this,function(){return t.editor.selection.range().collapsed?t._startPosition:t._getPosition("end")})())),this._endPosition},n.prototype._pushUndoState=function(){if(!1!==this.editor.triggerHandler("pushundostate")&&this.caretPosition().start)return this._index+=1,this._stack.length=this._index,this._stack.push({html:this.editor.body.html(),caret:this.caretPosition()}),this._stack.length>this._capacity?(this._stack.shift(),this._index-=1):void 0},n.prototype.currentState=function(){return this._stack.length&&this._index>-1?this._stack[this._index]:null},n.prototype.undo=function(){var t;if(!(this._index<1||this._stack.length<2))return this.editor.hidePopover(),this._index-=1,t=this._stack[this._index],this.editor.body.get(0).innerHTML=t.html,this.caretPosition(t.caret),this.editor.body.find(".selected").removeClass("selected"),this.editor.sync(),this.editor.trigger("valuechanged",["undo"])},n.prototype.redo=function(){var t;if(!(this._index<0||this._stack.length<this._index+2))return this.editor.hidePopover(),this._index+=1,t=this._stack[this._index],this.editor.body.get(0).innerHTML=t.html,this.caretPosition(t.caret),this.editor.body.find(".selected").removeClass("selected"),this.editor.sync(),this.editor.trigger("valuechanged",["redo"])},n.prototype.update=function(){var t;if(t=this.currentState())return t.html=this.editor.body.html(),t.caret=this.caretPosition()},n.prototype._getNodeOffset=function(e,i){var n,r,o;return n=t.isNumeric(i)?t(e):t(e).parent(),o=0,r=!1,n.contents().each(function(t,n){return e!==n&&(i!==t||0!==t)&&(n.nodeType===Node.TEXT_NODE?!r&&n.nodeValue.length>0&&(o+=1,r=!0):(o+=1,r=!1),i-1!==t&&null)}),o},n.prototype._getPosition=function(e){var i,n,r,o,s,a,l;if(null==e&&(e="start"),o=this.editor.selection.range()[e+"Offset"],(n=(i=this.editor.selection[e+"Nodes"]()).first()[0]).nodeType===Node.TEXT_NODE){for(a=n.previousSibling;a&&a.nodeType===Node.TEXT_NODE;)n=a,o+=this.editor.util.getNodeLength(a),a=a.previousSibling;(r=i.get())[0]=n,i=t(r)}else o=this._getNodeOffset(n,o);return s=[o],i.each((l=this,function(t,e){return s.unshift(l._getNodeOffset(e))})),s},n.prototype._getNodeByPosition=function(e){var i,n,r,o,s,a,l,d;for(a=this.editor.body[0],r=o=0,s=(d=e.slice(0,e.length-1)).length;o<s;r=++o){if((l=d[r])>(n=a.childNodes).length-1){if(r!==e.length-2||!t(a).is("pre:empty")){a=null;break}i=document.createTextNode(""),a.appendChild(i),n=a.childNodes}a=n[l]}return a},n.prototype.caretPosition=function(t){var e,i,n,r,o;if(t){if(!t.start)return;return r=this._getNodeByPosition(t.start),o=t.start[t.start.length-1],t.collapsed?(e=r,i=o):(e=this._getNodeByPosition(t.end),i=t.start[t.start.length-1]),r&&e?((n=document.createRange()).setStart(r,o),n.setEnd(e,i),this.editor.selection.range(n)):void("undefined"!=typeof console&&null!==console&&"function"==typeof console.warn&&console.warn("simditor: invalid caret state"))}return n=this.editor.selection.range(),t=this.editor.inputManager.focused&&null!=n?{start:this.startPosition(),end:this.endPosition(),collapsed:n.collapsed}:{}},n}(),W=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}var r,o,s,a,l,d,u,h,p,c,f,g;return z(n,e),n.pluginName="Util",n.prototype._init=function(){if(this.editor=this._module,this.browser.msie&&this.browser.version<11)return this.phBr=""},n.prototype.phBr="<br/>",n.prototype.os=(r={},/Mac/.test(navigator.appVersion)?r.mac=!0:/Linux/.test(navigator.appVersion)?r.linux=!0:/Win/.test(navigator.appVersion)?r.win=!0:/X11/.test(navigator.appVersion)&&(r.unix=!0),/Mobi/.test(navigator.appVersion)&&(r.mobile=!0),r),n.prototype.browser=(g=navigator.userAgent,l=/(msie|trident)/i.test(g),o=/chrome|crios/i.test(g),f=/safari/i.test(g)&&!o,a=/firefox/i.test(g),s=/edge/i.test(g),l?{msie:!0,version:1*(null!=(d=g.match(/(msie |rv:)(\d+(\.\d+)?)/i))?d[2]:void 0)}:s?{edge:!0,webkit:!0,version:1*(null!=(u=g.match(/edge\/(\d+(\.\d+)?)/i))?u[1]:void 0)}:o?{webkit:!0,chrome:!0,version:1*(null!=(h=g.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i))?h[1]:void 0)}:f?{webkit:!0,safari:!0,version:1*(null!=(p=g.match(/version\/(\d+(\.\d+)?)/i))?p[1]:void 0)}:a?{mozilla:!0,firefox:!0,version:1*(null!=(c=g.match(/firefox\/(\d+(\.\d+)?)/i))?c[1]:void 0)}:{}),n.prototype.support={onselectionchange:function(){var t;if(void 0!==(t=document.onselectionchange))try{return document.onselectionchange=0,null===document.onselectionchange}catch(t){}finally{document.onselectionchange=t}return!1}(),oninput:!/(msie|trident)/i.test(navigator.userAgent)},n.prototype.reflow=function(e){return null==e&&(e=document),t(e)[0].offsetHeight},n.prototype.metaKey=function(t){return/Mac/.test(navigator.userAgent)?t.metaKey:t.ctrlKey},n.prototype.isEmptyNode=function(e){var i;return(i=t(e)).is(":empty")||!i.text()&&!i.find(":not(br, span, div)").length},n.prototype.isDecoratedNode=function(e){return t(e).is('[class^="simditor-"]')},n.prototype.blockNodes=["div","p","ul","ol","li","blockquote","hr","pre","h1","h2","h3","h4","h5","table"],n.prototype.isBlockNode=function(e){return!(!(e=t(e)[0])||3===e.nodeType)&&new RegExp("^("+this.blockNodes.join("|")+")$").test(e.nodeName.toLowerCase())},n.prototype.getNodeLength=function(e){switch((e=t(e)[0]).nodeType){case 7:case 10:return 0;case 3:case 8:return e.length;default:return e.childNodes.length}},n.prototype.dataURLtoBlob=function(t){var e,i,n,r,o,s,a,l,d,u,h;if(o=(s=window.Blob&&function(){try{return Boolean(new Blob)}catch(t){return t,!1}}())&&window.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(t){return t,!1}}(),e=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,!((s||e)&&window.atob&&window.ArrayBuffer&&window.Uint8Array))return!1;for(r=t.split(",")[0].indexOf("base64")>=0?atob(t.split(",")[1]):decodeURIComponent(t.split(",")[1]),i=new ArrayBuffer(r.length),l=new Uint8Array(i),a=d=0,h=r.length;0<=h?d<=h:d>=h;a=0<=h?++d:--d)l[a]=r.charCodeAt(a);return u=t.split(",")[0].split(":")[1].split(";")[0],s?new Blob([o?l:i],{type:u}):((n=new e).append(i),n.getBlob(u))},n.prototype.throttle=function(t,e){var i,n,r,o,s,a,l;return o=0,l=0,r=i=s=null,n=function(){return l=0,o=+new Date,s=t.apply(r,i),r=null,i=null},(a=function(){var t;return r=this,i=arguments,t=new Date-o,l||(t>=e?n():l=setTimeout(n,e-t)),s}).clear=function(){if(l)return clearTimeout(l),n()},a},n.prototype.formatHTML=function(e){var i,n,r,o,s,a,l,d;for(s=/<(\/?)(.+?)(\/?)>/g,l="",r=0,n=null,"  ",a=function(t,e){return new Array(e+1).join(t)};null!==(o=s.exec(e));)o.isBlockNode=t.inArray(o[2],this.blockNodes)>-1,o.isStartTag="/"!==o[1]&&"/"!==o[3],o.isEndTag="/"===o[1]||"/"===o[3],i=n?n.index+n[0].length:0,(d=e.substring(i,o.index)).length>0&&t.trim(d)&&(l+=d),o.isBlockNode&&o.isEndTag&&!o.isStartTag&&(r-=1),o.isBlockNode&&o.isStartTag&&(n&&n.isBlockNode&&n.isEndTag||(l+="\n"),l+=a("  ",r)),l+=o[0],o.isBlockNode&&o.isEndTag&&(l+="\n"),o.isBlockNode&&o.isStartTag&&(r+=1),n=o;return t.trim(l)},n}(),M=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="Toolbar",n.prototype.opts={toolbar:!0,toolbarFloat:!0,toolbarHidden:!1,toolbarFloatOffset:0},n.prototype._tpl={wrapper:'<div class="simditor-toolbar"><ul></ul></div>',separator:'<li><span class="separator"></span></li>'},n.prototype._init=function(){var e,i,n,r;if(this.editor=this._module,this.opts.toolbar)return t.isArray(this.opts.toolbar)||(this.opts.toolbar=["bold","italic","underline","strikethrough","|","ol","ul","blockquote","code","|","link","image","|","indent","outdent"]),this._render(),this.list.on("click",function(t){return!1}),this.wrapper.on("mousedown",(r=this,function(t){return r.list.find(".menu-on").removeClass(".menu-on")})),t(document).on("mousedown.simditor"+this.editor.id,function(t){return function(e){return t.list.find(".menu-on").removeClass(".menu-on")}}(this)),!this.opts.toolbarHidden&&this.opts.toolbarFloat&&(this.wrapper.css("top",this.opts.toolbarFloatOffset),n=0,i=function(t){return function(){return t.wrapper.css("position","static"),t.wrapper.width("auto"),t.editor.util.reflow(t.wrapper),t.wrapper.width(t.wrapper.outerWidth()),t.wrapper.css("left",t.editor.util.os.mobile?t.wrapper.position().left:t.wrapper.offset().left),t.wrapper.css("position",""),n=t.wrapper.outerHeight(),t.editor.placeholderEl.css("top",n),!0}}(this),e=null,t(window).on("resize.simditor-"+this.editor.id,function(t){return e=i()}),t(window).on("scroll.simditor-"+this.editor.id,function(r){return function(o){var s,a,l;if(r.wrapper.is(":visible"))if(s=(l=r.editor.wrapper.offset().top)+r.editor.wrapper.outerHeight()-80,(a=t(document).scrollTop()+r.opts.toolbarFloatOffset)<=l||a>=s){if(r.editor.wrapper.removeClass("toolbar-floating").css("padding-top",""),r.editor.util.os.mobile)return r.wrapper.css("top",r.opts.toolbarFloatOffset)}else if(e||(e=i()),r.editor.wrapper.addClass("toolbar-floating").css("padding-top",n),r.editor.util.os.mobile)return r.wrapper.css("top",a-l+r.opts.toolbarFloatOffset)}}(this))),this.editor.on("destroy",function(t){return function(){return t.buttons.length=0}}(this)),t(document).on("mousedown.simditor-"+this.editor.id,function(t){return function(e){return t.list.find("li.menu-on").removeClass("menu-on")}}(this))},n.prototype._render=function(){var e,i,n,r;for(this.buttons=[],this.wrapper=t(this._tpl.wrapper).prependTo(this.editor.wrapper),this.list=this.wrapper.find("ul"),e=0,i=(r=this.opts.toolbar).length;e<i;e++)if("|"!==(n=r[e])){if(!this.constructor.buttons[n])throw new Error("simditor: invalid toolbar button "+n);this.buttons.push(new this.constructor.buttons[n]({editor:this.editor}))}else t(this._tpl.separator).appendTo(this.list);if(this.opts.toolbarHidden)return this.wrapper.hide()},n.prototype.findButton=function(t){var e;return null!=(e=this.list.find(".toolbar-item-"+t).data("button"))?e:null},n.addButton=function(t){return this.buttons[t.prototype.name]=t},n.buttons={},n}(),y=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="Indentation",n.prototype.opts={tabIndent:!0},n.prototype._init=function(){return this.editor=this._module,this.editor.keystroke.add("tab","*",(t=this,function(e){var i;if(i=t.editor.toolbar.findButton("code"),t.opts.tabIndent||i&&i.active)return t.indent(e.shiftKey)}));var t},n.prototype.indent=function(e){var i,n,r,o;return this.editor.selection.startNodes(),this.editor.selection.endNodes(),i=this.editor.selection.blockNodes(),n=[],i=i.each(function(e,i){var r,o,s,a,l;for(r=!0,o=s=0,a=n.length;s<a;o=++s){if(l=n[o],t.contains(i,l)){r=!1;break}if(t.contains(l,i)){n.splice(o,1,i),r=!1;break}}if(r)return n.push(i)}),i=t(n),r=!1,i.each((o=this,function(t,i){var n;if(n=e?o.outdentBlock(i):o.indentBlock(i))return r=n})),r},n.prototype.indentBlock=function(e){var i,n,r,o,s,a,l,d,u,h;if((i=t(e)).length){if(i.is("pre")){if(!(a=this.editor.selection.containerNode()).is(i)&&!a.closest("pre").is(i))return;this.indentText(this.editor.selection.range())}else if(i.is("li")){if((s=i.prev("li")).length<1)return;this.editor.selection.save(),h=i.parent()[0].tagName,(n=s.children("ul, ol")).length>0?n.append(i):t("<"+h+"/>").append(i).appendTo(s),this.editor.selection.restore()}else if(i.is("p, h1, h2, h3, h4"))u=parseInt(i.css("margin-left"))||0,u=(Math.round(u/this.opts.indentWidth)+1)*this.opts.indentWidth,i.css("margin-left",u);else{if(!i.is("table")&&!i.is(".simditor-table"))return!1;if((r=(l=this.editor.selection.containerNode().closest("td, th")).next("td, th")).length>0||((o=(d=l.parent("tr")).next("tr")).length<1&&d.parent().is("thead")&&(o=d.parent("thead").next("tbody").find("tr:first")),r=o.find("td:first, th:first")),!(l.length>0&&r.length>0))return;this.editor.selection.setRangeAtEndOf(r)}return!0}},n.prototype.indentText=function(t){var e,i;return e=t.toString().replace(/^(?=.+)/gm,"  "),i=document.createTextNode(e||"  "),t.deleteContents(),t.insertNode(i),e?(t.selectNode(i),this.editor.selection.range(t)):this.editor.selection.setRangeAfter(i)},n.prototype.outdentBlock=function(e){var i,n,r,o,s,a,l,d,u,h;if((i=t(e))&&i.length>0){if(i.is("pre")){if(!(o=this.editor.selection.containerNode()).is(i)&&!o.closest("pre").is(i))return;this.outdentText(h)}else if(i.is("li"))r=(n=i.parent()).parent("li"),this.editor.selection.save(),r.length<1?((h=document.createRange()).setStartBefore(n[0]),h.setEndBefore(i[0]),n.before(h.extractContents()),t("<p/>").insertBefore(n).after(i.children("ul, ol")).append(i.contents()),i.remove()):(i.next("li").length>0&&t("<"+n[0].tagName+"/>").append(i.nextAll("li")).appendTo(i),i.insertAfter(r),n.children("li").length<1&&n.remove()),this.editor.selection.restore();else if(i.is("p, h1, h2, h3, h4"))u=parseInt(i.css("margin-left"))||0,u=Math.max(Math.round(u/this.opts.indentWidth)-1,0)*this.opts.indentWidth,i.css("margin-left",0===u?"":u);else{if(!i.is("table")&&!i.is(".simditor-table"))return!1;if((s=(l=this.editor.selection.containerNode().closest("td, th")).prev("td, th")).length>0||((a=(d=l.parent("tr")).prev("tr")).length<1&&d.parent().is("tbody")&&(a=d.parent("tbody").prev("thead").find("tr:first")),s=a.find("td:last, th:last")),!(l.length>0&&s.length>0))return;this.editor.selection.setRangeAtEndOf(s)}return!0}},n.prototype.outdentText=function(t){},n}(),l=function(i){function n(){return n.__super__.constructor.apply(this,arguments)}return z(n,e),n.pluginName="Clipboard",n.prototype.opts={pasteImage:!1,cleanPaste:!1},n.prototype._init=function(){return this.editor=this._module,this.opts.pasteImage&&"string"!=typeof this.opts.pasteImage&&(this.opts.pasteImage="inline"),this.editor.body.on("paste",(t=this,function(e){var i;if(!t.pasting&&!t._pasteBin)return!1!==t.editor.triggerHandler(e)&&(i=t.editor.selection.deleteRangeContents(),t.editor.body.html()?i.collapsed||i.collapse(!0):(t.editor.formatter.format(),t.editor.selection.setRangeAtStartOf(t.editor.body.find("p:first"))),!t._processPasteByClipboardApi(e)&&(t.editor.inputManager.throttledValueChanged.clear(),t.editor.inputManager.throttledSelectionChanged.clear(),t.editor.undoManager.throttledPushState.clear(),t.editor.selection.reset(),t.editor.undoManager.resetCaretPosition(),t.pasting=!0,t._getPasteContent(function(e){return t._processPasteContent(e),t._pasteInBlockEl=null,t._pastePlainText=null,t.pasting=!1})))}));var t},n.prototype._processPasteByClipboardApi=function(t){var e,i,n,r;if(!this.editor.util.browser.edge&&t.originalEvent.clipboardData&&t.originalEvent.clipboardData.items&&t.originalEvent.clipboardData.items.length>0&&(i=t.originalEvent.clipboardData.items[0],/^image\//.test(i.type))){if(null==(e=i.getAsFile())||!this.opts.pasteImage)return;if(e.name||(e.name="Clipboard Image.png"),!1===this.editor.triggerHandler("pasting",[e]))return;return(r={})[this.opts.pasteImage]=!0,null!=(n=this.editor.uploader)&&n.upload(e,r),!0}},n.prototype._getPasteContent=function(e){var i,n;return this._pasteBin=t('<div contenteditable="true" />').addClass("simditor-paste-bin").attr("tabIndex","-1").appendTo(this.editor.el),i={html:this.editor.body.html(),caret:this.editor.undoManager.caretPosition()},this._pasteBin.focus(),setTimeout((n=this,function(){var r;return n.editor.hidePopover(),n.editor.body.get(0).innerHTML=i.html,n.editor.undoManager.caretPosition(i.caret),n.editor.body.focus(),n.editor.selection.reset(),n.editor.selection.range(),n._pasteInBlockEl=n.editor.selection.blockNodes().last(),n._pastePlainText=n.opts.cleanPaste||n._pasteInBlockEl.is("pre, table"),n._pastePlainText?r=n.editor.formatter.clearHtml(n._pasteBin.html(),!0):((r=t("<div/>").append(n._pasteBin.contents())).find("table colgroup").remove(),n.editor.formatter.format(r),n.editor.formatter.decorate(r),n.editor.formatter.beautify(r.children()),r=r.contents()),n._pasteBin.remove(),n._pasteBin=null,e(r)}),0)},n.prototype._processPasteContent=function(e){var i,n,r,o,s,a,l,d,u,h,p,c,f,g,m,v,y,_,b,w,x,C,T;if(!1!==this.editor.triggerHandler("pasting",[e])&&(i=this._pasteInBlockEl,e)){if(this._pastePlainText)if(i.is("table")){for(d=(m=e.split("\n")).pop(),a=0,u=m.length;a<u;a++)g=m[a],this.editor.selection.insertNode(document.createTextNode(g)),this.editor.selection.insertNode(t("<br/>"));this.editor.selection.insertNode(document.createTextNode(d))}else for(l=0,h=(w=(e=t("<div/>").text(e)).contents()).length;l<h;l++)y=w[l],this.editor.selection.insertNode(t(y)[0]);else if(i.is(this.editor.body))for(v=0,p=e.length;v<p;v++)y=e[v],this.editor.selection.insertNode(y);else{if(e.length<1)return;if(1===e.length)if(e.is("p")){if(1===(o=e.contents()).length&&o.is("img")){if(/^data:image/.test((n=o).attr("src"))){if(!this.opts.pasteImage)return;return(r=this.editor.util.dataURLtoBlob(n.attr("src"))).name="Clipboard Image.png",(T={})[this.opts.pasteImage]=!0,void(null!=(x=this.editor.uploader)&&x.upload(r,T))}if(n.is('img[src^="webkit-fake-url://"]'))return}for(_=0,c=o.length;_<c;_++)y=o[_],this.editor.selection.insertNode(y)}else if(i.is("p")&&this.editor.util.isEmptyNode(i))i.replaceWith(e),this.editor.selection.setRangeAtEndOf(e);else if(e.is("ul, ol"))if(1===e.find("li").length)for(b=0,f=(C=(e=t("<div/>").text(e.text())).contents()).length;b<f;b++)y=C[b],this.editor.selection.insertNode(t(y)[0]);else i.is("li")?(i.parent().after(e),this.editor.selection.setRangeAtEndOf(e)):(i.after(e),this.editor.selection.setRangeAtEndOf(e));else i.after(e),this.editor.selection.setRangeAtEndOf(e);else i.is("li")&&(i=i.parent()),this.editor.selection.rangeAtStartOf(i)?s="before":this.editor.selection.rangeAtEndOf(i)?s="after":(this.editor.selection.breakBlockEl(i),s="before"),i[s](e),this.editor.selection.setRangeAtEndOf(e.last())}return this.editor.inputManager.throttledValueChanged()}},n}(),(E=function(r){function o(){return o.__super__.constructor.apply(this,arguments)}return z(o,e),o.connect(W),o.connect(_),o.connect(A),o.connect(P),o.connect(w),o.connect(c),o.connect(M),o.connect(y),o.connect(l),o.count=0,o.prototype.opts={textarea:null,placeholder:"",defaultImage:"images/image.png",params:{},upload:!1,indentWidth:40},o.prototype._init=function(){var e,r,s,a;if(this.textarea=t(this.opts.textarea),this.opts.placeholder=this.opts.placeholder||this.textarea.attr("placeholder"),!this.textarea.length)throw new Error("simditor: param textarea is required.");if(null!=(e=this.textarea.data("simditor"))&&e.destroy(),this.id=++o.count,this._render(),!i)throw new Error("simditor: simple-hotkeys is required.");if(this.hotkeys=i({el:this.body}),this.opts.upload&&n&&(s="object"==typeof this.opts.upload?this.opts.upload:{},this.uploader=n(s)),(r=this.textarea.closest("form")).length&&(r.on("submit.simditor-"+this.id,(a=this,function(){return a.sync()})),r.on("reset.simditor-"+this.id,function(t){return function(){return t.setValue("")}}(this))),this.on("initialized",function(t){return function(){if(t.opts.placeholder&&t.on("valuechanged",function(){return t._placeholder()}),t.setValue(t.textarea.val().trim()||""),t.textarea.attr("autofocus"))return t.focus()}}(this)),this.util.browser.mozilla){this.util.reflow();try{return document.execCommand("enableObjectResizing",!1,!1),document.execCommand("enableInlineTableEditing",!1,!1)}catch(t){t}}},o.prototype._tpl='<div class="simditor">\n  <div class="simditor-wrapper">\n    <div class="simditor-placeholder"></div>\n    <div class="simditor-body" contenteditable="true">\n    </div>\n  </div>\n</div>',o.prototype._render=function(){var e,i,n,r;if(this.el=t(this._tpl).insertBefore(this.textarea),this.wrapper=this.el.find(".simditor-wrapper"),this.body=this.wrapper.find(".simditor-body"),this.placeholderEl=this.wrapper.find(".simditor-placeholder").append(this.opts.placeholder),this.el.data("simditor",this),this.wrapper.append(this.textarea),this.textarea.data("simditor",this).blur(),this.body.attr("tabindex",this.textarea.attr("tabindex")),this.util.os.mac?this.el.addClass("simditor-mac"):this.util.os.linux&&this.el.addClass("simditor-linux"),this.util.os.mobile&&this.el.addClass("simditor-mobile"),this.opts.params){for(e in n=[],i=this.opts.params)r=i[e],n.push(t("<input/>",{type:"hidden",name:e,value:r}).insertAfter(this.textarea));return n}},o.prototype._placeholder=function(){var t;return 0===(t=this.body.children()).length||1===t.length&&this.util.isEmptyNode(t)&&parseInt(t.css("margin-left")||0)<this.opts.indentWidth?this.placeholderEl.show():this.placeholderEl.hide()},o.prototype.setValue=function(t){return this.hidePopover(),this.textarea.val(t),this.body.get(0).innerHTML=t,this.formatter.format(),this.formatter.decorate(),this.util.reflow(this.body),this.inputManager.lastCaretPosition=null,this.trigger("valuechanged")},o.prototype.getValue=function(){return this.sync()},o.prototype.sync=function(){var e,i,n,r,o,s;for(i=this.body.clone(),this.formatter.undecorate(i),this.formatter.format(i),this.formatter.autolink(i),o=(e=i.children()).last("p"),r=e.first("p");o.is("p")&&this.util.isEmptyNode(o);)n=o,o=o.prev("p"),n.remove();for(;r.is("p")&&this.util.isEmptyNode(r);)n=r,r=o.next("p"),n.remove();return i.find("img.uploading").remove(),s=t.trim(i.html()),this.textarea.val(s),s},o.prototype.focus=function(){var e,i;if(this.body.is(":visible")&&this.body.is("[contenteditable]"))return this.inputManager.lastCaretPosition?(this.undoManager.caretPosition(this.inputManager.lastCaretPosition),this.inputManager.lastCaretPosition=null):((e=this.body.children().last()).is("p")||(e=t("<p/>").append(this.util.phBr).appendTo(this.body)),i=document.createRange(),this.selection.setRangeAtEndOf(e,i));this.el.find("textarea:visible").focus()},o.prototype.blur=function(){return this.body.is(":visible")&&this.body.is("[contenteditable]")?this.body.blur():this.body.find("textarea:visible").blur()},o.prototype.hidePopover=function(){return this.el.find(".simditor-popover").each(function(e,i){if((i=t(i).data("popover")).active)return i.hide()})},o.prototype.destroy=function(){return this.triggerHandler("destroy"),this.textarea.closest("form").off(".simditor .simditor-"+this.id),this.selection.clear(),this.inputManager.focused=!1,this.textarea.insertBefore(this.el).hide().val("").removeData("simditor"),this.el.remove(),t(document).off(".simditor-"+this.id),t(window).off(".simditor-"+this.id),this.off()},o}()).i18n={"zh-CN":{blockquote:"å¼•ç”¨",bold:"åŠ ç²—æ–‡å­—",code:"æ’å…¥ä»£ç ",color:"æ–‡å­—é¢œè‰²",coloredText:"å½©è‰²æ–‡å­—",hr:"åˆ†éš”çº¿",image:"æ’å…¥å›¾ç‰‡",externalImage:"å¤–é“¾å›¾ç‰‡",uploadImage:"ä¸Šä¼ å›¾ç‰‡",uploadFailed:"ä¸Šä¼ å¤±è´¥äº†",uploadError:"ä¸Šä¼ å‡ºé”™äº†",imageUrl:"å›¾ç‰‡åœ°å€",imageSize:"å›¾ç‰‡å°ºå¯¸",imageAlt:"å›¾ç‰‡æè¿°",restoreImageSize:"è¿˜åŽŸå›¾ç‰‡å°ºå¯¸",uploading:"æ­£åœ¨ä¸Šä¼ ",indent:"å‘å³ç¼©è¿›",outdent:"å‘å·¦ç¼©è¿›",italic:"æ–œä½“æ–‡å­—",link:"æ’å…¥é“¾æŽ¥",linkText:"é“¾æŽ¥æ–‡å­—",linkUrl:"é“¾æŽ¥åœ°å€",linkTarget:"æ‰“å¼€æ–¹å¼",openLinkInCurrentWindow:"åœ¨æ–°çª—å£ä¸­æ‰“å¼€",openLinkInNewWindow:"åœ¨å½“å‰çª—å£ä¸­æ‰“å¼€",removeLink:"ç§»é™¤é“¾æŽ¥",ol:"æœ‰åºåˆ—è¡¨",ul:"æ— åºåˆ—è¡¨",strikethrough:"åˆ é™¤çº¿æ–‡å­—",table:"è¡¨æ ¼",deleteRow:"åˆ é™¤è¡Œ",insertRowAbove:"åœ¨ä¸Šé¢æ’å…¥è¡Œ",insertRowBelow:"åœ¨ä¸‹é¢æ’å…¥è¡Œ",deleteColumn:"åˆ é™¤åˆ—",insertColumnLeft:"åœ¨å·¦è¾¹æ’å…¥åˆ—",insertColumnRight:"åœ¨å³è¾¹æ’å…¥åˆ—",deleteTable:"åˆ é™¤è¡¨æ ¼",title:"æ ‡é¢˜",normalText:"æ™®é€šæ–‡æœ¬",underline:"ä¸‹åˆ’çº¿æ–‡å­—",alignment:"æ°´å¹³å¯¹é½",alignCenter:"å±…ä¸­",alignLeft:"å±…å·¦",alignRight:"å±…å³",selectLanguage:"é€‰æ‹©ç¨‹åºè¯­è¨€",fontScale:"å­—ä½“å¤§å°",fontScaleXLarge:"è¶…å¤§å­—ä½“",fontScaleLarge:"å¤§å·å­—ä½“",fontScaleNormal:"æ­£å¸¸å¤§å°",fontScaleSmall:"å°å·å­—ä½“",fontScaleXSmall:"è¶…å°å­—ä½“"},"en-US":{blockquote:"Block Quote",bold:"Bold",code:"Code",color:"Text Color",coloredText:"Colored Text",hr:"Horizontal Line",image:"Insert Image",externalImage:"External Image",uploadImage:"Upload Image",uploadFailed:"Upload failed",uploadError:"Error occurs during upload",imageUrl:"Url",imageSize:"Size",imageAlt:"Alt",restoreImageSize:"Restore Origin Size",uploading:"Uploading",indent:"Indent",outdent:"Outdent",italic:"Italic",link:"Insert Link",linkText:"Text",linkUrl:"Url",linkTarget:"Target",openLinkInCurrentWindow:"Open link in current window",openLinkInNewWindow:"Open link in new window",removeLink:"Remove Link",ol:"Ordered List",ul:"Unordered List",strikethrough:"Strikethrough",table:"Table",deleteRow:"Delete Row",insertRowAbove:"Insert Row Above",insertRowBelow:"Insert Row Below",deleteColumn:"Delete Column",insertColumnLeft:"Insert Column Left",insertColumnRight:"Insert Column Right",deleteTable:"Delete Table",title:"Title",normalText:"Text",underline:"Underline",alignment:"Alignment",alignCenter:"Align Center",alignLeft:"Align Left",alignRight:"Align Right",selectLanguage:"Select Language",fontScale:"Font Size",fontScaleXLarge:"X Large Size",fontScaleLarge:"Large Size",fontScaleNormal:"Normal Size",fontScaleSmall:"Small Size",fontScaleXSmall:"X Small Size"}},a=function(i){function n(t){this.editor=t.editor,this.title=this._t(this.name),n.__super__.constructor.call(this,t)}return z(n,e),n.prototype._tpl={item:'<li><a tabindex="-1" unselectable="on" class="toolbar-item" href="javascript:;"><span></span></a></li>',menuWrapper:'<div class="toolbar-menu"></div>',menuItem:'<li><a tabindex="-1" unselectable="on" class="menu-item" href="javascript:;"><span></span></a></li>',separator:'<li><span class="separator"></span></li>'},n.prototype.name="",n.prototype.icon="",n.prototype.title="",n.prototype.text="",n.prototype.htmlTag="",n.prototype.disableTag="",n.prototype.menu=!1,n.prototype.active=!1,n.prototype.disabled=!1,n.prototype.needFocus=!0,n.prototype.shortcut=null,n.prototype._init=function(){var e,i,n,r,o;for(this.render(),this.el.on("mousedown",(o=this,function(t){var e,i;return t.preventDefault(),e=o.needFocus&&!o.editor.inputManager.focused,!(o.el.hasClass("disabled")||e||(o.menu?(o.wrapper.toggleClass("menu-on").siblings("li").removeClass("menu-on"),o.wrapper.is(".menu-on")&&(o.menuWrapper.offset().left+o.menuWrapper.outerWidth()+5-o.editor.wrapper.offset().left-o.editor.wrapper.outerWidth()>0&&o.menuWrapper.css({left:"auto",right:0}),o.trigger("menuexpand")),1):(i=o.el.data("param"),o.command(i),1)))})),this.wrapper.on("click","a.menu-item",function(e){return function(i){var n,r,o;return i.preventDefault(),n=t(i.currentTarget),e.wrapper.removeClass("menu-on"),r=e.needFocus&&!e.editor.inputManager.focused,!n.hasClass("disabled")&&!r&&(e.editor.toolbar.wrapper.removeClass("menu-on"),o=n.data("param"),e.command(o),!1)}}(this)),this.wrapper.on("mousedown","a.menu-item",function(t){return!1}),this.editor.on("blur",function(t){return function(){if(t.editor.body.is(":visible")&&t.editor.body.is("[contenteditable]")&&!t.editor.clipboard.pasting)return t.setActive(!1),t.setDisabled(!1)}}(this)),null!=this.shortcut&&this.editor.hotkeys.add(this.shortcut,function(t){return function(e){return t.el.mousedown(),!1}}(this)),e=0,i=(n=this.htmlTag.split(",")).length;e<i;e++)r=n[e],(r=t.trim(r))&&t.inArray(r,this.editor.formatter._allowedTags)<0&&this.editor.formatter._allowedTags.push(r);return this.editor.on("selectionchanged",function(t){return function(e){if(t.editor.inputManager.focused)return t._status()}}(this))},n.prototype.iconClassOf=function(t){return t?"simditor-icon simditor-icon-"+t:""},n.prototype.setIcon=function(t){return this.el.find("span").removeClass().addClass(this.iconClassOf(t)).text(this.text)},n.prototype.render=function(){if(this.wrapper=t(this._tpl.item).appendTo(this.editor.toolbar.list),this.el=this.wrapper.find("a.toolbar-item"),this.el.attr("title",this.title).addClass("toolbar-item-"+this.name).data("button",this),this.setIcon(this.icon),this.menu)return this.menuWrapper=t(this._tpl.menuWrapper).appendTo(this.wrapper),this.menuWrapper.addClass("toolbar-menu-"+this.name),this.renderMenu()},n.prototype.renderMenu=function(){var e,i,n,r,o,s,a;if(t.isArray(this.menu)){for(this.menuEl=t("<ul/>").appendTo(this.menuWrapper),a=[],i=0,n=(o=this.menu).length;i<n;i++)"|"!==(r=o[i])?(e=t(this._tpl.menuItem).appendTo(this.menuEl).find("a.menu-item").attr({title:null!=(s=r.title)?s:r.text,"data-param":r.param}).addClass("menu-item-"+r.name),r.icon?a.push(e.find("span").addClass(this.iconClassOf(r.icon))):a.push(e.find("span").text(r.text))):t(this._tpl.separator).appendTo(this.menuEl);return a}},n.prototype.setActive=function(t){if(t!==this.active)return this.active=t,this.el.toggleClass("active",this.active)},n.prototype.setDisabled=function(t){if(t!==this.disabled)return this.disabled=t,this.el.toggleClass("disabled",this.disabled)},n.prototype._disableStatus=function(){var t,e,i;return i=this.editor.selection.startNodes(),e=this.editor.selection.endNodes(),t=i.filter(this.disableTag).length>0||e.filter(this.disableTag).length>0,this.setDisabled(t),this.disabled&&this.setActive(!1),this.disabled},n.prototype._activeStatus=function(){var t,e,i,n,r;return r=this.editor.selection.startNodes(),i=this.editor.selection.endNodes(),n=r.filter(this.htmlTag),e=i.filter(this.htmlTag),t=n.length>0&&e.length>0&&n.is(e),this.node=t?n:null,this.setActive(t),this.active},n.prototype._status=function(){if(this._disableStatus(),!this.disabled)return this._activeStatus()},n.prototype.command=function(t){},n.prototype._t=function(){var t,e,i;return t=1<=arguments.length?q.call(arguments,0):[],(i=n.__super__._t.apply(this,t))||(i=(e=this.editor)._t.apply(e,t)),i},n}(),E.Button=a,S=function(i){function n(t){this.button=t.button,this.editor=t.button.editor,n.__super__.constructor.call(this,t)}return z(n,e),n.prototype.offset={top:4,left:0},n.prototype.target=null,n.prototype.active=!1,n.prototype._init=function(){var e;return this.el=t('<div class="simditor-popover"></div>').appendTo(this.editor.el).data("popover",this),this.render(),this.el.on("mouseenter",(e=this,function(t){return e.el.addClass("hover")})),this.el.on("mouseleave",function(t){return function(e){return t.el.removeClass("hover")}}(this))},n.prototype.render=function(){},n.prototype._initLabelWidth=function(){var e,i;if((e=this.el.find(".settings-field")).length>0)return this._labelWidth=0,e.each((i=this,function(e,n){var r;if((r=t(n).find("label")).length>0)return i._labelWidth=Math.max(i._labelWidth,r.width())})),e.find("label").width(this._labelWidth)},n.prototype.show=function(e,i){if(null==i&&(i="bottom"),null!=e)return this.el.siblings(".simditor-popover").each(function(e,i){if((i=t(i).data("popover")).active)return i.hide()}),this.active&&this.target&&this.target.removeClass("selected"),this.target=e.addClass("selected"),this.active?(this.refresh(i),this.trigger("popovershow")):(this.active=!0,this.el.css({left:-9999}).show(),this._labelWidth||this._initLabelWidth(),this.editor.util.reflow(),this.refresh(i),this.trigger("popovershow"))},n.prototype.hide=function(){if(this.active)return this.target&&this.target.removeClass("selected"),this.target=null,this.active=!1,this.el.hide(),this.trigger("popoverhide")},n.prototype.refresh=function(t){var e,i,n,r,o,s;if(null==t&&(t="bottom"),this.active)return e=this.editor.el.offset(),o=this.target.offset(),r=this.target.outerHeight(),"bottom"===t?s=o.top-e.top+r:"top"===t&&(s=o.top-e.top-this.el.height()),n=this.editor.wrapper.width()-this.el.outerWidth()-10,i=Math.min(o.left-e.left,n),this.el.css({top:s+this.offset.top,left:i+this.offset.left})},n.prototype.destroy=function(){return this.target=null,this.active=!1,this.editor.off(".linkpopover"),this.el.remove()},n.prototype._t=function(){var t,e,i;return t=1<=arguments.length?q.call(arguments,0):[],(i=n.__super__._t.apply(this,t))||(i=(e=this.button)._t.apply(e,t)),i},n}(),E.Popover=S,I=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="title",i.prototype.htmlTag="h1, h2, h3, h4, h5",i.prototype.disableTag="pre, table",i.prototype._init=function(){return this.menu=[{name:"normal",text:this._t("normalText"),param:"p"},"|",{name:"h1",text:this._t("title")+" 1",param:"h1"},{name:"h2",text:this._t("title")+" 2",param:"h2"},{name:"h3",text:this._t("title")+" 3",param:"h3"},{name:"h4",text:this._t("title")+" 4",param:"h4"},{name:"h5",text:this._t("title")+" 5",param:"h5"}],i.__super__._init.call(this)},i.prototype.setActive=function(t,e){if(i.__super__.setActive.call(this,t),t&&(e||(e=this.node[0].tagName.toLowerCase())),this.el.removeClass("active-p active-h1 active-h2 active-h3 active-h4 active-h5"),t)return this.el.addClass("active active-"+e)},i.prototype.command=function(e){var i,n;return i=this.editor.selection.rootNodes(),this.editor.selection.save(),i.each((n=this,function(i,r){var o;if(!((o=t(r)).is("blockquote")||o.is(e)||o.is(n.disableTag)||n.editor.util.isDecoratedNode(o)))return t("<"+e+"/>").append(o.contents()).replaceAll(o)})),this.editor.selection.restore(),this.editor.trigger("valuechanged")},i}(),E.Toolbar.addButton(I),p=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="fontScale",i.prototype.icon="font",i.prototype.disableTag="pre",i.prototype.htmlTag="span",i.prototype.sizeMap={"x-large":"1.5em",large:"1.25em",small:".75em","x-small":".5em"},i.prototype._init=function(){return this.menu=[{name:"150%",text:this._t("fontScaleXLarge"),param:"5"},{name:"125%",text:this._t("fontScaleLarge"),param:"4"},{name:"100%",text:this._t("fontScaleNormal"),param:"3"},{name:"75%",text:this._t("fontScaleSmall"),param:"2"},{name:"50%",text:this._t("fontScaleXSmall"),param:"1"}],i.__super__._init.call(this)},i.prototype._activeStatus=function(){var t,e,i,n,r;return this.editor.selection.range(),r=this.editor.selection.startNodes(),i=this.editor.selection.endNodes(),n=r.filter('span[style*="font-size"]'),e=i.filter('span[style*="font-size"]'),t=r.length>0&&i.length>0&&n.is(e),this.setActive(t),this.active},i.prototype.command=function(e){var i,n;if(!this.editor.selection.range().collapsed)return document.execCommand("styleWithCSS",!1,!0),document.execCommand("fontSize",!1,e),document.execCommand("styleWithCSS",!1,!1),this.editor.selection.reset(),this.editor.selection.range(),((i=this.editor.selection.containerNode())[0].nodeType===Node.TEXT_NODE?i.closest('span[style*="font-size"]'):i.find('span[style*="font-size"]')).each((n=this,function(e,i){var r,o;return r=t(i),o=i.style.fontSize,/large|x-large|small|x-small/.test(o)?r.css("fontSize",n.sizeMap[o]):"medium"===o?r.replaceWith(r.contents()):void 0})),this.editor.trigger("valuechanged")},i}(),E.Toolbar.addButton(p),s=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="bold",i.prototype.icon="bold",i.prototype.htmlTag="b, strong",i.prototype.disableTag="pre",i.prototype.shortcut="cmd+b",i.prototype._init=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + b )":(this.title=this.title+" ( Ctrl + b )",this.shortcut="ctrl+b"),i.__super__._init.call(this)},i.prototype._activeStatus=function(){var t;return t=!0===document.queryCommandState("bold"),this.setActive(t),this.active},i.prototype.command=function(){return document.execCommand("bold"),this.editor.util.support.oninput||this.editor.trigger("valuechanged"),t(document).trigger("selectionchange")},i}(),E.Toolbar.addButton(s),b=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="italic",i.prototype.icon="italic",i.prototype.htmlTag="i",i.prototype.disableTag="pre",i.prototype.shortcut="cmd+i",i.prototype._init=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + i )":(this.title=this.title+" ( Ctrl + i )",this.shortcut="ctrl+i"),i.__super__._init.call(this)},i.prototype._activeStatus=function(){var t;return t=!0===document.queryCommandState("italic"),this.setActive(t),this.active},i.prototype.command=function(){return document.execCommand("italic"),this.editor.util.support.oninput||this.editor.trigger("valuechanged"),t(document).trigger("selectionchange")},i}(),E.Toolbar.addButton(b),O=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="underline",i.prototype.icon="underline",i.prototype.htmlTag="u",i.prototype.disableTag="pre",i.prototype.shortcut="cmd+u",i.prototype.render=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + u )":(this.title=this.title+" ( Ctrl + u )",this.shortcut="ctrl+u"),i.__super__.render.call(this)},i.prototype._activeStatus=function(){var t;return t=!0===document.queryCommandState("underline"),this.setActive(t),this.active},i.prototype.command=function(){return document.execCommand("underline"),this.editor.util.support.oninput||this.editor.trigger("valuechanged"),t(document).trigger("selectionchange")},i}(),E.Toolbar.addButton(O),h=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="color",i.prototype.icon="tint",i.prototype.disableTag="pre",i.prototype.menu=!0,i.prototype.render=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.render.apply(this,t)},i.prototype.renderMenu=function(){return t('<ul class="color-list">\n  <li><a href="javascript:;" class="font-color font-color-1"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-2"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-3"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-4"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-5"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-6"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-7"></a></li>\n  <li><a href="javascript:;" class="font-color font-color-default"></a></li>\n</ul>').appendTo(this.menuWrapper),this.menuWrapper.on("mousedown",".color-list",function(t){return!1}),this.menuWrapper.on("click",".font-color",(e=this,function(i){var n,r,o,s,a,l;if(e.wrapper.removeClass("menu-on"),(n=t(i.currentTarget)).hasClass("font-color-default")){if(!((r=e.editor.body.find("p, li")).length>0))return;a=window.getComputedStyle(r[0],null).getPropertyValue("color"),o=e._convertRgbToHex(a)}else a=window.getComputedStyle(n[0],null).getPropertyValue("background-color"),o=e._convertRgbToHex(a);if(o)return s=e.editor.selection.range(),!n.hasClass("font-color-default")&&s.collapsed&&(l=document.createTextNode(e._t("coloredText")),s.insertNode(l),s.selectNodeContents(l),e.editor.selection.range(s)),document.execCommand("styleWithCSS",!1,!0),document.execCommand("foreColor",!1,o),document.execCommand("styleWithCSS",!1,!1),e.editor.util.support.oninput?void 0:e.editor.trigger("valuechanged")}));var e},i.prototype._convertRgbToHex=function(t){var e;return(e=/rgb\((\d+),\s?(\d+),\s?(\d+)\)/g.exec(t))?function(t,e,i){var n;return"#"+(n=function(t){var e;return 1===(e=t.toString(16)).length?"0"+e:e})(t)+n(e)+n(i)}(1*e[1],1*e[2],1*e[3]):""},i}(),E.Toolbar.addButton(h),T=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.type="",i.prototype.disableTag="pre, table",i.prototype.command=function(e){var i,n,r,o;return n=this.editor.selection.blockNodes(),r="ul"===this.type?"ol":"ul",this.editor.selection.save(),i=null,n.each((o=this,function(e,n){var s;if(!((s=t(n)).is("blockquote, li")||s.is(o.disableTag)||o.editor.util.isDecoratedNode(s))&&t.contains(document,n))return s.is(o.type)?(s.children("li").each(function(e,i){return t(i).children("ul, ol").insertAfter(s),t("<p/>").append(t(i).html()||o.editor.util.phBr).insertBefore(s)}),s.remove()):s.is(r)?t("<"+o.type+"/>").append(s.contents()).replaceAll(s):i&&s.prev().is(i)?(t("<li/>").append(s.html()||o.editor.util.phBr).appendTo(i),s.remove()):((i=t("<"+o.type+"><li></li></"+o.type+">")).find("li").append(s.html()||o.editor.util.phBr),i.replaceAll(s))})),this.editor.selection.restore(),this.editor.trigger("valuechanged")},i}(),k=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return z(e,T),e.prototype.type="ol",e.prototype.name="ol",e.prototype.icon="list-ol",e.prototype.htmlTag="ol",e.prototype.shortcut="cmd+/",e.prototype._init=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + / )":(this.title=this.title+" ( ctrl + / )",this.shortcut="ctrl+/"),e.__super__._init.call(this)},e}(),L=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return z(e,T),e.prototype.type="ul",e.prototype.name="ul",e.prototype.icon="list-ul",e.prototype.htmlTag="ul",e.prototype.shortcut="cmd+.",e.prototype._init=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + . )":(this.title=this.title+" ( Ctrl + . )",this.shortcut="ctrl+."),e.__super__._init.call(this)},e}(),E.Toolbar.addButton(k),E.Toolbar.addButton(L),o=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="blockquote",i.prototype.icon="quote-left",i.prototype.htmlTag="blockquote",i.prototype.disableTag="pre, table",i.prototype.command=function(){var e,i,n,r;return e=(e=this.editor.selection.rootNodes()).filter(function(e,i){return!t(i).parent().is("blockquote")}),this.editor.selection.save(),n=[],r=this,i=function(){if(n.length>0)return t("<"+r.htmlTag+"/>").insertBefore(n[0]).append(n),n.length=0},e.each(function(e){return function(r,o){var s;if((s=t(o)).parent().is(e.editor.body))return s.is(e.htmlTag)?(i(),s.children().unwrap()):s.is(e.disableTag)||e.editor.util.isDecoratedNode(s)?i():n.push(o)}}(this)),i(),this.editor.selection.restore(),this.editor.trigger("valuechanged")},i}(),E.Toolbar.addButton(o),d=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="code",i.prototype.icon="code",i.prototype.htmlTag="pre",i.prototype.disableTag="ul, ol, table",i.prototype._init=function(){var e;return i.__super__._init.call(this),this.editor.on("decorate",(e=this,function(i,n){return n.find("pre").each(function(i,n){return e.decorate(t(n))})})),this.editor.on("undecorate",function(e){return function(i,n){return n.find("pre").each(function(i,n){return e.undecorate(t(n))})}}(this))},i.prototype.render=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.render.apply(this,t),this.popover=new u({button:this})},i.prototype._checkMode=function(){var e;return e=this.editor.selection.range(),t(e.cloneContents()).find(this.editor.util.blockNodes.join(","))>0||e.collapsed&&0===this.editor.selection.startNodes().filter("code").length?(this.inlineMode=!1,this.htmlTag="pre"):(this.inlineMode=!0,this.htmlTag="code")},i.prototype._status=function(){if(this._checkMode(),i.__super__._status.call(this),!this.inlineMode)return this.active?this.popover.show(this.node):this.popover.hide()},i.prototype.decorate=function(t){var e,i,n,r;if((e=t.find("> code")).length>0&&(i=null!=(n=e.attr("class"))&&null!=(r=n.match(/lang-(\S+)/))?r[1]:void 0,e.contents().unwrap(),i))return t.attr("data-lang",i)},i.prototype.undecorate=function(e){var i,n;return n=e.attr("data-lang"),i=t("<code/>"),n&&-1!==n&&i.addClass("lang-"+n),e.wrapInner(i).removeAttr("data-lang")},i.prototype.command=function(){return this.inlineMode?this._inlineCommand():this._blockCommand()},i.prototype._blockCommand=function(){var e,i,n,r,o;return e=this.editor.selection.rootNodes(),n=[],r=[],o=this,i=function(){var e;if(n.length>0)return e=t("<"+o.htmlTag+"/>").insertBefore(n[0]).text(o.editor.formatter.clearHtml(n)),r.push(e[0]),n.length=0},e.each(function(e){return function(o,s){var a,l;return(a=t(s)).is(e.htmlTag)?(i(),l=t("<p/>").append(a.html().replace("\n","<br/>")).replaceAll(a),r.push(l[0])):a.is(e.disableTag)||e.editor.util.isDecoratedNode(a)||a.is("blockquote")?i():n.push(s)}}(this)),i(),this.editor.selection.setRangeAtEndOf(t(r).last()),this.editor.trigger("valuechanged")},i.prototype._inlineCommand=function(){var e,i,n;return n=this.editor.selection.range(),this.active?(n.selectNodeContents(this.node[0]),this.editor.selection.save(n),this.node.contents().unwrap(),this.editor.selection.restore()):(i=t(n.extractContents()),e=t("<"+this.htmlTag+"/>").append(i.contents()),n.insertNode(e[0]),n.selectNodeContents(e[0]),this.editor.selection.range(n)),this.editor.trigger("valuechanged")},i}(),u=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,S),i.prototype.render=function(){var e,i,n,r,o;for(this._tpl='<div class="code-settings">\n  <div class="settings-field">\n    <select class="select-lang">\n      <option value="-1">'+this._t("selectLanguage")+"</option>\n    </select>\n  </div>\n</div>",this.langs=this.editor.opts.codeLanguages||[{name:"Bash",value:"bash"},{name:"C++",value:"c++"},{name:"C#",value:"cs"},{name:"CSS",value:"css"},{name:"Erlang",value:"erlang"},{name:"Less",value:"less"},{name:"Sass",value:"sass"},{name:"Diff",value:"diff"},{name:"CoffeeScript",value:"coffeescript"},{name:"HTML,XML",value:"html"},{name:"JSON",value:"json"},{name:"Java",value:"java"},{name:"JavaScript",value:"js"},{name:"Markdown",value:"markdown"},{name:"Objective C",value:"oc"},{name:"PHP",value:"php"},{name:"Perl",value:"parl"},{name:"Python",value:"python"},{name:"Ruby",value:"ruby"},{name:"SQL",value:"sql"}],this.el.addClass("code-popover").append(this._tpl),this.selectEl=this.el.find(".select-lang"),e=0,n=(r=this.langs).length;e<n;e++)i=r[e],t("<option/>",{text:i.name,value:i.value}).appendTo(this.selectEl);return this.selectEl.on("change",(o=this,function(t){var e;return o.lang=o.selectEl.val(),e=o.target.hasClass("selected"),o.target.removeClass().removeAttr("data-lang"),-1!==o.lang&&o.target.attr("data-lang",o.lang),e&&o.target.addClass("selected"),o.editor.trigger("valuechanged")})),this.editor.on("valuechanged",function(t){return function(e){if(t.active)return t.refresh()}}(this))},i.prototype.show=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.show.apply(this,t),this.lang=this.target.attr("data-lang"),null!=this.lang?this.selectEl.val(this.lang):this.selectEl.val(-1)},i}(),E.Toolbar.addButton(d),x=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="link",i.prototype.icon="link",i.prototype.htmlTag="a",i.prototype.disableTag="pre",i.prototype.render=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.render.apply(this,t),this.popover=new C({button:this})},i.prototype._status=function(){return i.__super__._status.call(this),this.active&&!this.editor.selection.rangeAtEndOf(this.node)?this.popover.show(this.node):this.popover.hide()},i.prototype.command=function(){var e,i,n,r,o,s,a;return o=this.editor.selection.range(),this.active?(s=document.createTextNode(this.node.text()),this.node.replaceWith(s),o.selectNode(s)):(e=t(o.extractContents()),r=this.editor.formatter.clearHtml(e.contents(),!1),i=t("<a/>",{href:"http://www.example.com",target:"_blank",text:r||this._t("linkText")}),this.editor.selection.blockNodes().length>0?o.insertNode(i[0]):(n=t("<p/>").append(i),o.insertNode(n[0])),o.selectNodeContents(i[0]),this.popover.one("popovershow",(a=this,function(){return r?(a.popover.urlEl.focus(),a.popover.urlEl[0].select()):(a.popover.textEl.focus(),a.popover.textEl[0].select())}))),this.editor.selection.range(o),this.editor.trigger("valuechanged")},i}(),C=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,S),i.prototype.render=function(){var e,i;return e='<div class="link-settings">\n  <div class="settings-field">\n    <label>'+this._t("linkText")+'</label>\n    <input class="link-text" type="text"/>\n    <a class="btn-unlink" href="javascript:;" title="'+this._t("removeLink")+'"\n      tabindex="-1">\n      <span class="simditor-icon simditor-icon-unlink"></span>\n    </a>\n  </div>\n  <div class="settings-field">\n    <label>'+this._t("linkUrl")+'</label>\n    <input class="link-url" type="text"/>\n  </div>\n  <div class="settings-field">\n    <label>'+this._t("linkTarget")+'</label>\n    <select class="link-target">\n      <option value="_blank">'+this._t("openLinkInNewWindow")+' (_blank)</option>\n      <option value="_self">'+this._t("openLinkInCurrentWindow")+" (_self)</option>\n    </select>\n  </div>\n</div>",this.el.addClass("link-popover").append(e),this.textEl=this.el.find(".link-text"),this.urlEl=this.el.find(".link-url"),this.unlinkEl=this.el.find(".btn-unlink"),this.selectTarget=this.el.find(".link-target"),this.textEl.on("keyup",(i=this,function(t){if(13!==t.which)return i.target.text(i.textEl.val()),i.editor.inputManager.throttledValueChanged()})),this.urlEl.on("keyup",function(t){return function(e){var i;if(13!==e.which)return i=t.urlEl.val(),!/https?:\/\/|^\//gi.test(i)&&i&&(i="http://"+i),t.target.attr("href",i),t.editor.inputManager.throttledValueChanged()}}(this)),t([this.urlEl[0],this.textEl[0]]).on("keydown",function(e){return function(i){var n;if(13===i.which||27===i.which||!i.shiftKey&&9===i.which&&t(i.target).hasClass("link-url"))return i.preventDefault(),n=document.createRange(),e.editor.selection.setRangeAfter(e.target,n),e.hide(),e.editor.inputManager.throttledValueChanged()}}(this)),this.unlinkEl.on("click",function(t){return function(e){var i,n;return n=document.createTextNode(t.target.text()),t.target.replaceWith(n),t.hide(),i=document.createRange(),t.editor.selection.setRangeAfter(n,i),t.editor.inputManager.throttledValueChanged()}}(this)),this.selectTarget.on("change",function(t){return function(e){return t.target.attr("target",t.selectTarget.val()),t.editor.inputManager.throttledValueChanged()}}(this))},i.prototype.show=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.show.apply(this,t),this.textEl.val(this.target.text()),this.urlEl.val(this.target.attr("href"))},i}(),E.Toolbar.addButton(x),g=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="image",i.prototype.icon="picture-o",i.prototype.htmlTag="img",i.prototype.disableTag="pre, table",i.prototype.defaultImage="",i.prototype.needFocus=!1,i.prototype._init=function(){var e,n,r,o,s;if(this.editor.opts.imageButton)if(Array.isArray(this.editor.opts.imageButton))for(this.menu=[],n=0,r=(o=this.editor.opts.imageButton).length;n<r;n++)e=o[n],this.menu.push({name:e+"-image",text:this._t(e+"Image")});else this.menu=!1;else null!=this.editor.uploader?this.menu=[{name:"upload-image",text:this._t("uploadImage")},{name:"external-image",text:this._t("externalImage")}]:this.menu=!1;return this.defaultImage=this.editor.opts.defaultImage,this.editor.body.on("click","img:not([data-non-image])",(s=this,function(e){var i,n;return i=t(e.currentTarget),(n=document.createRange()).selectNode(i[0]),s.editor.selection.range(n),s.editor.util.support.onselectionchange||s.editor.trigger("selectionchanged"),!1})),this.editor.body.on("mouseup","img:not([data-non-image])",function(t){return!1}),this.editor.on("selectionchanged.image",function(e){return function(){var i,n,r;if(null!=(r=e.editor.selection.range()))return 1===(i=t(r.cloneContents()).contents()).length&&i.is("img:not([data-non-image])")?(n=t(r.startContainer).contents().eq(r.startOffset),e.popover.show(n)):e.popover.hide()}}(this)),this.editor.on("valuechanged.image",function(e){return function(){var i;if((i=e.editor.wrapper.find(".simditor-image-loading")).length>0)return i.each(function(i,n){var r,o,s;if(!((r=(o=t(n)).data("img"))&&r.parent().length>0)&&(o.remove(),r&&(s=r.data("file"))&&(e.editor.uploader.cancel(s),e.editor.body.find("img.uploading").length<1)))return e.editor.uploader.trigger("uploadready",[s])})}}(this)),i.__super__._init.call(this)},i.prototype.render=function(){var t;if(t=1<=arguments.length?q.call(arguments,0):[],i.__super__.render.apply(this,t),this.popover=new m({button:this}),"upload"===this.editor.opts.imageButton)return this._initUploader(this.el)},i.prototype.renderMenu=function(){return i.__super__.renderMenu.call(this),this._initUploader()},i.prototype._initUploader=function(e){var i,n,r,o;if(null==e&&(e=this.menuEl.find(".menu-item-upload-image")),null!=this.editor.uploader)return i=null,o=this,(n=function(){return i&&i.remove(),i=t("<input/>",{type:"file",title:o._t("uploadImage"),multiple:!0,accept:"image/*"}).appendTo(e)})(),e.on("click mousedown","input[type=file]",function(t){return t.stopPropagation()}),e.on("change","input[type=file]",function(t){return function(e){return t.editor.inputManager.focused?(t.editor.uploader.upload(i,{inline:!0}),n()):(t.editor.one("focus",function(e){return t.editor.uploader.upload(i,{inline:!0}),n()}),t.editor.focus()),t.wrapper.removeClass("menu-on")}}(this)),this.editor.uploader.on("beforeupload",function(e){return function(i,n){var r;if(n.inline)return n.img?r=t(n.img):(r=e.createImage(n.name),n.img=r),r.addClass("uploading"),r.data("file",n),e.editor.uploader.readImageFile(n.obj,function(t){var i;if(r.hasClass("uploading"))return i=t?t.src:e.defaultImage,e.loadImage(r,i,function(){if(e.popover.active)return e.popover.refresh(),e.popover.srcEl.val(e._t("uploading")).prop("disabled",!0)})})}}(this)),r=t.proxy(this.editor.util.throttle(function(t,e,i,n){var r,o,s;if(e.inline&&(o=e.img.data("mask"))){if((r=o.data("img")).hasClass("uploading")&&r.parent().length>0)return(s=(100*(s=i/n)).toFixed(0))>99&&(s=99),o.find(".progress").height(100-s+"%");o.remove()}},500),this),this.editor.uploader.on("uploadprogress",r),this.editor.uploader.on("uploadsuccess",function(e){return function(i,n,r){var o,s,a;if(n.inline&&(o=n.img).hasClass("uploading")&&o.parent().length>0){if("object"!=typeof r)try{r=t.parseJSON(r)}catch(t){t,r={success:!1}}return!1===r.success?(a=r.msg||e._t("uploadFailed"),alert(a),s=e.defaultImage):s=r.file_path,e.loadImage(o,s,function(){var t;if(o.removeData("file"),o.removeClass("uploading").removeClass("loading"),(t=o.data("mask"))&&t.remove(),o.removeData("mask"),e.editor.trigger("valuechanged"),e.editor.body.find("img.uploading").length<1)return e.editor.uploader.trigger("uploadready",[n,r])}),e.popover.active?(e.popover.srcEl.prop("disabled",!1),e.popover.srcEl.val(r.file_path)):void 0}}}(this)),this.editor.uploader.on("uploaderror",function(e){return function(i,n,r){var o,s,a;if(n.inline&&"abort"!==r.statusText){if(r.responseText){try{s=(a=t.parseJSON(r.responseText)).msg}catch(t){t,s=e._t("uploadError")}alert(s)}if((o=n.img).hasClass("uploading")&&o.parent().length>0)return e.loadImage(o,e.defaultImage,function(){var t;return o.removeData("file"),o.removeClass("uploading").removeClass("loading"),(t=o.data("mask"))&&t.remove(),o.removeData("mask")}),e.popover.active&&(e.popover.srcEl.prop("disabled",!1),e.popover.srcEl.val(e.defaultImage)),e.editor.trigger("valuechanged"),e.editor.body.find("img.uploading").length<1?e.editor.uploader.trigger("uploadready",[n,a]):void 0}}}(this));this.el.find(".btn-upload").remove()},i.prototype._status=function(){return this._disableStatus()},i.prototype.loadImage=function(e,i,n){var r,o,s,a;return a=this,s=function(){var t,i;return t=e.offset(),i=a.editor.wrapper.offset(),r.css({top:t.top-i.top,left:t.left-i.left,width:e.width(),height:e.height()}).show()},e.addClass("loading"),(r=e.data("mask"))||(r=t('<div class="simditor-image-loading">\n  <div class="progress"></div>\n</div>').hide().appendTo(this.editor.wrapper),s(),e.data("mask",r),r.data("img",e)),(o=new Image).onload=function(a){return function(){var l,d;if(e.hasClass("loading")||e.hasClass("uploading"))return d=o.width,l=o.height,e.attr({src:i,width:d,height:l,"data-image-size":d+","+l}).removeClass("loading"),e.hasClass("uploading")?(a.editor.util.reflow(a.editor.body),s()):(r.remove(),e.removeData("mask")),t.isFunction(n)?n(o):void 0}}(this),o.onerror=function(){return t.isFunction(n)&&n(!1),r.remove(),e.removeData("mask").removeClass("loading")},o.src=i},i.prototype.createImage=function(e){var i,n;return null==e&&(e="Image"),this.editor.inputManager.focused||this.editor.focus(),(n=this.editor.selection.range()).deleteContents(),this.editor.selection.range(n),i=t("<img/>").attr("alt",e),n.insertNode(i[0]),this.editor.selection.setRangeAfter(i,n),this.editor.trigger("valuechanged"),i},i.prototype.command=function(t){var e,i;return e=this.createImage(),this.loadImage(e,t||this.defaultImage,(i=this,function(){return i.editor.trigger("valuechanged"),i.editor.util.reflow(e),e.click(),i.popover.one("popovershow",function(){return i.popover.srcEl.focus(),i.popover.srcEl[0].select()})}))},i}(),m=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,S),i.prototype.offset={top:6,left:-4},i.prototype.render=function(){var e,i;return e='<div class="link-settings">\n  <div class="settings-field">\n    <label>'+this._t("imageUrl")+'</label>\n    <input class="image-src" type="text" tabindex="1" />\n    <a class="btn-upload" href="javascript:;"\n      title="'+this._t("uploadImage")+'" tabindex="-1">\n      <span class="simditor-icon simditor-icon-upload"></span>\n    </a>\n  </div>\n  <div class=\'settings-field\'>\n    <label>'+this._t("imageAlt")+'</label>\n    <input class="image-alt" id="image-alt" type="text" tabindex="1" />\n  </div>\n  <div class="settings-field">\n    <label>'+this._t("imageSize")+'</label>\n    <input class="image-size" id="image-width" type="text" tabindex="2" />\n    <span class="times">Ã—</span>\n    <input class="image-size" id="image-height" type="text" tabindex="3" />\n    <a class="btn-restore" href="javascript:;"\n      title="'+this._t("restoreImageSize")+'" tabindex="-1">\n      <span class="simditor-icon simditor-icon-undo"></span>\n    </a>\n  </div>\n</div>',this.el.addClass("image-popover").append(e),this.srcEl=this.el.find(".image-src"),this.widthEl=this.el.find("#image-width"),this.heightEl=this.el.find("#image-height"),this.altEl=this.el.find("#image-alt"),this.srcEl.on("keydown",(i=this,function(t){var e;if(13===t.which&&!i.target.hasClass("uploading"))return t.preventDefault(),e=document.createRange(),i.button.editor.selection.setRangeAfter(i.target,e),i.hide()})),this.srcEl.on("blur",function(t){return function(e){return t._loadImage(t.srcEl.val())}}(this)),this.el.find(".image-size").on("blur",function(e){return function(i){return e._resizeImg(t(i.currentTarget)),e.el.data("popover").refresh()}}(this)),this.el.find(".image-size").on("keyup",function(e){return function(i){var n;if(n=t(i.currentTarget),13!==i.which&&27!==i.which&&9!==i.which)return e._resizeImg(n,!0)}}(this)),this.el.find(".image-size").on("keydown",function(e){return function(i){var n,r,o;return r=t(i.currentTarget),13===i.which||27===i.which?(i.preventDefault(),13===i.which?e._resizeImg(r):e._restoreImg(),n=e.target,e.hide(),o=document.createRange(),e.button.editor.selection.setRangeAfter(n,o)):9===i.which?e.el.data("popover").refresh():void 0}}(this)),this.altEl.on("keydown",function(t){return function(e){var i;if(13===e.which)return e.preventDefault(),i=document.createRange(),t.button.editor.selection.setRangeAfter(t.target,i),t.hide()}}(this)),this.altEl.on("keyup",function(t){return function(e){if(13!==e.which&&27!==e.which&&9!==e.which)return t.alt=t.altEl.val(),t.target.attr("alt",t.alt)}}(this)),this.el.find(".btn-restore").on("click",function(t){return function(e){return t._restoreImg(),t.el.data("popover").refresh()}}(this)),this.editor.on("valuechanged",function(t){return function(e){if(t.active)return t.refresh()}}(this)),this._initUploader()},i.prototype._initUploader=function(){var e,i,n;if(e=this.el.find(".btn-upload"),null!=this.editor.uploader)return n=this,(i=function(){return n.input&&n.input.remove(),n.input=t("<input/>",{type:"file",title:n._t("uploadImage"),multiple:!0,accept:"image/*"}).appendTo(e)})(),this.el.on("click mousedown","input[type=file]",function(t){return t.stopPropagation()}),this.el.on("change","input[type=file]",function(t){return function(e){return t.editor.uploader.upload(t.input,{inline:!0,img:t.target}),i()}}(this));e.remove()},i.prototype._resizeImg=function(e,i){var n,r,o;if(null==i&&(i=!1),r=1*e.val(),this.target&&(t.isNumeric(r)||r<0))return e.is(this.widthEl)?(o=r,n=this.height*r/this.width,this.heightEl.val(n)):(n=r,o=this.width*r/this.height,this.widthEl.val(o)),i?void 0:(this.target.attr({width:o,height:n}),this.editor.trigger("valuechanged"))},i.prototype._restoreImg=function(){var t,e;return e=(null!=(t=this.target.data("image-size"))?t.split(","):void 0)||[this.width,this.height],this.target.attr({width:1*e[0],height:1*e[1]}),this.widthEl.val(e[0]),this.heightEl.val(e[1]),this.editor.trigger("valuechanged")},i.prototype._loadImage=function(t,e){var i;if(!/^data:image/.test(t)||this.editor.uploader){if(this.target.attr("src")!==t)return this.button.loadImage(this.target,t,(i=this,function(n){var r;if(n)return i.active&&(i.width=n.width,i.height=n.height,i.widthEl.val(i.width),i.heightEl.val(i.height)),/^data:image/.test(t)?((r=i.editor.util.dataURLtoBlob(t)).name="Base64 Image.png",i.editor.uploader.upload(r,{inline:!0,img:i.target})):i.editor.trigger("valuechanged"),e?e(n):void 0}))}else e&&e(!1)},i.prototype.show=function(){var t,e;return e=1<=arguments.length?q.call(arguments,0):[],i.__super__.show.apply(this,e),t=this.target,this.width=t.width(),this.height=t.height(),this.alt=t.attr("alt"),t.hasClass("uploading")?this.srcEl.val(this._t("uploading")).prop("disabled",!0):(this.srcEl.val(t.attr("src")).prop("disabled",!1),this.widthEl.val(this.width),this.heightEl.val(this.height),this.altEl.val(this.alt))},i}(),E.Toolbar.addButton(g),v=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return z(e,a),e.prototype.name="indent",e.prototype.icon="indent",e.prototype._init=function(){return this.title=this._t(this.name)+" (Tab)",e.__super__._init.call(this)},e.prototype._status=function(){},e.prototype.command=function(){return this.editor.indentation.indent()},e}(),E.Toolbar.addButton(v),N=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return z(e,a),e.prototype.name="outdent",e.prototype.icon="outdent",e.prototype._init=function(){return this.title=this._t(this.name)+" (Shift + Tab)",e.__super__._init.call(this)},e.prototype._status=function(){},e.prototype.command=function(){return this.editor.indentation.indent(!0)},e}(),E.Toolbar.addButton(N),f=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="hr",i.prototype.icon="minus",i.prototype.htmlTag="hr",i.prototype._status=function(){},i.prototype.command=function(){var e,i,n;return(n=this.editor.selection.rootNodes().first()).next().length>0?this.editor.selection.save():i=t("<p/>").append(this.editor.util.phBr),e=t("<hr/>").insertAfter(n),i?(i.insertAfter(e),this.editor.selection.setRangeAtStartOf(i)):this.editor.selection.restore(),this.editor.trigger("valuechanged")},i}(),E.Toolbar.addButton(f),R=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="table",i.prototype.icon="table",i.prototype.htmlTag="table",i.prototype.disableTag="pre, li, blockquote",i.prototype.menu=!0,i.prototype._init=function(){var e;return i.__super__._init.call(this),t.merge(this.editor.formatter._allowedTags,["thead","th","tbody","tr","td","colgroup","col"]),t.extend(this.editor.formatter._allowedAttributes,{td:["rowspan","colspan"],col:["width"]}),t.extend(this.editor.formatter._allowedStyles,{td:["text-align"],th:["text-align"]}),this._initShortcuts(),this.editor.on("decorate",(e=this,function(i,n){return n.find("table").each(function(i,n){return e.decorate(t(n))})})),this.editor.on("undecorate",function(e){return function(i,n){return n.find("table").each(function(i,n){return e.undecorate(t(n))})}}(this)),this.editor.on("selectionchanged.table",function(t){return function(e){var i,n;if(t.editor.body.find(".simditor-table td, .simditor-table th").removeClass("active"),n=t.editor.selection.range())return i=t.editor.selection.containerNode(),n.collapsed&&i.is(".simditor-table")&&(i=t.editor.selection.rangeAtStartOf(i)?i.find("th:first"):i.find("td:last"),t.editor.selection.setRangeAtEndOf(i)),i.closest("td, th",t.editor.body).addClass("active")}}(this)),this.editor.on("blur.table",function(t){return function(e){return t.editor.body.find(".simditor-table td, .simditor-table th").removeClass("active")}}(this)),this.editor.keystroke.add("up","td",function(t){return function(e,i){return t._tdNav(i,"up"),!0}}(this)),this.editor.keystroke.add("up","th",function(t){return function(e,i){return t._tdNav(i,"up"),!0}}(this)),this.editor.keystroke.add("down","td",function(t){return function(e,i){return t._tdNav(i,"down"),!0}}(this)),this.editor.keystroke.add("down","th",function(t){return function(e,i){return t._tdNav(i,"down"),!0}}(this))},i.prototype._tdNav=function(t,e){var i,n,r,o,s;return null==e&&(e="up"),r="up"===e?"prev":"next",(s="up"===e?["tbody","thead"]:["thead","tbody"])[0],s[1],n=t.parent("tr"),!((i=this["_"+r+"Row"](n)).length>0)||(o=n.find("td, th").index(t),this.editor.selection.setRangeAtEndOf(i.find("td, th").eq(o)))},i.prototype._nextRow=function(t){var e;return(e=t.next("tr")).length<1&&t.parent("thead").length>0&&(e=t.parent("thead").next("tbody").find("tr:first")),e},i.prototype._prevRow=function(t){var e;return(e=t.prev("tr")).length<1&&t.parent("tbody").length>0&&(e=t.parent("tbody").prev("thead").find("tr")),e},i.prototype.initResize=function(e){var i,n,r;return r=e.parent(".simditor-table"),(i=e.find("colgroup")).length<1&&(i=t("<colgroup/>").prependTo(e),e.find("thead tr th").each(function(e,n){return t("<col/>").appendTo(i)}),this.refreshTableWidth(e)),n=t("<div />",{class:"simditor-resize-handle",contenteditable:"false"}).appendTo(r),r.on("mousemove","td, th",function(e){var o,s,a,l,d;if(!r.hasClass("resizing"))if(s=t(e.currentTarget),e.pageX-t(e.currentTarget).offset().left<5&&s.prev().length>0&&(s=s.prev()),s.next("td, th").length<1)n.hide();else if(null!=(l=n.data("td"))&&l.is(s))n.show();else{if(a=s.parent().find("td, th").index(s),o=i.find("col").eq(a),null==(d=n.data("col"))||!d.is(o))return n.css("left",s.position().left+s.outerWidth()-5).data("td",s).data("col",o).show();n.show()}}),r.on("mouseleave",function(t){return n.hide()}),r.on("mousedown",".simditor-resize-handle",function(e){var i,n,o,s,a,l,d,u,h,p;return o=(i=t(e.currentTarget)).data("td"),n=i.data("col"),a=o.next("td, th"),s=n.next("col"),h=e.pageX,d=1*o.outerWidth(),u=1*a.outerWidth(),l=parseFloat(i.css("left")),p=o.closest("table").width(),50,t(document).on("mousemove.simditor-resize-table",function(t){var e,r,o;return e=t.pageX-h,o=u-e,(r=d+e)<50?(r=50,o=u-(e=50-d)):o<50&&(o=50,r=d+(e=u-50)),n.attr("width",r/p*100+"%"),s.attr("width",o/p*100+"%"),i.css("left",l+e)}),t(document).one("mouseup.simditor-resize-table",function(e){return t(document).off(".simditor-resize-table"),r.removeClass("resizing")}),r.addClass("resizing"),!1})},i.prototype._initShortcuts=function(){var t;return this.editor.hotkeys.add("ctrl+alt+up",(t=this,function(e){return t.editMenu.find(".menu-item[data-param=insertRowAbove]").click(),!1})),this.editor.hotkeys.add("ctrl+alt+down",function(t){return function(e){return t.editMenu.find(".menu-item[data-param=insertRowBelow]").click(),!1}}(this)),this.editor.hotkeys.add("ctrl+alt+left",function(t){return function(e){return t.editMenu.find(".menu-item[data-param=insertColLeft]").click(),!1}}(this)),this.editor.hotkeys.add("ctrl+alt+right",function(t){return function(e){return t.editMenu.find(".menu-item[data-param=insertColRight]").click(),!1}}(this))},i.prototype.decorate=function(e){var i,n,r;return e.parent(".simditor-table").length>0&&this.undecorate(e),e.wrap('<div class="simditor-table"></div>'),e.find("thead").length<1&&(r=t("<thead />"),i=e.find("tr").first(),r.append(i),this._changeCellTag(i,"th"),(n=e.find("tbody")).length>0?n.before(r):e.prepend(r)),this.initResize(e),e.parent()},i.prototype.undecorate=function(t){if(t.parent(".simditor-table").length>0)return t.parent().replaceWith(t)},i.prototype.renderMenu=function(){var e,i;return t('<div class="menu-create-table">\n</div>\n<div class="menu-edit-table">\n  <ul>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="deleteRow">\n        <span>'+this._t("deleteRow")+'</span>\n      </a>\n    </li>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="insertRowAbove">\n        <span>'+this._t("insertRowAbove")+' ( Ctrl + Alt + â†‘ )</span>\n      </a>\n    </li>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="insertRowBelow">\n        <span>'+this._t("insertRowBelow")+' ( Ctrl + Alt + â†“ )</span>\n      </a>\n    </li>\n    <li><span class="separator"></span></li>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="deleteCol">\n        <span>'+this._t("deleteColumn")+'</span>\n      </a>\n    </li>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="insertColLeft">\n        <span>'+this._t("insertColumnLeft")+' ( Ctrl + Alt + â† )</span>\n      </a>\n    </li>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="insertColRight">\n        <span>'+this._t("insertColumnRight")+' ( Ctrl + Alt + â†’ )</span>\n      </a>\n    </li>\n    <li><span class="separator"></span></li>\n    <li>\n      <a tabindex="-1" unselectable="on" class="menu-item"\n        href="javascript:;" data-param="deleteTable">\n        <span>'+this._t("deleteTable")+"</span>\n      </a>\n    </li>\n  </ul>\n</div>").appendTo(this.menuWrapper),this.createMenu=this.menuWrapper.find(".menu-create-table"),this.editMenu=this.menuWrapper.find(".menu-edit-table"),e=this.createTable(6,6).appendTo(this.createMenu),this.createMenu.on("mouseenter","td, th",(i=this,function(n){var r,o,s,a;return i.createMenu.find("td, th").removeClass("selected"),a=(o=(r=t(n.currentTarget)).parent()).find("td, th").index(r)+1,s=o.prevAll("tr").addBack(),o.parent().is("tbody")&&(s=s.add(e.find("thead tr"))),s.find("td:lt("+a+"), th:lt("+a+")").addClass("selected")})),this.createMenu.on("mouseleave",function(e){return t(e.currentTarget).find("td, th").removeClass("selected")}),this.createMenu.on("mousedown","td, th",function(i){return function(n){var r,o,s,a,l;if(i.wrapper.removeClass("menu-on"),i.editor.inputManager.focused)return a=(s=(o=t(n.currentTarget)).parent()).find("td").index(o)+1,l=s.prevAll("tr").length+1,s.parent().is("tbody")&&(l+=1),e=i.createTable(l,a,!0),r=i.editor.selection.blockNodes().last(),i.editor.util.isEmptyNode(r)?r.replaceWith(e):r.after(e),i.decorate(e),i.editor.selection.setRangeAtStartOf(e.find("th:first")),i.editor.trigger("valuechanged"),!1}}(this))},i.prototype.createTable=function(e,i,n){var r,o,s,a,l,d,u,h,p,c;for(r=t("<table/>"),a=t("<thead/>").appendTo(r),o=t("<tbody/>").appendTo(r),h=d=0,p=e;0<=p?d<p:d>p;h=0<=p?++d:--d)for((l=t("<tr/>")).appendTo(0===h?a:o),u=0,c=i;0<=c?u<c:u>c;0<=c?++u:--u)s=t(0===h?"<th/>":"<td/>").appendTo(l),n&&s.append(this.editor.util.phBr);return r},i.prototype.refreshTableWidth=function(e){var i,n;return n=e.width(),i=e.find("col"),e.find("thead tr th").each(function(e,r){return i.eq(e).attr("width",t(r).outerWidth()/n*100+"%")})},i.prototype.setActive=function(t){return i.__super__.setActive.call(this,t),t?(this.createMenu.hide(),this.editMenu.show()):(this.createMenu.show(),this.editMenu.hide())},i.prototype._changeCellTag=function(e,i){return e.find("td, th").each(function(e,n){var r;return(r=t(n)).replaceWith("<"+i+">"+r.html()+"</"+i+">")})},i.prototype.deleteRow=function(t){var e,i,n;return(i=t.parent("tr")).closest("table").find("tr").length<1?this.deleteTable(t):((e=this._nextRow(i)).length>0||(e=this._prevRow(i)),n=i.find("td, th").index(t),i.parent().is("thead")&&(e.appendTo(i.parent()),this._changeCellTag(e,"th")),i.remove(),this.editor.selection.setRangeAtEndOf(e.find("td, th").eq(n)))},i.prototype.insertRow=function(e,i){var n,r,o,s,a,l,d,u;for(null==i&&(i="after"),r=(o=e.parent("tr")).closest("table"),a=0,r.find("tr").each(function(e,i){return a=Math.max(a,t(i).find("td").length)}),l=o.find("td, th").index(e),n=t("<tr/>"),s="td","after"===i&&o.parent().is("thead")?o.parent().next("tbody").prepend(n):"before"===i&&o.parent().is("thead")?(o.before(n),o.parent().next("tbody").prepend(o),this._changeCellTag(o,"td"),s="th"):o[i](n),d=1,u=a;1<=u?d<=u:d>=u;1<=u?++d:--d)t("<"+s+"/>").append(this.editor.util.phBr).appendTo(n);return this.editor.selection.setRangeAtStartOf(n.find("td, th").eq(l))},i.prototype.deleteCol=function(e){var i,n,r,o,s,a;return a=(r=e.parent("tr")).closest("table").find("tr").length<2,s=e.siblings("td, th").length<1,a&&s?this.deleteTable(e):(o=r.find("td, th").index(e),(i=e.next("td, th")).length>0||(i=r.prev("td, th")),(n=r.closest("table")).find("col").eq(o).remove(),n.find("tr").each(function(e,i){return t(i).find("td, th").eq(o).remove()}),this.refreshTableWidth(n),this.editor.selection.setRangeAtEndOf(i))},i.prototype.insertCol=function(e,i){var n,r,o,s,a,l,d,u,h;return null==i&&(i="after"),a=e.parent("tr"),l=a.find("td, th").index(e),n=(s=e.closest("table")).find("col").eq(l),s.find("tr").each((h=this,function(e,n){var r,o;return o=t(n).parent().is("thead")?"th":"td",r=t("<"+o+"/>").append(h.editor.util.phBr),t(n).find("td, th").eq(l)[i](r)})),r=t("<col/>"),n[i](r),d=s.width(),u=Math.max(parseFloat(n.attr("width"))/2,50/d*100),n.attr("width",u+"%"),r.attr("width",u+"%"),this.refreshTableWidth(s),o="after"===i?e.next("td, th"):e.prev("td, th"),this.editor.selection.setRangeAtStartOf(o)},i.prototype.deleteTable=function(t){var e,i;if(e=(i=t.closest(".simditor-table")).next("p"),i.remove(),e.length>0)return this.editor.selection.setRangeAtStartOf(e)},i.prototype.command=function(t){var e;if((e=this.editor.selection.containerNode().closest("td, th")).length>0){if("deleteRow"===t)this.deleteRow(e);else if("insertRowAbove"===t)this.insertRow(e,"before");else if("insertRowBelow"===t)this.insertRow(e);else if("deleteCol"===t)this.deleteCol(e);else if("insertColLeft"===t)this.insertCol(e,"before");else if("insertColRight"===t)this.insertCol(e);else{if("deleteTable"!==t)return;this.deleteTable(e)}return this.editor.trigger("valuechanged")}},i}(),E.Toolbar.addButton(R),B=function(e){function i(){return i.__super__.constructor.apply(this,arguments)}return z(i,a),i.prototype.name="strikethrough",i.prototype.icon="strikethrough",i.prototype.htmlTag="strike",i.prototype.disableTag="pre",i.prototype._activeStatus=function(){var t;return t=!0===document.queryCommandState("strikethrough"),this.setActive(t),this.active},i.prototype.command=function(){return document.execCommand("strikethrough"),this.editor.util.support.oninput||this.editor.trigger("valuechanged"),t(document).trigger("selectionchange")},i}(),E.Toolbar.addButton(B),r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return z(e,a),e.prototype.name="alignment",e.prototype.icon="align-left",e.prototype.htmlTag="p, h1, h2, h3, h4, td, th",e.prototype._init=function(){return this.menu=[{name:"left",text:this._t("alignLeft"),icon:"align-left",param:"left"},{name:"center",text:this._t("alignCenter"),icon:"align-center",param:"center"},{name:"right",text:this._t("alignRight"),icon:"align-right",param:"right"}],e.__super__._init.call(this)},e.prototype.setActive=function(t,i){return null==i&&(i="left"),"left"!==i&&"center"!==i&&"right"!==i&&(i="left"),"left"===i?e.__super__.setActive.call(this,!1):e.__super__.setActive.call(this,t),this.el.removeClass("align-left align-center align-right"),t&&this.el.addClass("align-"+i),this.setIcon("align-"+i),this.menuEl.find(".menu-item").show().end().find(".menu-item-"+i).hide()},e.prototype._status=function(){return this.nodes=this.editor.selection.nodes().filter(this.htmlTag),this.nodes.length<1?(this.setDisabled(!0),this.setActive(!1)):(this.setDisabled(!1),this.setActive(!0,this.nodes.first().css("text-align")))},e.prototype.command=function(t){if("left"!==t&&"center"!==t&&"right"!==t)throw new Error("simditor alignment button: invalid align "+t);return this.nodes.css({"text-align":"left"===t?"":t}),this.editor.trigger("valuechanged"),this.editor.inputManager.throttledSelectionChanged()},e}(),E.Toolbar.addButton(r),E});
  