edittable.min.js 4.5 KB

1
  1. (function(){var h=$G("J_title"),d=$G("J_titleCol"),j=$G("J_caption"),c=$G("J_sorttable"),i=$G("J_autoSizeContent"),g=$G("J_autoSizePage"),b=$G("J_tone"),f,e=$G("J_preview");var a=function(){f=this;f.init()};a.prototype={init:function(){var k=new UE.ui.ColorPicker({editor:editor}),n=new UE.ui.Popup({editor:editor,content:k});h.checked=editor.queryCommandState("inserttitle")==-1;d.checked=editor.queryCommandState("inserttitlecol")==-1;j.checked=editor.queryCommandState("insertcaption")==-1;c.checked=editor.queryCommandState("enablesort")==1;var m=editor.queryCommandState("enablesort"),l=editor.queryCommandState("disablesort");c.checked=!!(m<0&&l>=0);c.disabled=!!(m<0&&l<0);c.title=m<0&&l<0?lang.errorMsg:"";f.createTable(h.checked,d.checked,j.checked);f.setAutoSize();f.setColor(f.getColor());domUtils.on(h,"click",f.titleHanler);domUtils.on(d,"click",f.titleColHanler);domUtils.on(j,"click",f.captionHanler);domUtils.on(c,"click",f.sorttableHanler);domUtils.on(i,"click",f.autoSizeContentHanler);domUtils.on(g,"click",f.autoSizePageHanler);domUtils.on(b,"click",function(){n.showAnchor(b)});domUtils.on(document,"mousedown",function(){n.hide()});k.addListener("pickcolor",function(){f.setColor(arguments[1]);n.hide()});k.addListener("picknocolor",function(){f.setColor("");n.hide()})},createTable:function(q,p,r){var l=[],s="<span>^</span>";l.push("<table id='J_example'>");if(r){l.push("<caption>"+lang.captionName+"</caption>")}if(q){l.push("<tr>");if(p){l.push("<th>"+lang.titleName+"</th>")}for(var n=0;n<5;n++){l.push("<th>"+lang.titleName+"</th>")}l.push("</tr>")}for(var o=0;o<6;o++){l.push("<tr>");if(p){l.push("<th>"+lang.titleName+"</th>")}for(var m=0;m<5;m++){l.push("<td>"+lang.cellsName+"</td>")}l.push("</tr>")}l.push("</table>");e.innerHTML=l.join("");this.updateSortSpan()},titleHanler:function(){var k=$G("J_example"),m=document.createDocumentFragment(),l=domUtils.getComputedStyle(domUtils.getElementsByTagName(k,"td")[0],"border-color"),p=k.rows[0].children.length;if(h.checked){k.insertRow(0);for(var n=0,o;n<p;n++){o=document.createElement("th");o.innerHTML=lang.titleName;m.appendChild(o)}k.rows[0].appendChild(m)}else{domUtils.remove(k.rows[0])}f.setColor(l);f.updateSortSpan()},titleColHanler:function(){var k=$G("J_example"),l=domUtils.getComputedStyle(domUtils.getElementsByTagName(k,"td")[0],"border-color"),p=k.rows,o=p.length;if(d.checked){for(var m=0,n;m<o;m++){n=document.createElement("th");n.innerHTML=lang.titleName;p[m].insertBefore(n,p[m].children[0])}}else{for(var m=0;m<o;m++){domUtils.remove(p[m].children[0])}}f.setColor(l);f.updateSortSpan()},captionHanler:function(){var k=$G("J_example");if(j.checked){var l=document.createElement("caption");l.innerHTML=lang.captionName;k.insertBefore(l,k.firstChild)}else{domUtils.remove(domUtils.getElementsByTagName(k,"caption")[0])}},sorttableHanler:function(){f.updateSortSpan()},autoSizeContentHanler:function(){var k=$G("J_example");k.removeAttribute("width")},autoSizePageHanler:function(){var k=$G("J_example");var l=k.getElementsByTagName(k,"td");utils.each(l,function(m){m.removeAttribute("width")});k.setAttribute("width","100%")},updateSortSpan:function(){var k=$G("J_example"),m=k.rows[0];var l=domUtils.getElementsByTagName(k,"span");utils.each(l,function(n){n.parentNode.removeChild(n)});if(c.checked){utils.each(m.cells,function(n,o){var p=document.createElement("span");p.innerHTML="^";n.appendChild(p)})}},getColor:function(){var m=editor.selection.getStart(),l,k=domUtils.findParentByTagName(m,["td","th","caption"],true);l=k&&domUtils.getComputedStyle(k,"border-color");if(!l){l="#DDDDDD"}return l},setColor:function(m){var l=$G("J_example"),k=domUtils.getElementsByTagName(l,"td").concat(domUtils.getElementsByTagName(l,"th"),domUtils.getElementsByTagName(l,"caption"));b.value=m;utils.each(k,function(n){n.style.borderColor=m})},setAutoSize:function(){var k=this;g.checked=true;k.autoSizePageHanler()}};new a;dialog.onok=function(){editor.__hasEnterExecCommand=true;var m={title:"inserttitle deletetitle",titleCol:"inserttitlecol deletetitlecol",caption:"insertcaption deletecaption",sorttable:"enablesort disablesort"};editor.fireEvent("saveScene");for(var n in m){var k=m[n].split(" "),l=$G("J_"+n);if(l.checked){editor.queryCommandState(k[0])!=-1&&editor.execCommand(k[0])}else{editor.queryCommandState(k[1])!=-1&&editor.execCommand(k[1])}}editor.execCommand("edittable",b.value);i.checked?editor.execCommand("adaptbytext"):"";g.checked?editor.execCommand("adaptbywindow"):"";editor.fireEvent("saveScene");editor.__hasEnterExecCommand=false}})();