/*! * Simditor v2.3.6 * http://simditor.tower.im/ * 2015-12-21 */ !function(a,b){"function"==typeof define&&define.amd? // AMD. Register as an anonymous module unless amdModuleId is set define("simditor",["jquery","simple-module","simple-hotkeys","simple-uploader"],function(c,d,e,f){return a.Simditor=b(c,d,e,f)}):"object"==typeof exports?module.exports=b(require("jquery"),require("simple-module"),require("simple-hotkeys"),require("simple-uploader")):a.Simditor=b(jQuery,SimpleModule,simple.hotkeys,simple.uploader)}(this,function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M=function(a,b){function c(){this.constructor=a}for(var d in b)N.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},N={}.hasOwnProperty,O=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1},P=[].slice;return C=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return M(c,b),c.pluginName="Selection",c.prototype._range=null,c.prototype._startNodes=null,c.prototype._endNodes=null,c.prototype._containerNode=null,c.prototype._nodes=null,c.prototype._blockNodes=null,c.prototype._rootNodes=null,c.prototype._init=function(){return this.editor=this._module,this._selection=document.getSelection(),this.editor.on("selectionchanged",function(a){return function(b){return a.reset(),a._range=a._selection.getRangeAt(0)}}(this)),this.editor.on("blur",function(a){return function(b){return a.reset()}}(this))},c.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},c.prototype.clear=function(){var a;try{this._selection.removeAllRanges()}catch(b){a=b}return this.reset()},c.prototype.range=function(a){var b;return a?(this.clear(),this._selection.addRange(a),this._range=a,b=this.editor.util.browser.firefox||this.editor.util.browser.msie,!this.editor.inputManager.focused&&b&&this.editor.body.focus()):!this._range&&this.editor.inputManager.focused&&this._selection.rangeCount&&(this._range=this._selection.getRangeAt(0)),this._range},c.prototype.startNodes=function(){return this._range&&(this._startNodes||(this._startNodes=function(b){return function(){var c;return c=a(b._range.startContainer).parentsUntil(b.editor.body).get(),c.unshift(b._range.startContainer),a(c)}}(this)())),this._startNodes},c.prototype.endNodes=function(){var b;return this._range&&(this._endNodes||(this._endNodes=this._range.collapsed?this.startNodes():(b=a(this._range.endContainer).parentsUntil(this.editor.body).get(),b.unshift(this._range.endContainer),a(b)))),this._endNodes},c.prototype.containerNode=function(){return this._range&&(this._containerNode||(this._containerNode=a(this._range.commonAncestorContainer))),this._containerNode},c.prototype.nodes=function(){return this._range&&(this._nodes||(this._nodes=function(b){return function(){var c;return c=[],b.startNodes().first().is(b.endNodes().first())?c=b.startNodes().get():(b.startNodes().each(function(d,e){var f,g,h,i,j,k,l;return g=a(e),b.endNodes().index(g)>-1?c.push(e):g.parent().is(b.editor.body)||(k=b.endNodes().index(g.parent()))>-1?(f=k&&k>-1?b.endNodes().eq(k-1):b.endNodes().last(),h=g.parent().contents(),l=h.index(g),i=h.index(f),a.merge(c,h.slice(l,i).get())):(h=g.parent().contents(),j=h.index(g),a.merge(c,h.slice(j).get()))}),b.endNodes().each(function(d,e){var f,g,h;return f=a(e),f.parent().is(b.editor.body)||b.startNodes().index(f.parent())>-1?(c.push(e),!1):(g=f.parent().contents(),h=g.index(f),a.merge(c,g.slice(0,h+1)))})),a(a.unique(c))}}(this)())),this._nodes},c.prototype.blockNodes=function(){return this._range?(this._blockNodes||(this._blockNodes=function(a){return function(){return a.nodes().filter(function(b,c){return a.editor.util.isBlockNode(c)})}}(this)()),this._blockNodes):void 0},c.prototype.rootNodes=function(){return this._range?(this._rootNodes||(this._rootNodes=function(b){return function(){return b.nodes().filter(function(c,d){var e;return e=a(d).parent(),e.is(b.editor.body)||e.is("blockquote")})}}(this)()),this._rootNodes):void 0},c.prototype.rangeAtEndOf=function(b,c){var d,e,f,g,h,i;return null==c&&(c=this.range()),c&&c.collapsed?(b=a(b)[0],f=c.endContainer,g=this.editor.util.getNodeLength(f),e=c.endOffset===g-1,h=a(f).contents().last().is("br"),d=c.endOffset===g,e&&h||d?b===f?!0:a.contains(b,f)?(i=!0,a(f).parentsUntil(b).addBack().each(function(b,c){var d,e,f,g;return g=a(c).parent().contents().filter(function(){return!(this!==c&&3===this.nodeType&&!this.nodeValue)}),d=g.last(),f=d.get(0)===c,e=d.is("br")&&d.prev().get(0)===c,f||e?void 0:(i=!1,!1)}),i):!1:!1):void 0},c.prototype.rangeAtStartOf=function(b,c){var d,e;return null==c&&(c=this.range()),c&&c.collapsed?(b=a(b)[0],e=c.startContainer,0!==c.startOffset?!1:b===e?!0:a.contains(b,e)?(d=!0,a(e).parentsUntil(b).addBack().each(function(b,c){var e;return e=a(c).parent().contents().filter(function(){return!(this!==c&&3===this.nodeType&&!this.nodeValue)}),e.first().get(0)!==c?d=!1:void 0}),d):!1):void 0},c.prototype.insertNode=function(b,c){return null==c&&(c=this.range()),c?(b=a(b)[0],c.insertNode(b),this.setRangeAfter(b,c)):void 0},c.prototype.setRangeAfter=function(b,c){return null==c&&(c=this.range()),null!=c?(b=a(b)[0],c.setEndAfter(b),c.collapse(!1),this.range(c)):void 0},c.prototype.setRangeBefore=function(b,c){return null==c&&(c=this.range()),null!=c?(b=a(b)[0],c.setEndBefore(b),c.collapse(!1),this.range(c)):void 0},c.prototype.setRangeAtStartOf=function(b,c){return null==c&&(c=this.range()),b=a(b).get(0),c.setEnd(b,0),c.collapse(!1),this.range(c)},c.prototype.setRangeAtEndOf=function(b,c){var d,e,f,g,h,i,j;return null==c&&(c=this.range()),e=a(b),b=e[0],e.is("pre")?(f=e.contents(),f.length>0?(g=f.last(),i=g.text(),h=this.editor.util.getNodeLength(g[0]),"\n"===i.charAt(i.length-1)?c.setEnd(g[0],h-1):c.setEnd(g[0],h)):c.setEnd(b,0)):(j=this.editor.util.getNodeLength(b),3!==b.nodeType&&j>0&&(d=a(b).contents().last(),d.is("br")?j-=1:3!==d[0].nodeType&&this.editor.util.isEmptyNode(d)&&(d.append(this.editor.util.phBr),b=d[0],j=0)),c.setEnd(b,j)),c.collapse(!1),this.range(c)},c.prototype.deleteRangeContents=function(a){var b,c,d,e;return null==a&&(a=this.range()),e=a.cloneRange(),d=a.cloneRange(),e.collapse(!0),d.collapse(!1),c=this.rangeAtStartOf(this.editor.body,e),b=this.rangeAtEndOf(this.editor.body,d),!a.collapsed&&c&&b?(this.editor.body.empty(),a.setStart(this.editor.body[0],0),a.collapse(!0),this.range(a)):a.deleteContents(),a},c.prototype.breakBlockEl=function(b,c){var d;return null==c&&(c=this.range()),d=a(b),c.collapsed?(c.setStartBefore(d.get(0)),c.collapsed?d:d.before(c.extractContents())):d},c.prototype.save=function(b){var c,d,e;return null==b&&(b=this.range()),this._selectionSaved?void 0:(d=b.cloneRange(),d.collapse(!1),e=a("").addClass("simditor-caret-start"),c=a("").addClass("simditor-caret-end"),d.insertNode(c[0]),b.insertNode(e[0]),this.clear(),this._selectionSaved=!0)},c.prototype.restore=function(){var a,b,c,d,e,f,g;return this._selectionSaved?(e=this.editor.body.find(".simditor-caret-start"),a=this.editor.body.find(".simditor-caret-end"),e.length&&a.length?(f=e.parent(),g=f.contents().index(e),b=a.parent(),c=b.contents().index(a),f[0]===b[0]&&(c-=1),d=document.createRange(),d.setStart(f.get(0),g),d.setEnd(b.get(0),c),e.remove(),a.remove(),this.range(d)):(e.remove(),a.remove()),this._selectionSaved=!1,d):!1},c}(b),n=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return M(c,b),c.pluginName="Formatter",c.prototype.opts={allowedTags:[],allowedAttributes:{},allowedStyles:{}},c.prototype._init=function(){return this.editor=this._module,this._allowedTags=a.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=a.extend({img:["src","alt","width","height","data-non-image"],a:["href","target"],font:["color"],code:["class"]},this.opts.allowedAttributes),this._allowedStyles=a.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(a){return!1})},c.prototype.decorate=function(a){return null==a&&(a=this.editor.body),this.editor.trigger("decorate",[a]),a},c.prototype.undecorate=function(a){return null==a&&(a=this.editor.body.clone()),this.editor.trigger("undecorate",[a]),a},c.prototype.autolink=function(b){var c,d,e,f,g,h,i,j,k,l,m,n,o;for(null==b&&(b=this.editor.body),i=[],e=function(c){return c.contents().each(function(c,d){var f,g;return f=a(d),f.is("a")||f.closest("a, pre",b).length?void 0:!f.is("iframe")&&f.contents().length?e(f):(g=f.text())&&/https?:\/\/|www\./gi.test(g)?i.push(f):void 0})},e(b),k=/(https?:\/\/|www\.)[\w\-\.\?&=\/#%:,@\!\+]+/gi,f=0,h=i.length;h>f;f++){for(d=i[f],n=d.text(),l=[],j=null,g=0;null!==(j=k.exec(n));)m=n.substring(g,j.index),l.push(document.createTextNode(m)),g=k.lastIndex,o=/^(http(s)?:\/\/|\/)/.test(j[0])?j[0]:"http://"+j[0],c=a('').text(j[0]),l.push(c[0]);l.push(document.createTextNode(n.substring(g))),d.replaceWith(a(l))}return b},c.prototype.format=function(b){var c,d,e,f,g,h,i,j,k,l;if(null==b&&(b=this.editor.body),b.is(":empty"))return b.append("

"+this.editor.util.phBr+"

"),b;for(k=b.contents(),e=0,g=k.length;g>e;e++)i=k[e],this.cleanNode(i,!0);for(l=b.contents(),f=0,h=l.length;h>f;f++)j=l[f],c=a(j),c.is("br")?("undefined"!=typeof d&&null!==d&&(d=null),c.remove()):this.editor.util.isBlockNode(j)?c.is("li")?d&&d.is("ul, ol")?d.append(j):(d=a("