!function(e){"use strict";if("function"==typeof define&&define.amd)define(["jquery"],function(t){return e(window,document,t)});else{if("undefined"==typeof exports)return e(window,document,jQuery);module.exports=e(window,document,require("jquery"))}}(function(e,t,n){"use strict";var o=function(e,t,n){var o,r,i,a,s,l,p,c;switch(a=Math.floor(6*e),s=6*e-a,l=n*(1-t),p=n*(1-s*t),c=n*(1-(1-s)*t),a%6){case 0:o=n,r=c,i=l;break;case 1:o=p,r=n,i=l;break;case 2:o=l,r=n,i=c;break;case 3:o=l,r=p,i=n;break;case 4:o=c,r=l,i=n;break;case 5:o=n,r=l,i=p}var u=Math.floor(255*o).toString(16),f=Math.floor(255*r).toString(16),d=Math.floor(255*i).toString(16);return"#"+(u.length<2?"0":"")+u+(f.length<2?"0":"")+f+(d.length<2?"0":"")+d},r=function(e){return e.replace(/[&<>"]/g,function(e){var t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"};return t[e]||e})},i=function(i,a,s,l,p,c,u,f,d,w,h,g,y,v,m,b,C,k){var P=function(e,t){t&&(e.getSelectedHTML()?e.insertLink(t):e.insertHTML('<a href="'+r(t)+'">'+r(t)+"</a>")),e.closePopup().collapseSelection()},x=function(e,t){var o=n('<input type="text" value="">').val(t?t.attr("href"):"").addClass("wysiwyg-input").keypress(function(n){10!=n.which&&13!=n.which||(t?(t.prop("href",o.val()),e.closePopup().collapseSelection()):P(e,o.val()))});f&&o.prop("placeholder",f);var r=n();c&&(r=I(c).click(function(n){return t?(t.prop("href",o.val()),e.closePopup().collapseSelection()):P(e,o.val()),n.stopPropagation(),n.preventDefault(),!1}));var i=n("<div/>").addClass("wysiwyg-toolbar-form").prop("unselectable","on");return i.append(o).append(r),i},L=function(t){var o=function(e,o){var i='<img id="wysiwyg-insert-image" src="" alt=""'+(o?' title="'+r(o)+'"':"")+">";t.insertHTML(i).closePopup().collapseSelection();var a=n("#wysiwyg-insert-image").removeAttr("id");w&&a.css({maxWidth:w[0]+"px",maxHeight:w[1]+"px"}).load(function(){a.css({maxWidth:"",maxHeight:""});var e=a.width(),t=a.height();(e>w[0]||t>w[1])&&(e/t>w[0]/w[1]?(t=parseInt(t/e*w[0]),e=w[0]):(e=parseInt(e/t*w[1]),t=w[1]),a.prop("width",e).prop("height",t))}),a.prop("src",e)},i=n("<div/>").addClass("wysiwyg-toolbar-form").prop("unselectable","on"),a=null,s=n('<input type="file">').css({position:"absolute",left:0,top:0,width:"100%",height:"100%",opacity:0,cursor:"pointer"});if(!y&&e.File&&e.FileReader&&e.FileList){var l=function(e){if(("function"!=typeof h||h(e))&&e.type.match(h)){var t=new FileReader;t.onload=function(t){var n=t.target.result;o(n,e.name)},t.readAsDataURL(e)}};a=s.prop("draggable","true").change(function(e){for(var t=e.target.files,n=0;n<t.length;++n)l(t[n])}).on("dragover",function(e){return e.originalEvent.dataTransfer.dropEffect="copy",e.stopPropagation(),e.preventDefault(),!1}).on("drop",function(e){for(var t=e.originalEvent.dataTransfer.files,n=0;n<t.length;++n)l(t[n]);return e.stopPropagation(),e.preventDefault(),!1})}else if(g){var p=s.change(function(e){g.call(this,o)});a=n("<form/>").append(p)}a&&n("<div/>").addClass("wysiwyg-browse").html(u).append(a).appendTo(i);var d=n('<input type="text" value="">').addClass("wysiwyg-input").keypress(function(e){10!=e.which&&13!=e.which||o(d.val())});f&&d.prop("placeholder",f);var v=n();return c&&(v=I(c).click(function(e){return o(d.val()),e.stopPropagation(),e.preventDefault(),!1})),i.append(n("<div/>").append(d).append(v)),i},T=function(e){var t=function(t,o){t=n.trim(t||""),o=n.trim(o||"");var i=!1;t.length&&!o.length?i=t:-1==o.indexOf("<")&&-1==o.indexOf(">")&&o.match(/^(?:https?:\/)?\/?(?:[^:\/\s]+)(?:(?:\/\w+)*\/)(?:[\w\-\.]+[^#?\s]+)(?:.*)?(?:#[\w\-]+)?$/)&&(i=o),i&&v&&(o=v(i)||""),!o.length&&i&&(o='<video src="'+r(i)+'">'),e.insertHTML(o).closePopup().collapseSelection()},o=n("<div/>").addClass("wysiwyg-toolbar-form").prop("unselectable","on"),i=n("<textarea>").addClass("wysiwyg-input wysiwyg-inputtextarea");d&&i.prop("placeholder",d),n("<div/>").addClass("wysiwyg-embedcode").append(i).appendTo(o);var a=n('<input type="text" value="">').addClass("wysiwyg-input").keypress(function(e){10!=e.which&&13!=e.which||t(a.val())});f&&a.prop("placeholder",f);var s=n();return c&&(s=I(c).click(function(e){return t(a.val(),i.val()),e.stopPropagation(),e.preventDefault(),!1})),o.append(n("<div/>").append(a).append(s)),o},S=function(e,t){for(var r=n("<table/>").prop("cellpadding","0").prop("cellspacing","0").prop("unselectable","on"),i=1;15>i;++i){for(var a=n("<tr/>"),s=0;25>s;++s){var l;if(24==s){var p=Math.floor(255/13*(14-i)).toString(16),c=(p.length<2?"0":"")+p;l="#"+c+c+c}else{var u=s/24,f=8>=i?i/8:1,d=i>8?(16-i)/8:1;l=o(u,f,d)}n("<td/>").addClass("wysiwyg-toolbar-color").prop("title",l).prop("unselectable","on").css({backgroundColor:l}).click(function(){var n=this.title;return t?e.forecolor(n).closePopup().collapseSelection():e.highlight(n).closePopup().collapseSelection(),!1}).appendTo(a)}r.append(a)}return r},j=function(e,t){switch(e){case"insertimage":return t?function(e){t(L(W),e)}:null;case"insertvideo":return t?function(e){t(T(W),e)}:null;case"insertlink":return t?function(e){t(x(W),e)}:null;case"bold":return function(){W.bold()};case"italic":return function(){W.italic()};case"underline":return function(){W.underline()};case"strikethrough":return function(){W.strikethrough()};case"forecolor":return t?function(e){t(S(W,!0),e)}:null;case"highlight":return t?function(e){t(S(W,!1),e)}:null;case"alignleft":return function(){W.align("left")};case"aligncenter":return function(){W.align("center")};case"alignright":return function(){W.align("right")};case"alignjustify":return function(){W.align("justify")};case"subscript":return function(){W.subscript()};case"superscript":return function(){W.superscript()};case"indent":return function(){W.indent()};case"outdent":return function(){W.indent(!0)};case"orderedList":return function(){W.insertList(!0)};case"unorderedList":return function(){W.insertList()};case"removeformat":return function(){W.removeFormat().closePopup().collapseSelection()}}return null},I=function(e){var t=n("<a/>").addClass("wysiwyg-toolbar-icon").prop("href","#").prop("unselectable","on").append(e.image);return n.each(e,function(e,n){switch(e){case"class":t.addClass(n);break;case"image":case"html":case"popup":case"click":case"showstatic":case"showselection":break;default:t.attr(e,n)}}),t},E=function(e,t,o,r){n.each(p,function(i,a){if(a&&(!(t===!1&&"showstatic"in a)||a.showstatic)&&(!(t===!0&&"showselection"in a)||a.showselection)){var s;s="click"in a?function(e){a.click(n(e))}:"popup"in a?function(e){var t=o(),i=a.popup(t,n(e));r(t,e,i)}:j(i,function(e,t){var n=o();n.append(e),r(n,t),n.find("input[type=text]:first").focus()});var l;s?l=I(a).click(function(e){return s(e.currentTarget),j(i)&&W.getElement().focus(),e.stopPropagation(),e.preventDefault(),!1}):a.html&&(l=n(a.html)),l&&e.append(l)}})},M=function(o,r,i,a){for(var s=r.get(0),l=s.offsetParent,p=0,c=0,u=!1,f=0,d=0,w=!1,h=!1,g=o.width(),y=l;y;){f+=y.offsetLeft,d+=y.offsetTop;var v=n(y),m=v.css("position");"static"!=m?u=!0:u||(p+=y.offsetLeft,c+=y.offsetTop),"fixed"==m&&(w=!0),"visible"!=v.css("overflow")&&(h=!0),y=y.offsetParent}var b=n(l||t.body);b.append(o),i+=p+s.offsetLeft,a+=c+s.offsetTop,(w||h)&&(i+g>b.width()-1&&(i=b.width()-g-1),1>i&&(i=1));var C=n(e).width();f+i+g>C-1&&(i=C-f-g-1);var k=w?0:n(e).scrollLeft();k+1>f+i&&(i=k-f+1),o.css({left:parseInt(i)+"px",top:parseInt(a)+"px"})},D={},H=null,U=function(e,t,o,r){var i=function(e,t,o,r,i,a,l){if(k){var p=H||"";switch(t){case 8:p=p.substring(0,p.length-1);case 13:case 27:case 33:case 34:case 35:case 36:case 37:case 38:case 39:case 40:if(e)return;o=!1;break;default:if(!e)return;p+=o}var c=k(p,t,o,r,i,a,l);if("object"!=typeof c||!c.length)return s.closePopup(),H=null,c;var u=n(s.openPopup());u.hide().addClass("wysiwyg-popup wysiwyg-popuphover").empty().append(c),H=p}},a={element:e.get(0),contenteditable:t?t.get(0):null,onKeyDown:function(e,t,n,o,r,a){if(m&&m(e,t,n,o,r,a)===!1)return!1;if(t&&!n&&!o&&r&&!a){var s=t.toLowerCase();if(!D[s])return;return D[s](),!1}return i(!1,e,t,n,o,r,a)},onKeyPress:function(e,t,n,o,r,a){return b&&b(e,t,n,o,r,a)===!1?!1:i(!0,e,t,n,o,r,a)},onKeyUp:function(e,t,n,o,r,i){return C&&C(e,t,n,o,r,i)===!1?!1:void 0},onSelection:function(t,o,r,i){var a=!0,p=null;if(t&&n.each(r,function(e,t){var o=n(t).closest("a");return 0!=o.length?(p=x(s,o),!1):void 0}),s.readOnly()?a=!1:o?p||i||H||(-1==n.inArray("selection",l.split("-"))?a=!1:t?a=!1:1==r.length&&"IMG"==r[0].nodeName&&(a=!1)):a=!1,!a)return void s.closePopup();var c,u=function(){var t=c.outerWidth(),r=e.parent(),i=r.offset(),a=n(s.getElement()).offset(),l=o.left+parseInt(o.width/2)-parseInt(t/2)+a.left-i.left,p=o.top+o.height+a.top-i.top;M(c,r,l,p)};c=n(s.openPopup()),c.hasClass("wysiwyg-popuphover")&&!c.data("wysiwygjs-special")==!p||(c=n(s.closePopup().openPopup())),H?c.show():c.hasClass("wysiwyg-popup")||(c.addClass("wysiwyg-popup wysiwyg-popuphover"),p?c.empty().append(p).data("wysiwygjs-special",!0):E(c,!0,function(){return c.empty()},u)),u()},onOpenpopup:function(){$()},onClosepopup:function(){H=null,z()},hijackContextmenu:"selection"==l,readOnly:!!e.prop("readonly")};r&&(a.onPlaceholder=function(e){e?r.show():r.hide()});var s=wysiwyg(a);return s},A=i.closest(".wysiwyg-container");0==A.length&&(A=n("<div/>").addClass("wysiwyg-container"),a&&A.addClass(a),i.wrap(A),A=i.closest(".wysiwyg-container"));var F=i.closest(".wysiwyg-wrapper");s&&0==F.length&&(F=n("<div/>").addClass("wysiwyg-wrapper"),i.wrap(F),F=i.closest(".wysiwyg-wrapper"));var K=null;0!=F.length&&(K=F.find(".wysiwyg-placeholder")),!s||K&&0!=K.length||(K=n("<div/>").addClass("wysiwyg-placeholder").html(s).hide(),F.prepend(K));var O=A.find(".wysiwyg-editor");0==O.length&&(O=null);var W=U(i,O,A,K);if(W.legacy){O&&O.hide(),K&&K.hide();var i=n(W.getElement());i.show().addClass("wysiwyg-textarea"),i.is(":visible")&&i.width(A.width()-(i.outerWidth()-i.width()))}else{O||n(W.getElement()).addClass("wysiwyg-editor"),F.click(function(){W.getElement().focus()});var q=null,R=null,$=function(){q&&clearTimeout(q),q=null,R&&(R(),R=null),A.addClass("wysiwyg-active"),A.find(".wysiwyg-toolbar-focus").slideDown(200)},z=function(){q||t.activeElement==W.getElement()||(q=setTimeout(function(){q=null,A.removeClass("wysiwyg-active"),0==n.trim(W.getHTML().replace(/<br\s*[\/]?>/gi,"")).length&&A.find(".wysiwyg-toolbar-focus").slideUp(200)},100))};n(W.getElement()).focus($).blur(z),i.closest("form").on("reset",z);var G={};if(n.each(p,function(e,t){if(t&&t.hotkey){var n=j(e);n&&(D[t.hotkey.toLowerCase()]=n,G[e]=n)}}),!n.isEmptyObject(p)&&"selection"!=l){var N=-1!=n.inArray("top",l.split("-")),Q=-1!=n.inArray("focus",l.split("-")),B=function(){var e=n("<div/>").addClass("wysiwyg-toolbar").addClass(N?"wysiwyg-toolbar-top":"wysiwyg-toolbar-bottom");Q&&e.hide().addClass("wysiwyg-toolbar-focus"),E(e,!1,function(){var e=n(W.openPopup());return e.hasClass("wysiwyg-popup")&&e.hasClass("wysiwyg-popuphover")&&(e=n(W.closePopup().openPopup())),e.hasClass("wysiwyg-popup")||e.addClass("wysiwyg-popup"),e},function(e,t,o){var r=n(t),i=e.outerWidth(),a=r.offset().left-A.offset().left+parseInt(r.width()/2)-parseInt(i/2),s=r.offset().top-A.offset().top;N?s+=r.outerHeight():s-=e.outerHeight(),o&&(a=o.left,s=o.top),M(e,A,a,s)}),N?A.prepend(e):A.append(e)};Q?R=B:B()}}return{wysiwygeditor:W,$container:A}};n.fn.wysiwyg=function(e,t){if(!e||"object"==typeof e)return e=n.extend({},e),this.each(function(){var t=n(this);if(!t.data("wysiwygjs")){var o=e["class"],r=e.placeholder||t.prop("placeholder"),a=e.toolbar||"top",s=e.buttons||{},l=e.submit,p=e.selectImage,c=e.placeholderUrl||null,u=e.placeholderEmbed||null,f=e.maxImageSize||null,d=e.filterImageType||"^image/",w=e.onImageUpload||null,h=e.forceImageUpload&&w,g=e.videoFromUrl||null,y=e.onKeyDown||null,v=e.onKeyPress||null,m=e.onKeyUp||null,b=e.onAutocomplete||null,C=i(t,o,r,a,s,l,p,c,u,f,d,w,h,g,y,v,m,b);t.data("wysiwygjs",C)}});if(1==this.length){var o=this.data("wysiwygjs");if(!o)return this;if("container"==e)return o.$container;if("shell"==e)return o.wysiwygeditor}return this}});
