/*!
* froala_editor v2.7.5 (https://www.froala.com/wysiwyg-editor)
* License https://froala.com/wysiwyg-editor/terms/
* Copyright 2014-2018 Froala Labs
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof module&&module.exports?module.exports=function(b,c){return void 0===c&&(c="undefined"!=typeof window?require("jquery"):require("jquery")(b)),a(c)}:a(window.jQuery)}(function(a){a.extend(a.FE.POPUP_TEMPLATES,{"table.insert":"[_BUTTONS_][_ROWS_COLUMNS_]","table.edit":"[_BUTTONS_]","table.colors":"[_BUTTONS_][_COLORS_][_CUSTOM_COLOR_]"}),a.extend(a.FE.DEFAULTS,{tableInsertMaxSize:10,tableEditButtons:["tableHeader","tableRemove","|","tableRows","tableColumns","tableStyle","-","tableCells","tableCellBackground","tableCellVerticalAlign","tableCellHorizontalAlign","tableCellStyle"],tableInsertButtons:["tableBack","|"],tableResizer:!0,tableResizerOffset:5,tableResizingLimit:30,tableColorsButtons:["tableBack","|"],tableColors:["#61BD6D","#1ABC9C","#54ACD2","#2C82C9","#9365B8","#475577","#CCCCCC","#41A85F","#00A885","#3D8EB9","#2969B0","#553982","#28324E","#000000","#F7DA64","#FBA026","#EB6B56","#E25041","#A38F84","#EFEFEF","#FFFFFF","#FAC51C","#F37934","#D14841","#B8312F","#7C706B","#D1D5D8","REMOVE"],tableColorsStep:7,tableCellStyles:{"fr-highlighted":"Highlighted","fr-thick":"Thick"},tableStyles:{"fr-dashed-borders":"Dashed Borders","fr-alternate-rows":"Alternate Rows"},tableCellMultipleStyles:!0,tableMultipleStyles:!0,tableInsertHelper:!0,tableInsertHelperOffset:15}),a.FE.PLUGINS.table=function(b){function c(){var a=b.$tb.find('.fr-command[data-cmd="insertTable"]'),c=b.popups.get("table.insert");if(c||(c=g()),!c.hasClass("fr-active")){b.popups.refresh("table.insert"),b.popups.setContainer("table.insert",b.$tb);var d=a.offset().left+a.outerWidth()/2,e=a.offset().top+(b.opts.toolbarBottom?10:a.outerHeight()-10);b.popups.show("table.insert",d,e,a.outerHeight())}}function d(){var a=J();if(a){var c=b.popups.get("table.edit");if(c||(c=k()),c){b.popups.setContainer("table.edit",b.$sc);var d=R(a),e=(d.left+d.right)/2,f=d.bottom;b.popups.show("table.edit",e,f,d.bottom-d.top),b.edit.isDisabled()&&(b.toolbar.disable(),b.$el.removeClass("fr-no-selection"),b.edit.on(),b.button.bulkRefresh(),b.selection.setAtEnd(b.$el.find(".fr-selected-cell:last").get(0)),b.selection.restore())}}}function e(){var a=J();if(a){var c=b.popups.get("table.colors");c||(c=l()),b.popups.setContainer("table.colors",b.$sc);var d=R(a),e=(d.left+d.right)/2,f=d.bottom;p(),b.popups.show("table.colors",e,f,d.bottom-d.top)}}function f(){0===ta().length&&b.toolbar.enable()}function g(c){if(c)return b.popups.onHide("table.insert",function(){b.popups.get("table.insert").find('.fr-table-size .fr-select-table-size > span[data-row="1"][data-col="1"]').trigger("mouseenter")}),!0;var d="";b.opts.tableInsertButtons.length>0&&(d='
'+b.button.buildList(b.opts.tableInsertButtons)+"
");var e={buttons:d,rows_columns:i()},f=b.popups.create("table.insert",e);return b.events.$on(f,"mouseenter",".fr-table-size .fr-select-table-size .fr-table-cell",function(b){h(a(b.currentTarget))},!0),j(f),f}function h(a){var c=a.data("row"),d=a.data("col"),e=a.parent();e.siblings(".fr-table-size-info").html(c+" × "+d),e.find("> span").removeClass("hover fr-active-item");for(var f=1;f<=b.opts.tableInsertMaxSize;f++)for(var g=0;g<=b.opts.tableInsertMaxSize;g++){var h=e.find('> span[data-row="'+f+'"][data-col="'+g+'"]');c>=f&&d>=g?h.addClass("hover"):c+1>=f||2>=f&&!b.helpers.isMobile()?h.css("display","inline-block"):f>2&&!b.helpers.isMobile()&&h.css("display","none")}a.addClass("fr-active-item")}function i(){for(var a='1 × 1
',c=1;c<=b.opts.tableInsertMaxSize;c++){for(var d=1;d<=b.opts.tableInsertMaxSize;d++){var e="inline-block";c>2&&!b.helpers.isMobile()&&(e="none");var f="fr-table-cell ";1==c&&1==d&&(f+=" hover"),a+='
'+c+" × "+d+" "}a+='
'}return a+"
"}function j(c){b.events.$on(c,"focus","[tabIndex]",function(b){h(a(b.currentTarget))}),b.events.on("popup.tab",function(c){var d=a(c.currentTarget);if(!b.popups.isVisible("table.insert")||!d.is("span, a"))return!0;var e,f=c.which;if(a.FE.KEYCODE.ARROW_UP==f||a.FE.KEYCODE.ARROW_DOWN==f||a.FE.KEYCODE.ARROW_LEFT==f||a.FE.KEYCODE.ARROW_RIGHT==f){if(d.is("span.fr-table-cell")){var g=d.parent().find("span.fr-table-cell"),i=g.index(d),j=b.opts.tableInsertMaxSize,k=i%j,l=Math.floor(i/j);a.FE.KEYCODE.ARROW_UP==f?l=Math.max(0,l-1):a.FE.KEYCODE.ARROW_DOWN==f?l=Math.min(b.opts.tableInsertMaxSize-1,l+1):a.FE.KEYCODE.ARROW_LEFT==f?k=Math.max(0,k-1):a.FE.KEYCODE.ARROW_RIGHT==f&&(k=Math.min(b.opts.tableInsertMaxSize-1,k+1));var m=l*j+k,n=a(g.get(m));h(n),b.events.disableBlur(),n.focus(),e=!1}}else a.FE.KEYCODE.ENTER==f&&(b.button.exec(d),e=!1);return!1===e&&(c.preventDefault(),c.stopPropagation()),e},!0)}function k(a){if(a)return b.popups.onHide("table.edit",f),!0;if(b.opts.tableEditButtons.length>0){var e={buttons:''+b.button.buildList(b.opts.tableEditButtons)+"
"},g=b.popups.create("table.edit",e);return b.events.$on(b.$wp,"scroll.table-edit",function(){b.popups.isVisible("table.edit")&&d()}),g}return!1}function l(){var a="";b.opts.tableColorsButtons.length>0&&(a=''+b.button.buildList(b.opts.tableColorsButtons)+"
");var c="";b.opts.colorsHEXInput&&(c='");var d={buttons:a,colors:m(),custom_color:c},f=b.popups.create("table.colors",d);return b.events.$on(b.$wp,"scroll.table-colors",function(){b.popups.isVisible("table.colors")&&e()}),o(f),f}function m(){for(var a='',c=0;c"),a+="REMOVE"!=b.opts.tableColors[c]?''+b.language.translate("Color")+" "+b.opts.tableColors[c]+" ":''+b.icon.create("tableColorRemove")+''+b.language.translate("Clear Formatting")+"";return a+"
"}function n(){var c=b.popups.get("table.colors").find(".fr-table-colors-hex-layer input");c.length&&F(c.val())}function o(c){b.events.on("popup.tab",function(d){var e=a(d.currentTarget);if(!b.popups.isVisible("table.colors")||!e.is("span"))return!0;var f=d.which,g=!0;if(a.FE.KEYCODE.TAB==f){var h=c.find(".fr-buttons");g=!b.accessibility.focusToolbar(h,!!d.shiftKey)}else if(a.FE.KEYCODE.ARROW_UP==f||a.FE.KEYCODE.ARROW_DOWN==f||a.FE.KEYCODE.ARROW_LEFT==f||a.FE.KEYCODE.ARROW_RIGHT==f){var i=e.parent().find("span.fr-command"),j=i.index(e),k=b.opts.colorsStep,l=Math.floor(i.length/k),m=j%k,o=Math.floor(j/k)*k+m,p=l*k;a.FE.KEYCODE.ARROW_UP==f?o=((o-k)%p+p)%p:a.FE.KEYCODE.ARROW_DOWN==f?o=(o+k)%p:a.FE.KEYCODE.ARROW_LEFT==f?o=((o-1)%p+p)%p:a.FE.KEYCODE.ARROW_RIGHT==f&&(o=(o+1)%p);var q=a(i.get(o));b.events.disableBlur(),q.focus(),g=!1}else a.FE.KEYCODE.ENTER==f&&(b.button.exec(e),g=!1);return!1===g&&(d.preventDefault(),d.stopPropagation()),g},!0)}function p(){var a=b.popups.get("table.colors"),c=b.$el.find(".fr-selected-cell:first"),d=b.helpers.RGBToHex(c.css("background-color")),e=a.find(".fr-table-colors-hex-layer input");a.find(".fr-selected-color").removeClass("fr-selected-color fr-active-item"),a.find('span[data-param1="'+d+'"]').addClass("fr-selected-color fr-active-item"),e.val(d).trigger("change")}function q(c,d){var e,f,g='',h=100/d;for(e=0;c>e;e++){for(g+="",f=0;d>f;f++)g+='',0===e&&0===f&&(g+=a.FE.MARKERS),g+="
| ";g+="
"}g+="
",b.html.insert(g),b.selection.restore();var i=b.$el.find(".fr-inserted-table");i.removeClass("fr-inserted-table"),b.events.trigger("table.inserted",[i.get(0)])}function r(){if(ta().length>0){var a=ua();b.selection.setBefore(a.get(0))||b.selection.setAfter(a.get(0)),b.selection.restore(),b.popups.hide("table.edit"),a.remove(),b.toolbar.enable()}}function s(){var b=ua();if(b.length>0&&0===b.find("th").length){var c,e="",f=0;for(b.find("tr:first > td").each(function(){var b=a(this);f+=parseInt(b.attr("colspan"),10)||1}),c=0;f>c;c++)e+="
| ";e+="
",b.prepend(e),d()}}function t(){var a=ua(),c=a.find("thead");if(c.length>0)if(0===a.find("tbody tr").length)r();else if(c.remove(),ta().length>0)d();else{b.popups.hide("table.edit");var e=a.find("tbody tr:first td:first").get(0);e&&(b.selection.setAtEnd(e),b.selection.restore())}}function u(c){var e=ua();if(e.length>0){if(b.$el.find("th.fr-selected-cell").length>0&&"above"==c)return;var f,g,h,i=J(),j=P(i);g="above"==c?j.min_i:j.max_i;var k="";for(f=0;f0&&i[g][f]==i[g-1][f]){if(0===f||f>0&&i[g][f]!=i[g][f-1]){var l=a(i[g][f]);l.attr("rowspan",parseInt(l.attr("rowspan"),10)+1)}}else k+="
| ";k+="
",h=a(b.$el.find("th.fr-selected-cell").length>0&&"below"==c?e.find("tbody").not(e.find("table tbody")):e.find("tr").not(e.find("table tr")).get(g)),"below"==c?"TBODY"==h.prop("tagName")?h.prepend(k):h.after(k):"above"==c&&(h.before(k),b.popups.isVisible("table.edit")&&d())}}function v(){var c=ua();if(c.length>0){var d,e,f,g=J(),h=P(g);if(0===h.min_i&&h.max_i==g.length-1)r();else{for(d=h.max_i;d>=h.min_i;d--){for(f=a(c.find("tr").not(c.find("table tr")).get(d)),e=0;e1){var j=parseInt(i.attr("rowspan"),10)-1;1==j?i.removeAttr("rowspan"):i.attr("rowspan",j)}if(d0&&g[d][l]==g[d][l-1];)l--;0===l?a(c.find("tr").not(c.find("table tr")).get(d+1)).prepend(k):a(g[d+1][l-1]).after(k)}}var m=f.parent();f.remove(),0===m.find("tr").length&&m.remove(),g=J(c)}B(0,g.length-1,0,g[0].length-1,c),h.min_i>0?b.selection.setAtEnd(g[h.min_i-1][0]):b.selection.setAtEnd(g[0][0]),b.selection.restore(),b.popups.hide("table.edit")}}}function w(c){var e=ua();if(e.length>0){var f,g=J(),h=P(g);f="before"==c?h.min_j:h.max_j;var i,j=100/g[0].length,k=100/(g[0].length+1);e.find("th, td").each(function(){(i=a(this)).data("old-width",i.outerWidth()/e.outerWidth()*100)}),e.find("tr").not(e.find("table tr")).each(function(b){for(var d,e=a(this),h=0,i=0;f>h-1;){if(!(d=e.find("> th, > td").get(i))){d=null;break}d==g[b][h]?(h+=parseInt(a(d).attr("colspan"),10)||1,i++):(h+=parseInt(a(g[b][h]).attr("colspan"),10)||1,"after"==c&&(d=0===i?-1:e.find("> th, > td").get(i-1)))}var n,l=a(d);if("after"==c&&h-1>f||"before"==c&&f>0&&g[b][f]==g[b][f-1]){if(0===b||b>0&&g[b][f]!=g[b-1][f]){var m=parseInt(l.attr("colspan"),10)+1;l.attr("colspan",m),l.css("width",(l.data("old-width")*k/j+k).toFixed(4)+"%"),l.removeData("old-width")}}else n=e.find("th").length>0?'
| ':'
| ',-1==d?e.prepend(n):null==d?e.append(n):"before"==c?l.before(n):"after"==c&&l.after(n)}),e.find("th, td").each(function(){(i=a(this)).data("old-width")&&(i.css("width",(i.data("old-width")*k/j).toFixed(4)+"%"),i.removeData("old-width"))}),b.popups.isVisible("table.edit")&&d()}}function x(){var c=ua();if(c.length>0){var d,e,f,g=J(),h=P(g);if(0===h.min_j&&h.max_j==g[0].length-1)r();else{var i=100/g[0].length,j=100/(g[0].length-h.max_j+h.min_j-1);for(c.find("th, td").each(function(){(f=a(this)).hasClass("fr-selected-cell")||f.data("old-width",f.outerWidth()/c.outerWidth()*100)}),e=h.max_j;e>=h.min_j;e--)for(d=0;d1){var k=parseInt(f.attr("colspan"),10)-1;1==k?f.removeAttr("colspan"):f.attr("colspan",k),f.css("width",((f.data("old-width")-la(e,g))*j/i).toFixed(4)+"%"),f.removeData("old-width")}else{var l=a(f.parent().get(0));f.remove(),0===l.find("> th, > td").length&&(0===l.prev().length||0===l.next().length||l.prev().find("> th[rowspan], > td[rowspan]").length th, > td").length)&&l.remove()}B(0,g.length-1,0,g[0].length-1,c),h.min_j>0?b.selection.setAtEnd(g[h.min_i][h.min_j-1]):b.selection.setAtEnd(g[h.min_i][0]),b.selection.restore(),b.popups.hide("table.edit"),c.find("th, td").each(function(){(f=a(this)).data("old-width")&&(f.css("width",(f.data("old-width")*j/i).toFixed(4)+"%"),f.removeData("old-width"))})}}}function y(a,b,c){var d,e,f,g,h,i=0,j=J(c);if((b=Math.min(b,j[0].length-1))>a)for(e=a;b>=e;e++)if(!(e>a&&j[0][e]==j[0][e-1])&&((g=Math.min(parseInt(j[0][e].getAttribute("colspan"),10)||1,b-a+1))>1&&j[0][e]==j[0][e+1]))for(i=g-1,d=1;df;f++)if((h=parseInt(j[d][f].getAttribute("colspan"),10)||1)>1&&j[d][f]==j[d][f+1])f+=i=Math.min(i,h-1);else if(!(i=Math.max(0,i-1)))break;if(!i)break}i&&A(j,i,"colspan",0,j.length-1,a,b)}function z(a,b,c){var d,e,f,g,h,i=0,j=J(c);if((b=Math.min(b,j.length-1))>a)for(d=a;b>=d;d++)if(!(d>a&&j[d][0]==j[d-1][0])&&((g=Math.min(parseInt(j[d][0].getAttribute("rowspan"),10)||1,b-a+1))>1&&j[d][0]==j[d+1][0]))for(i=g-1,e=1;ef;f++)if((h=parseInt(j[f][e].getAttribute("rowspan"),10)||1)>1&&j[f][e]==j[f+1][e])f+=i=Math.min(i,h-1);else if(!(i=Math.max(0,i-1)))break;if(!i)break}i&&A(j,i,"rowspan",a,b,0,j[0].length-1)}function A(a,b,c,d,e,f,g){var h,i,j;for(h=d;e>=h;h++)for(i=f;g>=i;i++)h>d&&a[h][i]==a[h-1][i]||i>f&&a[h][i]==a[h][i-1]||(j=parseInt(a[h][i].getAttribute(c),10)||1)>1&&(j-b>1?a[h][i].setAttribute(c,j-b):a[h][i].removeAttribute(c))}function B(a,b,c,d,e){z(a,b,e),y(c,d,e)}function C(){if(ta().length>1&&(0===b.$el.find("th.fr-selected-cell").length||0===b.$el.find("td.fr-selected-cell").length)){M();var c,e,g=P(J()),h=b.$el.find(".fr-selected-cell"),i=a(h[0]),k=i.parent().find(".fr-selected-cell"),l=i.closest("table"),m=i.html(),n=0;for(c=0;c"!=(e=a(h[c])).html()&&""!==e.html()&&(m+="
"+e.html()),e.remove();i.html(m),b.selection.setAtEnd(i.get(0)),b.selection.restore(),b.toolbar.enable(),z(g.min_i,g.max_i,l);var o=l.find("tr:empty");for(c=o.length-1;c>=0;c--)a(o[c]).remove();y(g.min_j,g.max_j,l),d()}}function D(){if(1==ta().length){var c=b.$el.find(".fr-selected-cell"),d=c.parent(),e=c.closest("table"),f=parseInt(c.attr("rowspan"),10),g=J(),h=K(c.get(0),g),i=c.clone().html("
");if(f>1){var j=Math.ceil(f/2);j>1?c.attr("rowspan",j):c.removeAttr("rowspan"),f-j>1?i.attr("rowspan",f-j):i.removeAttr("rowspan");for(var k=h.row+j,l=0===h.col?h.col:h.col-1;l>=0&&(g[k][l]==g[k][l-1]||k>0&&g[k][l]==g[k-1][l]);)l--;-1==l?a(e.find("tr").not(e.find("table tr")).get(k)).prepend(i):a(g[k][l]).after(i)}else{var m,n=a("").append(i);for(m=0;m"),h=J(),i=K(c.get(0),h);if(d>1){var j=Math.ceil(d/2);f=ma(i.col,i.col+j-1,h)/e*100;var k=ma(i.col+j,i.col+d-1,h)/e*100;j>1?c.attr("colspan",j):c.removeAttr("colspan"),d-j>1?g.attr("colspan",d-j):g.removeAttr("colspan"),c.css("width",f.toFixed(4)+"%"),g.css("width",k.toFixed(4)+"%")}else{var l;for(l=0;l0){if(!c){var e=Object.keys(d);e.splice(e.indexOf(a),1),b.removeClass(e.join(" "))}b.toggleClass(a)}}function J(b){var c=[];return null==(b=b||null)&&ta().length>0&&(b=ua()),b&&b.find("tr").not(b.find("table tr")).each(function(b,d){var e=a(d),f=0;e.find("> th, > td").each(function(d,e){for(var g=a(e),h=parseInt(g.attr("colspan"),10)||1,i=parseInt(g.attr("rowspan"),10)||1,j=b;b+i>j;j++)for(var k=f;f+h>k;k++)c[j]||(c[j]=[]),c[j][k]?f++:c[j][k]=e;f+=h})}),c}function K(a,b){for(var c=0;c0&&c.each(function(){var b=a(this);b.removeClass("fr-selected-cell"),""===b.attr("class")&&b.removeAttr("class")}),M()}function O(){b.events.disableBlur(),b.selection.clear(),b.$el.addClass("fr-no-selection"),b.$el.blur(),b.events.enableBlur()}function P(a){var c=b.$el.find(".fr-selected-cell");if(c.length>0){var d,e=a.length,f=0,g=a[0].length,h=0;for(d=0;d=g;g++)((parseInt(a(f[g][m]).attr("rowspan"),10)||1)>1||(parseInt(a(f[g][m]).attr("colspan"),10)||1)>1)&&(j=L((i=K(f[g][m],f)).row,i.col,f),k=Math.min(i.row,k),l=Math.max(j.row,l),m=Math.min(i.col,m),n=Math.max(j.col,n)),((parseInt(a(f[g][n]).attr("rowspan"),10)||1)>1||(parseInt(a(f[g][n]).attr("colspan"),10)||1)>1)&&(j=L((i=K(f[g][n],f)).row,i.col,f),k=Math.min(i.row,k),l=Math.max(j.row,l),m=Math.min(i.col,m),n=Math.max(j.col,n));for(h=m;n>=h;h++)((parseInt(a(f[k][h]).attr("rowspan"),10)||1)>1||(parseInt(a(f[k][h]).attr("colspan"),10)||1)>1)&&(j=L((i=K(f[k][h],f)).row,i.col,f),k=Math.min(i.row,k),l=Math.max(j.row,l),m=Math.min(i.col,m),n=Math.max(j.col,n)),((parseInt(a(f[l][h]).attr("rowspan"),10)||1)>1||(parseInt(a(f[l][h]).attr("colspan"),10)||1)>1)&&(j=L((i=K(f[l][h],f)).row,i.col,f),k=Math.min(i.row,k),l=Math.max(j.row,l),m=Math.min(i.col,m),n=Math.max(j.col,n));return k==b&&l==c&&m==d&&n==e?{min_i:b,max_i:c,min_j:d,max_j:e}:Q(k,l,m,n,f)}function R(b){var c=P(b),d=a(b[c.min_i][c.min_j]),e=a(b[c.min_i][c.max_j]),f=a(b[c.max_i][c.min_j]);return{left:d.offset().left,right:e.offset().left+e.outerWidth(),top:d.offset().top,bottom:f.offset().top+f.outerHeight()}}function S(c,d){if(a(c).is(d))N(),b.edit.on(),a(c).addClass("fr-selected-cell");else{O(),b.edit.off();var e=J(),f=K(c,e),g=K(d,e),h=Q(Math.min(f.row,g.row),Math.max(f.row,g.row),Math.min(f.col,g.col),Math.max(f.col,g.col),e);N(),c.classList.add("fr-cell-fixed"),d.classList.add("fr-cell-handler");for(var i=h.min_i;i<=h.max_i;i++)for(var j=h.min_j;j<=h.max_j;j++)a(e[i][j]).addClass("fr-selected-cell")}}function T(c){var d=null,e=a(c.target);return"TD"==c.target.tagName||"TH"==c.target.tagName?d=c.target:e.closest("td").length>0?d=e.closest("td").get(0):e.closest("th").length>0&&(d=e.closest("th").get(0)),0===b.$el.find(d).length?null:d}function U(){N(),b.popups.hide("table.edit")}function V(c){var d=T(c);if(ta().length>0&&!d&&U(),!b.edit.isDisabled()||b.popups.isVisible("table.edit"))if(1!=c.which||1==c.which&&b.helpers.isMac()&&c.ctrlKey)(3==c.which||1==c.which&&b.helpers.isMac()&&c.ctrlKey)&&d&&U();else if(Ba=!0,d){ta().length>0&&!c.shiftKey&&U(),c.stopPropagation(),b.events.trigger("image.hideResizer"),b.events.trigger("video.hideResizer"),Aa=!0;var e=d.tagName.toLowerCase();c.shiftKey&&b.$el.find(e+".fr-selected-cell").length>0?a(b.$el.find(e+".fr-selected-cell").closest("table")).is(a(d).closest("table"))?S(Ca,d):O():((b.keys.ctrlKey(c)||c.shiftKey)&&(ta().length>1||0===a(d).find(b.selection.element()).length&&!a(d).is(b.selection.element()))&&O(),S(Ca=d,Ca))}}function W(c){if(Aa||b.$tb.is(c.target)||b.$tb.is(a(c.target).closest(b.$tb.get(0)))||(ta().length>0&&b.toolbar.enable(),N()),!(1!=c.which||1==c.which&&b.helpers.isMac()&&c.ctrlKey)){if(Ba=!1,Aa)Aa=!1,T(c)||1!=ta().length?ta().length>0&&(b.selection.isCollapsed()?d():N()):N();if(Ea){Ea=!1,ya.removeClass("fr-moving"),b.$el.removeClass("fr-no-selection"),b.edit.on();var f=parseFloat(ya.css("left"))+b.opts.tableResizerOffset+b.$wp.offset().left;b.opts.iframe&&(f-=b.$iframe.offset().left),ya.data("release-position",f),ya.removeData("max-left"),ya.removeData("max-right"),ka(c),ca()}}}function X(c){if(!0===Aa){if(a(c.currentTarget).closest("table").is(ua())){if("TD"==c.currentTarget.tagName&&0===b.$el.find("th.fr-selected-cell").length)return void S(Ca,c.currentTarget);if("TH"==c.currentTarget.tagName&&0===b.$el.find("td.fr-selected-cell").length)return void S(Ca,c.currentTarget)}O()}}function Y(c,d){for(var e=c;e&&"TABLE"!=e.tagName&&e.parentNode!=b.el;)e=e.parentNode;if(e&&"TABLE"==e.tagName){var f=J(a(e));"up"==d?$(K(c,f),e,f):"down"==d&&_(K(c,f),e,f)}}function Z(a,c,d,e){for(var f,g=c;g!=b.el&&"TD"!=g.tagName&&"TH"!=g.tagName&&("up"==e?f=g.previousElementSibling:"down"==e&&(f=g.nextElementSibling),!f);)g=g.parentNode;"TD"==g.tagName||"TH"==g.tagName?Y(g,e):f&&("up"==e&&b.selection.setAtEnd(f),"down"==e&&b.selection.setAtStart(f))}function $(a,c,d){a.row>0?b.selection.setAtEnd(d[a.row-1][a.col]):Z(a,c,d,"up")}function _(a,c,d){var e=parseInt(d[a.row][a.col].getAttribute("rowspan"),10)||1;a.row0&&U(),b.browser.webkit&&(a.FE.KEYCODE.ARROW_UP==d||a.FE.KEYCODE.ARROW_DOWN==d))){var g=b.selection.ranges(0).startContainer;if(g.nodeType==Node.TEXT_NODE&&(a.FE.KEYCODE.ARROW_UP==d&&g.previousSibling||a.FE.KEYCODE.ARROW_DOWN==d&&g.nextSibling))return;c.preventDefault(),c.stopPropagation();var h=J(a(f)),i=K(e,h);return a.FE.KEYCODE.ARROW_UP==d?$(i,f,h):a.FE.KEYCODE.ARROW_DOWN==d&&_(i,f,h),b.selection.restore(),!1}}}function ba(){b.shared.$table_resizer||(b.shared.$table_resizer=a('')),ya=b.shared.$table_resizer,b.events.$on(ya,"mousedown",function(a){return!b.core.sameInstance(ya)||(ta().length>0&&U(),1==a.which?(b.selection.save(),Ea=!0,ya.addClass("fr-moving"),O(),b.edit.off(),ya.find("div").css("opacity",1),!1):void 0)}),b.events.$on(ya,"mousemove",function(a){return!b.core.sameInstance(ya)||void(Ea&&(b.opts.iframe&&(a.pageX-=b.$iframe.offset().left),na(a)))}),b.events.on("shared.destroy",function(){ya.html("").removeData().remove(),ya=null},!0),b.events.on("destroy",function(){b.$el.find(".fr-selected-cell").removeClass("fr-selected-cell"),ya.hide().appendTo(a("body:first"))},!0)}function ca(){ya&&(ya.find("div").css("opacity",0),ya.css("top",0),ya.css("left",0),ya.css("height",0),ya.find("div").css("height",0),ya.hide())}function da(){za&&za.removeClass("fr-visible").css("left","-9999px")}function ea(c,d){var e=a(d),f=e.closest("table"),g=f.parent();if(d&&"TD"!=d.tagName&&"TH"!=d.tagName&&(e.closest("td").length>0?d=e.closest("td"):e.closest("th").length>0&&(d=e.closest("th"))),!d||"TD"!=d.tagName&&"TH"!=d.tagName)ya&&e.get(0)!=ya.get(0)&&e.parent().get(0)!=ya.get(0)&&b.core.sameInstance(ya)&&ca();else{if(e=a(d),0===b.$el.find(e).length)return!1;var h=e.offset().left-1,i=h+e.outerWidth();if(Math.abs(c.pageX-h)<=b.opts.tableResizerOffset||Math.abs(i-c.pageX)<=b.opts.tableResizerOffset){var j,k,l,m,n,o=J(f),p=K(d,o),q=L(p.row,p.col,o),r=f.offset().top,s=f.outerHeight()-1;"rtl"!=b.opts.direction?c.pageX-h<=b.opts.tableResizerOffset?(l=h,p.col>0?(m=h-la(p.col-1,o)+b.opts.tableResizingLimit,n=h+la(p.col,o)-b.opts.tableResizingLimit,j=p.col-1,k=p.col):(j=null,k=0,m=f.offset().left-1-parseInt(f.css("margin-left"),10),n=f.offset().left-1+f.width()-o[0].length*b.opts.tableResizingLimit)):i-c.pageX<=b.opts.tableResizerOffset&&(l=i,q.col0?(m=i-la(p.col,o)+b.opts.tableResizingLimit,n=i+la(p.col-1,o)-b.opts.tableResizingLimit,j=p.col,k=p.col-1):(j=null,k=0,m=f.offset().left+o[0].length*b.opts.tableResizingLimit,n=g.offset().left-1+g.width()+parseFloat(g.css("padding-left")))):c.pageX-h<=b.opts.tableResizerOffset&&(l=h,q.col=d;d++)e+=la(d,c);return e}function na(a){if(ta().length>1&&Ba&&O(),!1===Ba&&!1===Aa&&!1===Ea)Da&&clearTimeout(Da),(!b.edit.isDisabled()||b.popups.isVisible("table.edit"))&&(Da=setTimeout(ia,30,a));else if(Ea){var c=a.pageX-b.win.pageXOffset;b.opts.iframe&&(c+=b.$iframe.offset().left);var d=ya.data("max-left"),e=ya.data("max-right");c>=d&&e>=c?ya.css("left",c-b.opts.tableResizerOffset-b.$wp.offset().left):d>c&&parseFloat(ya.css("left"),10)>d-b.opts.tableResizerOffset?ya.css("left",d-b.opts.tableResizerOffset-b.$wp.offset().left):c>e&&parseFloat(ya.css("left"),10)0)e=b.$el.find(".fr-selected-cell:last");else{var f=b.selection.element();"TD"==f.tagName||"TH"==f.tagName?e=a(f):f!=b.el&&(a(f).parentsUntil(b.$el,"td").length>0?e=a(f).parents("td:first"):a(f).parentsUntil(b.$el,"th").length>0&&(e=a(f).parents("th:first")))}if(e)return c.preventDefault(),!!(a(b.selection.element()).parents("ol, ul").length>0&&(a(b.selection.element()).parents("li").prev().length>0||a(b.selection.element()).is("li")&&a(b.selection.element()).prev().length>0))||(U(),c.shiftKey?e.prev().length>0?oa(e.prev()):e.closest("tr").length>0&&e.closest("tr").prev().length>0?oa(e.closest("tr").prev().find("td:last")):e.closest("tbody").length>0&&e.closest("table").find("thead tr").length>0&&oa(e.closest("table").find("thead tr th:last")):e.next().length>0?oa(e.next()):e.closest("tr").length>0&&e.closest("tr").next().length>0?oa(e.closest("tr").next().find("td:first")):e.closest("thead").length>0&&e.closest("table").find("tbody tr").length>0?oa(e.closest("table").find("tbody tr td:first")):(e.addClass("fr-selected-cell"),u("below"),N(),oa(e.closest("tr").next().find("td:first"))),b.selection.restore(),!1)}}function qa(){b.shared.$ti_helper||(b.shared.$ti_helper=a(''),b.events.bindClick(b.shared.$ti_helper,"a",function(){var a=za.data("selected-cell"),c=za.data("position"),d=za.data("instance")||b;"before"==c?(b.undo.saveStep(),a.addClass("fr-selected-cell"),d.table.insertColumn(c),a.removeClass("fr-selected-cell"),b.undo.saveStep()):"after"==c?(b.undo.saveStep(),a.addClass("fr-selected-cell"),d.table.insertColumn(c),a.removeClass("fr-selected-cell"),b.undo.saveStep()):"above"==c?(b.undo.saveStep(),a.addClass("fr-selected-cell"),d.table.insertRow(c),a.removeClass("fr-selected-cell"),b.undo.saveStep()):"below"==c&&(b.undo.saveStep(),a.addClass("fr-selected-cell"),d.table.insertRow(c),a.removeClass("fr-selected-cell"),b.undo.saveStep()),da()}),b.events.on("shared.destroy",function(){b.shared.$ti_helper.html("").removeData().remove(),b.shared.$ti_helper=null},!0),b.events.$on(b.shared.$ti_helper,"mousemove",function(a){a.stopPropagation()},!0),b.events.$on(a(b.o_win),"scroll",function(){da()},!0),b.events.$on(b.$wp,"scroll",function(){da()},!0)),za=b.shared.$ti_helper,b.events.on("destroy",function(){za=null}),b.tooltip.bind(b.$box,".fr-insert-helper > a.fr-floating-btn")}function ra(){Ca=null,clearTimeout(Da)}function sa(){ta().length>0?d():(b.popups.hide("table.insert"),b.toolbar.showInline())}function ta(){return b.el.querySelectorAll(".fr-selected-cell")}function ua(){var c=ta();if(c.length){for(var d=c[0];d&&"TABLE"!=d.tagName&&d.parentNode!=b.el;)d=d.parentNode;return a(d&&"TABLE"==d.tagName?d:[])}return a([])}function va(c){if(c.altKey&&c.which==a.FE.KEYCODE.SPACE){var e,f=b.selection.element();if("TD"==f.tagName||"TH"==f.tagName?e=f:a(f).closest("td").length>0?e=a(f).closest("td").get(0):a(f).closest("th").length>0&&(e=a(f).closest("th").get(0)),e)return c.preventDefault(),S(e,e),d(),!1}}function wa(c){var d=ta();if(d.length>0){var e,f,g=J(),h=c.which;1==d.length?f=e=d[0]:(e=b.el.querySelector(".fr-cell-fixed"),f=b.el.querySelector(".fr-cell-handler"));var i=K(f,g);if(a.FE.KEYCODE.ARROW_RIGHT==h){if(i.col0)return S(e,g[i.row][i.col-1]),!1}else if(a.FE.KEYCODE.ARROW_UP==h&&i.row>0)return S(e,g[i.row-1][i.col]),!1}}function xa(){if(!b.$wp)return!1;if(!b.helpers.isMobile()){Ba=!1,Aa=!1,Ea=!1,b.events.$on(b.$el,"mousedown",V),b.popups.onShow("image.edit",function(){N(),Ba=!1,Aa=!1}),b.popups.onShow("link.edit",function(){N(),Ba=!1,Aa=!1}),b.events.on("commands.mousedown",function(a){a.parents(".fr-toolbar").length>0&&N()}),b.events.$on(b.$el,"mouseenter","th, td",X),b.events.$on(b.$win,"mouseup",W),b.opts.iframe&&b.events.$on(a(b.o_win),"mouseup",W),b.events.$on(b.$win,"mousemove",na),b.events.$on(a(b.o_win),"scroll",ja),b.events.on("contentChanged",function(){ta().length>0&&(d(),b.$el.find("img").on("load.selected-cells",function(){a(this).off("load.selected-cells"),ta().length>0&&d()}))}),b.events.$on(a(b.o_win),"resize",function(){N()}),b.events.on("toolbar.esc",function(){return ta().length>0?(b.events.disableBlur(),b.events.focus(),!1):void 0},!0),b.events.$on(a(b.o_win),"keydown",function(){Ba&&Aa&&(Ba=!1,Aa=!1,b.$el.removeClass("fr-no-selection"),b.edit.on(),b.selection.setAtEnd(b.$el.find(".fr-selected-cell:last").get(0)),b.selection.restore(),N())}),b.events.$on(b.$el,"keydown",function(a){a.shiftKey?!1===wa(a)&&setTimeout(function(){d()},0):aa(a)}),b.events.on("keydown",function(c){if(!1===pa(c))return!1;var d=ta();if(d.length>0){if(d.length>0&&b.keys.ctrlKey(c)&&c.which==a.FE.KEYCODE.A)return N(),b.popups.isVisible("table.edit")&&b.popups.hide("table.edit"),d=[],!0;if(c.which==a.FE.KEYCODE.ESC&&b.popups.isVisible("table.edit"))return N(),b.popups.hide("table.edit"),c.preventDefault(),c.stopPropagation(),c.stopImmediatePropagation(),d=[],!1;if(d.length>1&&(c.which==a.FE.KEYCODE.BACKSPACE||c.which==a.FE.KEYCODE.DELETE)){b.undo.saveStep();for(var e=0;e"),e==d.length-1&&a(d[e]).prepend(a.FE.MARKERS);return b.selection.restore(),b.undo.saveStep(),d=[],!1}if(d.length>1&&c.which!=a.FE.KEYCODE.F10&&!b.keys.isBrowserAction(c))return c.preventDefault(),d=[],!1}else if(d=[],!1===va(c))return!1},!0);var c=[];b.events.on("html.beforeGet",function(){c=ta();for(var a=0;a0&&(0===b.find("th").length?a.removeClass("fr-active").attr("aria-pressed",!1):a.addClass("fr-active").attr("aria-pressed",!0))}}),a.FE.DefineIcon("tableRows",{NAME:"bars"}),a.FE.RegisterCommand("tableRows",{type:"dropdown",focus:!1,title:"Row",options:{above:"Insert row above",below:"Insert row below","delete":"Delete row"},html:function(){var b='"},callback:function(a,b){"above"==b||"below"==b?this.table.insertRow(b):this.table.deleteRow()}}),a.FE.DefineIcon("tableColumns",{NAME:"bars fa-rotate-90"}),a.FE.RegisterCommand("tableColumns",{type:"dropdown",focus:!1,title:"Column",options:{before:"Insert column before",after:"Insert column after","delete":"Delete column"},html:function(){var b='"},callback:function(a,b){"before"==b||"after"==b?this.table.insertColumn(b):this.table.deleteColumn()}}),a.FE.DefineIcon("tableCells",{NAME:"square-o"}),a.FE.RegisterCommand("tableCells",{type:"dropdown",focus:!1,title:"Cell",options:{merge:"Merge cells","vertical-split":"Vertical split","horizontal-split":"Horizontal split"},html:function(){var b='"},callback:function(a,b){"merge"==b?this.table.mergeCells():"vertical-split"==b?this.table.splitCellVertically():this.table.splitCellHorizontally()},refreshOnShow:function(a,b){this.$el.find(".fr-selected-cell").length>1?(b.find('a[data-param1="vertical-split"]').addClass("fr-disabled").attr("aria-disabled",!0),b.find('a[data-param1="horizontal-split"]').addClass("fr-disabled").attr("aria-disabled",!0),b.find('a[data-param1="merge"]').removeClass("fr-disabled").attr("aria-disabled",!1)):(b.find('a[data-param1="merge"]').addClass("fr-disabled").attr("aria-disabled",!0),b.find('a[data-param1="vertical-split"]').removeClass("fr-disabled").attr("aria-disabled",!1),b.find('a[data-param1="horizontal-split"]').removeClass("fr-disabled").attr("aria-disabled",!1))}}),a.FE.DefineIcon("tableRemove",{NAME:"trash"}),a.FE.RegisterCommand("tableRemove",{title:"Remove Table",focus:!1,callback:function(){this.table.remove()}}),a.FE.DefineIcon("tableStyle",{NAME:"paint-brush"}),a.FE.RegisterCommand("tableStyle",{title:"Table Style",type:"dropdown",focus:!1,html:function(){var a='"},callback:function(a,b){this.table.applyStyle(b,this.$el.find(".fr-selected-cell").closest("table"),this.opts.tableMultipleStyles,this.opts.tableStyles)},refreshOnShow:function(b,c){var d=this.$el.find(".fr-selected-cell").closest("table");d&&c.find(".fr-command").each(function(){var b=a(this).data("param1"),c=d.hasClass(b);a(this).toggleClass("fr-active",c).attr("aria-selected",c)})}}),a.FE.DefineIcon("tableCellBackground",{NAME:"tint"}),a.FE.RegisterCommand("tableCellBackground",{title:"Cell Background",focus:!1,popup:!0,callback:function(){this.table.showColorsPopup()}}),a.FE.RegisterCommand("tableCellBackgroundColor",{undo:!0,focus:!1,callback:function(a,b){this.table.setBackground(b)}}),a.FE.DefineIcon("tableBack",{NAME:"arrow-left"}),a.FE.RegisterCommand("tableBack",{title:"Back",undo:!1,focus:!1,back:!0,callback:function(){this.table.back()},refresh:function(a){0!==this.table.selectedCells().length||this.opts.toolbarInline?(a.removeClass("fr-hidden"),a.next(".fr-separator").removeClass("fr-hidden")):(a.addClass("fr-hidden"),a.next(".fr-separator").addClass("fr-hidden"))}}),a.FE.DefineIcon("tableCellVerticalAlign",{NAME:"arrows-v"}),a.FE.RegisterCommand("tableCellVerticalAlign",{type:"dropdown",focus:!1,title:"Vertical Align",options:{Top:"Align Top",Middle:"Align Middle",Bottom:"Align Bottom"},html:function(){var b='"},callback:function(a,b){this.table.verticalAlign(b)},refreshOnShow:function(a,b){b.find('.fr-command[data-param1="'+this.$el.find(".fr-selected-cell").css("vertical-align")+'"]').addClass("fr-active").attr("aria-selected",!0)}}),a.FE.DefineIcon("tableCellHorizontalAlign",{NAME:"align-left"}),a.FE.DefineIcon("align-left",{NAME:"align-left"}),a.FE.DefineIcon("align-right",{NAME:"align-right"}),a.FE.DefineIcon("align-center",{NAME:"align-center"}),a.FE.DefineIcon("align-justify",{NAME:"align-justify"}),a.FE.RegisterCommand("tableCellHorizontalAlign",{type:"dropdown",focus:!1,title:"Horizontal Align",options:{left:"Align Left",center:"Align Center",right:"Align Right",justify:"Align Justify"},html:function(){var b='"},callback:function(a,b){this.table.horizontalAlign(b)},refresh:function(b){var c=this.table.selectedCells();c.length&&b.find("> *:first").replaceWith(this.icon.create("align-"+this.helpers.getAlignment(a(c[0]))))},refreshOnShow:function(a,b){b.find('.fr-command[data-param1="'+this.helpers.getAlignment(this.$el.find(".fr-selected-cell:first"))+'"]').addClass("fr-active").attr("aria-selected",!0)}}),a.FE.DefineIcon("tableCellStyle",{NAME:"magic"}),a.FE.RegisterCommand("tableCellStyle",{title:"Cell Style",type:"dropdown",focus:!1,html:function(){var a='"},callback:function(a,b){this.table.applyStyle(b,this.$el.find(".fr-selected-cell"),this.opts.tableCellMultipleStyles,this.opts.tableCellStyles)},refreshOnShow:function(b,c){var d=this.$el.find(".fr-selected-cell:first");d&&c.find(".fr-command").each(function(){var b=a(this).data("param1"),c=d.hasClass(b);a(this).toggleClass("fr-active",c).attr("aria-selected",c)})}}),a.FE.RegisterCommand("tableCellBackgroundCustomColor",{title:"OK",undo:!0,callback:function(){this.table.customColor()}}),a.FE.DefineIcon("tableColorRemove",{NAME:"eraser"})});