mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2026-03-27 03:33:25 +08:00
9 lines
100 KiB
JavaScript
9 lines
100 KiB
JavaScript
|
|
/*!
|
||
|
|
* Simditor v2.3.5
|
||
|
|
* http://simditor.tower.im/
|
||
|
|
* 2015-11-19
|
||
|
|
*/
|
||
|
|
!function(a,b){"function"==typeof define&&define.amd?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){
|
||
|
|
toolbarFloat:!0,toolbarHidden:!1,toolbarFloatOffset:0},c.prototype._tpl={wrapper:'<div class="simditor-toolbar"><ul></ul></div>',separator:'<li><span class="separator"></span></li>'},c.prototype._init=function(){var b,c,d;return this.editor=this._module,this.opts.toolbar?(a.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(a){return!1}),this.wrapper.on("mousedown",function(a){return function(b){return a.list.find(".menu-on").removeClass(".menu-on")}}(this)),a(document).on("mousedown.simditor"+this.editor.id,function(a){return function(b){return a.list.find(".menu-on").removeClass(".menu-on")}}(this)),!this.opts.toolbarHidden&&this.opts.toolbarFloat&&(this.wrapper.css("top",this.opts.toolbarFloatOffset),d=0,c=function(a){return 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",""),d=a.wrapper.outerHeight(),a.editor.placeholderEl.css("top",d),!0}}(this),b=null,a(window).on("resize.simditor-"+this.editor.id,function(a){return b=c()}),a(window).on("scroll.simditor-"+this.editor.id,function(e){return function(f){var g,h,i;if(e.wrapper.is(":visible"))if(i=e.editor.wrapper.offset().top,g=i+e.editor.wrapper.outerHeight()-80,h=a(document).scrollTop()+e.opts.toolbarFloatOffset,i>=h||h>=g){if(e.editor.wrapper.removeClass("toolbar-floating").css("padding-top",""),e.editor.util.os.mobile)return e.wrapper.css("top",e.opts.toolbarFloatOffset)}else if(b||(b=c()),e.editor.wrapper.addClass("toolbar-floating").css("padding-top",d),e.editor.util.os.mobile)return e.wrapper.css("top",h-i+e.opts.toolbarFloatOffset)}}(this))),this.editor.on("destroy",function(a){return function(){return a.buttons.length=0}}(this)),a(document).on("mousedown.simditor-"+this.editor.id,function(a){return function(b){return a.list.find("li.menu-on").removeClass("menu-on")}}(this))):void 0},c.prototype._render=function(){var b,c,d,e;for(this.buttons=[],this.wrapper=a(this._tpl.wrapper).prependTo(this.editor.wrapper),this.list=this.wrapper.find("ul"),e=this.opts.toolbar,b=0,c=e.length;c>b;b++)if(d=e[b],"|"!==d){if(!this.constructor.buttons[d])throw new Error("simditor: invalid toolbar button "+d);this.buttons.push(new this.constructor.buttons[d]({editor:this.editor}))}else a(this._tpl.separator).appendTo(this.list);return this.opts.toolbarHidden?this.wrapper.hide():void 0},c.prototype.findButton=function(a){var b;return b=this.list.find(".toolbar-item-"+a).data("button"),null!=b?b:null},c.addButton=function(a){return this.buttons[a.prototype.name]=a},c.buttons={},c}(b),s=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return M(c,b),c.pluginName="Indentation",c.prototype.opts={tabIndent:!0},c.prototype._init=function(){return this.editor=this._module,this.editor.keystroke.add("tab","*",function(a){return function(b){var c;return c=a.editor.toolbar.findButton("code"),a.opts.tabIndent||c&&c.active?a.indent(b.shiftKey):void 0}}(this))},c.prototype.indent=function(b){var c,d,e,f,g;return e=this.editor.selection.startNodes(),d=this.editor.selection.endNodes(),c=this.editor.selection.blockNodes(),f=[],c=c.each(function(b,c){var d,e,g,h,i;for(d=!0,e=g=0,h=f.length;h>g;e=++g){if(i=f[e],a.contains(c,i)){d=!1;break}if(a.contains(i,c)){f.splice(e,1,c),d=!1;break}}return d?f.push(c):void 0}),c=a(f),g=!1,c.each(function(a){return function(c,d){var e;return e=b?a.outdentBlock(d):a.indentBlock(d),e?g=e:void 0}}(this)),g},c.prototype.indentBlock=function(b){var c,d,e,f,g,h,i,j,k,l;if(c=a(b),c.length){if(c.is("pre")){if(h=this.editor.selection.containerNode(),!h.is(c)&&!h.closest("pre").is(c))return;this.indentText(this.editor.selection.range())}else if(c.is("li")){if(g=c.prev("li"),g.length<1)return;this.editor.selection.save(),l=c.parent()[0].tagName,d=g.children("ul, ol"),d.
|
||
|
|
var e,f;return f=a(d),e=f.children("ul, ol").insertAfter(g),a("<p/>").append(a(d).html()||b.editor.util.phBr).insertBefore(g)}),g.remove()):g.is(e)?a("<"+b.type+"/>").append(g.contents()).replaceAll(g):c&&g.prev().is(c)?(a("<li/>").append(g.html()||b.editor.util.phBr).appendTo(c),g.remove()):(c=a("<"+b.type+"><li></li></"+b.type+">"),c.find("li").append(g.html()||b.editor.util.phBr),c.replaceAll(g))}}(this)),this.editor.selection.restore(),this.editor.trigger("valuechanged")},c}(h),z=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return M(b,a),b.prototype.type="ol",b.prototype.name="ol",b.prototype.icon="list-ol",b.prototype.htmlTag="ol",b.prototype.shortcut="cmd+/",b.prototype._init=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + / )":(this.title=this.title+" ( ctrl + / )",this.shortcut="ctrl+/"),b.__super__._init.call(this)},b}(y),K=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return M(b,a),b.prototype.type="ul",b.prototype.name="ul",b.prototype.icon="list-ul",b.prototype.htmlTag="ul",b.prototype.shortcut="cmd+.",b.prototype._init=function(){return this.editor.util.os.mac?this.title=this.title+" ( Cmd + . )":(this.title=this.title+" ( Ctrl + . )",this.shortcut="ctrl+."),b.__super__._init.call(this)},b}(y),D.Toolbar.addButton(z),D.Toolbar.addButton(K),f=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return M(c,b),c.prototype.name="blockquote",c.prototype.icon="quote-left",c.prototype.htmlTag="blockquote",c.prototype.disableTag="pre, table",c.prototype.command=function(){var b,c,d;return b=this.editor.selection.rootNodes(),b=b.filter(function(b,c){return!a(c).parent().is("blockquote")}),this.editor.selection.save(),d=[],c=function(b){return function(){return d.length>0?(a("<"+b.htmlTag+"/>").insertBefore(d[0]).append(d),d.length=0):void 0}}(this),b.each(function(b){return function(e,f){var g;return g=a(f),g.parent().is(b.editor.body)?g.is(b.htmlTag)?(c(),g.children().unwrap()):g.is(b.disableTag)||b.editor.util.isDecoratedNode(g)?c():d.push(f):void 0}}(this)),c(),this.editor.selection.restore(),this.editor.trigger("valuechanged")},c}(h),D.Toolbar.addButton(f),j=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return M(c,b),c.prototype.name="code",c.prototype.icon="code",c.prototype.htmlTag="pre",c.prototype.disableTag="ul, ol, table",c.prototype._init=function(){return c.__super__._init.call(this),this.editor.on("decorate",function(b){return function(c,d){return d.find("pre").each(function(c,d){return b.decorate(a(d))})}}(this)),this.editor.on("undecorate",function(b){return function(c,d){return d.find("pre").each(function(c,d){return b.undecorate(a(d))})}}(this))},c.prototype.render=function(){var a;return a=1<=arguments.length?P.call(arguments,0):[],c.__super__.render.apply(this,a),this.popover=new k({button:this})},c.prototype._checkMode=function(){var b,c;return c=this.editor.selection.range(),(b=a(c.cloneContents()).find(this.editor.util.blockNodes.join(",")))>0||c.collapsed&&0===this.editor.selection.startNodes().filter("code").length?(this.inlineMode=!1,this.htmlTag="pre"):(this.inlineMode=!0,this.htmlTag="code")},c.prototype._status=function(){return this._checkMode(),c.__super__._status.call(this),this.inlineMode?void 0:this.active?this.popover.show(this.node):this.popover.hide()},c.prototype.decorate=function(a){var b,c,d,e;return b=a.find("> code"),b.length>0&&(c=null!=(d=b.attr("class"))&&null!=(e=d.match(/lang-(\S+)/))?e[1]:void 0,b.contents().unwrap(),c)?a.attr("data-lang",c):void 0},c.prototype.undecorate=function(b){var c,d;return d=b.attr("data-lang"),c=a("<code/>"),d&&-1!==d&&c.addClass("lang-"+d),b.wrapInner(c).removeAttr("data-lang")},c.prototype.command=function(){return this.inlineMode?this._inlineCommand():this._blockCommand()},c.prototype._blockCommand=function(){var b,c,d,e;return b=this.editor.selection.rootNodes(),d=[],e=[],c=function(b){return function(){var c;if(d.length>0)return c=a("<"+b.htmlTag+"/>").insertBefore(d[0]).text(b.editor.formatter
|
||
|
|
i.appendTo(0===m?h:f),j=l=0,o=c;o>=0?o>l:l>o;j=o>=0?++l:--l)g=a(0===m?"<th/>":"<td/>").appendTo(i),d&&g.append(this.editor.util.phBr);return e},c.prototype.refreshTableWidth=function(b){var c,d;return d=b.width(),c=b.find("col"),b.find("thead tr th").each(function(b,e){var f;return f=c.eq(b),f.attr("width",a(e).outerWidth()/d*100+"%")})},c.prototype.setActive=function(a){return c.__super__.setActive.call(this,a),a?(this.createMenu.hide(),this.editMenu.show()):(this.createMenu.show(),this.editMenu.hide())},c.prototype._changeCellTag=function(b,c){return b.find("td, th").each(function(b,d){var e;return e=a(d),e.replaceWith("<"+c+">"+e.html()+"</"+c+">")})},c.prototype.deleteRow=function(a){var b,c,d;return c=a.parent("tr"),c.closest("table").find("tr").length<1?this.deleteTable(a):(b=this._nextRow(c),b.length>0||(b=this._prevRow(c)),d=c.find("td, th").index(a),c.parent().is("thead")&&(b.appendTo(c.parent()),this._changeCellTag(b,"th")),c.remove(),this.editor.selection.setRangeAtEndOf(b.find("td, th").eq(d)))},c.prototype.insertRow=function(b,c){var d,e,f,g,h,i,j,k,l;for(null==c&&(c="after"),f=b.parent("tr"),e=f.closest("table"),h=0,e.find("tr").each(function(b,c){return h=Math.max(h,a(c).find("td").length)}),j=f.find("td, th").index(b),d=a("<tr/>"),g="td","after"===c&&f.parent().is("thead")?f.parent().next("tbody").prepend(d):"before"===c&&f.parent().is("thead")?(f.before(d),f.parent().next("tbody").prepend(f),this._changeCellTag(f,"td"),g="th"):f[c](d),i=k=1,l=h;l>=1?l>=k:k>=l;i=l>=1?++k:--k)a("<"+g+"/>").append(this.editor.util.phBr).appendTo(d);return this.editor.selection.setRangeAtStartOf(d.find("td, th").eq(j))},c.prototype.deleteCol=function(b){var c,d,e,f,g,h;return e=b.parent("tr"),h=e.closest("table").find("tr").length<2,g=b.siblings("td, th").length<1,h&&g?this.deleteTable(b):(f=e.find("td, th").index(b),c=b.next("td, th"),c.length>0||(c=e.prev("td, th")),d=e.closest("table"),d.find("col").eq(f).remove(),d.find("tr").each(function(b,c){return a(c).find("td, th").eq(f).remove()}),this.refreshTableWidth(d),this.editor.selection.setRangeAtEndOf(c))},c.prototype.insertCol=function(b,c){var d,e,f,g,h,i,j,k;return null==c&&(c="after"),h=b.parent("tr"),i=h.find("td, th").index(b),g=b.closest("table"),d=g.find("col").eq(i),g.find("tr").each(function(b){return function(d,e){var f,g;return g=a(e).parent().is("thead")?"th":"td",f=a("<"+g+"/>").append(b.editor.util.phBr),a(e).find("td, th").eq(i)[c](f)}}(this)),e=a("<col/>"),d[c](e),j=g.width(),k=Math.max(parseFloat(d.attr("width"))/2,50/j*100),d.attr("width",k+"%"),e.attr("width",k+"%"),this.refreshTableWidth(g),f="after"===c?b.next("td, th"):b.prev("td, th"),this.editor.selection.setRangeAtStartOf(f)},c.prototype.deleteTable=function(a){var b,c;return c=a.closest(".simditor-table"),b=c.next("p"),c.remove(),b.length>0?this.editor.selection.setRangeAtStartOf(b):void 0},c.prototype.command=function(a){var b;if(b=this.editor.selection.containerNode().closest("td, th"),b.length>0){if("deleteRow"===a)this.deleteRow(b);else if("insertRowAbove"===a)this.insertRow(b,"before");else if("insertRowBelow"===a)this.insertRow(b);else if("deleteCol"===a)this.deleteCol(b);else if("insertColLeft"===a)this.insertCol(b,"before");else if("insertColRight"===a)this.insertCol(b);else{if("deleteTable"!==a)return;this.deleteTable(b)}return this.editor.trigger("valuechanged")}},c}(h),D.Toolbar.addButton(F),E=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return M(c,b),c.prototype.name="strikethrough",c.prototype.icon="strikethrough",c.prototype.htmlTag="strike",c.prototype.disableTag="pre",c.prototype._activeStatus=function(){var a;return a=document.queryCommandState("strikethrough")===!0,this.setActive(a),this.active},c.prototype.command=function(){return document.execCommand("strikethrough"),this.editor.util.support.oninput||this.editor.trigger("valuechanged"),a(document).trigger("selectionchange")},c}(h),D.Toolbar.addButton(E),e=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}return M(b,a),b.prototype.name="alignment",b.prototype.icon=
|