File manager - Edit - /home/linknsbh/m.linkat.online/includes/assets/plugins/simditor/scripts/simditor.js
Back
!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,h,u,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,e;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",(e=this,function(t){return e.reset()}))},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,h,u;return s=t(r),e.endNodes().index(s)>-1?i.push(r):s.parent().is(e.editor.body)||(h=e.endNodes().index(s.parent()))>-1?(o=h&&h>-1?e.endNodes().eq(h-1):e.endNodes().last(),u=(a=s.parent().contents()).index(s),l=a.index(o),t.merge(i,a.slice(u,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,h,u,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),h=/(https?:\/\/|www\.)[\w\-\.\?&=\/#%:,@\!\+]+/gi,o=0,a=l.length;o<a;o++){for(c=(n=l[o]).text(),u=[],d=null,s=0;null!==(d=h.exec(c));)p=c.substring(s,d.index),u.push(document.createTextNode(p)),s=h.lastIndex,f=/^(http(s)?:\/\/|\/)/.test(d[0])?d[0]:"http://"+d[0],i=t('<a href="'+f+'" rel="nofollow"></a>').text(d[0]),u.push(i[0]);u.push(document.createTextNode(c.substring(s))),n.replaceWith(t(u))}return e},n.prototype.format=function(e){var i,n,r,o,s,a,l,d,h,u;if(null==e&&(e=this.editor.body),e.is(":empty"))return e.append("<p>"+this.editor.util.phBr+"</p>"),e;for(r=0,s=(h=e.contents()).length;r<s;r++)l=h[r],this.cleanNode(l,!0);for(o=0,a=(u=e.contents()).length;o<a;o++)d=u[o],(i=t(d)).is("br")?(void 0!==n&&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,h,u,p,c,f,g,m,v,y,_,b;if((o=t(e)).length>0){if(3!==o[0].nodeType){if(h=o.is("iframe")?null:o.contents(),u=this.editor.util.isDecoratedNode(o),o.is(this._allowedTags.join(","))||u){if(o.is("a")&&(r=o.find("img")).length>0&&(o.replaceWith(r),o=r,h=null),o.is("td")&&(n=o.find(this.editor.util.blockNodes.join(","))).length>0&&(n.each(function(e,i){return t(i).contents().unwrap()}),h=o.contents()),o.is("img")&&o.hasClass("uploading")&&o.remove(),!u){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(),h=null):o.is("div, article, dl, header, footer, tr")?(o.append("<br/>"),h.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),h=null):o.is("thead, tfoot")?(o.remove(),h=null):o.is("th")?(a=t("<td/>").append(o.contents()),o.replaceWith(a)):h.first().unwrap();if(i&&null!=h&&!o.is("pre"))for(c=0,g=h.length;c<g;c++)m=h[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,h;if(d=e.attr("style")){if(e.removeAttr("style"),!((i=this._allowedStyles[e[0].tagName.toLowerCase()])&&i.length>0))return e;for(h={},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&&(h[t.trim(o[0])]=t.trim(o[1])));return Object.keys(h).length>0&&e.css(h),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,r,o,s,a,l,d,h;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((r=this,function(){return r.editor.trigger("selectionchanged")}),50),t(document).on("selectionchange.simditor"+this.editor.id,(o=this,function(t){var e;if(o.focused&&!o.editor.clipboard.pasting)return(e=function(){return o._selectionTimer&&(clearTimeout(o._selectionTimer),o._selectionTimer=null),o.editor.selection._selection.rangeCount>0?o.throttledSelectionChanged():o._selectionTimer=setTimeout(function(){if(o._selectionTimer=null,o.focused)return e()},10)})()})),this.editor.on("valuechanged",(s=this,function(){var e;if(s.lastCaretPosition=null,e=s.editor.body.children().filter(function(t,e){return s.editor.util.isBlockNode(e)}),s.focused&&0===e.length&&(s.editor.selection.save(),s.editor.formatter.format(),s.editor.selection.restore()),s.editor.body.find("hr, pre, .simditor-table").each(function(e,i){var n,r;if(((n=t(i)).parent().is("blockquote")||n.parent()[0]===s.editor.body[0])&&(r=!1,0===n.next().length&&(t("<p/>").append(s.editor.util.phBr).insertAfter(n),r=!0),0===n.prev().length&&(t("<p/>").append(s.editor.util.phBr).insertBefore(n),r=!0),r))return s.throttledValueChanged()}),s.editor.body.find("pre:empty").append(s.editor.util.phBr),!s.editor.util.support.onselectionchange&&s.focused)return s.throttledSelectionChanged()})),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",(d=this,function(t){return t.preventDefault(),d.editor.selection._selection.modify("move","backward","lineboundary"),!1})),this.editor.hotkeys.add("cmd+right",(l=this,function(t){return t.preventDefault(),l.editor.selection._selection.modify("move","forward","lineboundary"),!1})),e=this.editor.util.os.mac?"cmd+a":"ctrl+a",this.editor.hotkeys.add(e,(a=this,function(t){var e,i,n,r;if((e=a.editor.body.children()).length>0)return i=e.first().get(0),n=e.last().get(0),(r=document.createRange()).setStart(i,0),r.setEnd(n,a.editor.util.getNodeLength(n)),a.editor.selection.range(r),!1}))),i=this.editor.util.os.mac?"cmd+enter":"ctrl+enter",this.editor.hotkeys.add(i,(h=this,function(t){return h.editor.el.closest("form").find("button:submit").click(),!1}))},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,n,r,o,s,a,l,d,h;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)&&(n=this,e=function(e,i){var r;if(n.editor.selection.rangeAtEndOf(i))return r=t("<p/>").append(n.editor.util.phBr).insertAfter(i),n.editor.selection.setRangeAtStartOf(r),!0},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","*",(r=this,function(t){var e,i,n;return(i=(n=r.editor.selection.rootNodes().first()).prev()).is("hr")&&r.editor.selection.rangeAtStartOf(n)?(r.editor.selection.save(),i.remove(),r.editor.selection.restore(),!0):(e=r.editor.selection.blockNodes().last(),r.editor.util.browser.webkit&&r.editor.selection.rangeAtStartOf(e)?(r.editor.selection.save(),r.editor.formatter.cleanNode(e,!0),r.editor.selection.restore(),null):void 0)})),this.add("enter","li",(o=this,function(e,i){var n,r,s,a;if((n=i.clone()).find("ul, ol").remove(),o.editor.util.isEmptyNode(n)&&i.is(o.editor.selection.blockNodes().last())){if(r=i.parent(),i.next("li").length>0){if(!o.editor.util.isEmptyNode(i))return;r.parent("li").length>0?(s=t("<li/>").append(o.editor.util.phBr).insertAfter(r.parent("li")),a=t("<"+r[0].tagName+"/>").append(i.nextAll("li")),s.append(a)):(s=t("<p/>").append(o.editor.util.phBr).insertAfter(r),a=t("<"+r[0].tagName+"/>").append(i.nextAll("li")),s.after(a))}else r.parent("li").length>0?(s=t("<li/>").insertAfter(r.parent("li")),i.contents().length>0?s.append(i.contents()):s.append(o.editor.util.phBr)):(s=t("<p/>").append(o.editor.util.phBr).insertAfter(r),i.children("ul, ol").length>0&&s.after(i.children("ul, ol")));return i.prev("li").length?i.remove():r.remove(),o.editor.selection.setRangeAtStartOf(s),!0}})),this.add("enter","pre",(s=this,function(e,i){var n,r,o;return e.preventDefault(),e.shiftKey?(n=t("<p/>").append(s.editor.util.phBr).insertAfter(i),s.editor.selection.setRangeAtStartOf(n),!0):(r=null,(o=s.editor.selection.range()).deleteContents(),!s.editor.util.browser.msie&&s.editor.selection.rangeAtEndOf(i)?(r=document.createTextNode("\n\n"),o.insertNode(r),o.setEnd(r,1)):(r=document.createTextNode("\n"),o.insertNode(r),o.setStartAfter(r)),o.collapse(!1),s.editor.selection.range(o),!0)})),this.add("enter","blockquote",(a=this,function(t,e){var i,n;if((i=a.editor.selection.blockNodes().last()).is("p")&&!i.next().length&&a.editor.util.isEmptyNode(i))return e.after(i),n=document.createRange(),a.editor.selection.setRangeAtStartOf(i,n),!0})),this.add("backspace","li",(l=this,function(e,i){var n,r,o,s,a,d,h,u,p;return r=i.children("ul, ol"),a=i.prev("li"),r.length>0&&a.length>0&&(p="",d=null,i.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)))}),h=l.editor.util.browser.firefox&&!d.next("br").length,d&&1===p.length&&h?(n=t(l.editor.util.phBr).insertAfter(d),d.remove(),l.editor.selection.setRangeBefore(n),!0):!(p.length>0||(u=document.createRange(),(s=a.children("ul, ol")).length>0?(o=t("<li/>").append(l.editor.util.phBr).appendTo(s),s.append(r.children("li")),i.remove(),l.editor.selection.setRangeAtEndOf(o,u)):(l.editor.selection.setRangeAtEndOf(a,u),a.append(r),i.remove(),l.editor.selection.range(u)),0)))})),this.add("backspace","pre",(d=this,function(e,i){var n,r,o;if(d.editor.selection.rangeAtStartOf(i))return r=i.html().replace("\n","<br/>")||d.editor.util.phBr,n=t("<p/>").append(r).insertAfter(i),i.remove(),o=document.createRange(),d.editor.selection.setRangeAtStartOf(n,o),!0})),this.add("backspace","blockquote",(h=this,function(t,e){var i,n;if(h.editor.selection.rangeAtStartOf(e))return i=e.children().first().unwrap(),n=document.createRange(),h.editor.selection.setRangeAtStartOf(i,n),!0}))},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,n,r,o,s,a,l;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,(n=this,function(t){return t.preventDefault(),n.redo(),!1})),this.throttledPushState=this.editor.util.throttle((r=this,function(){return r._pushUndoState()}),2e3),this.editor.on("valuechanged",(o=this,function(t,e){if("undo"!==e&&"redo"!==e)return o.throttledPushState()})),this.editor.on("selectionchanged",(s=this,function(t){return s.resetCaretPosition(),s.update()})),this.editor.on("focus",(a=this,function(t){if(0===a._stack.length)return a._pushUndoState()})),this.editor.on("blur",(l=this,function(t){return l.resetCaretPosition()}))},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,h,u,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!=(h=g.match(/edge\/(\d+(\.\d+)?)/i))?h[1]:void 0)}:o?{webkit:!0,chrome:!0,version:1*(null!=(u=g.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i))?u[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,h,u;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,u=r.length;0<=u?d<=u:d>=u;a=0<=u?++d:--d)l[a]=r.charCodeAt(a);return h=t.split(",")[0].split(":")[1].split(";")[0],s?new Blob([o?l:i],{type:h}):((n=new e).append(i),n.getBlob(h))},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,o,s,a,l,d;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,(o=this,function(t){return o.list.find(".menu-on").removeClass(".menu-on")})),!this.opts.toolbarHidden&&this.opts.toolbarFloat&&(this.wrapper.css("top",this.opts.toolbarFloatOffset),n=0,a=this,i=function(){return a.wrapper.css("position","static"),a.wrapper.width("auto"),a.editor.util.reflow(a.wrapper),a.wrapper.width(a.wrapper.outerWidth()),a.wrapper.css("left",a.editor.util.os.mobile?a.wrapper.position().left:a.wrapper.offset().left),a.wrapper.css("position",""),n=a.wrapper.outerHeight(),a.editor.placeholderEl.css("top",n),!0},e=null,t(window).on("resize.simditor-"+this.editor.id,function(t){return e=i()}),t(window).on("scroll.simditor-"+this.editor.id,(s=this,function(r){var o,a,l;if(s.wrapper.is(":visible"))if(o=(l=s.editor.wrapper.offset().top)+s.editor.wrapper.outerHeight()-80,(a=t(document).scrollTop()+s.opts.toolbarFloatOffset)<=l||a>=o){if(s.editor.wrapper.removeClass("toolbar-floating").css("padding-top",""),s.editor.util.os.mobile)return s.wrapper.css("top",s.opts.toolbarFloatOffset)}else if(e||(e=i()),s.editor.wrapper.addClass("toolbar-floating").css("padding-top",n),s.editor.util.os.mobile)return s.wrapper.css("top",a-l+s.opts.toolbarFloatOffset)}))),this.editor.on("destroy",(l=this,function(){return l.buttons.length=0})),t(document).on("mousedown.simditor-"+this.editor.id,(d=this,function(t){return d.list.find("li.menu-on").removeClass("menu-on")}))},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,h,u;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(),u=i.parent()[0].tagName,(n=s.children("ul, ol")).length>0?n.append(i):t("<"+u+"/>").append(i).appendTo(s),this.editor.selection.restore()}else if(i.is("p, h1, h2, h3, h4"))h=parseInt(i.css("margin-left"))||0,h=(Math.round(h/this.opts.indentWidth)+1)*this.opts.indentWidth,i.css("margin-left",h);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,h,u;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(u)}else if(i.is("li"))r=(n=i.parent()).parent("li"),this.editor.selection.save(),r.length<1?((u=document.createRange()).setStartBefore(n[0]),u.setEndBefore(i[0]),n.before(u.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"))h=parseInt(i.css("margin-left"))||0,h=Math.max(Math.round(h/this.opts.indentWidth)-1,0)*this.opts.indentWidth,i.css("margin-left",0===h?"":h);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,h,u,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,h=m.length;a<h;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,u=(w=(e=t("<div/>").text(e)).contents()).length;l<u;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,l,d;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,(l=this,function(){return l.sync()})),r.on("reset.simditor-"+this.id,(a=this,function(){return a.setValue("")}))),this.on("initialized",(d=this,function(){if(d.opts.placeholder&&d.on("valuechanged",function(){return d._placeholder()}),d.setValue(d.textarea.val().trim()||""),d.textarea.attr("autofocus"))return d.focus()})),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){i=this.opts.params,n=[];for(e in i)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,s,a,l,d;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",(s=this,function(e){var i,n,r;return e.preventDefault(),i=t(e.currentTarget),s.wrapper.removeClass("menu-on"),n=s.needFocus&&!s.editor.inputManager.focused,!i.hasClass("disabled")&&!n&&(s.editor.toolbar.wrapper.removeClass("menu-on"),r=i.data("param"),s.command(r),!1)})),this.wrapper.on("mousedown","a.menu-item",function(t){return!1}),this.editor.on("blur",(a=this,function(){if(a.editor.body.is(":visible")&&a.editor.body.is("[contenteditable]")&&!a.editor.clipboard.pasting)return a.setActive(!1),a.setDisabled(!1)})),null!=this.shortcut&&this.editor.hotkeys.add(this.shortcut,(l=this,function(t){return l.el.mousedown(),!1})),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",(d=this,function(t){if(d.editor.inputManager.focused)return d._status()}))},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,i;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",(i=this,function(t){return i.el.removeClass("hover")}))},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),u=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(u),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,o;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((o=this,function(e,r){var s;if((s=t(r)).parent().is(o.editor.body))return s.is(o.htmlTag)?(i(),s.children().unwrap()):s.is(o.disableTag)||o.editor.util.isDecoratedNode(s)?i():n.push(r)})),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,n;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",(n=this,function(e,i){return i.find("pre").each(function(e,i){return n.undecorate(t(i))})}))},i.prototype.render=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.render.apply(this,t),this.popover=new h({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,s;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((s=this,function(e,o){var a,l;return(a=t(o)).is(s.htmlTag)?(i(),l=t("<p/>").append(a.html().replace("\n","<br/>")).replaceAll(a),r.push(l[0])):a.is(s.disableTag)||s.editor.util.isDecoratedNode(a)||a.is("blockquote")?i():n.push(o)})),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}(),h=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,s;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",(s=this,function(t){if(s.active)return s.refresh()}))},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,n,r,o,s;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",(n=this,function(t){var e;if(13!==t.which)return e=n.urlEl.val(),!/https?:\/\/|^\//gi.test(e)&&e&&(e="http://"+e),n.target.attr("href",e),n.editor.inputManager.throttledValueChanged()})),t([this.urlEl[0],this.textEl[0]]).on("keydown",(r=this,function(e){var i;if(13===e.which||27===e.which||!e.shiftKey&&9===e.which&&t(e.target).hasClass("link-url"))return e.preventDefault(),i=document.createRange(),r.editor.selection.setRangeAfter(r.target,i),r.hide(),r.editor.inputManager.throttledValueChanged()})),this.unlinkEl.on("click",(o=this,function(t){var e,i;return i=document.createTextNode(o.target.text()),o.target.replaceWith(i),o.hide(),e=document.createRange(),o.editor.selection.setRangeAfter(i,e),o.editor.inputManager.throttledValueChanged()})),this.selectTarget.on("change",(s=this,function(t){return s.target.attr("target",s.selectTarget.val()),s.editor.inputManager.throttledValueChanged()}))},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,a,l;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",(a=this,function(){var e,i,n;if(null!=(n=a.editor.selection.range()))return 1===(e=t(n.cloneContents()).contents()).length&&e.is("img:not([data-non-image])")?(i=t(n.startContainer).contents().eq(n.startOffset),a.popover.show(i)):a.popover.hide()})),this.editor.on("valuechanged.image",(l=this,function(){var e;if((e=l.editor.wrapper.find(".simditor-image-loading")).length>0)return e.each(function(e,i){var n,r,o;if(!((n=(r=t(i)).data("img"))&&n.parent().length>0)&&(r.remove(),n&&(o=n.data("file"))&&(l.editor.uploader.cancel(o),l.editor.body.find("img.uploading").length<1)))return l.editor.uploader.trigger("uploadready",[o])})})),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,s,a,l,d;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]",(s=this,function(t){return s.editor.inputManager.focused?(s.editor.uploader.upload(i,{inline:!0}),n()):(s.editor.one("focus",function(t){return s.editor.uploader.upload(i,{inline:!0}),n()}),s.editor.focus()),s.wrapper.removeClass("menu-on")})),this.editor.uploader.on("beforeupload",(a=this,function(e,i){var n;if(i.inline)return i.img?n=t(i.img):(n=a.createImage(i.name),i.img=n),n.addClass("uploading"),n.data("file",i),a.editor.uploader.readImageFile(i.obj,function(t){var e;if(n.hasClass("uploading"))return e=t?t.src:a.defaultImage,a.loadImage(n,e,function(){if(a.popover.active)return a.popover.refresh(),a.popover.srcEl.val(a._t("uploading")).prop("disabled",!0)})})})),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",(l=this,function(e,i,n){var r,o,s;if(i.inline&&(r=i.img).hasClass("uploading")&&r.parent().length>0){if("object"!=typeof n)try{n=t.parseJSON(n)}catch(t){n={success:!1}}return!1===n.success?(s=n.msg||l._t("uploadFailed"),alert(s),o=l.defaultImage):o=n.file_path,l.loadImage(r,o,function(){var t;if(r.removeData("file"),r.removeClass("uploading").removeClass("loading"),(t=r.data("mask"))&&t.remove(),r.removeData("mask"),l.editor.trigger("valuechanged"),l.editor.body.find("img.uploading").length<1)return l.editor.uploader.trigger("uploadready",[i,n])}),l.popover.active?(l.popover.srcEl.prop("disabled",!1),l.popover.srcEl.val(n.file_path)):void 0}})),this.editor.uploader.on("uploaderror",(d=this,function(e,i,n){var r,o,s;if(i.inline&&"abort"!==n.statusText){if(n.responseText){try{s=t.parseJSON(n.responseText),o=s.msg}catch(t){o=d._t("uploadError")}alert(o)}if((r=i.img).hasClass("uploading")&&r.parent().length>0)return d.loadImage(r,d.defaultImage,function(){var t;return r.removeData("file"),r.removeClass("uploading").removeClass("loading"),(t=r.data("mask"))&&t.remove(),r.removeData("mask")}),d.popover.active&&(d.popover.srcEl.prop("disabled",!1),d.popover.srcEl.val(d.defaultImage)),d.editor.trigger("valuechanged"),d.editor.body.find("img.uploading").length<1?d.editor.uploader.trigger("uploadready",[i,s]):void 0}}));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,l;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=(l=this,function(){var a,d;if(e.hasClass("loading")||e.hasClass("uploading"))return d=o.width,a=o.height,e.attr({src:i,width:d,height:a,"data-image-size":d+","+a}).removeClass("loading"),e.hasClass("uploading")?(l.editor.util.reflow(l.editor.body),s()):(r.remove(),e.removeData("mask")),t.isFunction(n)?n(o):void 0}),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,n,r,o,s,a,l,d,h;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",(n=this,function(t){return n._loadImage(n.srcEl.val())})),this.el.find(".image-size").on("blur",(r=this,function(e){return r._resizeImg(t(e.currentTarget)),r.el.data("popover").refresh()})),this.el.find(".image-size").on("keyup",(o=this,function(e){var i;if(i=t(e.currentTarget),13!==e.which&&27!==e.which&&9!==e.which)return o._resizeImg(i,!0)})),this.el.find(".image-size").on("keydown",(s=this,function(e){var i,n,r;return n=t(e.currentTarget),13===e.which||27===e.which?(e.preventDefault(),13===e.which?s._resizeImg(n):s._restoreImg(),i=s.target,s.hide(),r=document.createRange(),s.button.editor.selection.setRangeAfter(i,r)):9===e.which?s.el.data("popover").refresh():void 0})),this.altEl.on("keydown",(a=this,function(t){var e;if(13===t.which)return t.preventDefault(),e=document.createRange(),a.button.editor.selection.setRangeAfter(a.target,e),a.hide()})),this.altEl.on("keyup",(l=this,function(t){if(13!==t.which&&27!==t.which&&9!==t.which)return l.alt=l.altEl.val(),l.target.attr("alt",l.alt)})),this.el.find(".btn-restore").on("click",(d=this,function(t){return d._restoreImg(),d.el.data("popover").refresh()})),this.editor.on("valuechanged",(h=this,function(t){if(h.active)return h.refresh()})),this._initUploader()},i.prototype._initUploader=function(){var e,i,n,r;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]",(r=this,function(t){return r.editor.uploader.upload(r.input,{inline:!0,img:r.target}),i()}));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,n,r,o,s,a,l,d;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",(n=this,function(e,i){return i.find("table").each(function(e,i){return n.undecorate(t(i))})})),this.editor.on("selectionchanged.table",(r=this,function(t){var e,i;if(r.editor.body.find(".simditor-table td, .simditor-table th").removeClass("active"),i=r.editor.selection.range())return e=r.editor.selection.containerNode(),i.collapsed&&e.is(".simditor-table")&&(e=r.editor.selection.rangeAtStartOf(e)?e.find("th:first"):e.find("td:last"),r.editor.selection.setRangeAtEndOf(e)),e.closest("td, th",r.editor.body).addClass("active")})),this.editor.on("blur.table",(o=this,function(t){return o.editor.body.find(".simditor-table td, .simditor-table th").removeClass("active")})),this.editor.keystroke.add("up","td",(s=this,function(t,e){return s._tdNav(e,"up"),!0})),this.editor.keystroke.add("up","th",(a=this,function(t,e){return a._tdNav(e,"up"),!0})),this.editor.keystroke.add("down","td",(l=this,function(t,e){return l._tdNav(e,"down"),!0})),this.editor.keystroke.add("down","th",(d=this,function(t,e){return d._tdNav(e,"down"),!0}))},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,h,u,p;return o=(i=t(e.currentTarget)).data("td"),n=i.data("col"),a=o.next("td, th"),s=n.next("col"),u=e.pageX,d=1*o.outerWidth(),h=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-u,o=h-e,(r=d+e)<50?(r=50,o=h-(e=50-d)):o<50&&(o=50,r=d+(e=h-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,e,i,n;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",(e=this,function(t){return e.editMenu.find(".menu-item[data-param=insertRowBelow]").click(),!1})),this.editor.hotkeys.add("ctrl+alt+left",(i=this,function(t){return i.editMenu.find(".menu-item[data-param=insertColLeft]").click(),!1})),this.editor.hotkeys.add("ctrl+alt+right",(n=this,function(t){return n.editMenu.find(".menu-item[data-param=insertColRight]").click(),!1}))},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,n;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",(n=this,function(i){var r,o,s,a,l;if(n.wrapper.removeClass("menu-on"),n.editor.inputManager.focused)return a=(s=(o=t(i.currentTarget)).parent()).find("td").index(o)+1,l=s.prevAll("tr").length+1,s.parent().is("tbody")&&(l+=1),e=n.createTable(l,a,!0),r=n.editor.selection.blockNodes().last(),n.editor.util.isEmptyNode(r)?r.replaceWith(e):r.after(e),n.decorate(e),n.editor.selection.setRangeAtStartOf(e.find("th:first")),n.editor.trigger("valuechanged"),!1}))},i.prototype.createTable=function(e,i,n){var r,o,s,a,l,d,h,u,p,c;for(r=t("<table/>"),a=t("<thead/>").appendTo(r),o=t("<tbody/>").appendTo(r),u=d=0,p=e;0<=p?d<p:d>p;u=0<=p?++d:--d)for((l=t("<tr/>")).appendTo(0===u?a:o),h=0,c=i;0<=c?h<c:h>c;0<=c?++h:--h)s=t(0===u?"<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,h;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,h=a;1<=h?d<=h:d>=h;1<=h?++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,h,u;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((u=this,function(e,n){var r,o;return o=t(n).parent().is("thead")?"th":"td",r=t("<"+o+"/>").append(u.editor.util.phBr),t(n).find("td, th").eq(l)[i](r)})),r=t("<col/>"),n[i](r),d=s.width(),h=Math.max(parseFloat(n.attr("width"))/2,50/d*100),n.attr("width",h+"%"),r.attr("width",h+"%"),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}),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,h,u,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,e;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",(e=this,function(t){return e.reset()}))},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,h,u;return s=t(r),e.endNodes().index(s)>-1?i.push(r):s.parent().is(e.editor.body)||(h=e.endNodes().index(s.parent()))>-1?(o=h&&h>-1?e.endNodes().eq(h-1):e.endNodes().last(),u=(a=s.parent().contents()).index(s),l=a.index(o),t.merge(i,a.slice(u,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,h,u,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),h=/(https?:\/\/|www\.)[\w\-\.\?&=\/#%:,@\!\+]+/gi,o=0,a=l.length;o<a;o++){for(c=(n=l[o]).text(),u=[],d=null,s=0;null!==(d=h.exec(c));)p=c.substring(s,d.index),u.push(document.createTextNode(p)),s=h.lastIndex,f=/^(http(s)?:\/\/|\/)/.test(d[0])?d[0]:"http://"+d[0],i=t('<a href="'+f+'" rel="nofollow"></a>').text(d[0]),u.push(i[0]);u.push(document.createTextNode(c.substring(s))),n.replaceWith(t(u))}return e},n.prototype.format=function(e){var i,n,r,o,s,a,l,d,h,u;if(null==e&&(e=this.editor.body),e.is(":empty"))return e.append("<p>"+this.editor.util.phBr+"</p>"),e;for(r=0,s=(h=e.contents()).length;r<s;r++)l=h[r],this.cleanNode(l,!0);for(o=0,a=(u=e.contents()).length;o<a;o++)d=u[o],(i=t(d)).is("br")?(void 0!==n&&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,h,u,p,c,f,g,m,v,y,_,b;if((o=t(e)).length>0){if(3!==o[0].nodeType){if(h=o.is("iframe")?null:o.contents(),u=this.editor.util.isDecoratedNode(o),o.is(this._allowedTags.join(","))||u){if(o.is("a")&&(r=o.find("img")).length>0&&(o.replaceWith(r),o=r,h=null),o.is("td")&&(n=o.find(this.editor.util.blockNodes.join(","))).length>0&&(n.each(function(e,i){return t(i).contents().unwrap()}),h=o.contents()),o.is("img")&&o.hasClass("uploading")&&o.remove(),!u){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(),h=null):o.is("div, article, dl, header, footer, tr")?(o.append("<br/>"),h.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),h=null):o.is("thead, tfoot")?(o.remove(),h=null):o.is("th")?(a=t("<td/>").append(o.contents()),o.replaceWith(a)):h.first().unwrap();if(i&&null!=h&&!o.is("pre"))for(c=0,g=h.length;c<g;c++)m=h[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,h;if(d=e.attr("style")){if(e.removeAttr("style"),!((i=this._allowedStyles[e[0].tagName.toLowerCase()])&&i.length>0))return e;for(h={},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&&(h[t.trim(o[0])]=t.trim(o[1])));return Object.keys(h).length>0&&e.css(h),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,r,o,s,a,l,d,h;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((r=this,function(){return r.editor.trigger("selectionchanged")}),50),t(document).on("selectionchange.simditor"+this.editor.id,(o=this,function(t){var e;if(o.focused&&!o.editor.clipboard.pasting)return(e=function(){return o._selectionTimer&&(clearTimeout(o._selectionTimer),o._selectionTimer=null),o.editor.selection._selection.rangeCount>0?o.throttledSelectionChanged():o._selectionTimer=setTimeout(function(){if(o._selectionTimer=null,o.focused)return e()},10)})()})),this.editor.on("valuechanged",(s=this,function(){var e;if(s.lastCaretPosition=null,e=s.editor.body.children().filter(function(t,e){return s.editor.util.isBlockNode(e)}),s.focused&&0===e.length&&(s.editor.selection.save(),s.editor.formatter.format(),s.editor.selection.restore()),s.editor.body.find("hr, pre, .simditor-table").each(function(e,i){var n,r;if(((n=t(i)).parent().is("blockquote")||n.parent()[0]===s.editor.body[0])&&(r=!1,0===n.next().length&&(t("<p/>").append(s.editor.util.phBr).insertAfter(n),r=!0),0===n.prev().length&&(t("<p/>").append(s.editor.util.phBr).insertBefore(n),r=!0),r))return s.throttledValueChanged()}),s.editor.body.find("pre:empty").append(s.editor.util.phBr),!s.editor.util.support.onselectionchange&&s.focused)return s.throttledSelectionChanged()})),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",(d=this,function(t){return t.preventDefault(),d.editor.selection._selection.modify("move","backward","lineboundary"),!1})),this.editor.hotkeys.add("cmd+right",(l=this,function(t){return t.preventDefault(),l.editor.selection._selection.modify("move","forward","lineboundary"),!1})),e=this.editor.util.os.mac?"cmd+a":"ctrl+a",this.editor.hotkeys.add(e,(a=this,function(t){var e,i,n,r;if((e=a.editor.body.children()).length>0)return i=e.first().get(0),n=e.last().get(0),(r=document.createRange()).setStart(i,0),r.setEnd(n,a.editor.util.getNodeLength(n)),a.editor.selection.range(r),!1}))),i=this.editor.util.os.mac?"cmd+enter":"ctrl+enter",this.editor.hotkeys.add(i,(h=this,function(t){return h.editor.el.closest("form").find("button:submit").click(),!1}))},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,n,r,o,s,a,l,d,h;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)&&(n=this,e=function(e,i){var r;if(n.editor.selection.rangeAtEndOf(i))return r=t("<p/>").append(n.editor.util.phBr).insertAfter(i),n.editor.selection.setRangeAtStartOf(r),!0},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","*",(r=this,function(t){var e,i,n;return(i=(n=r.editor.selection.rootNodes().first()).prev()).is("hr")&&r.editor.selection.rangeAtStartOf(n)?(r.editor.selection.save(),i.remove(),r.editor.selection.restore(),!0):(e=r.editor.selection.blockNodes().last(),r.editor.util.browser.webkit&&r.editor.selection.rangeAtStartOf(e)?(r.editor.selection.save(),r.editor.formatter.cleanNode(e,!0),r.editor.selection.restore(),null):void 0)})),this.add("enter","li",(o=this,function(e,i){var n,r,s,a;if((n=i.clone()).find("ul, ol").remove(),o.editor.util.isEmptyNode(n)&&i.is(o.editor.selection.blockNodes().last())){if(r=i.parent(),i.next("li").length>0){if(!o.editor.util.isEmptyNode(i))return;r.parent("li").length>0?(s=t("<li/>").append(o.editor.util.phBr).insertAfter(r.parent("li")),a=t("<"+r[0].tagName+"/>").append(i.nextAll("li")),s.append(a)):(s=t("<p/>").append(o.editor.util.phBr).insertAfter(r),a=t("<"+r[0].tagName+"/>").append(i.nextAll("li")),s.after(a))}else r.parent("li").length>0?(s=t("<li/>").insertAfter(r.parent("li")),i.contents().length>0?s.append(i.contents()):s.append(o.editor.util.phBr)):(s=t("<p/>").append(o.editor.util.phBr).insertAfter(r),i.children("ul, ol").length>0&&s.after(i.children("ul, ol")));return i.prev("li").length?i.remove():r.remove(),o.editor.selection.setRangeAtStartOf(s),!0}})),this.add("enter","pre",(s=this,function(e,i){var n,r,o;return e.preventDefault(),e.shiftKey?(n=t("<p/>").append(s.editor.util.phBr).insertAfter(i),s.editor.selection.setRangeAtStartOf(n),!0):(r=null,(o=s.editor.selection.range()).deleteContents(),!s.editor.util.browser.msie&&s.editor.selection.rangeAtEndOf(i)?(r=document.createTextNode("\n\n"),o.insertNode(r),o.setEnd(r,1)):(r=document.createTextNode("\n"),o.insertNode(r),o.setStartAfter(r)),o.collapse(!1),s.editor.selection.range(o),!0)})),this.add("enter","blockquote",(a=this,function(t,e){var i,n;if((i=a.editor.selection.blockNodes().last()).is("p")&&!i.next().length&&a.editor.util.isEmptyNode(i))return e.after(i),n=document.createRange(),a.editor.selection.setRangeAtStartOf(i,n),!0})),this.add("backspace","li",(l=this,function(e,i){var n,r,o,s,a,d,h,u,p;return r=i.children("ul, ol"),a=i.prev("li"),r.length>0&&a.length>0&&(p="",d=null,i.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)))}),h=l.editor.util.browser.firefox&&!d.next("br").length,d&&1===p.length&&h?(n=t(l.editor.util.phBr).insertAfter(d),d.remove(),l.editor.selection.setRangeBefore(n),!0):!(p.length>0||(u=document.createRange(),(s=a.children("ul, ol")).length>0?(o=t("<li/>").append(l.editor.util.phBr).appendTo(s),s.append(r.children("li")),i.remove(),l.editor.selection.setRangeAtEndOf(o,u)):(l.editor.selection.setRangeAtEndOf(a,u),a.append(r),i.remove(),l.editor.selection.range(u)),0)))})),this.add("backspace","pre",(d=this,function(e,i){var n,r,o;if(d.editor.selection.rangeAtStartOf(i))return r=i.html().replace("\n","<br/>")||d.editor.util.phBr,n=t("<p/>").append(r).insertAfter(i),i.remove(),o=document.createRange(),d.editor.selection.setRangeAtStartOf(n,o),!0})),this.add("backspace","blockquote",(h=this,function(t,e){var i,n;if(h.editor.selection.rangeAtStartOf(e))return i=e.children().first().unwrap(),n=document.createRange(),h.editor.selection.setRangeAtStartOf(i,n),!0}))},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,n,r,o,s,a,l;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,(n=this,function(t){return t.preventDefault(),n.redo(),!1})),this.throttledPushState=this.editor.util.throttle((r=this,function(){return r._pushUndoState()}),2e3),this.editor.on("valuechanged",(o=this,function(t,e){if("undo"!==e&&"redo"!==e)return o.throttledPushState()})),this.editor.on("selectionchanged",(s=this,function(t){return s.resetCaretPosition(),s.update()})),this.editor.on("focus",(a=this,function(t){if(0===a._stack.length)return a._pushUndoState()})),this.editor.on("blur",(l=this,function(t){return l.resetCaretPosition()}))},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,h,u,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!=(h=g.match(/edge\/(\d+(\.\d+)?)/i))?h[1]:void 0)}:o?{webkit:!0,chrome:!0,version:1*(null!=(u=g.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i))?u[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,h,u;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,u=r.length;0<=u?d<=u:d>=u;a=0<=u?++d:--d)l[a]=r.charCodeAt(a);return h=t.split(",")[0].split(":")[1].split(";")[0],s?new Blob([o?l:i],{type:h}):((n=new e).append(i),n.getBlob(h))},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,o,s,a,l,d;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,(o=this,function(t){return o.list.find(".menu-on").removeClass(".menu-on")})),!this.opts.toolbarHidden&&this.opts.toolbarFloat&&(this.wrapper.css("top",this.opts.toolbarFloatOffset),n=0,a=this,i=function(){return a.wrapper.css("position","static"),a.wrapper.width("auto"),a.editor.util.reflow(a.wrapper),a.wrapper.width(a.wrapper.outerWidth()),a.wrapper.css("left",a.editor.util.os.mobile?a.wrapper.position().left:a.wrapper.offset().left),a.wrapper.css("position",""),n=a.wrapper.outerHeight(),a.editor.placeholderEl.css("top",n),!0},e=null,t(window).on("resize.simditor-"+this.editor.id,function(t){return e=i()}),t(window).on("scroll.simditor-"+this.editor.id,(s=this,function(r){var o,a,l;if(s.wrapper.is(":visible"))if(o=(l=s.editor.wrapper.offset().top)+s.editor.wrapper.outerHeight()-80,(a=t(document).scrollTop()+s.opts.toolbarFloatOffset)<=l||a>=o){if(s.editor.wrapper.removeClass("toolbar-floating").css("padding-top",""),s.editor.util.os.mobile)return s.wrapper.css("top",s.opts.toolbarFloatOffset)}else if(e||(e=i()),s.editor.wrapper.addClass("toolbar-floating").css("padding-top",n),s.editor.util.os.mobile)return s.wrapper.css("top",a-l+s.opts.toolbarFloatOffset)}))),this.editor.on("destroy",(l=this,function(){return l.buttons.length=0})),t(document).on("mousedown.simditor-"+this.editor.id,(d=this,function(t){return d.list.find("li.menu-on").removeClass("menu-on")}))},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,h,u;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(),u=i.parent()[0].tagName,(n=s.children("ul, ol")).length>0?n.append(i):t("<"+u+"/>").append(i).appendTo(s),this.editor.selection.restore()}else if(i.is("p, h1, h2, h3, h4"))h=parseInt(i.css("margin-left"))||0,h=(Math.round(h/this.opts.indentWidth)+1)*this.opts.indentWidth,i.css("margin-left",h);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,h,u;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(u)}else if(i.is("li"))r=(n=i.parent()).parent("li"),this.editor.selection.save(),r.length<1?((u=document.createRange()).setStartBefore(n[0]),u.setEndBefore(i[0]),n.before(u.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"))h=parseInt(i.css("margin-left"))||0,h=Math.max(Math.round(h/this.opts.indentWidth)-1,0)*this.opts.indentWidth,i.css("margin-left",0===h?"":h);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,h,u,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,h=m.length;a<h;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,u=(w=(e=t("<div/>").text(e)).contents()).length;l<u;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,l,d;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,(l=this,function(){return l.sync()})),r.on("reset.simditor-"+this.id,(a=this,function(){return a.setValue("")}))),this.on("initialized",(d=this,function(){if(d.opts.placeholder&&d.on("valuechanged",function(){return d._placeholder()}),d.setValue(d.textarea.val().trim()||""),d.textarea.attr("autofocus"))return d.focus()})),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){i=this.opts.params,n=[];for(e in i)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,s,a,l,d;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",(s=this,function(e){var i,n,r;return e.preventDefault(),i=t(e.currentTarget),s.wrapper.removeClass("menu-on"),n=s.needFocus&&!s.editor.inputManager.focused,!i.hasClass("disabled")&&!n&&(s.editor.toolbar.wrapper.removeClass("menu-on"),r=i.data("param"),s.command(r),!1)})),this.wrapper.on("mousedown","a.menu-item",function(t){return!1}),this.editor.on("blur",(a=this,function(){if(a.editor.body.is(":visible")&&a.editor.body.is("[contenteditable]")&&!a.editor.clipboard.pasting)return a.setActive(!1),a.setDisabled(!1)})),null!=this.shortcut&&this.editor.hotkeys.add(this.shortcut,(l=this,function(t){return l.el.mousedown(),!1})),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",(d=this,function(t){if(d.editor.inputManager.focused)return d._status()}))},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,i;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",(i=this,function(t){return i.el.removeClass("hover")}))},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),u=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(u),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,o;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((o=this,function(e,r){var s;if((s=t(r)).parent().is(o.editor.body))return s.is(o.htmlTag)?(i(),s.children().unwrap()):s.is(o.disableTag)||o.editor.util.isDecoratedNode(s)?i():n.push(r)})),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,n;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",(n=this,function(e,i){return i.find("pre").each(function(e,i){return n.undecorate(t(i))})}))},i.prototype.render=function(){var t;return t=1<=arguments.length?q.call(arguments,0):[],i.__super__.render.apply(this,t),this.popover=new h({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,s;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((s=this,function(e,o){var a,l;return(a=t(o)).is(s.htmlTag)?(i(),l=t("<p/>").append(a.html().replace("\n","<br/>")).replaceAll(a),r.push(l[0])):a.is(s.disableTag)||s.editor.util.isDecoratedNode(a)||a.is("blockquote")?i():n.push(o)})),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}(),h=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,s;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",(s=this,function(t){if(s.active)return s.refresh()}))},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,n,r,o,s;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",(n=this,function(t){var e;if(13!==t.which)return e=n.urlEl.val(),!/https?:\/\/|^\//gi.test(e)&&e&&(e="http://"+e),n.target.attr("href",e),n.editor.inputManager.throttledValueChanged()})),t([this.urlEl[0],this.textEl[0]]).on("keydown",(r=this,function(e){var i;if(13===e.which||27===e.which||!e.shiftKey&&9===e.which&&t(e.target).hasClass("link-url"))return e.preventDefault(),i=document.createRange(),r.editor.selection.setRangeAfter(r.target,i),r.hide(),r.editor.inputManager.throttledValueChanged()})),this.unlinkEl.on("click",(o=this,function(t){var e,i;return i=document.createTextNode(o.target.text()),o.target.replaceWith(i),o.hide(),e=document.createRange(),o.editor.selection.setRangeAfter(i,e),o.editor.inputManager.throttledValueChanged()})),this.selectTarget.on("change",(s=this,function(t){return s.target.attr("target",s.selectTarget.val()),s.editor.inputManager.throttledValueChanged()}))},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,a,l;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",(a=this,function(){var e,i,n;if(null!=(n=a.editor.selection.range()))return 1===(e=t(n.cloneContents()).contents()).length&&e.is("img:not([data-non-image])")?(i=t(n.startContainer).contents().eq(n.startOffset),a.popover.show(i)):a.popover.hide()})),this.editor.on("valuechanged.image",(l=this,function(){var e;if((e=l.editor.wrapper.find(".simditor-image-loading")).length>0)return e.each(function(e,i){var n,r,o;if(!((n=(r=t(i)).data("img"))&&n.parent().length>0)&&(r.remove(),n&&(o=n.data("file"))&&(l.editor.uploader.cancel(o),l.editor.body.find("img.uploading").length<1)))return l.editor.uploader.trigger("uploadready",[o])})})),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,s,a,l,d;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]",(s=this,function(t){return s.editor.inputManager.focused?(s.editor.uploader.upload(i,{inline:!0}),n()):(s.editor.one("focus",function(t){return s.editor.uploader.upload(i,{inline:!0}),n()}),s.editor.focus()),s.wrapper.removeClass("menu-on")})),this.editor.uploader.on("beforeupload",(a=this,function(e,i){var n;if(i.inline)return i.img?n=t(i.img):(n=a.createImage(i.name),i.img=n),n.addClass("uploading"),n.data("file",i),a.editor.uploader.readImageFile(i.obj,function(t){var e;if(n.hasClass("uploading"))return e=t?t.src:a.defaultImage,a.loadImage(n,e,function(){if(a.popover.active)return a.popover.refresh(),a.popover.srcEl.val(a._t("uploading")).prop("disabled",!0)})})})),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",(l=this,function(e,i,n){var r,o,s;if(i.inline&&(r=i.img).hasClass("uploading")&&r.parent().length>0){if("object"!=typeof n)try{n=t.parseJSON(n)}catch(t){n={success:!1}}return!1===n.success?(s=n.msg||l._t("uploadFailed"),alert(s),o=l.defaultImage):o=n.file_path,l.loadImage(r,o,function(){var t;if(r.removeData("file"),r.removeClass("uploading").removeClass("loading"),(t=r.data("mask"))&&t.remove(),r.removeData("mask"),l.editor.trigger("valuechanged"),l.editor.body.find("img.uploading").length<1)return l.editor.uploader.trigger("uploadready",[i,n])}),l.popover.active?(l.popover.srcEl.prop("disabled",!1),l.popover.srcEl.val(n.file_path)):void 0}})),this.editor.uploader.on("uploaderror",(d=this,function(e,i,n){var r,o,s;if(i.inline&&"abort"!==n.statusText){if(n.responseText){try{s=t.parseJSON(n.responseText),o=s.msg}catch(t){o=d._t("uploadError")}alert(o)}if((r=i.img).hasClass("uploading")&&r.parent().length>0)return d.loadImage(r,d.defaultImage,function(){var t;return r.removeData("file"),r.removeClass("uploading").removeClass("loading"),(t=r.data("mask"))&&t.remove(),r.removeData("mask")}),d.popover.active&&(d.popover.srcEl.prop("disabled",!1),d.popover.srcEl.val(d.defaultImage)),d.editor.trigger("valuechanged"),d.editor.body.find("img.uploading").length<1?d.editor.uploader.trigger("uploadready",[i,s]):void 0}}));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,l;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=(l=this,function(){var a,d;if(e.hasClass("loading")||e.hasClass("uploading"))return d=o.width,a=o.height,e.attr({src:i,width:d,height:a,"data-image-size":d+","+a}).removeClass("loading"),e.hasClass("uploading")?(l.editor.util.reflow(l.editor.body),s()):(r.remove(),e.removeData("mask")),t.isFunction(n)?n(o):void 0}),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,n,r,o,s,a,l,d,h;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",(n=this,function(t){return n._loadImage(n.srcEl.val())})),this.el.find(".image-size").on("blur",(r=this,function(e){return r._resizeImg(t(e.currentTarget)),r.el.data("popover").refresh()})),this.el.find(".image-size").on("keyup",(o=this,function(e){var i;if(i=t(e.currentTarget),13!==e.which&&27!==e.which&&9!==e.which)return o._resizeImg(i,!0)})),this.el.find(".image-size").on("keydown",(s=this,function(e){var i,n,r;return n=t(e.currentTarget),13===e.which||27===e.which?(e.preventDefault(),13===e.which?s._resizeImg(n):s._restoreImg(),i=s.target,s.hide(),r=document.createRange(),s.button.editor.selection.setRangeAfter(i,r)):9===e.which?s.el.data("popover").refresh():void 0})),this.altEl.on("keydown",(a=this,function(t){var e;if(13===t.which)return t.preventDefault(),e=document.createRange(),a.button.editor.selection.setRangeAfter(a.target,e),a.hide()})),this.altEl.on("keyup",(l=this,function(t){if(13!==t.which&&27!==t.which&&9!==t.which)return l.alt=l.altEl.val(),l.target.attr("alt",l.alt)})),this.el.find(".btn-restore").on("click",(d=this,function(t){return d._restoreImg(),d.el.data("popover").refresh()})),this.editor.on("valuechanged",(h=this,function(t){if(h.active)return h.refresh()})),this._initUploader()},i.prototype._initUploader=function(){var e,i,n,r;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]",(r=this,function(t){return r.editor.uploader.upload(r.input,{inline:!0,img:r.target}),i()}));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,n,r,o,s,a,l,d;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",(n=this,function(e,i){return i.find("table").each(function(e,i){return n.undecorate(t(i))})})),this.editor.on("selectionchanged.table",(r=this,function(t){var e,i;if(r.editor.body.find(".simditor-table td, .simditor-table th").removeClass("active"),i=r.editor.selection.range())return e=r.editor.selection.containerNode(),i.collapsed&&e.is(".simditor-table")&&(e=r.editor.selection.rangeAtStartOf(e)?e.find("th:first"):e.find("td:last"),r.editor.selection.setRangeAtEndOf(e)),e.closest("td, th",r.editor.body).addClass("active")})),this.editor.on("blur.table",(o=this,function(t){return o.editor.body.find(".simditor-table td, .simditor-table th").removeClass("active")})),this.editor.keystroke.add("up","td",(s=this,function(t,e){return s._tdNav(e,"up"),!0})),this.editor.keystroke.add("up","th",(a=this,function(t,e){return a._tdNav(e,"up"),!0})),this.editor.keystroke.add("down","td",(l=this,function(t,e){return l._tdNav(e,"down"),!0})),this.editor.keystroke.add("down","th",(d=this,function(t,e){return d._tdNav(e,"down"),!0}))},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,h,u,p;return o=(i=t(e.currentTarget)).data("td"),n=i.data("col"),a=o.next("td, th"),s=n.next("col"),u=e.pageX,d=1*o.outerWidth(),h=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-u,o=h-e,(r=d+e)<50?(r=50,o=h-(e=50-d)):o<50&&(o=50,r=d+(e=h-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,e,i,n;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",(e=this,function(t){return e.editMenu.find(".menu-item[data-param=insertRowBelow]").click(),!1})),this.editor.hotkeys.add("ctrl+alt+left",(i=this,function(t){return i.editMenu.find(".menu-item[data-param=insertColLeft]").click(),!1})),this.editor.hotkeys.add("ctrl+alt+right",(n=this,function(t){return n.editMenu.find(".menu-item[data-param=insertColRight]").click(),!1}))},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,n;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",(n=this,function(i){var r,o,s,a,l;if(n.wrapper.removeClass("menu-on"),n.editor.inputManager.focused)return a=(s=(o=t(i.currentTarget)).parent()).find("td").index(o)+1,l=s.prevAll("tr").length+1,s.parent().is("tbody")&&(l+=1),e=n.createTable(l,a,!0),r=n.editor.selection.blockNodes().last(),n.editor.util.isEmptyNode(r)?r.replaceWith(e):r.after(e),n.decorate(e),n.editor.selection.setRangeAtStartOf(e.find("th:first")),n.editor.trigger("valuechanged"),!1}))},i.prototype.createTable=function(e,i,n){var r,o,s,a,l,d,h,u,p,c;for(r=t("<table/>"),a=t("<thead/>").appendTo(r),o=t("<tbody/>").appendTo(r),u=d=0,p=e;0<=p?d<p:d>p;u=0<=p?++d:--d)for((l=t("<tr/>")).appendTo(0===u?a:o),h=0,c=i;0<=c?h<c:h>c;0<=c?++h:--h)s=t(0===u?"<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,h;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,h=a;1<=h?d<=h:d>=h;1<=h?++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,h,u;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((u=this,function(e,n){var r,o;return o=t(n).parent().is("thead")?"th":"td",r=t("<"+o+"/>").append(u.editor.util.phBr),t(n).find("td, th").eq(l)[i](r)})),r=t("<col/>"),n[i](r),d=s.width(),h=Math.max(parseFloat(n.attr("width"))/2,50/d*100),n.attr("width",h+"%"),r.attr("width",h+"%"),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});
| ver. 1.4 |
Github
|
.
| PHP 8.2.31 | Generation time: 1.11 |
proxy
|
phpinfo
|
Settings