|
|
|
|
!function(a,b){"function"==typeof define&&define.amd?define("simditor",["jquery","simple-module","simple-hotkeys","simple-uploader"],function(c,d,e,f){return a.returnExportsGlobal=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={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};e=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return g(c,b),c.pluginName="Selection",c.prototype._init=function(){return this.editor=this._module,this.sel=document.getSelection()},c.prototype.clear=function(){var a;try{return this.sel.removeAllRanges()}catch(b){a=b}},c.prototype.getRange=function(){return this.editor.inputManager.focused&&this.sel.rangeCount?this.sel.getRangeAt(0):null},c.prototype.selectRange=function(a){return this.clear(),this.sel.addRange(a),this.editor.inputManager.focused||!this.editor.util.browser.firefox&&!this.editor.util.browser.msie||this.editor.body.focus(),a},c.prototype.rangeAtEndOf=function(b,c){var d,e,f;return null==c&&(c=this.getRange()),null!=c&&c.collapsed?(b=a(b)[0],d=c.endContainer,e=this.editor.util.getNodeLength(d),c.endOffset===e-1&&a(d).contents().last().is("br")||c.endOffset===e?b===d?!0:a.contains(b,d)?(f=!0,a(d).parentsUntil(b).addBack().each(function(){return function(b,c){var d,e;return e=a(c).parent().contents().filter(function(){return!(this!==c&&3===this.nodeType&&!this.nodeValue)}),d=e.last(),d.get(0)===c||d.is("br")&&d.prev().get(0)===c?void 0:(f=!1,!1)}}(this)),f):!1:!1):void 0},c.prototype.rangeAtStartOf=function(b,c){var d,e;return null==c&&(c=this.getRange()),null!=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(){return 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}}(this)),d):!1):void 0},c.prototype.insertNode=function(b,c){return null==c&&(c=this.getRange()),null!=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.getRange()),null!=c?(b=a(b)[0],c.setEndAfter(b),c.collapse(!1),this.selectRange(c)):void 0},c.prototype.setRangeBefore=function(b,c){return null==c&&(c=this.getRange()),null!=c?(b=a(b)[0],c.setEndBefore(b),c.collapse(!1),this.selectRange(c)):void 0},c.prototype.setRangeAtStartOf=function(b,c){return null==c&&(c=this.getRange()),b=a(b).get(0),c.setEnd(b,0),c.collapse(!1),this.selectRange(c)},c.prototype.setRangeAtEndOf=function(b,c){var d,e,f,g,h,i;return null==c&&(c=this.getRange()),e=a(b),b=e.get(0),e.is("pre")?(f=e.contents(),f.length>0?(g=f.last(),h=g.text(),"\n"===h.charAt(h.length-1)?c.setEnd(g[0],this.editor.util.getNodeLength(g[0])-1):c.setEnd(g[0],this.editor.util.getNodeLength(g[0]))):c.setEnd(b,0)):(i=this.editor.util.getNodeLength(b),3!==b.nodeType&&i>0&&(d=a(b).contents().last(),d.is("br")?i-=1:3!==d[0].nodeType&&this.editor.util.isEmptyNode(d)&&(d.append(this.editor.util.phBr),b=d[0],i=0)),c.setEnd(b,i)),c.collapse(!1),this.selectRange(c)},c.prototype.deleteRangeContents=function(a){var b,c;return null==a&&(a=this.getRange()),c=a.cloneRange(),b=a.cloneRange(),c.collapse(!0),b.collapse(!1),!a.collapsed&&this.rangeAtStartOf(this.editor.body,c)&&this.rangeAtEndOf(this.editor.body,b)?(this.editor.body.empty(),a.setStart(this.editor.body[0],0),a.collapse(!0),this.selectRange(a)):a.deleteContents(),a},c.prototype.breakBlockEl=function(b,c){var d;return null==c&&(c=this.getRange()),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.getRange()),this._selectionSaved?void 0:(d=b.cloneRange(),d.collapse(!1),e=a("<span/>").addClass("s
|
|
|
|
|
this.editor.selection.setRangeAtEndOf(d)}else i=document.createTextNode(" "),this.editor.selection.insertNode(i);return this.editor.trigger("valuechanged"),!0},c.prototype.outdent=function(){var b,c,d,e,f,g,h,i,j;if(b=this.editor.util.closestBlockEl(),!(b&&b.length>0))return!1;if(b.is("pre"))return!1;if(b.is("li")){if(c=b.parent(),d=c.parent("li"),d.length<1)return g=this.editor.toolbar.findButton(c[0].tagName.toLowerCase()),null!=g&&g.command(),!1;this.editor.selection.save(),b.next("li").length>0&&a("<"+c[0].tagName+"/>").append(b.nextAll("li")).appendTo(b),b.insertAfter(d),c.children("li").length<1&&c.remove(),this.editor.selection.restore()}else if(b.is("p, h1, h2, h3, h4"))h=null!=(j=b.attr("data-indent"))?j:0,h=1*h-1,0>h&&(h=0),b.attr("data-indent",h);else{if(!b.is("table"))return!1;if(i=this.editor.selection.getRange(),f=a(i.commonAncestorContainer).closest("td"),e=f.prev("td"),e.length>0||(e=f.parent("tr").prev("tr").find("td:last")),!(f.length>0&&e.length>0))return!1;this.editor.selection.setRangeAtEndOf(e)}return this.editor.trigger("valuechanged"),!0},c.prototype.dataURLtoBlob=function(a){var b,c,d,e,f,g,h,i,j,k,l;if(g=window.Blob&&function(){var a;try{return Boolean(new Blob)}catch(b){return a=b,!1}}(),f=g&&window.Uint8Array&&function(){var a;try{return 100===new Blob([new Uint8Array(100)]).size}catch(b){return a=b,!1}}(),b=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder,!((g||b)&&window.atob&&window.ArrayBuffer&&window.Uint8Array))return!1;for(e=a.split(",")[0].indexOf("base64")>=0?atob(a.split(",")[1]):decodeURIComponent(a.split(",")[1]),c=new ArrayBuffer(e.length),i=new Uint8Array(c),h=k=0,l=e.length;l>=0?l>=k:k>=l;h=l>=0?++k:--k)i[h]=e.charCodeAt(h);return j=a.split(",")[0].split(":")[1].split(";")[0],g?new Blob([f?i:c],{type:j}):(d=new b,d.append(c),d.getBlob(j))},c}(b);var n,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};n=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return g(c,b),c.pluginName="Toolbar",c.prototype.opts={toolbar:!0,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;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(){return function(){return!1}}(this)),this.wrapper.on("mousedown",function(a){return function(){return a.list.find(".menu-on").removeClass(".menu-on")}}(this)),a(document).on("mousedown.simditor"+this.editor.id,function(a){return function(){return a.list.find(".menu-on").removeClass(".menu-on")}}(this)),!this.opts.toolbarHidden&&this.opts.toolbarFloat&&(this.wrapper.width(this.wrapper.outerWidth()),this.wrapper.css("top",this.opts.toolbarFloatOffset),b=this.wrapper.outerHeight(),this.editor.util.os.mobile||a(window).on("resize.simditor-"+this.editor.id,function(a){return function(){return a.wrapper.css("position","static"),a.editor.util.reflow(a.wrapper),a.wrapper.css("left",a.wrapper.offset().left),a.wrapper.css("position","")}}(this)).resize(),a(window).on("scroll.simditor-"+this.editor.id,function(c){return function(){var d,e,f;if(f=c.editor.wrapper.offset().top,d=f+c.editor.wrapper.outerHeight()-80,e=a(document).scrollTop()+c.opts.toolbarFloatOffset,f>=e||e>=d){if(c.editor.wrapper.removeClass("toolbar-floating").css("padding-top",""),c.editor.util.os.mobile)return c.wrapper.css("top",c.opts.toolbarFloatOffset)}else if(c.editor.wrapper.addClass("toolbar-floating").css("padding-top",b),c.editor.util.os.mobile)return c.wrapper.css("top",e-f+c.opts.toolbarFloatOffset)}}(this))),this.editor.on("selectionchanged",function(a){return function(){return a.toolbarStatus()}}(this)),this.edit
|
|
|
|
|
var D,E,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},q=[].slice;D=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return g(c,b),c.prototype.name="link",c.prototype.icon="link",c.prototype.htmlTag="a",c.prototype.disableTag="pre",c.prototype.render=function(){var a;return a=1<=arguments.length?q.call(arguments,0):[],c.__super__.render.apply(this,a),this.popover=new E({button:this})},c.prototype.status=function(a){var b;return null!=a&&this.setDisabled(a.is(this.disableTag)),this.disabled?!0:null==a?this.active:(b=!0,!a.is(this.htmlTag)||a.is('[class^="simditor-"]')?(this.setActive(!1),b=!1):this.editor.selection.rangeAtEndOf(a)?(this.setActive(!0),b=!1):this.setActive(!0),b?this.popover.show(a):this.editor.util.isBlockNode(a)&&this.popover.hide(),this.active)},c.prototype.command=function(){var b,c,d,e,f,g,h,i,j,k;return i=this.editor.selection.getRange(),this.active?(d=a(i.commonAncestorContainer).closest("a"),k=document.createTextNode(d.text()),d.replaceWith(k),i.selectNode(k)):(j=i.startContainer,g=i.endContainer,f=this.editor.util.closestBlockEl(j),c=this.editor.util.closestBlockEl(g),b=a(i.extractContents()),h=this.editor.formatter.clearHtml(b.contents(),!1),d=a("<a/>",{href:"http://www.example.com",target:"_blank",text:h||this._t("linkText")}),f[0]===c[0]?i.insertNode(d[0]):(e=a("<p/>").append(d),i.insertNode(e[0])),i.selectNodeContents(d[0]),this.popover.one("popovershow",function(a){return function(){return h?(a.popover.urlEl.focus(),a.popover.urlEl[0].select()):(a.popover.textEl.focus(),a.popover.textEl[0].select())}}(this))),this.editor.selection.selectRange(i),this.editor.trigger("valuechanged")},c}(p),E=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return g(c,b),c.prototype.render=function(){var b;return b='<div class="link-settings">\n <div class="settings-field">\n <label>'+this._t("text")+'</label>\n <input class="link-text" type="text"/>\n <a class="btn-unlink" href="javascript:;" title="'+this._t("removeLink")+'" tabindex="-1"><span class="fa fa-unlink"></span></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>',this.el.addClass("link-popover").append(b),this.textEl=this.el.find(".link-text"),this.urlEl=this.el.find(".link-url"),this.unlinkEl=this.el.find(".btn-unlink"),this.textEl.on("keyup",function(a){return function(b){return 13!==b.which?a.target.text(a.textEl.val()):void 0}}(this)),this.urlEl.on("keyup",function(a){return function(b){var c;if(13!==b.which)return c=a.urlEl.val(),!/https?:\/\/|^\//gi.test(c)&&c&&(c="http://"+c),a.target.attr("href",c)}}(this)),a([this.urlEl[0],this.textEl[0]]).on("keydown",function(b){return function(c){return 13===c.which||27===c.which||!c.shiftKey&&9===c.which&&a(c.target).hasClass("link-url")?(c.preventDefault(),setTimeout(function(){var a;return a=document.createRange(),b.editor.selection.setRangeAfter(b.target,a),b.hide(),b.editor.trigger("valuechanged")},0)):void 0}}(this)),this.unlinkEl.on("click",function(a){return function(){var b,c;return c=document.createTextNode(a.target.text()),a.target.replaceWith(c),a.hide(),b=document.createRange(),a.editor.selection.setRangeAfter(c,b),a.editor.trigger("valuechanged")}}(this))},c.prototype.show=function(){var a;return a=1<=arguments.length?q.call(arguments,0):[],c.__super__.show.apply(this,a),this.textEl.val(this.target.text()),this.urlEl.val(this.target.attr("href"))},c}(r),o.Toolbar.addButton(D);var F,G,f={}.hasOwnProperty,g=function(a,b){function c(){this.constructor=a}for(var d in b)f.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a},q=[].slice;F=function(b){function c(){return c.__super__.constructor.apply(this,arguments)}return g(c,b),c.prototype.name="image",c.prototype.icon="picture-o",c.prototype.htmlTag="img",c.prototype.disableTag="pre, table",c.prototype
|