KISSY.Editor.add("table/dialog/support",function(){function e(a){return f(a).length!=0}function k(a){this.editor=a;i.Utils.lazyRun(this,"_prepareTableShow","_realTableShow")}var j=KISSY,i=j.Editor,n=j.Node,l=j.DOM,o=j.UA,f=j.trim,p=i.TableUI,q=i.Dialog;l.addStyleSheet(".ke-table-config td {padding:2px;}","ke-table-dialog");p.Dialog=k;var r=i.Utils.addRes,s=i.Utils.destroyRes;j.augment(k,{_tableInit:function(){var a=new q({autoRender:true,width:"500px",mask:true,headerContent:"\u8868\u683c",bodyContent:"<div style='padding:20px 20px 10px 20px;'><table class='ke-table-config' style='width:100%'><tr><td><label>\u884c\u6570\uff1a <input  data-verify='^(?!0$)\\d+$'  data-warning='\u884c\u6570\u8bf7\u8f93\u5165\u6b63\u6574\u6570'  value='2'  class='ke-table-rows ke-table-create-only ke-input' style='margin-left:2px;vertical-align:middle;' size='6' /></label></td><td><label>\u5bbd&nbsp;&nbsp;&nbsp;\u5ea6\uff1a <input  data-verify='^(?!0$)\\d+$'  data-warning='\u5bbd\u5ea6\u8bf7\u8f93\u5165\u6b63\u6574\u6570' value='200' style='margin-left:2px;vertical-align:middle;' class='ke-table-width ke-input' size='6'/></label> <select class='ke-table-width-unit'><option value='px'>\u50cf\u7d20</option><option value='%'>\u767e\u5206\u6bd4</option></select></td></tr><tr><td><label>\u5217\u6570\uff1a <input  data-verify='^(?!0$)\\d+$'  data-warning='\u5217\u6570\u8bf7\u8f93\u5165\u6b63\u6574\u6570' class='ke-table-cols ke-table-create-only ke-input' style='margin-left:2px;vertical-align:middle;'value='3' size='6'/></label></td><td><label>\u9ad8&nbsp;&nbsp;&nbsp;\u5ea6\uff1a <input  data-verify='^((?!0$)\\d+)?$'  data-warning='\u9ad8\u5ea6\u8bf7\u8f93\u5165\u6b63\u6574\u6570' value='' style='margin-left:2px;vertical-align:middle;'class='ke-table-height ke-input' size='6'/></label> &nbsp;\u50cf\u7d20</td></tr><tr><td><label>\u5bf9\u9f50\uff1a <select class='ke-table-align'><option value=''>\u65e0</option><option value='left'>\u5de6\u5bf9\u9f50</option><option value='right'>\u53f3\u5bf9\u9f50</option><option value='center'>\u4e2d\u95f4\u5bf9\u9f50</option></select></label></td><td><label>\u6807\u9898\u683c\uff1a <select class='ke-table-head ke-table-create-only'><option value=''>\u65e0</option><option value='1'>\u6709</option></select></td></tr><tr><td><label>\u8fb9\u6846\uff1a <input  data-verify='^\\d+$'  data-warning='\u8fb9\u6846\u8bf7\u8f93\u5165\u975e\u8d1f\u6574\u6570' value='1' style='margin-left:2px;vertical-align:middle;'class='ke-table-border ke-input' size='6'/></label> &nbsp;\u50cf\u7d20 <label><input type=\"checkbox\" style=\"vertical-align: middle; margin-left: 5px;\" class=\"ke-table-collapse\" /> \u5408\u5e76\u8fb9\u6846</label></td><td><label class='ke-table-cellpadding-holder'>\u8fb9&nbsp;&nbsp;&nbsp;\u8ddd\uff1a <input  data-verify='^(\\d+)?$'  data-warning='\u8fb9\u6846\u8bf7\u8f93\u5165\u975e\u8d1f\u6574\u6570' value='0' style='margin-left:2px;vertical-align:middle;'class='ke-table-cellpadding ke-input' size='6'/> &nbsp;\u50cf\u7d20</label></td></tr><tr><td colspan='2'><label>\u6807\u9898\uff1a <input class='ke-table-caption ke-input' style='width:380px;margin-left:2px;vertical-align:middle;'></label></td></tr></table></div>",
footerContent:"<div style='padding:5px 20px 20px;'><a class='ke-table-ok ke-button' style='margin-right:20px;'>\u786e\u5b9a</a> <a class='ke-table-cancel ke-button'>\u53d6\u6d88</a></div>"}),b=a.get("body"),c=a.get("footer");a.twidth=b.one(".ke-table-width");a.theight=b.one(".ke-table-height");a.tborder=b.one(".ke-table-border");a.tcaption=b.one(".ke-table-caption");a.talign=i.Select.decorate(b.one(".ke-table-align"));a.trows=b.one(".ke-table-rows");a.tcols=b.one(".ke-table-cols");a.thead=i.Select.decorate(b.one(".ke-table-head"));
a.cellpaddingHolder=b.one(".ke-table-cellpadding-holder");a.cellpadding=b.one(".ke-table-cellpadding");a.tcollapse=b.one(".ke-table-collapse");var d=c.one(".ke-table-ok");c=c.one(".ke-table-cancel");a.twidthunit=i.Select.decorate(b.one(".ke-table-width-unit"));this.tableDialog=a;d.on("click",this._tableOk,this);c.on("click",function(g){g&&g.halt();a.hide()});r.call(this,a,a.twidthunit,d,c)},_tableOk:function(a){a&&a.halt();var b=this,c=b.tableDialog;a=c.get("el").all("input");if(c.twidthunit.val()==
"%"){c=parseInt(c.twidth.val());if(!c||c>100||c<0){alert("\u5bbd\u5ea6\u767e\u5206\u6bd4\uff1a\u8bf7\u8f93\u51651-100\u4e4b\u95f4");return}}if(i.Utils.verifyInputs(a)){b.tableDialog.hide();setTimeout(function(){b.selectedTable?b._modifyTable():b._genTable()},0)}},_modifyTable:function(){var a=this.tableDialog,b=this.selectedTable,c=b.one("caption"),d=a.talign.val(),g=a.tborder.val();e(d)?b.attr("align",f(d)):b.removeAttr("align");e(g)?b.attr("border",f(g)):b.removeAttr("border");!e(g)||g=="0"?b.addClass("ke_show_border"):b.removeClass("ke_show_border");
e(a.twidth.val())?b.css("width",f(a.twidth.val())+a.twidthunit.val()):b.css("width","");e(a.theight.val())?b.css("height",f(a.theight.val())):b.css("height","");a.tcollapse[0].checked?b.addClass("k-e-collapse-table"):b.removeClass("k-e-collapse-table");a.cellpadding.val(parseInt(a.cellpadding.val())||0);this.selectedTd&&this.selectedTd.css("padding",a.cellpadding.val());if(e(a.tcaption.val())){a=i.Utils.htmlEncode(f(a.tcaption.val()));if(c&&c[0])c.html(a);else{b=b[0].createCaption();l.html(b,"<span>"+
a+"</span>")}}else c&&c._4e_remove()},_genTable:function(){var a=this.tableDialog,b="<table ",c=parseInt(a.tcols.val())||1,d=parseInt(a.trows.val())||1,g=o.ie?"&nbsp;":"&nbsp;<br/>",m=this.editor;if(e(a.talign.val()))b+="align='"+f(a.talign.val())+"' ";if(e(a.tborder.val()))b+="border='"+f(a.tborder.val())+"' ";var h=[];e(a.twidth.val())&&h.push("width:"+f(a.twidth.val())+a.twidthunit.val()+";");e(a.theight.val())&&h.push("height:"+f(a.theight.val())+"px;");if(h.length)b+="style='"+h.join("")+"' ";
h=[];if(!e(a.tborder.val())||String(f(a.tborder.val()))=="0")h.push("ke_show_border");a.tcollapse[0].checked&&h.push("k-e-collapse-table");if(h.length)b+="class='"+h.join(" ")+"' ";b+=">";if(e(a.tcaption.val()))b+="<caption><span>"+i.Utils.htmlEncode(f(a.tcaption.val()))+"</span></caption>";if(a.thead.val()){b+="<thead>";b+="<tr>";for(a=0;a<c;a++)b+="<th>"+g+"</th>";b+="</tr>";b+="</thead>";d-=1}b+="<tbody>";for(h=0;h<d;h++){b+="<tr>";for(a=0;a<c;a++)b+="<td>"+g+"</td>";b+="</tr>"}b+="</tbody>";b+=
"</table>";b=new n(b,null,m.document);m.insertElement(b)},_fillTableDialog:function(){var a=this.tableDialog,b=this.selectedTable,c=b.one("caption");if(this.selectedTd)a.cellpadding.val(parseInt(this.selectedTd.css("padding"))||"0");a.talign.val(b.attr("align")||"");a.tborder.val(b.attr("border")||"0");var d=b._4e_style("width")||""+b.width();a.tcollapse[0].checked=!!b.hasClass("k-e-collapse-table");a.twidth.val(d.replace(/px|%|(.*pt)/i,""));d.indexOf("%")!=-1?a.twidthunit.val("%"):a.twidthunit.val("px");
a.theight.val((b._4e_style("height")||"").replace(/px|%/i,""));d="";if(c)d=c.text();a.tcaption.val(d);c=b._4e_first(function(g){return g._4e_name()=="thead"});d=(b.one("tbody")?b.one("tbody").children().length:0)+(c?c.children("tr").length:0);a.trows.val(d);a.tcols.val(b.one("tr")?b.one("tr").children().length:0);a.thead.val(c?"1":"")},_realTableShow:function(){var a=this.tableDialog;if(this.selectedTable){this._fillTableDialog();a.get("el").all(".ke-table-create-only").attr("disabled","disabled");
a.thead.disable()}else{a.get("el").all(".ke-table-create-only").removeAttr("disabled");a.thead.enable()}this.selectedTd?a.cellpaddingHolder.show():a.cellpaddingHolder.hide();this.tableDialog.show()},_prepareTableShow:function(){this._tableInit()},show:function(a,b){this.selectedTable=a;this.selectedTd=b;this._prepareTableShow()},destroy:function(){s.call(this)}})},{attach:false});
