!function(e){e.fn.richText=function(t){function a(){var t,a,n="";C.useParagraph!==!1&&document.execCommand("DefaultParagraphSeparator",!1,"p"),"TEXTAREA"===N.prop("tagName")||(N.val()?(t=N.val(),a=N.prop("attributes"),e.each(a,function(){this.name&&(n+=" "+this.name+'="'+this.value+'"')}),N.replaceWith(e("'+t+"")),N=e('[data-richtext="init"]'),N.removeAttr("data-richtext")):N.html()?(t=N.html(),a=N.prop("attributes"),e.each(a,function(){this.name&&(n+=" "+this.name+'="'+this.value+'"')}),N.replaceWith(e("'+t+"")),N=e('[data-richtext="init"]'),N.removeAttr("data-richtext")):(a=N.prop("attributes"),e.each(a,function(){this.name&&(n+=" "+this.name+'="'+this.value+'"')}),N.replaceWith(e("')),N=e('[data-richtext="init"]'),N.removeAttr("data-richtext"))),R=e("
",{"class":"richText"});var i=e("
",{"class":"richText-toolbar"}),o=e("
",{"class":"richText-editor",id:ne,contenteditable:!0});if(i.append(L),C.bold===!0&&L.append(k.clone().append(U)),C.italic===!0&&L.append(k.clone().append(D)),C.underline===!0&&L.append(k.clone().append(A)),C.leftAlign===!0&&L.append(k.clone().append(F)),C.centerAlign===!0&&L.append(k.clone().append(H)),C.rightAlign===!0&&L.append(k.clone().append(E)),C.ol===!0&&L.append(k.clone().append(B)),C.ul===!0&&L.append(k.clone().append(I)),C.fonts===!0&&C.fontList.length>0&&L.append(k.clone().append(P)),C.heading===!0&&L.append(k.clone().append(M)),C.fontColor===!0&&L.append(k.clone().append(W)),C.imageUpload===!0&&L.append(k.clone().append(X)),C.fileUpload===!0&&L.append(k.clone().append(Q)),C.videoEmbed===!0&&L.append(k.clone().append(Y)),C.urls===!0&&L.append(k.clone().append(z)),C.table===!0&&L.append(k.clone().append(_)),C.removeStyles===!0&&L.append(k.clone().append(V)),C.code===!0&&L.append(k.clone().append(G)),o.html(N.val()),R.append(i),R.append(o),R.append(N.clone().hide()),N.replaceWith(R),R.append(e("
",{"class":"richText-toolbar"}).append(e("",{"class":"richText-undo is-disabled",html:''})).append(e("",{"class":"richText-redo is-disabled",html:''})).append(e("",{"class":"richText-help",html:''}))),C.height&&C.height>0)R.children(".richText-editor, .richText-initial").css({"min-height":C.height+"px",height:C.height+"px"});else if(C.heightPercentage&&C.heightPercentage>0){var r=R.parent().innerHeight(),l=C.heightPercentage/100*r;l-=2*i.outerHeight(),l-=parseInt(R.css("margin-top")),l-=parseInt(R.css("margin-bottom")),l-=parseInt(R.find(".richText-editor").css("padding-top")),l-=parseInt(R.find(".richText-editor").css("padding-bottom")),R.children(".richText-editor, .richText-initial").css({"min-height":l+"px",height:l+"px"})}C["class"]&&R.addClass(C["class"]),C.id&&R.attr("id",C.id),y(),oe.push(R.find("textarea").val())}function n(e,t){"undefined"==typeof t&&(t=null),m(),"heading"===e&&s()?g("<"+t+">"+s()+""):document.execCommand(e,!1,t)}function i(){var t=e("#"+ne),a=t.html();C.useSingleQuotes===!0&&(a=v(a)),t.siblings(".richText-initial").val(a)}function o(t){var a=e("#"+t),n=a.siblings(".richText-initial").val();a.html(n)}function r(e){var t=document.getElementById(e);if(window.getSelection&&document.createRange){var a=window.getSelection&&window.getSelection();if(a&&a.rangeCount>0){var n=window.getSelection().getRangeAt(0),i=n.cloneRange();i.selectNodeContents(t),i.setEnd(n.startContainer,n.startOffset);var o=i.toString().length;return{start:o,end:o+n.toString().length}}return S?S:{start:0,end:0}}if(document.selection&&document.body.createTextRange){var r=document.selection.createRange(),l=document.body.createTextRange();l.moveToElementText(t),l.setEndPoint("EndToStart",r);var o=l.text.length;return{start:o,end:o+r.text.length}}}function l(){var e=document.getElementById(ne),t=S;if(window.getSelection&&document.createRange){var a=0,n=document.createRange();n.setStart(e,0),n.collapse(!0);for(var i,o=[e],r=!1,l=!1;!l&&(i=o.pop());)if(3===i.nodeType){var d=a+i.length;!r&&t.start>=a&&t.start<=d&&(n.setStart(i,t.start-a),r=!0),r&&t.end>=a&&t.end<=d&&(n.setEnd(i,t.end-a),l=!0),a=d}else for(var s=i.childNodes.length;s--;)o.push(i.childNodes[s]);var c=window.getSelection();c.removeAllRanges(),c.addRange(n)}else if(document.selection&&document.body.createTextRange){var p=document.body.createTextRange();p.moveToElementText(e),p.collapse(!0),p.moveEnd("character",t.end),p.moveStart("character",t.start),p.select()}}function d(t,a){if(9!==a.keyCode)return!1;var n;if(t.getSelection&&(n=t.getSelection(),n.rangeCount>0)){var i=null,o=null;if(a.shiftKey?(o="previous",i="TD"===n.focusNode.nodeName?null!=n.focusNode.previousSibling?n.focusNode.previousSibling:null!=n.focusNode.parentNode.previousSibling?n.focusNode.parentNode.previousSibling.childNodes[n.focusNode.parentNode.previousSibling.childNodes.length-1]:null:null!=n.focusNode.parentNode.previousSibling?n.focusNode.parentNode.previousSibling:null!=n.focusNode.parentNode.parentNode.previousSibling?n.focusNode.parentNode.parentNode.previousSibling.childNodes[n.focusNode.parentNode.parentNode.previousSibling.childNodes.length-1]:null):(o="next",i="TD"===n.focusNode.nodeName?null!=n.focusNode.nextSibling?n.focusNode.nextSibling:null!=n.focusNode.parentNode.nextSibling?n.focusNode.parentNode.nextSibling.childNodes[0]:null:null!=n.focusNode.parentNode.nextSibling?n.focusNode.parentNode.nextSibling:null!=n.focusNode.parentNode.parentNode.nextSibling?n.focusNode.parentNode.parentNode.nextSibling.childNodes[0]:null),null!=i)return n.collapse(i,Math.min(i.length,n.focusOffset+1)),null!=i.textContent&&n.selectAllChildren(i),a.preventDefault(),!0;if(null===i&&"next"===o&&"TD"===n.focusNode.nodeName){for(var r=e(n.focusNode).parents("table"),l=r.find("tr").first().children("td").length,s=e(""),c=e(""),p=1;l>=p;p++)s.append(c.clone());r.append(s),d(window,{keyCode:9,shiftKey:!1,preventDefault:function(){}})}}return!1}function s(){var e;return window.getSelection?(e=window.getSelection(),e.toString()):document.selection.createRange?(e=document.selection.createRange(),e.text):!1}function c(t){var a=e(".richText-editor#"+t).siblings(".richText-initial");p(a.val()),S=r(t)}function p(e){oe.length-1>re&&(oe.length=re+1),oe[oe.length-1]!==e&&oe.push(e),re=oe.length-1,h()}function h(){0>=re?R.find(".richText-undo").addClass("is-disabled"):R.find(".richText-undo").removeClass("is-disabled"),re>=oe.length-1||0===oe.length?R.find(".richText-redo").addClass("is-disabled"):R.find(".richText-redo").removeClass("is-disabled")}function f(){re--;var e=oe[re];R.find("textarea").val(e),R.find(".richText-editor").html(e),h()}function u(){re++;var e=oe[re];R.find("textarea").val(e),R.find(".richText-editor").html(e),h()}function m(){S&&l()}function g(e){var t,a;if(window.getSelection){if(t=window.getSelection(),t.getRangeAt&&t.rangeCount){a=t.getRangeAt(0),a.deleteContents();var n=document.createElement("div");n.innerHTML=e;for(var i,o,r=document.createDocumentFragment();i=n.firstChild;)o=r.appendChild(i);a.insertNode(r),o&&(a=a.cloneRange(),a.setStartAfter(o),a.collapse(!0),t.removeAllRanges(),t.addRange(a))}}else document.selection&&"Control"!==document.selection.type&&document.selection.createRange().pasteHTML(e)}function v(e){if(!e)return"";var t,a;return C.useSingleQuotes===!0?(t=/\s+(\w+\s*=\s*(["][^"]*["])|(['][^']*[']))+/g,a=e.replace(t,function(e,t,a){return a?e.replace(a,a.replace(/\"/g,"'")):e})):(t=/\s+(\w+\s*=\s*(['][^']*['])|(["][^"]*["]))+/g,a=e.replace(t,function(e,t,a){return a?e.replace(a,a.replace(/'/g,'"')):e})),a}function x(e){var t=[],a="";t["#FFFFFF"]="White",t["#000000"]="Black",t["#7F6000"]="Brown",t["#938953"]="Beige",t["#1F497D"]="Dark Blue",t.blue="Blue",t["#4F81BD"]="Light blue",t["#953734"]="Dark red",t.red="Red",t["#4F6128"]="Dark green",t.green="Green",t["#3F3151"]="Purple",t["#31859B"]="Dark Turquois",t["#4BACC6"]="Turquois",t["#E36C09"]="Dark orange",t["#F79646"]="Orange",t["#FFFF00"]="Yellow",C.colors&&C.colors.length>0&&(t=C.colors);for(var n in t)a+='
  • ';return a}function b(){R.find(".richText-editor").is(":visible")?(R.find(".richText-initial").show(),R.find(".richText-editor").hide(),e(".richText-toolbar").find(".richText-btn").each(function(){e(this).hasClass("fa-code")||e(this).parent("li").attr("data-disable","true")})):(R.find(".richText-initial").hide(),R.find(".richText-editor").show(),e(".richText-toolbar").find("li").removeAttr("data-disable"))}function T(e,t){var a=w(e),n=!1,i=!1;if(!a)return!1;t?"responsive"!==t?t=t.split("x"):(n=!0,t="640x360",t=t.split("x")):(t="640x360",t=t.split("x"));var o="

    ";n===!0&&(o+='
    ');var r="webkitallowfullscreen mozallowfullscreen allowfullscreen";return"YouTube"===a.platform?(o+='",i=!0):"Vimeo"===a.platform?(o+='",i=!0):"Facebook"===a.platform?(o+='",i=!0):"Dailymotion"===a.platform&&(o+='",i=!0),n===!0&&(o+="
    "),o+="

    ",i?o:!1}function w(e){var t=/(?:http?s?:\/\/)?(?:www\.)?(?:vimeo\.com)\/?(.+)/,a=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/,n=/(?:http?s?:\/\/)?(?:www\.)?(?:facebook\.com)\/.*\/videos\/[0-9]+/,i=/(?:http?s?:\/\/)?(?:www\.)?(?:dailymotion\.com)\/video\/([a-zA-Z0-9]+)/,o=e.match(a),r=e.match(t),l=e.match(n),d=e.match(i);return o&&11===o[2].length?{platform:"YouTube",id:o[2]}:r&&r[1]?{platform:"Vimeo",id:r[1]}:l&&l[0]?{platform:"Facebook",id:l[0]}:d&&d[1]?{platform:"Dailymotion",id:d[1]}:!1}function y(){R&&!R.find(".richText-editor").html()&&(C.useParagraph!==!1?R.find(".richText-editor").html("


    "):R.find(".richText-editor").html("

    "),i())}var C=e.extend({bold:!0,italic:!0,underline:!0,leftAlign:!0,centerAlign:!0,rightAlign:!0,ol:!0,ul:!0,heading:!0,fonts:!0,fontList:["Arial","Arial Black","Comic Sans MS","Courier New","Geneva","Georgia","Helvetica","Impact","Lucida Console","Tahoma","Times New Roman","Verdana"],fontColor:!0,imageUpload:!0,fileUpload:!0,videoEmbed:!0,urls:!0,table:!0,removeStyles:!0,code:!0,colors:[],fileHTML:"",imageHTML:"",useSingleQuotes:!1,height:0,heightPercentage:0,id:"","class":"",useParagraph:!1},t),N=e(this);N.addClass("richText-initial");var R,S,L=e("