/*! * froala_editor v1.1.6 (http://editor.froala.com) * Copyright 2014-2014 Froala */ $.Editable.commands=$.extend($.Editable.commands,{table:{title:"Table",icon:"fa fa-table"}}),$.Editable.DEFAULTS.buttons[$.Editable.DEFAULTS.buttons.indexOf("insertHorizontalRule")]="table",$.Editable.prototype.execCommand=$.extend($.Editable.prototype.execCommand,{insertTable:function(a,b,c){this.insertTable(b,c)},insertRowAbove:function(){this.insertRow("above")},insertRowBelow:function(){this.insertRow("below")},insertColumnBefore:function(){this.insertColumn("before")},insertColumnAfter:function(){this.insertColumn("after")},deleteColumn:function(){this.deleteColumn()},deleteRow:function(){this.deleteRow()},insertCellBefore:function(){this.insertCell("before")},insertCellAfter:function(){this.insertCell("after")},mergeCells:function(){this.mergeCells()},deleteCell:function(){this.deleteCell()},splitVertical:function(){this.splitVertical()},splitHorizontal:function(){this.splitHorizontal()},insertHeader:function(){this.insertHeader()},deleteHeader:function(){this.deleteHeader()},deleteTable:function(){this.deleteTable()}}),$.Editable.prototype.command_dispatcher=$.extend($.Editable.prototype.command_dispatcher,{table:function(a){var b=this.buildDropdownTable(),c=this.buildDropdownButton(a,b,"fr-table");this.$bttn_wrapper.append(c),this.bindTableDropdownEvents()}}),$.Editable.prototype.buildDropdownTable=function(){var a='"},$.Editable.prototype.bindTableDropdownEvents=function(){var a=this;this.$bttn_wrapper.on("mouseenter",".fr-table .select-table > span",function(){var b=$(this).data("val"),c=$(this).data("param");a.$bttn_wrapper.find(".fr-table .select-table .fr-t-info").text(b+" x "+c),a.$bttn_wrapper.find(".fr-table .select-table > span").removeClass("hover");for(var d=1;10>=d;d++)for(var e=0;10>=e;e++){var f=a.$bttn_wrapper.find('.fr-table .select-table > span[data-val="'+d+'"][data-param="'+e+'"]');b>=d&&c>=e?f.addClass("hover"):(b+1>=d||5>=d)&&(c+1>=e||5>=e)?f.css("display","inline-block"):(d>5||e>5)&&f.css("display","none")}}),this.$bttn_wrapper.on("mouseleave",".fr-table .select-table",function(){a.$bttn_wrapper.find('.fr-table .select-table > span[data-val="1"][data-param="1"]').trigger("mouseenter")})},$.Editable.prototype.tableMap=function(){var a=this.currentTable(),b=[];return a&&a.find("tr").each(function(a,c){var d=$(c),e=0;d.find("td").each(function(c,d){for(var f=$(d),g=parseInt(f.attr("colspan"))||1,h=parseInt(f.attr("rowspan"))||1,i=a;a+h>i;i++)for(var j=e;e+g>j;j++)b[i]||(b[i]=[]),b[i][j]?e++:b[i][j]=d;e+=g})}),b},$.Editable.prototype.cellOrigin=function(a,b){for(var c=0;c0?a[0]:null},$.Editable.prototype.currentTable=function(){for(var a=$(this.getSelectionElement());a.get(0)!=this.$element.get(0)&&a.get(0)!=$("body").get(0)&&"TABLE"!=a.get(0).tagName;)a=a.parent();return a.get(0)!=this.$element.get(0)?a:null},$.Editable.prototype.focusOnTable=function(){var a=this.currentTable();if(a){var b=a.find("td:first");this.setSelection(b.get(0),0,null,0)}},$.Editable.prototype.insertCell=function(a){for(var b=this.getSelectionCells(),c=0;c")):"after"==a&&d.after(d.clone().removeAttr("colspan").removeAttr("rowspan").html("
"))}"before"==a?this.callback("insertCellBefore"):"after"==a&&this.callback("insertCellAfter")},$.Editable.prototype.mergeCells=function(){var a=this.canMergeCells();if(a){var b=$(a.map[a.row][a.col]);b.attr("colspan",a.colspan),b.attr("rowspan",a.rowspan);for(var c=0;c thead").length>0&&this.callback("insertHeader")},$.Editable.prototype.deleteHeader=function(){},$.Editable.prototype.insertColumn=function(a){var b=this.currentCell();if(b)for(var c=$(b),d=this.tableMap(),e=this.cellOrigin(c.get(0),d),f=0;f1?$(j).after("
"):$(g).before("
"):$(g).before("
")}else if("after"==a){var k=d[f][e.col+1];k?k==g?$(k).attr("colspan",h+1):i>1?$(k).before("
"):$(g).after("
"):$(g).after("
")}}"before"==a?this.callback("insertColumnBefore"):"after"==a&&this.callback("insertColumnAfter")},$.Editable.prototype.deleteColumn=function(){for(var a=this.getSelectionCells(),b=0;bh;h++)m+="
";m+="","below"==a?c.closest("tr").after(m):"above"==a&&c.closest("tr").before(m)}"below"==a?this.callback("insertRowBelow"):"above"==a&&this.callback("insertRowAbove")},$.Editable.prototype.deleteRow=function(){for(var a=this.getSelectionCells(),b=0;b1){var h=Math.floor(g/2),i=e.row+(g-h),j=d[i][e.col-1];j||(j=d[i][e.col+f]),j?$(j).before(c.clone().attr("rowspan",h).html("
")):c.parents("tr:first").after($("").append(c.clone().attr("rowspan",h).html("
"))),c.attr("rowspan",g-h)}else{for(var k=$("").append(c.clone().html("
")),l=null,m=0;m1){var g=Math.floor(f/2);c.after(c.clone().attr("colspan",g).html("
")),c.attr("colspan",f-g)}else{for(var h=null,i=0;i"))}}this.callback("splitVertical")},$.Editable.prototype.insertTable=function(a,b){for(var c='',d=0;a>d;d++){c+="";for(var e=0;b>e;e++)c+="";c+=""}c+="

",this.insertHTML(c);var f=this.$element.find("table.f-t-l");f.removeClass("f-t-l"),this.setSelection(f.find("td:first").get(0),0,null,0),this.$element.focus(),this.callback("insertTable")},$.Editable.prototype.deleteTable=function(){var a=this.currentTable();a&&(a.remove(),this.callback("deleteTable"))};