/** Trumbowyg v2.24.0 - A lightweight WYSIWYG editor - alex-d.github.io/Trumbowyg - License MIT - Author : Alexandre Demode (Alex-D) / alex-d.fr */
/**
 * Trumbowyg v2.24.0 - A lightweight WYSIWYG editor
 * Trumbowyg core file
 * ------------------------
 * @link http://alex-d.github.io/Trumbowyg
 * @license MIT
 * @author Alexandre Demode (Alex-D)
 *         Twitter : @AlexandreDemode
 *         Website : alex-d.fr
 */
jQuery.trumbowyg={langs:{en:{viewHTML:"Plain Text",undo:"Undo",redo:"Redo",formatting:"Formatting",p:"Paragraph",blockquote:"Quote",code:"Code",header:"Header",bold:"Bold",italic:"Italic",strikethrough:"Strikethrough",underline:"Underline",strong:"Strong",em:"Emphasis",del:"Deleted",superscript:"Superscript",subscript:"Subscript",unorderedList:"Unordered list",orderedList:"Ordered list",insertImage:"Insert Image",link:"Link",createLink:"Insert link",unlink:"Remove link",justifyLeft:"Align Left",justifyCenter:"Align Center",justifyRight:"Align Right",justifyFull:"Align Justify",horizontalRule:"Insert horizontal rule",removeformat:"Remove format",fullscreen:"Fullscreen",close:"Close",submit:"Confirm",reset:"Cancel",required:"Required",description:"Description",title:"Title",text:"Text",target:"Target",width:"Width"}},plugins:{},svgPath:null,svgAbsoluteUseHref:!1,hideButtonTexts:null},Object.defineProperty(jQuery.trumbowyg,"defaultOptions",{value:{lang:"en",fixedBtnPane:!1,fixedFullWidth:!1,autogrow:!1,autogrowOnEnter:!1,imageWidthModalEdit:!1,hideButtonTexts:null,prefix:"trumbowyg-",tagClasses:{},semantic:!0,semanticKeepAttributes:!1,resetCss:!1,removeformatPasted:!1,tabToIndent:!1,tagsToRemove:[],tagsToKeep:["hr","img","embed","iframe","input"],btns:[["viewHTML"],["undo","redo"],["formatting"],["strong","em","del"],["superscript","subscript"],["link"],["insertImage"],["justifyLeft","justifyCenter","justifyRight","justifyFull"],["unorderedList","orderedList"],["horizontalRule"],["removeformat"],["fullscreen"]],btnsDef:{},changeActiveDropdownIcon:!1,inlineElementsSelector:"a,abbr,acronym,b,caption,cite,code,col,dfn,dir,dt,dd,em,font,hr,i,kbd,li,q,span,strikeout,strong,sub,sup,u",pasteHandlers:[],plugins:{},urlProtocol:!1,minimalLinks:!1,defaultLinkTarget:void 0,svgPath:null},writable:!1,enumerable:!0,configurable:!1}),function(l,d,c,u){"use strict";var g="tbwconfirm",h="tbwcancel";u.fn.trumbowyg=function(e,t){var n="trumbowyg";if(e===Object(e)||!e)return this.each(function(){u(this).data(n)||u(this).data(n,new o(this,e))});if(1===this.length)try{var a=u(this).data(n);switch(e){case"execCmd":return a.execCmd(t.cmd,t.param,t.forceCss,t.skipTrumbowyg);case"openModal":return a.openModal(t.title,t.content);case"closeModal":return a.closeModal();case"openModalInsert":return a.openModalInsert(t.title,t.fields,t.callback);case"saveRange":return a.saveRange();case"getRange":return a.range;case"getRangeText":return a.getRangeText();case"restoreRange":return a.restoreRange();case"enable":return a.setDisabled(!1);case"disable":return a.setDisabled(!0);case"toggle":return a.toggle();case"destroy":return a.destroy();case"empty":return a.empty();case"html":return a.html(t)}}catch(e){}return!1};var o=function(e,t){var n=this,a="trumbowyg-icons",o=u.trumbowyg;n.doc=e.ownerDocument||c,n.$ta=u(e),n.$c=u(e),null!=(t=t||{}).lang||null!=o.langs[t.lang]?n.lang=u.extend(!0,{},o.langs.en,o.langs[t.lang]):n.lang=o.langs.en,n.hideButtonTexts=(null!=o.hideButtonTexts?o:t).hideButtonTexts;var r,i=(null!=o.svgPath?o:t).svgPath;n.hasSvg=!1!==i,!1===i||!o.svgAbsoluteUseHref&&0!==u("#"+a,n.doc).length||(null==i&&u("script[src]").each(function(e,t){var n=t.src,t=n.match("trumbowyg(.min)?.js");null!=t&&(i=n.substring(0,n.indexOf(t[0]))+"ui/icons.svg")}),null==i?console.warn("You must define svgPath: https://goo.gl/CfTY9U"):o.svgAbsoluteUseHref||((r=n.doc.createElement("div")).id=a,n.doc.body.insertBefore(r,n.doc.body.childNodes[0]),u.ajax({async:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",dataType:"xml",crossDomain:!0,url:i,data:null,beforeSend:null,complete:null,success:function(e){r.innerHTML=(new XMLSerializer).serializeToString(e.documentElement)}})));var s=n.doc.querySelector("base")?d.location.href.split(/[?#]/)[0]:"";n.svgPath=o.svgAbsoluteUseHref?i:s;a=n.lang.header,s=function(){return(d.chrome||d.Intl&&Intl.v8BreakIterator)&&"CSS"in d};n.btnsDef={viewHTML:{fn:"toggle",class:"trumbowyg-not-disable",name1:"name1"},undo:{isSupported:s,key:"Z"},redo:{isSupported:s,key:"Y"},p:{fn:"formatBlock"},blockquote:{fn:"formatBlock"},h1:{fn:"formatBlock",title:a+" 1"},h2:{fn:"formatBlock",title:a+" 2"},h3:{fn:"formatBlock",title:a+" 3"},h4:{fn:"formatBlock",title:a+" 4"},h5:{fn:"formatBlock",title:a+" 5"},h6:{fn:"formatBlock",title:a+" 6"},subscript:{tag:"sub"},superscript:{tag:"sup"},bold:{key:"B",tag:"b"},italic:{key:"I",tag:"i"},underline:{tag:"u"},strikethrough:{tag:"strike"},strong:{fn:"bold",key:"B"},em:{fn:"italic",key:"I"},del:{fn:"strikethrough"},createLink:{key:"K",tag:"a"},unlink:{},insertImage:{},justifyLeft:{tag:"left",forceCss:!0},justifyCenter:{tag:"center",forceCss:!0},justifyRight:{tag:"right",forceCss:!0},justifyFull:{tag:"justify",forceCss:!0},unorderedList:{fn:"insertUnorderedList",tag:"ul"},orderedList:{fn:"insertOrderedList",tag:"ol"},horizontalRule:{fn:"insertHorizontalRule"},removeformat:{},fullscreen:{class:"trumbowyg-not-disable"},close:{fn:"destroy",class:"trumbowyg-not-disable"},formatting:{dropdown:["p","h1","h2","h3","h4"],ico:"p"},link:{dropdown:["createLink","unlink"]}},n.o=u.extend(!0,{},o.defaultOptions,t),n.o.hasOwnProperty("imgDblClickHandler")||(n.o.imgDblClickHandler=n.getDefaultImgDblClickHandler()),n.urlPrefix=n.setupUrlPrefix(),n.disabled=n.o.disabled||"TEXTAREA"===e.nodeName&&e.disabled,t.btns?n.o.btns=t.btns:n.o.semantic||(n.o.btns[3]=["bold","italic","underline","strikethrough"]),u.each(n.o.btnsDef,function(e,t){n.addBtnDef(e,t)}),n.eventNamespace="trumbowyg-event",n.keys=[],n.tagToButton={},n.tagHandlers=[],n.pasteHandlers=[].concat(n.o.pasteHandlers),n.isIE=-1!==l.userAgent.indexOf("MSIE")||-1!==l.appVersion.indexOf("Trident/"),n.isMac=-1!==l.platform.toUpperCase().indexOf("MAC"),n.init()};o.prototype={DEFAULT_SEMANTIC_MAP:{b:"strong",i:"em",s:"del",strike:"del",div:"p"},init:function(){var e=this;e.height=e.$ta.height(),e.initPlugins();try{e.doc.execCommand("enableObjectResizing",!1,!1),e.doc.execCommand("defaultParagraphSeparator",!1,"p")}catch(e){}e.buildEditor(),e.buildBtnPane(),e.fixedBtnPaneEvents(),e.buildOverlay(),setTimeout(function(){e.disabled&&e.setDisabled(!0),e.$c.trigger("tbwinit")})},addBtnDef:function(e,t){this.btnsDef[e]=u.extend(t,this.btnsDef[e]||{})},setupUrlPrefix:function(){var e=this.o.urlProtocol;if(e)return"string"!=typeof e?"https://":e.replace("://","")+"://"},buildEditor:function(){var a=this,t=a.o.prefix,e="";a.$box=u("<div/>",{class:t+"box "+t+"editor-visible "+t+a.o.lang+" trumbowyg"}),a.isTextarea=a.$ta.is("textarea"),a.isTextarea?(e=a.$ta.val(),a.$ed=u("<div/>"),a.$box.insertAfter(a.$ta).append(a.$ed,a.$ta)):(a.$ed=a.$ta,e=a.$ed.html(),a.$ta=u("<textarea/>",{name:a.$ta.attr("id"),height:a.height}).val(e),a.$box.insertAfter(a.$ed).append(a.$ta,a.$ed),a.syncCode()),a.$ta.addClass(t+"textarea").attr("tabindex",-1),a.$ed.addClass(t+"editor").attr({contenteditable:!0,dir:a.lang._dir||"ltr"}).html(e),a.o.tabindex&&a.$ed.attr("tabindex",a.o.tabindex),a.$c.is("[placeholder]")&&a.$ed.attr("placeholder",a.$c.attr("placeholder")),a.$c.is("[spellcheck]")&&a.$ed.attr("spellcheck",a.$c.attr("spellcheck")),a.o.resetCss&&a.$ed.addClass(t+"reset-css"),a.o.autogrow||a.$ta.add(a.$ed).css({height:a.height}),a.semanticCode(),a.o.autogrowOnEnter&&a.$ed.addClass(t+"autogrow-on-enter");var n,o=!1,r=!1;a.$ed.on("dblclick","img",a.o.imgDblClickHandler).on("keydown",function(e){var t=e.which;if(8!==t&&13!==t&&46!==t||a.toggleSpan(!0),!e.ctrlKey&&!e.metaKey||e.altKey){if(a.o.tabToIndent&&"Tab"===e.key)try{return e.shiftKey?a.execCmd("outdent",!0,null):a.execCmd("indent",!0,null),!1}catch(e){}}else{o=!0;var n=a.keys[String.fromCharCode(e.which).toUpperCase()];try{return a.execCmd(n.fn,n.param),!1}catch(e){}}}).on("compositionstart compositionupdate",function(){r=!0}).on("keyup compositionend",function(e){if("compositionend"===e.type)r=!1;else if(r)return;var t=e.which;37<=t&&t<=40||(8!==t&&13!==t&&46!==t||a.toggleSpan(),!e.ctrlKey&&!e.metaKey||89!==t&&90!==t?o||17===t?void 0===e.which&&a.semanticCode(!1,!1,!0):(e=!a.isIE||"compositionend"===e.type,a.semanticCode(!1,e&&13===t),a.$c.trigger("tbwchange")):(a.semanticCode(!1,!0),a.$c.trigger("tbwchange")),setTimeout(function(){o=!1},50))}).on("mouseup keydown keyup",function(e){(e.ctrlKey||e.metaKey)&&!e.altKey||setTimeout(function(){o=!1},50),clearTimeout(n),n=setTimeout(function(){a.updateButtonPaneStatus()},50)}).on("focus blur",function(e){"blur"===e.type&&a.clearButtonPaneStatus(),a.$c.trigger("tbw"+e.type),a.o.autogrowOnEnter&&(a.autogrowOnEnterDontClose||("focus"===e.type?(a.autogrowOnEnterWasFocused=!0,a.autogrowEditorOnEnter()):a.o.autogrow||(a.$ed.css({height:a.$ed.css("min-height")}),a.$c.trigger("tbwresize"))))}).on("keyup focus",function(){a.$ta.val().match(/<.*>/)||a.$ed.html().match(/<.*>/)||setTimeout(function(){var e=a.isIE?"<p>":"p";a.doc.execCommand("formatBlock",!1,e),a.syncCode()},0)}).on("cut drop",function(){setTimeout(function(){a.semanticCode(!1,!0),a.$c.trigger("tbwchange")},0)}).on("paste",function(n){if(a.o.removeformatPasted){n.preventDefault(),d.getSelection&&d.getSelection().deleteFromDocument&&d.getSelection().deleteFromDocument();try{var t=d.clipboardData.getData("Text");try{a.doc.selection.createRange().pasteHTML(t)}catch(e){a.doc.getSelection().getRangeAt(0).insertNode(a.doc.createTextNode(t))}a.$c.trigger("tbwchange",n)}catch(e){a.execCmd("insertText",(n.originalEvent||n).clipboardData.getData("text/plain"))}}u.each(a.pasteHandlers,function(e,t){t(n)}),setTimeout(function(){a.semanticCode(!1,!0),a.$c.trigger("tbwpaste",n),a.$c.trigger("tbwchange")},0)}),a.$ta.on("keyup",function(){a.$c.trigger("tbwchange")}).on("paste",function(){setTimeout(function(){a.$c.trigger("tbwchange")},0)}),u(a.doc.body).on("keydown."+a.eventNamespace,function(e){if(27===e.which&&1<=u("."+t+"modal-box").length)return a.closeModal(),!1})},autogrowEditorOnEnter:function(){var e=this;e.$ed.removeClass("autogrow-on-enter");var t=e.$ed[0].clientHeight;e.$ed.height("auto");var n=e.$ed[0].scrollHeight;e.$ed.addClass("autogrow-on-enter"),t!==n&&(e.$ed.height(t),setTimeout(function(){e.$ed.css({height:n}),e.$c.trigger("tbwresize")},0))},buildBtnPane:function(){var a=this,o=a.o.prefix,r=a.$btnPane=u("<div/>",{class:o+"button-pane"});u.each(a.o.btns,function(e,t){u.isArray(t)||(t=[t]);var n=u("<div/>",{class:o+"button-group "+(0<=t.indexOf("fullscreen")?o+"right":"")});u.each(t,function(e,t){try{a.isSupportedBtn(t)&&n.append(a.buildBtn(t))}catch(e){}}),0<n.html().trim().length&&r.append(n)}),a.$box.prepend(r)},buildBtn:function(e){var n,a=this,t=a.o.prefix,o=a.btnsDef[e],r=o.dropdown,i=null==o.hasIcon||o.hasIcon,s=a.lang[e]||e,l=u("<button/>",{type:"button",class:t+e+"-button "+(o.class||"")+(i?"":" "+t+"textual-button"),html:!o.name1&&a.hasSvg&&i?'<svg><use xlink:href="'+a.svgPath+"#"+t+(o.ico||e).replace(/([A-Z]+)/g,"-$1").toLowerCase()+'"/></svg>':a.hideButtonTexts?"":o.text||o.title||a.lang[e]||e,title:(o.title||o.text||s)+(o.key?" ("+(a.isMac?"Cmd":"Ctrl")+" + "+o.key+")":""),tabindex:-1,mousedown:function(){return r&&!u("."+e+"-"+t+"dropdown",a.$box).is(":hidden")||u("body",a.doc).trigger("mousedown"),(!a.$btnPane.hasClass(t+"disable")&&!a.$box.hasClass(t+"disabled")||u(this).hasClass(t+"active")||u(this).hasClass(t+"not-disable"))&&a.execCmd((!r?o.fn:"dropdown")||e,o.param||e,o.forceCss),!1}});return r?(l.addClass(t+"open-dropdown"),(s={class:(i=t+"dropdown")+"-"+e+" "+i+" "+t+"fixed-top "+(o.dropdownClass||"")})["data-"+i]=e,n=u("<div/>",s),u.each(r,function(e,t){a.btnsDef[t]&&a.isSupportedBtn(t)&&n.append(a.buildSubBtn(t))}),a.$box.append(n.hide())):o.key&&(a.keys[o.key]={fn:o.fn||e,param:o.param||e}),r||(a.tagToButton[(o.tag||e).toLowerCase()]=e),l},buildSubBtn:function(e){var t=this,n=t.o.prefix,a=t.btnsDef[e],o=null==a.hasIcon||a.hasIcon;return a.key&&(t.keys[a.key]={fn:a.fn||e,param:a.param||e}),t.tagToButton[(a.tag||e).toLowerCase()]=e,u("<button/>",{type:"button",class:n+e+"-dropdown-button "+(a.class||"")+(a.ico?" "+n+a.ico+"-button":""),html:t.hasSvg&&o?'<svg><use xlink:href="'+t.svgPath+"#"+n+(a.ico||e).replace(/([A-Z]+)/g,"-$1").toLowerCase()+'"/></svg>'+(a.text||a.title||t.lang[e]||e):a.text||a.title||t.lang[e]||e,title:a.key?"("+(t.isMac?"Cmd":"Ctrl")+" + "+a.key+")":null,style:a.style||null,mousedown:function(){return u("body",t.doc).trigger("mousedown"),t.execCmd(a.fn||e,a.param||e,a.forceCss),!1}})},isSupportedBtn:function(e){try{return this.btnsDef[e].isSupported()}catch(e){}return!0},buildOverlay:function(){return this.$overlay=u("<div/>",{class:this.o.prefix+"overlay"}).appendTo(this.$box),this.$overlay},showOverlay:function(){u(d).trigger("scroll"),this.$overlay.fadeIn(200),this.$box.addClass(this.o.prefix+"box-blur")},hideOverlay:function(){this.$overlay.fadeOut(50),this.$box.removeClass(this.o.prefix+"box-blur")},fixedBtnPaneEvents:function(){var o=this,r=o.o.fixedFullWidth,i=o.$box;o.o.fixedBtnPane&&(o.isFixed=!1,u(d).on("scroll."+o.eventNamespace+" resize."+o.eventNamespace,function(){var e,t,n,a;i&&(o.syncCode(),e=u(d).scrollTop(),t=i.offset().top+1,a=(n=o.$btnPane).outerHeight()-2,0<e-t&&e-t-o.height<0?(o.isFixed||(o.isFixed=!0,n.css({position:"fixed",top:0,left:r?0:"auto",zIndex:7}),o.$box.css({paddingTop:n.height()})),n.css({width:r?"100%":i.width()-1}),u("."+o.o.prefix+"fixed-top",i).css({position:r?"fixed":"absolute",top:r?a:e-t+a,zIndex:15})):o.isFixed&&(o.isFixed=!1,n.removeAttr("style"),o.$box.css({paddingTop:0}),u("."+o.o.prefix+"fixed-top",i).css({position:"absolute",top:a})))}))},setDisabled:function(e){var t=this,n=t.o.prefix;(t.disabled=e)?t.$ta.attr("disabled",!0):t.$ta.removeAttr("disabled"),t.$box.toggleClass(n+"disabled",e),t.$ed.attr("contenteditable",!e)},destroy:function(){var e=this,t=e.o.prefix;e.isTextarea?e.$box.after(e.$ta.css({height:""}).val(e.html()).removeClass(t+"textarea").show()):e.$box.after(e.$ed.css({height:""}).removeClass(t+"editor").removeAttr("contenteditable").removeAttr("dir").html(e.html()).show()),e.$ed.off("dblclick","img"),e.destroyPlugins(),e.$box.remove(),e.$c.removeData("trumbowyg"),u("body").removeClass(t+"body-fullscreen"),e.$c.trigger("tbwclose"),u(d).off("scroll."+e.eventNamespace+" resize."+e.eventNamespace),u(e.doc.body).off("keydown."+e.eventNamespace)},empty:function(){this.$ta.val(""),this.syncCode(!0)},toggle:function(){var e=this,t=e.o.prefix;e.o.autogrowOnEnter&&(e.autogrowOnEnterDontClose=!e.$box.hasClass(t+"editor-hidden")),e.semanticCode(!1,!0),e.$c.trigger("tbwchange"),setTimeout(function(){e.doc.activeElement.blur(),e.$box.toggleClass(t+"editor-hidden "+t+"editor-visible"),e.$btnPane.toggleClass(t+"disable"),e.$btnPane.find(".trumbowyg-viewHTML-button").text(e.$box.hasClass(t+"editor-hidden")?"Formatted Text":"Plain Text").attr("data-original-title",e.$box.hasClass(t+"editor-hidden")?"Formatted Text":"Plain Text"),u("."+t+"viewHTML-button",e.$btnPane).toggleClass(t+"active"),e.$box.hasClass(t+"editor-visible")?e.$ta.attr("tabindex",-1):e.$ta.removeAttr("tabindex"),e.o.autogrowOnEnter&&!e.autogrowOnEnterDontClose&&e.autogrowEditorOnEnter()},0)},toggleSpan:function(e){this.$ed.find("span").each(function(){!0===e?u(this).attr("data-tbw-flag",!0):u(this).attr("data-tbw-flag")?u(this).removeAttr("data-tbw-flag"):u(this).contents().unwrap()})},dropdown:function(e){var t=this,n=u("body",t.doc),a=t.o.prefix,o=u("[data-"+a+"dropdown="+e+"]",t.$box),r=u("."+a+e+"-button",t.$btnPane),e=o.is(":hidden");n.trigger("mousedown"),e&&(e=r.offset().left,r.addClass(a+"active"),o.css({position:"absolute",top:r.offset().top-t.$btnPane.offset().top+r.outerHeight(),left:t.o.fixedFullWidth&&t.isFixed?e:e-t.$btnPane.offset().left}).show(),u(d).trigger("scroll"),n.on("mousedown."+t.eventNamespace,function(e){o.is(e.target)||(u("."+a+"dropdown",t.$box).hide(),u("."+a+"active",t.$btnPane).removeClass(a+"active"),n.off("mousedown."+t.eventNamespace))}))},html:function(e){var t=this;return null!=e?(t.$ta.val(e),t.syncCode(!0),t.$c.trigger("tbwchange"),t):t.$ta.val()},syncTextarea:function(){var e=this;e.$ta.val(0<e.$ed.text().trim().length||0<e.$ed.find(e.o.tagsToKeep.join(",")).length?e.$ed.html():"")},syncCode:function(e){var t,n=this;!e&&n.$ed.is(":visible")?n.syncTextarea():(t=u("<div>").html(n.$ta.val()),t=u("<div>").append(t),u(n.o.tagsToRemove.join(","),t).remove(),n.$ed.html(t.contents().html())),n.o.autogrow&&(n.height=n.$ed.height(),n.height!==n.$ta.css("height")&&(n.$ta.css({height:n.height}),n.$c.trigger("tbwresize"))),n.o.autogrowOnEnter&&(n.$ed.height("auto"),(t=n.autogrowOnEnterWasFocused?n.$ed[0].scrollHeight:n.$ed.css("min-height"))!==n.$ta.css("height")&&(n.$ed.css({height:t}),n.$c.trigger("tbwresize")))},semanticCode:function(e,t,n){var a=this;a.saveRange(),a.syncCode(e);var o,r,i,e=!0;a.range&&a.range.collapsed&&(e=!1),a.o.semantic&&(a.semanticTag("b",a.o.semanticKeepAttributes),a.semanticTag("i",a.o.semanticKeepAttributes),a.semanticTag("s",a.o.semanticKeepAttributes),t&&(o=a.o.inlineElementsSelector,r=":not("+o+")",a.$ed.contents().filter(function(){return 3===this.nodeType&&0<this.nodeValue.trim().length}).wrap("<span data-tbw/>"),(i=function(e){var t;0!==e.length&&(e=(t=e.nextUntil(r).addBack().wrapAll("<p/>").parent()).nextAll(o).first(),t.next("br").remove(),i(e))})(a.$ed.children(o).first()),a.semanticTag("div",!0),u("[data-tbw]",a.$ed).contents().unwrap(),a.$ed.find("p:empty").remove()),!n&&e&&a.restoreRange(),a.syncTextarea())},semanticTag:function(e,a,t){var o,r=this,n=e;if(null!=this.o.semantic&&"object"==typeof this.o.semantic&&this.o.semantic.hasOwnProperty(e))o=this.o.semantic[e];else{if(!0!==this.o.semantic||!this.DEFAULT_SEMANTIC_MAP.hasOwnProperty(e))return;o=this.DEFAULT_SEMANTIC_MAP[e]}t&&(e=o,o=n),u(e,this.$ed).each(function(){var e=!1,t=u(this);if(0===t.contents().length)return!1;r.range.startContainer.parentNode&&r.range.startContainer.parentNode===this&&(e=!0);var n=u("<"+o+"/>");n.insertBefore(t),a&&u.each(t.prop("attributes"),function(){n.attr(this.name,this.value)}),n.html(t.html()),t.remove(),!0===e&&(r.range.selectNodeContents(n.get(0)),r.range.collapse(!1))})},createLink:function(){for(var e,t,n,a=this,o=a.doc.getSelection(),r=o.getRangeAt(0),i=o.focusNode,s=(new XMLSerializer).serializeToString(r.cloneContents())||r+"";["A","DIV"].indexOf(i.nodeName)<0;)i=i.parentNode;i&&"A"===i.nodeName&&(s=(r=u(i)).text(),n=r.attr("href"),a.o.minimalLinks||(e=r.attr("title"),t=r.attr("target")||a.o.defaultLinkTarget),(r=a.doc.createRange()).selectNode(i),o.removeAllRanges(),o.addRange(r)),a.saveRange();s={url:{label:a.lang.linkUrl||"URL",required:!0,value:n},text:{label:a.lang.text,value:s}};a.o.minimalLinks||u.extend(s,{title:{label:a.lang.title,value:e},target:{label:a.lang.target,value:t}}),a.openModalInsert(a.lang.createLink,s,function(e){var t=a.prependUrlPrefix(e.url);if(!t.length)return!1;t=u(['<a href="',t,'">',e.text||e.url,"</a>"].join(""));return e.title&&t.attr("title",e.title),(e.target||a.o.defaultLinkTarget)&&t.attr("target",e.target||a.o.defaultLinkTarget),a.range.deleteContents(),a.range.insertNode(t[0]),a.syncCode(),a.$c.trigger("tbwchange"),!0})},prependUrlPrefix:function(e){if(!this.urlPrefix)return e;if(/^([a-z][-+.a-z0-9]*:|\/|#)/i.test(e))return e;return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?"mailto:"+e:this.urlPrefix+e},unlink:function(){var e,t=this.doc.getSelection(),n=t.focusNode;if(t.isCollapsed){for(;["A","DIV"].indexOf(n.nodeName)<0;)n=n.parentNode;n&&"A"===n.nodeName&&((e=this.doc.createRange()).selectNode(n),t.removeAllRanges(),t.addRange(e))}this.execCmd("unlink",void 0,void 0,!0)},insertImage:function(){var n=this;n.saveRange();var e={url:{label:"URL",required:!0},alt:{label:n.lang.description,value:n.getRangeText()}};n.o.imageWidthModalEdit&&(e.width={}),n.openModalInsert(n.lang.insertImage,e,function(e){n.execCmd("insertImage",e.url,!1,!0);var t=u('img[src="'+e.url+'"]:not([alt])',n.$box);return t.attr("alt",e.alt),n.o.imageWidthModalEdit&&t.attr({width:e.width}),n.syncCode(),n.$c.trigger("tbwchange"),!0})},fullscreen:function(){var e=this,t=e.o.prefix,n=t+"fullscreen",a=n+"-placeholder",o=e.$box.outerHeight();e.$box.toggleClass(n),(n=e.$box.hasClass(n))?e.$box.before(u("<div/>",{class:a}).css({height:o})):u("."+a).remove(),u("body").toggleClass(t+"body-fullscreen",n),u(d).trigger("scroll"),e.$c.trigger("tbw"+(n?"open":"close")+"fullscreen")},execCmd:function(t,n,e,a){var o=this;a=!!a||"","dropdown"!==t&&o.$ed.focus(),"strikethrough"===t&&o.o.semantic&&o.semanticTag("strike",o.o.semanticKeepAttributes,!0);try{o.doc.execCommand("styleWithCSS",!1,e||!1)}catch(e){}try{o[t+a](n)}catch(e){try{t(n)}catch(e){"insertHorizontalRule"===t?n=void 0:"formatBlock"===t&&o.isIE&&(n="<"+n+">"),o.doc.execCommand(t,!1,n),o.syncCode(),o.semanticCode(!1,!0);try{var r=d.getSelection().focusNode;u(d.getSelection().focusNode.parentNode).hasClass("trumbowyg-editor")||(r=d.getSelection().focusNode.parentNode);var i=o.o.tagClasses[n];i&&u(r).addClass(i)}catch(e){}}"dropdown"!==t&&(o.updateButtonPaneStatus(),o.$c.trigger("tbwchange"))}},openModal:function(e,t,n){var a=this,o=a.o.prefix;if(n=!1!==n,0<u("."+o+"modal-box",a.$box).length)return!1;a.o.autogrowOnEnter&&(a.autogrowOnEnterDontClose=!0),a.saveRange(),a.showOverlay(),a.$btnPane.addClass(o+"disable");var r=u("<div/>",{class:o+"modal "+o+"fixed-top"}).css({top:a.$box.offset().top+a.$btnPane.height(),zIndex:99999}).appendTo(u(a.doc.body));a.$overlay.one("click",function(){return r.trigger(h),!1}),t=n?u("<form/>",{action:"",html:t}).on("submit",function(){return r.trigger(g),!1}).on("reset",function(){return r.trigger(h),!1}).on("submit reset",function(){a.o.autogrowOnEnter&&(a.autogrowOnEnterDontClose=!1)}):t;t=u("<div/>",{class:o+"modal-box",html:t}).css({top:"-"+a.$btnPane.outerHeight(),opacity:0,paddingBottom:n?null:"5%"}).appendTo(r).animate({top:0,opacity:1},100);return e&&u("<span/>",{text:e,class:o+"modal-title"}).prependTo(t),n&&(u("input:first",t).focus(),a.buildModalBtn("submit",t),a.buildModalBtn("reset",t),r.height(t.outerHeight()+10)),u(d).trigger("scroll"),a.$c.trigger("tbwmodalopen"),r},buildModalBtn:function(e,t){var n=this.o.prefix;return u("<button/>",{class:n+"modal-button "+n+"modal-"+e,type:e,text:this.lang[e]||e}).appendTo(u("form",t))},closeModal:function(){var e=this,t=e.o.prefix;e.$btnPane.removeClass(t+"disable"),e.$overlay.off();var n=u("."+t+"modal-box",u(e.doc.body));n.animate({top:"-"+n.height()},100,function(){n.parent().remove(),e.hideOverlay(),e.$c.trigger("tbwmodalclose")}),e.restoreRange()},openModalInsert:function(e,t,n){var s=this,r=s.o.prefix,i=s.lang,l="";return u.each(t,function(e,t){var n=t.label||e,a=t.name||e,o=t.attributes||{},e=Object.keys(o).map(function(e){return e+'="'+o[e]+'"'}).join(" ");l+='<label><input type="'+(t.type||"text")+'" name="'+a+'"'+("checkbox"===t.type&&t.value?' checked="checked"':' value="'+(t.value||"").replace(/"/g,"&quot;"))+'"'+e+'><span class="'+r+'input-infos"><span>'+(i[n]||n)+"</span></span></label>"}),s.openModal(e,l).on(g,function(){var o=u("form",u(this)),r=!0,i={};u.each(t,function(e,t){var n=t.name||e,a=u('input[name="'+n+'"]',o);switch(a.attr("type").toLowerCase()){case"checkbox":i[n]=a.is(":checked");break;case"radio":i[n]=a.filter(":checked").val();break;default:i[n]=u.trim(a.val())}t.required&&""===i[n]?(r=!1,s.addErrorOnModalField(a,s.lang.required)):t.pattern&&!t.pattern.test(i[n])&&(r=!1,s.addErrorOnModalField(a,t.patternError))}),r&&(s.restoreRange(),n(i,t)&&(s.syncCode(),s.$c.trigger("tbwchange"),s.closeModal(),u(this).off(g)))}).one(h,function(){u(this).off(g),s.closeModal()})},addErrorOnModalField:function(e,t){var n=this.o.prefix,a=n+"msg-error",o=e.parent();e.on("change keyup",function(){o.removeClass(n+"input-error"),setTimeout(function(){o.find("."+a).remove()},150)}),o.addClass(n+"input-error").find("input+span").append(u("<span/>",{class:a,text:t}))},getDefaultImgDblClickHandler:function(){var a=this;return function(){var t=u(this),e=t.attr("src"),n="(Base64)";0===e.indexOf("data:image")&&(e=n);e={url:{label:"URL",value:e,required:!0},alt:{label:a.lang.description,value:t.attr("alt")}};return a.o.imageWidthModalEdit&&(e.width={value:t.attr("width")?t.attr("width"):""}),a.openModalInsert(a.lang.insertImage,e,function(e){return e.url!==n&&t.attr({src:e.url}),t.attr({alt:e.alt}),a.o.imageWidthModalEdit&&(0<parseInt(e.width)?t.attr({width:e.width}):t.removeAttr("width")),!0}),!1}},saveRange:function(){var e,t=this,n=t.doc.getSelection();t.range=null,n&&n.rangeCount&&(e=t.range=n.getRangeAt(0),(n=t.doc.createRange()).selectNodeContents(t.$ed[0]),n.setEnd(e.startContainer,e.startOffset),n=(n+"").length,t.metaRange={start:n,end:n+(e+"").length})},restoreRange:function(){var e=this,t=e.metaRange,n=e.range,a=e.doc.getSelection();if(n){if(t&&t.start!==t.end)for(var o,r=0,i=[e.$ed[0]],s=!1,l=!1,d=e.doc.createRange();!l&&(o=i.pop());)if(3===o.nodeType){var c=r+o.length;!s&&t.start>=r&&t.start<=c&&(d.setStart(o,t.start-r),s=!0),s&&t.end>=r&&t.end<=c&&(d.setEnd(o,t.end-r),l=!0),r=c}else for(var u=o.childNodes,g=u.length;0<g;)--g,i.push(u[g]);try{a.removeAllRanges()}catch(e){}a.addRange(d||n)}},getRangeText:function(){return this.range+""},clearButtonPaneStatus:function(){var e=this.o.prefix,t=e+"active-button "+e+"active",n=e+"original-icon";u("."+e+"active-button",this.$btnPane).removeClass(t),u("."+n,this.$btnPane).each(function(){u(this).find("svg use").attr("xlink:href",u(this).data(n))})},updateButtonPaneStatus:function(){var s=this,l=s.o.prefix,d=l+"active-button "+l+"active",c=l+"original-icon",e=s.getTagsRecursive(s.doc.getSelection().focusNode);s.clearButtonPaneStatus(),u.each(e,function(e,t){var n=s.tagToButton[t.toLowerCase()],a=u("."+l+n+"-button",s.$btnPane);if(0<a.length)a.addClass(d);else try{var o=(a=u("."+l+"dropdown ."+l+n+"-dropdown-button",s.$box)).find("svg use"),r=a.parent().data(l+"dropdown"),i=u("."+l+r+"-button",s.$box),r=i.find("svg use");i.addClass(d),s.o.changeActiveDropdownIcon&&0<o.length&&(i.addClass(c).data(c,r.attr("xlink:href")),r.attr("xlink:href",o.attr("xlink:href")))}catch(e){}})},getTagsRecursive:function(n,a){var o=this;if(a=a||(n&&n.tagName?[n.tagName]:[]),!n||!n.parentNode)return a;var e=(n=n.parentNode).tagName;return"DIV"===e?a:("P"===e&&""!==n.style.textAlign&&a.push(n.style.textAlign),u.each(o.tagHandlers,function(e,t){a=a.concat(t(n,o))}),a.push(e),o.getTagsRecursive(n,a).filter(function(e){return null!=e}))},initPlugins:function(){var n=this;n.loadedPlugins=[],u.each(u.trumbowyg.plugins,function(e,t){t.shouldInit&&!t.shouldInit(n)||(t.init(n),t.tagHandler&&n.tagHandlers.push(t.tagHandler),n.loadedPlugins.push(t))})},destroyPlugins:function(){var n=this;u.each(this.loadedPlugins,function(e,t){t.destroy&&t.destroy(n)})}}}(navigator,window,document,jQuery);