summaryrefslogtreecommitdiff
path: root/program/js/tiny_mce/plugins/table
diff options
context:
space:
mode:
Diffstat (limited to 'program/js/tiny_mce/plugins/table')
-rw-r--r--program/js/tiny_mce/plugins/table/cell.htm9
-rw-r--r--program/js/tiny_mce/plugins/table/editor_plugin.js2
-rw-r--r--program/js/tiny_mce/plugins/table/editor_plugin_src.js1862
-rw-r--r--program/js/tiny_mce/plugins/table/js/cell.js63
-rw-r--r--program/js/tiny_mce/plugins/table/js/merge_cells.js38
-rw-r--r--program/js/tiny_mce/plugins/table/js/row.js69
-rw-r--r--program/js/tiny_mce/plugins/table/js/table.js25
-rw-r--r--program/js/tiny_mce/plugins/table/merge_cells.htm11
-rw-r--r--program/js/tiny_mce/plugins/table/row.htm9
-rw-r--r--program/js/tiny_mce/plugins/table/table.htm9
10 files changed, 1021 insertions, 1076 deletions
diff --git a/program/js/tiny_mce/plugins/table/cell.htm b/program/js/tiny_mce/plugins/table/cell.htm
index 1fabc8dc2..d243e1d83 100644
--- a/program/js/tiny_mce/plugins/table/cell.htm
+++ b/program/js/tiny_mce/plugins/table/cell.htm
@@ -170,13 +170,8 @@
</select>
</div>
- <div style="float: left">
- <div><input type="submit" id="insert" name="insert" value="{#update}" /></div>
- </div>
-
- <div style="float: right">
- <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
- </div>
+ <input type="submit" id="insert" name="insert" value="{#update}" />
+ <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
</div>
</form>
</body>
diff --git a/program/js/tiny_mce/plugins/table/editor_plugin.js b/program/js/tiny_mce/plugins/table/editor_plugin.js
index 806ef288f..39f2c694b 100644
--- a/program/js/tiny_mce/plugins/table/editor_plugin.js
+++ b/program/js/tiny_mce/plugins/table/editor_plugin.js
@@ -1 +1 @@
-(function(){var b=tinymce.each;function a(d,e){var f=e.ownerDocument,c=f.createRange(),g;c.setStartBefore(e);c.setEnd(d.endContainer,d.endOffset);g=f.createElement("body");g.appendChild(c.cloneContents());return g.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi,"-").replace(/<[^>]+>/g,"").length==0}tinymce.create("tinymce.plugins.TablePlugin",{init:function(c,d){var e=this;e.editor=c;e.url=d;b([["table","table.desc","mceInsertTable",true],["delete_table","table.del","mceTableDelete"],["delete_col","table.delete_col_desc","mceTableDeleteCol"],["delete_row","table.delete_row_desc","mceTableDeleteRow"],["col_after","table.col_after_desc","mceTableInsertColAfter"],["col_before","table.col_before_desc","mceTableInsertColBefore"],["row_after","table.row_after_desc","mceTableInsertRowAfter"],["row_before","table.row_before_desc","mceTableInsertRowBefore"],["row_props","table.row_desc","mceTableRowProps",true],["cell_props","table.cell_desc","mceTableCellProps",true],["split_cells","table.split_cells_desc","mceTableSplitCells",true],["merge_cells","table.merge_cells_desc","mceTableMergeCells",true]],function(f){c.addButton(f[0],{title:f[1],cmd:f[2],ui:f[3]})});if(c.getParam("inline_styles")){c.onPreProcess.add(function(f,h){var g=f.dom;b(g.select("table",h.node),function(j){var i;if(i=g.getAttrib(j,"width")){g.setStyle(j,"width",i);g.setAttrib(j,"width")}if(i=g.getAttrib(j,"height")){g.setStyle(j,"height",i);g.setAttrib(j,"height")}})})}c.onInit.add(function(){if(!tinymce.isIE&&c.getParam("forced_root_block")){function f(){var g=c.getBody().lastChild;if(g&&g.nodeName=="TABLE"){c.dom.add(c.getBody(),"p",null,'<br mce_bogus="1" />')}}if(tinymce.isGecko){c.onKeyDown.add(function(h,j){var g,i,k=h.dom;if(j.keyCode==37||j.keyCode==38){g=h.selection.getRng();i=k.getParent(g.startContainer,"table");if(i&&h.getBody().firstChild==i){if(a(g,i)){g=k.createRng();g.setStartBefore(i);g.setEndBefore(i);h.selection.setRng(g);j.preventDefault()}}}})}c.onKeyUp.add(f);c.onSetContent.add(f);c.onVisualAid.add(f);c.onPreProcess.add(function(g,i){var h=i.node.lastChild;if(h&&h.childNodes.length==1&&h.firstChild.nodeName=="BR"){g.dom.remove(h)}});f()}if(c&&c.plugins.contextmenu){c.plugins.contextmenu.onContextMenu.add(function(i,g,k){var l,j=c.selection,h=j.getNode()||c.getBody();if(c.dom.getParent(k,"td")||c.dom.getParent(k,"th")){g.removeAll();if(h.nodeName=="A"&&!c.dom.getAttrib(h,"name")){g.add({title:"advanced.link_desc",icon:"link",cmd:c.plugins.advlink?"mceAdvLink":"mceLink",ui:true});g.add({title:"advanced.unlink_desc",icon:"unlink",cmd:"UnLink"});g.addSeparator()}if(h.nodeName=="IMG"&&h.className.indexOf("mceItem")==-1){g.add({title:"advanced.image_desc",icon:"image",cmd:c.plugins.advimage?"mceAdvImage":"mceImage",ui:true});g.addSeparator()}g.add({title:"table.desc",icon:"table",cmd:"mceInsertTable",ui:true,value:{action:"insert"}});g.add({title:"table.props_desc",icon:"table_props",cmd:"mceInsertTable",ui:true});g.add({title:"table.del",icon:"delete_table",cmd:"mceTableDelete",ui:true});g.addSeparator();l=g.addMenu({title:"table.cell"});l.add({title:"table.cell_desc",icon:"cell_props",cmd:"mceTableCellProps",ui:true});l.add({title:"table.split_cells_desc",icon:"split_cells",cmd:"mceTableSplitCells",ui:true});l.add({title:"table.merge_cells_desc",icon:"merge_cells",cmd:"mceTableMergeCells",ui:true});l=g.addMenu({title:"table.row"});l.add({title:"table.row_desc",icon:"row_props",cmd:"mceTableRowProps",ui:true});l.add({title:"table.row_before_desc",icon:"row_before",cmd:"mceTableInsertRowBefore"});l.add({title:"table.row_after_desc",icon:"row_after",cmd:"mceTableInsertRowAfter"});l.add({title:"table.delete_row_desc",icon:"delete_row",cmd:"mceTableDeleteRow"});l.addSeparator();l.add({title:"table.cut_row_desc",icon:"cut",cmd:"mceTableCutRow"});l.add({title:"table.copy_row_desc",icon:"copy",cmd:"mceTableCopyRow"});l.add({title:"table.paste_row_before_desc",icon:"paste",cmd:"mceTablePasteRowBefore"});l.add({title:"table.paste_row_after_desc",icon:"paste",cmd:"mceTablePasteRowAfter"});l=g.addMenu({title:"table.col"});l.add({title:"table.col_before_desc",icon:"col_before",cmd:"mceTableInsertColBefore"});l.add({title:"table.col_after_desc",icon:"col_after",cmd:"mceTableInsertColAfter"});l.add({title:"table.delete_col_desc",icon:"delete_col",cmd:"mceTableDeleteCol"})}else{g.add({title:"table.desc",icon:"table",cmd:"mceInsertTable",ui:true})}})}});c.onKeyDown.add(function(f,g){if(g.keyCode==9&&f.dom.getParent(f.selection.getNode(),"TABLE")){if(!tinymce.isGecko&&!tinymce.isOpera){tinyMCE.execInstanceCommand(f.editorId,"mceTableMoveToNextRow",true);return tinymce.dom.Event.cancel(g)}f.undoManager.add()}});if(!tinymce.isIE){if(c.getParam("table_selection",true)){c.onClick.add(function(f,g){g=g.target;if(g.nodeName==="TABLE"){f.selection.select(g)}})}}c.onNodeChange.add(function(g,f,i){var h=g.dom.getParent(i,"td,th,caption");f.setActive("table",i.nodeName==="TABLE"||!!h);if(h&&h.nodeName==="CAPTION"){h=null}f.setDisabled("delete_table",!h);f.setDisabled("delete_col",!h);f.setDisabled("delete_table",!h);f.setDisabled("delete_row",!h);f.setDisabled("col_after",!h);f.setDisabled("col_before",!h);f.setDisabled("row_after",!h);f.setDisabled("row_before",!h);f.setDisabled("row_props",!h);f.setDisabled("cell_props",!h);f.setDisabled("split_cells",!h||(parseInt(g.dom.getAttrib(h,"colspan","1"))<2&&parseInt(g.dom.getAttrib(h,"rowspan","1"))<2));f.setDisabled("merge_cells",!h)});if(!tinymce.isIE){c.onBeforeSetContent.add(function(f,g){if(g.initial){g.content=g.content.replace(/<(td|th)([^>]+|)>\s*<\/(td|th)>/g,tinymce.isOpera?"<$1$2>&nbsp;</$1>":'<$1$2><br mce_bogus="1" /></$1>')}})}},execCommand:function(f,e,g){var d=this.editor,c;switch(f){case"mceTableMoveToNextRow":case"mceInsertTable":case"mceTableRowProps":case"mceTableCellProps":case"mceTableSplitCells":case"mceTableMergeCells":case"mceTableInsertRowBefore":case"mceTableInsertRowAfter":case"mceTableDeleteRow":case"mceTableInsertColBefore":case"mceTableInsertColAfter":case"mceTableDeleteCol":case"mceTableCutRow":case"mceTableCopyRow":case"mceTablePasteRowBefore":case"mceTablePasteRowAfter":case"mceTableDelete":d.execCommand("mceBeginUndoLevel");this._doExecCommand(f,e,g);d.execCommand("mceEndUndoLevel");return true}return false},getInfo:function(){return{longname:"Tables",author:"Moxiecode Systems AB",authorurl:"http://tinymce.moxiecode.com",infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table",version:tinymce.majorVersion+"."+tinymce.minorVersion}},_doExecCommand:function(s,aa,af){var W=this.editor,av=W,h=this.url;var o=W.selection.getNode();var X=W.dom.getParent(o,"tr");var ar=W.dom.getParent(o,"td,th");var G=W.dom.getParent(o,"table");var l=W.contentWindow.document;var aw=G?G.getAttribute("border"):"";if(X&&ar==null){ar=X.cells[0]}function aq(y,x){for(var ay=0;ay<y.length;ay++){if(y[ay].length>0&&aq(y[ay],x)){return true}if(y[ay]==x){return true}}return false}function ak(x,i){var y;ae=f(G);x=x||0;i=i||0;x=Math.max(p.cellindex+x,0);i=Math.max(p.rowindex+i,0);W.execCommand("mceRepaint");y=e(ae,i,x);if(y){W.selection.select(y.firstChild||y);W.selection.collapse(1)}}function ai(){var i=l.createElement("td");if(!tinymce.isIE){i.innerHTML='<br mce_bogus="1"/>'}}function k(y){var x=W.dom.getAttrib(y,"colspan");var i=W.dom.getAttrib(y,"rowspan");x=x==""?1:parseInt(x);i=i==""?1:parseInt(i);return{colspan:x,rowspan:i}}function am(ay,aA){var i,az;for(az=0;az<ay.length;az++){for(i=0;i<ay[az].length;i++){if(ay[az][i]==aA){return{cellindex:i,rowindex:az}}}}return null}function e(x,y,i){if(x[y]&&x[y][i]){return x[y][i]}return null}function B(aD,ay){var aA=[],y=0,aB,az,ay,aC;for(aB=0;aB<aD.rows.length;aB++){for(az=0;az<aD.rows[aB].cells.length;az++,y++){aA[y]=aD.rows[aB].cells[az]}}for(aB=0;aB<aA.length;aB++){if(aA[aB]==ay){if(aC=aA[aB+1]){return aC}}}}function f(aF){var i=[],aG=aF.rows,aD,aC,az,aA,aE,ay,aB;for(aC=0;aC<aG.length;aC++){for(aD=0;aD<aG[aC].cells.length;aD++){az=aG[aC].cells[aD];aA=k(az);for(aE=aD;i[aC]&&i[aC][aE];aE++){}for(aB=aC;aB<aC+aA.rowspan;aB++){if(!i[aB]){i[aB]=[]}for(ay=aE;ay<aE+aA.colspan;ay++){i[aB][ay]=az}}}}return i}function n(aH,aE,az,ay){var y=f(aH),aG=am(y,az);var aI,aD;if(ay.cells.length!=aE.childNodes.length){aI=aE.childNodes;aD=null;for(var aF=0;az=e(y,aG.rowindex,aF);aF++){var aB=true;var aC=k(az);if(aq(aI,az)){ay.childNodes[aF]._delete=true}else{if((aD==null||az!=aD)&&aC.colspan>1){for(var aA=aF;aA<aF+az.colSpan;aA++){ay.childNodes[aA]._delete=true}}}if((aD==null||az!=aD)&&aC.rowspan>1){az.rowSpan=aC.rowspan+1}aD=az}C(G)}}function P(x,i){while((x=x.previousSibling)!=null){if(x.nodeName==i){return x}}return null}function ag(ay,az){var x=az.split(",");while((ay=ay.nextSibling)!=null){for(var y=0;y<x.length;y++){if(ay.nodeName.toLowerCase()==x[y].toLowerCase()){return ay}}}return null}function C(ay){if(ay.rows==0){return}var y=ay.rows[0];do{var x=ag(y,"TR");if(y._delete){y.parentNode.removeChild(y);continue}var az=y.cells[0];if(az.cells>1){do{var i=ag(az,"TD,TH");if(az._delete){az.parentNode.removeChild(az)}}while((az=i)!=null)}}while((y=x)!=null)}function q(ay,aB,aA){ay.rowSpan=1;var x=ag(aB,"TR");for(var az=1;az<aA&&x;az++){var y=l.createElement("td");if(!tinymce.isIE){y.innerHTML='<br mce_bogus="1"/>'}if(tinymce.isIE){x.insertBefore(y,x.cells(ay.cellIndex))}else{x.insertBefore(y,x.cells[ay.cellIndex])}x=ag(x,"TR")}}function T(aG,aI,aC){var y=f(aI);var ay=aC.cloneNode(false);var aH=am(y,aC.cells[0]);var aD=null;var aB=W.dom.getAttrib(aI,"border");var aA=null;for(var aF=0;aA=e(y,aH.rowindex,aF);aF++){var aE=null;if(aD!=aA){for(var az=0;az<aC.cells.length;az++){if(aA==aC.cells[az]){aE=aA.cloneNode(true);break}}}if(aE==null){aE=aG.createElement("td");if(!tinymce.isIE){aE.innerHTML='<br mce_bogus="1"/>'}}aE.colSpan=1;aE.rowSpan=1;ay.appendChild(aE);aD=aA}return ay}switch(s){case"mceTableMoveToNextRow":var M=B(G,ar);if(!M){W.execCommand("mceTableInsertRowAfter",ar);M=B(G,ar)}W.selection.select(M);W.selection.collapse(true);return true;case"mceTableRowProps":if(X==null){return true}if(aa){W.windowManager.open({url:h+"/row.htm",width:400+parseInt(W.getLang("table.rowprops_delta_width",0)),height:295+parseInt(W.getLang("table.rowprops_delta_height",0)),inline:1},{plugin_url:h})}return true;case"mceTableCellProps":if(ar==null){return true}if(aa){W.windowManager.open({url:h+"/cell.htm",width:400+parseInt(W.getLang("table.cellprops_delta_width",0)),height:295+parseInt(W.getLang("table.cellprops_delta_height",0)),inline:1},{plugin_url:h})}return true;case"mceInsertTable":if(aa){W.windowManager.open({url:h+"/table.htm",width:400+parseInt(W.getLang("table.table_delta_width",0)),height:320+parseInt(W.getLang("table.table_delta_height",0)),inline:1},{plugin_url:h,action:af?af.action:0})}return true;case"mceTableDelete":var H=W.dom.getParent(W.selection.getNode(),"table");if(H){H.parentNode.removeChild(H);W.execCommand("mceRepaint")}return true;case"mceTableSplitCells":case"mceTableMergeCells":case"mceTableInsertRowBefore":case"mceTableInsertRowAfter":case"mceTableDeleteRow":case"mceTableInsertColBefore":case"mceTableInsertColAfter":case"mceTableDeleteCol":case"mceTableCutRow":case"mceTableCopyRow":case"mceTablePasteRowBefore":case"mceTablePasteRowAfter":if(!G){return true}if(X&&G!=X.parentNode){G=X.parentNode}if(G&&X){switch(s){case"mceTableCutRow":if(!X||!ar){return true}W.tableRowClipboard=T(l,G,X);W.execCommand("mceTableDeleteRow");break;case"mceTableCopyRow":if(!X||!ar){return true}W.tableRowClipboard=T(l,G,X);break;case"mceTablePasteRowBefore":if(!X||!ar){return true}var w=W.tableRowClipboard.cloneNode(true);var j=P(X,"TR");if(j!=null){n(G,j,j.cells[0],w)}X.parentNode.insertBefore(w,X);break;case"mceTablePasteRowAfter":if(!X||!ar){return true}var Y=ag(X,"TR");var w=W.tableRowClipboard.cloneNode(true);n(G,X,ar,w);if(Y==null){X.parentNode.appendChild(w)}else{Y.parentNode.insertBefore(w,Y)}break;case"mceTableInsertRowBefore":if(!X||!ar){return true}var ae=f(G);var p=am(ae,ar);var w=l.createElement("tr");var v=null;p.rowindex--;if(p.rowindex<0){p.rowindex=0}for(var ad=0;ar=e(ae,p.rowindex,ad);ad++){if(ar!=v){var F=k(ar);if(F.rowspan==1){var K=l.createElement("td");if(!tinymce.isIE){K.innerHTML='<br mce_bogus="1"/>'}K.colSpan=ar.colSpan;w.appendChild(K)}else{ar.rowSpan=F.rowspan+1}v=ar}}X.parentNode.insertBefore(w,X);ak(0,1);break;case"mceTableInsertRowAfter":if(!X||!ar){return true}var ae=f(G);var p=am(ae,ar);var w=l.createElement("tr");var v=null;for(var ad=0;ar=e(ae,p.rowindex,ad);ad++){if(ar!=v){var F=k(ar);if(F.rowspan==1){var K=l.createElement("td");if(!tinymce.isIE){K.innerHTML='<br mce_bogus="1"/>'}K.colSpan=ar.colSpan;w.appendChild(K)}else{ar.rowSpan=F.rowspan+1}v=ar}}if(w.hasChildNodes()){var Y=ag(X,"TR");if(Y){Y.parentNode.insertBefore(w,Y)}else{G.appendChild(w)}}ak(0,1);break;case"mceTableDeleteRow":if(!X||!ar){return true}var ae=f(G);var p=am(ae,ar);if(ae.length==1&&G.nodeName=="TBODY"){W.dom.remove(W.dom.getParent(G,"table"));return true}var E=X.cells;var Y=ag(X,"TR");for(var ad=0;ad<E.length;ad++){if(E[ad].rowSpan>1){var K=E[ad].cloneNode(true);var F=k(E[ad]);K.rowSpan=F.rowspan-1;var al=Y.cells[ad];if(al==null){Y.appendChild(K)}else{Y.insertBefore(K,al)}}}var v=null;for(var ad=0;ar=e(ae,p.rowindex,ad);ad++){if(ar!=v){var F=k(ar);if(F.rowspan>1){ar.rowSpan=F.rowspan-1}else{X=ar.parentNode;if(X.parentNode){X._delete=true}}v=ar}}C(G);ak(0,-1);break;case"mceTableInsertColBefore":if(!X||!ar){return true}var ae=f(W.dom.getParent(G,"table"));var p=am(ae,ar);var v=null;for(var ab=0;ar=e(ae,ab,p.cellindex);ab++){if(ar!=v){var F=k(ar);if(F.colspan==1){var K=l.createElement(ar.nodeName);if(!tinymce.isIE){K.innerHTML='<br mce_bogus="1"/>'}K.rowSpan=ar.rowSpan;ar.parentNode.insertBefore(K,ar)}else{ar.colSpan++}v=ar}}ak();break;case"mceTableInsertColAfter":if(!X||!ar){return true}var ae=f(W.dom.getParent(G,"table"));var p=am(ae,ar);var v=null;for(var ab=0;ar=e(ae,ab,p.cellindex);ab++){if(ar!=v){var F=k(ar);if(F.colspan==1){var K=l.createElement(ar.nodeName);if(!tinymce.isIE){K.innerHTML='<br mce_bogus="1"/>'}K.rowSpan=ar.rowSpan;var al=ag(ar,"TD,TH");if(al==null){ar.parentNode.appendChild(K)}else{al.parentNode.insertBefore(K,al)}}else{ar.colSpan++}v=ar}}ak(1);break;case"mceTableDeleteCol":if(!X||!ar){return true}var ae=f(G);var p=am(ae,ar);var v=null;if((ae.length>1&&ae[0].length<=1)&&G.nodeName=="TBODY"){W.dom.remove(W.dom.getParent(G,"table"));return true}for(var ab=0;ar=e(ae,ab,p.cellindex);ab++){if(ar!=v){var F=k(ar);if(F.colspan>1){ar.colSpan=F.colspan-1}else{if(ar.parentNode){ar.parentNode.removeChild(ar)}}v=ar}}ak(-1);break;case"mceTableSplitCells":if(!X||!ar){return true}var m=k(ar);var D=m.colspan;var I=m.rowspan;if(D>1||I>1){ar.colSpan=1;for(var an=1;an<D;an++){var K=l.createElement("td");if(!tinymce.isIE){K.innerHTML='<br mce_bogus="1"/>'}X.insertBefore(K,ag(ar,"TD,TH"));if(I>1){q(K,X,I)}}q(ar,X,I)}G=W.dom.getParent(W.selection.getNode(),"table");break;case"mceTableMergeCells":var ap=[];var S=W.selection.getSel();var ae=f(G);if(tinymce.isIE||S.rangeCount==1){if(aa){var u=k(ar);W.windowManager.open({url:h+"/merge_cells.htm",width:240+parseInt(W.getLang("table.merge_cells_delta_width",0)),height:110+parseInt(W.getLang("table.merge_cells_delta_height",0)),inline:1},{action:"update",numcols:u.colspan,numrows:u.rowspan,plugin_url:h});return true}else{var V=parseInt(af.numrows);var d=parseInt(af.numcols);var p=am(ae,ar);if((""+V)=="NaN"){V=1}if((""+d)=="NaN"){d=1}var c=G.rows;for(var ab=p.rowindex;ab<ae.length;ab++){var ah=[];for(var ad=p.cellindex;ad<ae[ab].length;ad++){var g=e(ae,ab,ad);if(g&&!aq(ap,g)&&!aq(ah,g)){var O=am(ae,g);if(O.cellindex<p.cellindex+d&&O.rowindex<p.rowindex+V){ah[ah.length]=g}}}if(ah.length>0){ap[ap.length]=ah}var g=e(ae,p.rowindex,p.cellindex);b(av.dom.select("br",g),function(y,x){if(x>0&&av.dom.getAttrib("mce_bogus")){av.dom.remove(y)}})}}}else{var E=[];var S=W.selection.getSel();var Z=null;var ao=null;var A=-1,ax=-1,z,au;if(S.rangeCount<2){return true}for(var an=0;an<S.rangeCount;an++){var aj=S.getRangeAt(an);var ar=aj.startContainer.childNodes[aj.startOffset];if(!ar){break}if(ar.nodeName=="TD"||ar.nodeName=="TH"){E[E.length]=ar}}var c=G.rows;for(var ab=0;ab<c.length;ab++){var ah=[];for(var ad=0;ad<c[ab].cells.length;ad++){var g=c[ab].cells[ad];for(var an=0;an<E.length;an++){if(g==E[an]){ah[ah.length]=g}}}if(ah.length>0){ap[ap.length]=ah}}var ao=[];var Z=null;for(var ab=0;ab<ae.length;ab++){for(var ad=0;ad<ae[ab].length;ad++){ae[ab][ad]._selected=false;for(var an=0;an<E.length;an++){if(ae[ab][ad]==E[an]){if(A==-1){A=ad;ax=ab}z=ad;au=ab;ae[ab][ad]._selected=true}}}}for(var ab=ax;ab<=au;ab++){for(var ad=A;ad<=z;ad++){if(!ae[ab][ad]._selected){alert("Invalid selection for merge.");return true}}}}var t=1,r=1;var U=-1;for(var ab=0;ab<ap.length;ab++){var J=0;for(var ad=0;ad<ap[ab].length;ad++){var F=k(ap[ab][ad]);J+=F.colspan;if(U!=-1&&F.rowspan!=U){alert("Invalid selection for merge.");return true}U=F.rowspan}if(J>r){r=J}U=-1}var R=-1;for(var ad=0;ad<ap[0].length;ad++){var N=0;for(var ab=0;ab<ap.length;ab++){var F=k(ap[ab][ad]);N+=F.rowspan;if(R!=-1&&F.colspan!=R){alert("Invalid selection for merge.");return true}R=F.colspan}if(N>t){t=N}R=-1}ar=ap[0][0];ar.rowSpan=t;ar.colSpan=r;for(var ab=0;ab<ap.length;ab++){for(var ad=0;ad<ap[ab].length;ad++){var Q=ap[ab][ad].innerHTML;var L=Q.replace(/[ \t\r\n]/g,"");if(L!="<br/>"&&L!="<br>"&&L!='<br mce_bogus="1"/>'&&(ad+ab>0)){ar.innerHTML+=Q}if(ap[ab][ad]!=ar&&!ap[ab][ad]._deleted){var p=am(ae,ap[ab][ad]);var at=ap[ab][ad].parentNode;at.removeChild(ap[ab][ad]);ap[ab][ad]._deleted=true;if(!at.hasChildNodes()){at.parentNode.removeChild(at);var ac=null;for(var ad=0;cellElm=e(ae,p.rowindex,ad);ad++){if(cellElm!=ac&&cellElm.rowSpan>1){cellElm.rowSpan--}ac=cellElm}if(ar.rowSpan>1){ar.rowSpan--}}}}}b(av.dom.select("br",ar),function(y,x){if(x>0&&av.dom.getAttrib(y,"mce_bogus")){av.dom.remove(y)}});break}G=W.dom.getParent(W.selection.getNode(),"table");W.addVisual(G);W.nodeChanged()}return true}return false}});tinymce.PluginManager.add("table",tinymce.plugins.TablePlugin)})(); \ No newline at end of file
+(function(b){var c=b.each;function a(E,D,H){var e,I,A,n;r();n=D.getParent(H.getStart(),"th,td");if(n){I=C(n);A=F();n=v(I.x,I.y)}function r(){var J=0;e=[];c(["thead","tbody","tfoot"],function(K){var L=D.select(K+" tr",E);c(L,function(M,N){N+=J;c(D.select("td,th",M),function(T,O){var P,Q,R,S;if(e[N]){while(e[N][O]){O++}}R=g(T,"rowspan");S=g(T,"colspan");for(Q=N;Q<N+R;Q++){if(!e[Q]){e[Q]=[]}for(P=O;P<O+S;P++){e[Q][P]={part:K,real:Q==N&&P==O,elm:T,rowspan:R,colspan:S}}}})});J+=L.length})}function v(J,L){var K;K=e[L];if(K){return K[J]}}function g(K,J){return parseInt(K.getAttribute(J)||1)}function h(J){return D.hasClass(J.elm,"mceSelected")||J==n}function j(){var J=[];c(E.rows,function(K){c(K.cells,function(L){if(D.hasClass(L,"mceSelected")||L==n.elm){J.push(K);return false}})});return J}function q(){var J=D.createRng();J.setStartAfter(E);J.setEndAfter(E);H.setRng(J);D.remove(E)}function d(J){var K;b.walk(J,function(M){var L;if(M.nodeType==3){c(D.getParents(M.parentNode,null,J).reverse(),function(N){N=N.cloneNode(false);if(!K){K=L=N}else{if(L){L.appendChild(N)}}L=N});if(L){L.innerHTML=b.isIE?"&nbsp;":'<br _mce_bogus="1" />'}return false}},"childNodes");J=J.cloneNode(false);J.rowSpan=J.colSpan=1;if(K){J.appendChild(K)}else{if(!b.isIE){J.innerHTML='<br _mce_bogus="1" />'}}return J}function p(){var J=D.createRng();c(D.select("tr",E),function(K){if(K.cells.length==0){D.remove(K)}});if(D.select("tr",E).length==0){J.setStartAfter(E);J.setEndAfter(E);H.setRng(J);D.remove(E);return}c(D.select("thead,tbody,tfoot",E),function(K){if(K.rows.length==0){D.remove(K)}});r();row=e[Math.min(e.length-1,I.y)];if(row){H.select(row[Math.min(row.length-1,I.x)].elm,true);H.collapse(true)}}function s(P,N,R,O){var M,K,J,L,Q;M=e[N][P].elm.parentNode;for(J=1;J<=R;J++){M=D.getNext(M,"tr");if(M){for(K=P;K>=0;K--){Q=e[N+J][K].elm;if(Q.parentNode==M){for(L=1;L<=O;L++){D.insertAfter(d(Q),Q)}break}}if(K==-1){for(L=1;L<=O;L++){M.insertBefore(d(M.cells[0]),M.cells[0])}}}}}function z(){c(e,function(J,K){c(J,function(M,L){var P,O,Q,N;if(h(M)){M=M.elm;P=g(M,"colspan");O=g(M,"rowspan");if(P>1||O>1){M.colSpan=M.rowSpan=1;for(N=0;N<P-1;N++){D.insertAfter(d(M),M)}s(L,K,O-1,P)}}})})}function o(R,O,U){var M,L,T,S,Q,N,P,J,R,K;if(R){pos=C(R);M=pos.x;L=pos.y;T=M+(O-1);S=L+(U-1)}else{M=I.x;L=I.y;T=A.x;S=A.y}P=v(M,L);J=v(T,S);if(P&&J&&P.part==J.part){z();r();P=v(M,L).elm;P.colSpan=(T-M)+1;P.rowSpan=(S-L)+1;for(N=L;N<=S;N++){for(Q=M;Q<=T;Q++){R=e[N][Q].elm;if(R!=P){K=b.grep(R.childNodes);c(K,function(W,V){if(W.nodeName!="BR"||V!=K.length-1){P.appendChild(W)}});D.remove(R)}}}p()}}function k(M){var J,O,L,N,P,Q,K,R;c(e,function(S,T){c(S,function(V,U){if(h(V)){V=V.elm;P=V.parentNode;Q=P.cloneNode(false);J=T;if(M){return false}}});if(M){return !J}});for(N=0;N<e[0].length;N++){O=e[J][N].elm;if(O!=L){if(!M){rowSpan=g(O,"rowspan");if(rowSpan>1){O.rowSpan=rowSpan+1;continue}}else{if(J>0&&e[J-1][N]){R=e[J-1][N].elm;rowSpan=g(R,"rowspan");if(rowSpan>1){R.rowSpan=rowSpan+1;continue}}}K=d(O);K.colSpan=O.colSpan;Q.appendChild(K);L=O}}if(Q.hasChildNodes()){if(!M){D.insertAfter(Q,P)}else{P.parentNode.insertBefore(Q,P)}}}function f(K){var L,J;c(e,function(M,N){c(M,function(P,O){if(h(P)){L=O;if(K){return false}}});if(K){return !L}});c(e,function(P,Q){var M=P[L].elm,N,O;if(M!=J){O=g(M,"colspan");N=g(M,"rowspan");if(O==1){if(!K){D.insertAfter(d(M),M);s(L,Q,N-1,O)}else{M.parentNode.insertBefore(d(M),M);s(L,Q,N-1,O)}}else{M.colSpan++}J=M}})}function m(){var J=[];c(e,function(K,L){c(K,function(N,M){if(h(N)&&b.inArray(J,M)===-1){c(e,function(Q){var O=Q[M].elm,P;P=g(O,"colspan");if(P>1){O.colSpan=P-1}else{D.remove(O)}});J.push(M)}})});p()}function l(){var K;function J(N){var M,O,L;M=D.getNext(N,"tr");c(N.cells,function(P){var Q=g(P,"rowspan");if(Q>1){P.rowSpan=Q-1;O=C(P);s(O.x,O.y,1,1)}});O=C(N.cells[0]);c(e[O.y],function(P){var Q;P=P.elm;if(P!=L){Q=g(P,"rowspan");if(Q<=1){D.remove(P)}else{P.rowSpan=Q-1}L=P}})}K=j();c(K.reverse(),function(L){J(L)});p()}function B(){var J=j();D.remove(J);p();return J}function G(){var J=j();c(J,function(L,K){J[K]=L.cloneNode(true)});return J}function w(L,K){var M=j(),J=M[K?0:M.length-1],N=J.cells.length;c(e,function(P){var O;N=0;c(P,function(R,Q){if(R.real){N+=R.colspan}if(R.elm.parentNode==J){O=1}});if(O){return false}});if(!K){L.reverse()}c(L,function(Q){var P=Q.cells.length,O;for(i=0;i<P;i++){O=Q.cells[i];O.colSpan=O.rowSpan=1}for(i=P;i<N;i++){Q.appendChild(d(Q.cells[P-1]))}for(i=N;i<P;i++){D.remove(Q.cells[i])}if(K){J.parentNode.insertBefore(Q,J)}else{D.insertAfter(Q,J)}})}function C(J){var K;c(e,function(L,M){c(L,function(O,N){if(O.elm==J){K={x:N,y:M};return false}});return !K});return K}function u(J){I=C(J)}function F(){var L,K,J;K=J=0;c(e,function(M,N){c(M,function(P,O){var R,Q;if(h(P)){P=e[N][O];if(O>K){K=O}if(N>J){J=N}if(P.real){R=P.colspan-1;Q=P.rowspan-1;if(R){if(O+R>K){K=O+R}}if(Q){if(N+Q>J){J=N+Q}}}}})});return{x:K,y:J}}function t(P){var M,L,R,Q,K,J,N,O;A=C(P);if(I&&A){M=Math.min(I.x,A.x);L=Math.min(I.y,A.y);R=Math.max(I.x,A.x);Q=Math.max(I.y,A.y);K=R;J=Q;for(y=L;y<=J;y++){P=e[y][M];if(!P.real){if(M-(P.colspan-1)<M){M-=P.colspan-1}}}for(x=M;x<=K;x++){P=e[L][x];if(!P.real){if(L-(P.rowspan-1)<L){L-=P.rowspan-1}}}for(y=L;y<=Q;y++){for(x=M;x<=R;x++){P=e[y][x];if(P.real){N=P.colspan-1;O=P.rowspan-1;if(N){if(x+N>K){K=x+N}}if(O){if(y+O>J){J=y+O}}}}}D.removeClass(D.select("td.mceSelected,th.mceSelected"),"mceSelected");for(y=L;y<=J;y++){for(x=M;x<=K;x++){D.addClass(e[y][x].elm,"mceSelected")}}}}b.extend(this,{deleteTable:q,split:z,merge:o,insertRow:k,insertCol:f,deleteCols:m,deleteRows:l,cutRows:B,copyRows:G,pasteRows:w,getPos:C,setStartCell:u,setEndCell:t})}b.create("tinymce.plugins.TablePlugin",{init:function(e,f){var d,j;function h(m){var l=e.selection,k=e.dom.getParent(m||l.getNode(),"table");if(k){return new a(k,e.dom,l)}}function g(){e.getBody().style.webkitUserSelect="";e.dom.removeClass(e.dom.select("td.mceSelected,th.mceSelected"),"mceSelected")}c([["table","table.desc","mceInsertTable",true],["delete_table","table.del","mceTableDelete"],["delete_col","table.delete_col_desc","mceTableDeleteCol"],["delete_row","table.delete_row_desc","mceTableDeleteRow"],["col_after","table.col_after_desc","mceTableInsertColAfter"],["col_before","table.col_before_desc","mceTableInsertColBefore"],["row_after","table.row_after_desc","mceTableInsertRowAfter"],["row_before","table.row_before_desc","mceTableInsertRowBefore"],["row_props","table.row_desc","mceTableRowProps",true],["cell_props","table.cell_desc","mceTableCellProps",true],["split_cells","table.split_cells_desc","mceTableSplitCells",true],["merge_cells","table.merge_cells_desc","mceTableMergeCells",true]],function(k){e.addButton(k[0],{title:k[1],cmd:k[2],ui:k[3]})});if(!b.isIE){e.onClick.add(function(k,l){l=l.target;if(l.nodeName==="TABLE"){k.selection.select(l)}})}e.onNodeChange.add(function(l,k,o){var m;o=l.selection.getStart();m=l.dom.getParent(o,"td,th,caption");k.setActive("table",o.nodeName==="TABLE"||!!m);if(m&&m.nodeName==="CAPTION"){m=0}k.setDisabled("delete_table",!m);k.setDisabled("delete_col",!m);k.setDisabled("delete_table",!m);k.setDisabled("delete_row",!m);k.setDisabled("col_after",!m);k.setDisabled("col_before",!m);k.setDisabled("row_after",!m);k.setDisabled("row_before",!m);k.setDisabled("row_props",!m);k.setDisabled("cell_props",!m);k.setDisabled("split_cells",!m);k.setDisabled("merge_cells",!m)});e.onInit.add(function(l){var k,o,p=l.dom,m;d=l.windowManager;l.onMouseDown.add(function(q,r){if(r.button!=2){g();o=p.getParent(r.target,"td,th");k=p.getParent(o,"table")}});p.bind(l.getDoc(),"mouseover",function(t){var r,q,s=t.target;if(o&&(m||s!=o)&&(s.nodeName=="TD"||s.nodeName=="TH")){q=p.getParent(s,"table");if(q==k){if(!m){m=h(q);m.setStartCell(o);l.getBody().style.webkitUserSelect="none"}m.setEndCell(s)}r=l.selection.getSel();if(r.removeAllRanges){r.removeAllRanges()}else{r.empty()}t.preventDefault()}});l.onMouseUp.add(function(z,A){var r,t=z.selection,B,C=t.getSel(),q,u,s,w;if(o){if(m){z.getBody().style.webkitUserSelect=""}function v(D,F){var E=new b.dom.TreeWalker(D,D);do{if(D.nodeType==3&&b.trim(D.nodeValue).length!=0){if(F){r.setStart(D,0)}else{r.setEnd(D,D.nodeValue.length)}return}if(D.nodeName=="BR"){if(F){r.setStartBefore(D)}else{r.setEndBefore(D)}return}}while(D=(F?E.next():E.prev()))}B=p.select("td.mceSelected,th.mceSelected");if(B.length>0){r=p.createRng();u=B[0];w=B[B.length-1];v(u,1);q=new b.dom.TreeWalker(u,p.getParent(B[0],"table"));do{if(u.nodeName=="TD"||u.nodeName=="TH"){if(!p.hasClass(u,"mceSelected")){break}s=u}}while(u=q.next());v(s);t.setRng(r)}z.nodeChanged();o=m=k=null}});l.onKeyUp.add(function(q,r){g()});if(l&&l.plugins.contextmenu){l.plugins.contextmenu.onContextMenu.add(function(s,q,u){var v,t=l.selection,r=t.getNode()||l.getBody();if(l.dom.getParent(u,"td")||l.dom.getParent(u,"th")){q.removeAll();if(r.nodeName=="A"&&!l.dom.getAttrib(r,"name")){q.add({title:"advanced.link_desc",icon:"link",cmd:l.plugins.advlink?"mceAdvLink":"mceLink",ui:true});q.add({title:"advanced.unlink_desc",icon:"unlink",cmd:"UnLink"});q.addSeparator()}if(r.nodeName=="IMG"&&r.className.indexOf("mceItem")==-1){q.add({title:"advanced.image_desc",icon:"image",cmd:l.plugins.advimage?"mceAdvImage":"mceImage",ui:true});q.addSeparator()}q.add({title:"table.desc",icon:"table",cmd:"mceInsertTable",value:{action:"insert"}});q.add({title:"table.props_desc",icon:"table_props",cmd:"mceInsertTable"});q.add({title:"table.del",icon:"delete_table",cmd:"mceTableDelete"});q.addSeparator();v=q.addMenu({title:"table.cell"});v.add({title:"table.cell_desc",icon:"cell_props",cmd:"mceTableCellProps"});v.add({title:"table.split_cells_desc",icon:"split_cells",cmd:"mceTableSplitCells"});v.add({title:"table.merge_cells_desc",icon:"merge_cells",cmd:"mceTableMergeCells"});v=q.addMenu({title:"table.row"});v.add({title:"table.row_desc",icon:"row_props",cmd:"mceTableRowProps"});v.add({title:"table.row_before_desc",icon:"row_before",cmd:"mceTableInsertRowBefore"});v.add({title:"table.row_after_desc",icon:"row_after",cmd:"mceTableInsertRowAfter"});v.add({title:"table.delete_row_desc",icon:"delete_row",cmd:"mceTableDeleteRow"});v.addSeparator();v.add({title:"table.cut_row_desc",icon:"cut",cmd:"mceTableCutRow"});v.add({title:"table.copy_row_desc",icon:"copy",cmd:"mceTableCopyRow"});v.add({title:"table.paste_row_before_desc",icon:"paste",cmd:"mceTablePasteRowBefore"}).setDisabled(!j);v.add({title:"table.paste_row_after_desc",icon:"paste",cmd:"mceTablePasteRowAfter"}).setDisabled(!j);v=q.addMenu({title:"table.col"});v.add({title:"table.col_before_desc",icon:"col_before",cmd:"mceTableInsertColBefore"});v.add({title:"table.col_after_desc",icon:"col_after",cmd:"mceTableInsertColAfter"});v.add({title:"table.delete_col_desc",icon:"delete_col",cmd:"mceTableDeleteCol"})}else{q.add({title:"table.desc",icon:"table",cmd:"mceInsertTable"})}})}if(!b.isIE){function n(){var q;for(q=l.getBody().lastChild;q&&q.nodeType==3&&!q.nodeValue.length;q=q.previousSibling){}if(q&&q.nodeName=="TABLE"){l.dom.add(l.getBody(),"p",null,'<br mce_bogus="1" />')}}if(b.isGecko){l.onKeyDown.add(function(r,t){var q,s,u=r.dom;if(t.keyCode==37||t.keyCode==38){q=r.selection.getRng();s=u.getParent(q.startContainer,"table");if(s&&r.getBody().firstChild==s){if(isAtStart(q,s)){q=u.createRng();q.setStartBefore(s);q.setEndBefore(s);r.selection.setRng(q);t.preventDefault()}}}})}l.onKeyUp.add(n);l.onSetContent.add(n);l.onVisualAid.add(n);l.onPreProcess.add(function(q,s){var r=s.node.lastChild;if(r&&r.childNodes.length==1&&r.firstChild.nodeName=="BR"){q.dom.remove(r)}});n()}});c({mceTableSplitCells:function(k){k.split()},mceTableMergeCells:function(l){var m,n,k;k=e.dom.getParent(e.selection.getNode(),"th,td");if(k){m=k.rowSpan;n=k.colSpan}if(!e.dom.select("td.mceSelected,th.mceSelected").length){d.open({url:f+"/merge_cells.htm",width:240+parseInt(e.getLang("table.merge_cells_delta_width",0)),height:110+parseInt(e.getLang("table.merge_cells_delta_height",0)),inline:1},{rows:m,cols:n,onaction:function(o){l.merge(k,o.cols,o.rows)},plugin_url:f})}else{l.merge()}},mceTableInsertRowBefore:function(k){k.insertRow(true)},mceTableInsertRowAfter:function(k){k.insertRow()},mceTableInsertColBefore:function(k){k.insertCol(true)},mceTableInsertColAfter:function(k){k.insertCol()},mceTableDeleteCol:function(k){k.deleteCols()},mceTableDeleteRow:function(k){k.deleteRows()},mceTableCutRow:function(k){j=k.cutRows()},mceTableCopyRow:function(k){j=k.copyRows()},mceTablePasteRowBefore:function(k){k.pasteRows(j,true)},mceTablePasteRowAfter:function(k){k.pasteRows(j)},mceTableDelete:function(k){k.deleteTable()}},function(l,k){e.addCommand(k,function(){var m=h();if(m){l(m);e.execCommand("mceRepaint");g()}})});c({mceInsertTable:function(k){d.open({url:f+"/table.htm",width:400+parseInt(e.getLang("table.table_delta_width",0)),height:320+parseInt(e.getLang("table.table_delta_height",0)),inline:1},{plugin_url:f,action:k?k.action:0})},mceTableRowProps:function(){d.open({url:f+"/row.htm",width:400+parseInt(e.getLang("table.rowprops_delta_width",0)),height:295+parseInt(e.getLang("table.rowprops_delta_height",0)),inline:1},{plugin_url:f})},mceTableCellProps:function(){d.open({url:f+"/cell.htm",width:400+parseInt(e.getLang("table.cellprops_delta_width",0)),height:295+parseInt(e.getLang("table.cellprops_delta_height",0)),inline:1},{plugin_url:f})}},function(l,k){e.addCommand(k,function(m,n){l(n)})})}});b.PluginManager.add("table",b.plugins.TablePlugin)})(tinymce); \ No newline at end of file
diff --git a/program/js/tiny_mce/plugins/table/editor_plugin_src.js b/program/js/tiny_mce/plugins/table/editor_plugin_src.js
index 87b10556f..2260f34a3 100644
--- a/program/js/tiny_mce/plugins/table/editor_plugin_src.js
+++ b/program/js/tiny_mce/plugins/table/editor_plugin_src.js
@@ -1,1202 +1,1118 @@
/**
- * $Id: editor_plugin_src.js 1209 2009-08-20 12:35:10Z spocke $
+ * editor_plugin_src.js
*
- * @author Moxiecode
- * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
+ * Copyright 2009, Moxiecode Systems AB
+ * Released under LGPL License.
+ *
+ * License: http://tinymce.moxiecode.com/license
+ * Contributing: http://tinymce.moxiecode.com/contributing
*/
-(function() {
+(function(tinymce) {
var each = tinymce.each;
- // Checks if the selection/caret is at the start of the specified block element
- function isAtStart(rng, par) {
- var doc = par.ownerDocument, rng2 = doc.createRange(), elm;
+ /**
+ * Table Grid class.
+ */
+ function TableGrid(table, dom, selection) {
+ var grid, startPos, endPos, selectedCell;
+
+ buildGrid();
+ selectedCell = dom.getParent(selection.getStart(), 'th,td');
+ if (selectedCell) {
+ startPos = getPos(selectedCell);
+ endPos = findEndPos();
+ selectedCell = getCell(startPos.x, startPos.y);
+ }
- rng2.setStartBefore(par);
- rng2.setEnd(rng.endContainer, rng.endOffset);
+ function buildGrid() {
+ var startY = 0;
- elm = doc.createElement('body');
- elm.appendChild(rng2.cloneContents());
+ grid = [];
- // Check for text characters of other elements that should be treated as content
- return elm.innerHTML.replace(/<(br|img|object|embed|input|textarea)[^>]*>/gi, '-').replace(/<[^>]+>/g, '').length == 0;
- };
+ each(['thead', 'tbody', 'tfoot'], function(part) {
+ var rows = dom.select(part + ' tr', table);
- tinymce.create('tinymce.plugins.TablePlugin', {
- init : function(ed, url) {
- var t = this;
+ each(rows, function(tr, y) {
+ y += startY;
- t.editor = ed;
- t.url = url;
+ each(dom.select('td,th', tr), function(td, x) {
+ var x2, y2, rowspan, colspan;
- // Register buttons
- each([
- ['table', 'table.desc', 'mceInsertTable', true],
- ['delete_table', 'table.del', 'mceTableDelete'],
- ['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
- ['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
- ['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
- ['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
- ['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
- ['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
- ['row_props', 'table.row_desc', 'mceTableRowProps', true],
- ['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
- ['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
- ['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
- ], function(c) {
- ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
- });
-
- if (ed.getParam('inline_styles')) {
- // Force move of attribs to styles in strict mode
- ed.onPreProcess.add(function(ed, o) {
- var dom = ed.dom;
+ // Skip over existing cells produced by rowspan
+ if (grid[y]) {
+ while (grid[y][x])
+ x++;
+ }
- each(dom.select('table', o.node), function(n) {
- var v;
+ // Get col/rowspan from cell
+ rowspan = getSpanVal(td, 'rowspan');
+ colspan = getSpanVal(td, 'colspan');
- if (v = dom.getAttrib(n, 'width')) {
- dom.setStyle(n, 'width', v);
- dom.setAttrib(n, 'width');
- }
+ // Fill out rowspan/colspan right and down
+ for (y2 = y; y2 < y + rowspan; y2++) {
+ if (!grid[y2])
+ grid[y2] = [];
- if (v = dom.getAttrib(n, 'height')) {
- dom.setStyle(n, 'height', v);
- dom.setAttrib(n, 'height');
+ for (x2 = x; x2 < x + colspan; x2++) {
+ grid[y2][x2] = {
+ part : part,
+ real : y2 == y && x2 == x,
+ elm : td,
+ rowspan : rowspan,
+ colspan : colspan
+ };
+ }
}
});
});
- }
- ed.onInit.add(function() {
- // Fixes an issue on Gecko where it's impossible to place the caret behind a table
- // This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
- if (!tinymce.isIE && ed.getParam('forced_root_block')) {
- function fixTableCaretPos() {
- var last = ed.getBody().lastChild;
+ startY += rows.length;
+ });
+ };
- if (last && last.nodeName == 'TABLE')
- ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
- };
+ function getCell(x, y) {
+ var row;
- // Fixes an bug where it's impossible to place the caret before a table in Gecko
- // this fix solves it by detecting when the caret is at the beginning of such a table
- // and then manually moves the caret infront of the table
- if (tinymce.isGecko) {
- ed.onKeyDown.add(function(ed, e) {
- var rng, table, dom = ed.dom;
+ row = grid[y];
+ if (row)
+ return row[x];
+ };
- // On gecko it's not possible to place the caret before a table
- if (e.keyCode == 37 || e.keyCode == 38) {
- rng = ed.selection.getRng();
- table = dom.getParent(rng.startContainer, 'table');
+ function getSpanVal(td, name) {
+ return parseInt(td.getAttribute(name) || 1);
+ };
- if (table && ed.getBody().firstChild == table) {
- if (isAtStart(rng, table)) {
- rng = dom.createRng();
-
- rng.setStartBefore(table);
- rng.setEndBefore(table);
+ function isCellSelected(cell) {
+ return dom.hasClass(cell.elm, 'mceSelected') || cell == selectedCell;
+ };
- ed.selection.setRng(rng);
+ function getSelectedRows() {
+ var rows = [];
- e.preventDefault();
- }
- }
- }
- });
+ each(table.rows, function(row) {
+ each(row.cells, function(cell) {
+ if (dom.hasClass(cell, 'mceSelected') || cell == selectedCell.elm) {
+ rows.push(row);
+ return false;
}
+ });
+ });
- ed.onKeyUp.add(fixTableCaretPos);
- ed.onSetContent.add(fixTableCaretPos);
- ed.onVisualAid.add(fixTableCaretPos);
+ return rows;
+ };
- ed.onPreProcess.add(function(ed, o) {
- var last = o.node.lastChild;
+ function deleteTable() {
+ var rng = dom.createRng();
- if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
- ed.dom.remove(last);
- });
+ rng.setStartAfter(table);
+ rng.setEndAfter(table);
- fixTableCaretPos();
- }
+ selection.setRng(rng);
- if (ed && ed.plugins.contextmenu) {
- ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
- var sm, se = ed.selection, el = se.getNode() || ed.getBody();
+ dom.remove(table);
+ };
- if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) {
- m.removeAll();
+ function cloneCell(cell) {
+ var formatNode;
- if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
- m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
- m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
- m.addSeparator();
- }
+ // Clone formats
+ tinymce.walk(cell, function(node) {
+ var curNode;
- if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
- m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
- m.addSeparator();
- }
+ if (node.nodeType == 3) {
+ each(dom.getParents(node.parentNode, null, cell).reverse(), function(node) {
+ node = node.cloneNode(false);
- m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true, value : {action : 'insert'}});
- m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable', ui : true});
- m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete', ui : true});
- m.addSeparator();
-
- // Cell menu
- sm = m.addMenu({title : 'table.cell'});
- sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps', ui : true});
- sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells', ui : true});
- sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells', ui : true});
-
- // Row menu
- sm = m.addMenu({title : 'table.row'});
- sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps', ui : true});
- sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
- sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
- sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
- sm.addSeparator();
- sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
- sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
- sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'});
- sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'});
+ if (!formatNode)
+ formatNode = curNode = node;
+ else if (curNode)
+ curNode.appendChild(node);
- // Column menu
- sm = m.addMenu({title : 'table.col'});
- sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
- sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
- sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
- } else
- m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', ui : true});
+ curNode = node;
});
- }
- });
- // Add undo level when new rows are created using the tab key
- ed.onKeyDown.add(function(ed, e) {
- if (e.keyCode == 9 && ed.dom.getParent(ed.selection.getNode(), 'TABLE')) {
- if (!tinymce.isGecko && !tinymce.isOpera) {
- tinyMCE.execInstanceCommand(ed.editorId, "mceTableMoveToNextRow", true);
- return tinymce.dom.Event.cancel(e);
- }
+ // Add something to the inner node
+ if (curNode)
+ curNode.innerHTML = tinymce.isIE ? '&nbsp;' : '<br _mce_bogus="1" />';
- ed.undoManager.add();
+ return false;
}
- });
+ }, 'childNodes');
- // Select whole table is a table border is clicked
- if (!tinymce.isIE) {
- if (ed.getParam('table_selection', true)) {
- ed.onClick.add(function(ed, e) {
- e = e.target;
+ cell = cell.cloneNode(false);
+ cell.rowSpan = cell.colSpan = 1;
- if (e.nodeName === 'TABLE')
- ed.selection.select(e);
- });
- }
+ if (formatNode) {
+ cell.appendChild(formatNode);
+ } else {
+ if (!tinymce.isIE)
+ cell.innerHTML = '<br _mce_bogus="1" />';
}
- ed.onNodeChange.add(function(ed, cm, n) {
- var p = ed.dom.getParent(n, 'td,th,caption');
+ return cell;
+ };
- cm.setActive('table', n.nodeName === 'TABLE' || !!p);
- if (p && p.nodeName === 'CAPTION')
- p = null;
+ function cleanup() {
+ var rng = dom.createRng();
- cm.setDisabled('delete_table', !p);
- cm.setDisabled('delete_col', !p);
- cm.setDisabled('delete_table', !p);
- cm.setDisabled('delete_row', !p);
- cm.setDisabled('col_after', !p);
- cm.setDisabled('col_before', !p);
- cm.setDisabled('row_after', !p);
- cm.setDisabled('row_before', !p);
- cm.setDisabled('row_props', !p);
- cm.setDisabled('cell_props', !p);
- cm.setDisabled('split_cells', !p || (parseInt(ed.dom.getAttrib(p, 'colspan', '1')) < 2 && parseInt(ed.dom.getAttrib(p, 'rowspan', '1')) < 2));
- cm.setDisabled('merge_cells', !p);
+ // Empty rows
+ each(dom.select('tr', table), function(tr) {
+ if (tr.cells.length == 0)
+ dom.remove(tr);
});
- // Padd empty table cells
- if (!tinymce.isIE) {
- ed.onBeforeSetContent.add(function(ed, o) {
- if (o.initial)
- o.content = o.content.replace(/<(td|th)([^>]+|)>\s*<\/(td|th)>/g, tinymce.isOpera ? '<$1$2>&nbsp;</$1>' : '<$1$2><br mce_bogus="1" /></$1>');
- });
- }
- },
-
- execCommand : function(cmd, ui, val) {
- var ed = this.editor, b;
-
- // Is table command
- switch (cmd) {
- case "mceTableMoveToNextRow":
- case "mceInsertTable":
- case "mceTableRowProps":
- case "mceTableCellProps":
- case "mceTableSplitCells":
- case "mceTableMergeCells":
- case "mceTableInsertRowBefore":
- case "mceTableInsertRowAfter":
- case "mceTableDeleteRow":
- case "mceTableInsertColBefore":
- case "mceTableInsertColAfter":
- case "mceTableDeleteCol":
- case "mceTableCutRow":
- case "mceTableCopyRow":
- case "mceTablePasteRowBefore":
- case "mceTablePasteRowAfter":
- case "mceTableDelete":
- ed.execCommand('mceBeginUndoLevel');
- this._doExecCommand(cmd, ui, val);
- ed.execCommand('mceEndUndoLevel');
-
- return true;
+ // Empty table
+ if (dom.select('tr', table).length == 0) {
+ rng.setStartAfter(table);
+ rng.setEndAfter(table);
+ selection.setRng(rng);
+ dom.remove(table);
+ return;
}
- // Pass to next handler in chain
- return false;
- },
-
- getInfo : function() {
- return {
- longname : 'Tables',
- author : 'Moxiecode Systems AB',
- authorurl : 'http://tinymce.moxiecode.com',
- infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/table',
- version : tinymce.majorVersion + "." + tinymce.minorVersion
- };
- },
-
- // Private plugin internal methods
-
- /**
- * Executes the table commands.
- */
- _doExecCommand : function(command, user_interface, value) {
- var inst = this.editor, ed = inst, url = this.url;
- var focusElm = inst.selection.getNode();
- var trElm = inst.dom.getParent(focusElm, "tr");
- var tdElm = inst.dom.getParent(focusElm, "td,th");
- var tableElm = inst.dom.getParent(focusElm, "table");
- var doc = inst.contentWindow.document;
- var tableBorder = tableElm ? tableElm.getAttribute("border") : "";
-
- // Get first TD if no TD found
- if (trElm && tdElm == null)
- tdElm = trElm.cells[0];
-
- function inArray(ar, v) {
- for (var i=0; i<ar.length; i++) {
- // Is array
- if (ar[i].length > 0 && inArray(ar[i], v))
- return true;
-
- // Found value
- if (ar[i] == v)
- return true;
- }
+ // Empty header/body/footer
+ each(dom.select('thead,tbody,tfoot', table), function(part) {
+ if (part.rows.length == 0)
+ dom.remove(part);
+ });
+
+ // Restore selection to start position if it still exists
+ buildGrid();
- return false;
+ // Restore the selection to the closest table position
+ row = grid[Math.min(grid.length - 1, startPos.y)];
+ if (row) {
+ selection.select(row[Math.min(row.length - 1, startPos.x)].elm, true);
+ selection.collapse(true);
}
+ };
- function select(dx, dy) {
- var td;
+ function fillLeftDown(x, y, rows, cols) {
+ var tr, x2, r, c, cell;
- grid = getTableGrid(tableElm);
- dx = dx || 0;
- dy = dy || 0;
- dx = Math.max(cpos.cellindex + dx, 0);
- dy = Math.max(cpos.rowindex + dy, 0);
+ tr = grid[y][x].elm.parentNode;
+ for (r = 1; r <= rows; r++) {
+ tr = dom.getNext(tr, 'tr');
- // Recalculate grid and select
- inst.execCommand('mceRepaint');
- td = getCell(grid, dy, dx);
+ if (tr) {
+ // Loop left to find real cell
+ for (x2 = x; x2 >= 0; x2--) {
+ cell = grid[y + r][x2].elm;
- if (td) {
- inst.selection.select(td.firstChild || td);
- inst.selection.collapse(1);
- }
- };
+ if (cell.parentNode == tr) {
+ // Append clones after
+ for (c = 1; c <= cols; c++)
+ dom.insertAfter(cloneCell(cell), cell);
- function makeTD() {
- var newTD = doc.createElement("td");
+ break;
+ }
+ }
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
+ if (x2 == -1) {
+ // Insert nodes before first cell
+ for (c = 1; c <= cols; c++)
+ tr.insertBefore(cloneCell(tr.cells[0]), tr.cells[0]);
+ }
+ }
}
+ };
- function getColRowSpan(td) {
- var colspan = inst.dom.getAttrib(td, "colspan");
- var rowspan = inst.dom.getAttrib(td, "rowspan");
+ function split() {
+ each(grid, function(row, y) {
+ each(row, function(cell, x) {
+ var colSpan, rowSpan, newCell, i;
- colspan = colspan == "" ? 1 : parseInt(colspan);
- rowspan = rowspan == "" ? 1 : parseInt(rowspan);
+ if (isCellSelected(cell)) {
+ cell = cell.elm;
+ colSpan = getSpanVal(cell, 'colspan');
+ rowSpan = getSpanVal(cell, 'rowspan');
- return {colspan : colspan, rowspan : rowspan};
+ if (colSpan > 1 || rowSpan > 1) {
+ cell.colSpan = cell.rowSpan = 1;
+
+ // Insert cells right
+ for (i = 0; i < colSpan - 1; i++)
+ dom.insertAfter(cloneCell(cell), cell);
+
+ fillLeftDown(x, y, rowSpan - 1, colSpan);
+ }
+ }
+ });
+ });
+ };
+
+ function merge(cell, cols, rows) {
+ var startX, startY, endX, endY, x, y, startCell, endCell, cell, children;
+
+ // Use specified cell and cols/rows
+ if (cell) {
+ pos = getPos(cell);
+ startX = pos.x;
+ startY = pos.y;
+ endX = startX + (cols - 1);
+ endY = startY + (rows - 1);
+ } else {
+ // Use selection
+ startX = startPos.x;
+ startY = startPos.y;
+ endX = endPos.x;
+ endY = endPos.y;
}
- function getCellPos(grid, td) {
- var x, y;
+ // Find start/end cells
+ startCell = getCell(startX, startY);
+ endCell = getCell(endX, endY);
+
+ // Check if the cells exists and if they are of the same part for example tbody = tbody
+ if (startCell && endCell && startCell.part == endCell.part) {
+ // Split and rebuild grid
+ split();
+ buildGrid();
+
+ // Set row/col span to start cell
+ startCell = getCell(startX, startY).elm;
+ startCell.colSpan = (endX - startX) + 1;
+ startCell.rowSpan = (endY - startY) + 1;
+
+ // Remove other cells and add it's contents to the start cell
+ for (y = startY; y <= endY; y++) {
+ for (x = startX; x <= endX; x++) {
+ cell = grid[y][x].elm;
+
+ if (cell != startCell) {
+ // Move children to startCell
+ children = tinymce.grep(cell.childNodes);
+ each(children, function(node, i) {
+ // Jump over last BR element
+ if (node.nodeName != 'BR' || i != children.length - 1)
+ startCell.appendChild(node);
+ });
- for (y=0; y<grid.length; y++) {
- for (x=0; x<grid[y].length; x++) {
- if (grid[y][x] == td)
- return {cellindex : x, rowindex : y};
+ // Remove cell
+ dom.remove(cell);
+ }
}
}
- return null;
+ // Remove empty rows etc and restore caret location
+ cleanup();
}
+ };
+
+ function insertRow(before) {
+ var posY, cell, lastCell, x, rowElm, newRow, newCell, otherCell;
+
+ // Find first/last row
+ each(grid, function(row, y) {
+ each(row, function(cell, x) {
+ if (isCellSelected(cell)) {
+ cell = cell.elm;
+ rowElm = cell.parentNode;
+ newRow = rowElm.cloneNode(false);
+ posY = y;
+
+ if (before)
+ return false;
+ }
+ });
- function getCell(grid, row, col) {
- if (grid[row] && grid[row][col])
- return grid[row][col];
+ if (before)
+ return !posY;
+ });
- return null;
- }
+ for (x = 0; x < grid[0].length; x++) {
+ cell = grid[posY][x].elm;
- function getNextCell(table, cell) {
- var cells = [], x = 0, i, j, cell, nextCell;
+ if (cell != lastCell) {
+ if (!before) {
+ rowSpan = getSpanVal(cell, 'rowspan');
+ if (rowSpan > 1) {
+ cell.rowSpan = rowSpan + 1;
+ continue;
+ }
+ } else {
+ // Check if cell above can be expanded
+ if (posY > 0 && grid[posY - 1][x]) {
+ otherCell = grid[posY - 1][x].elm;
+ rowSpan = getSpanVal(otherCell, 'rowspan');
+ if (rowSpan > 1) {
+ otherCell.rowSpan = rowSpan + 1;
+ continue;
+ }
+ }
+ }
- for (i = 0; i < table.rows.length; i++)
- for (j = 0; j < table.rows[i].cells.length; j++, x++)
- cells[x] = table.rows[i].cells[j];
+ // Insert new cell into new row
+ newCell = cloneCell(cell)
+ newCell.colSpan = cell.colSpan;
+ newRow.appendChild(newCell);
- for (i = 0; i < cells.length; i++)
- if (cells[i] == cell)
- if (nextCell = cells[i+1])
- return nextCell;
+ lastCell = cell;
+ }
}
- function getTableGrid(table) {
- var grid = [], rows = table.rows, x, y, td, sd, xstart, x2, y2;
-
- for (y=0; y<rows.length; y++) {
- for (x=0; x<rows[y].cells.length; x++) {
- td = rows[y].cells[x];
- sd = getColRowSpan(td);
+ if (newRow.hasChildNodes()) {
+ if (!before)
+ dom.insertAfter(newRow, rowElm);
+ else
+ rowElm.parentNode.insertBefore(newRow, rowElm);
+ }
+ };
- // All ready filled
- for (xstart = x; grid[y] && grid[y][xstart]; xstart++) ;
+ function insertCol(before) {
+ var posX, lastCell;
- // Fill box
- for (y2=y; y2<y+sd['rowspan']; y2++) {
- if (!grid[y2])
- grid[y2] = [];
+ // Find first/last column
+ each(grid, function(row, y) {
+ each(row, function(cell, x) {
+ if (isCellSelected(cell)) {
+ posX = x;
- for (x2=xstart; x2<xstart+sd['colspan']; x2++)
- grid[y2][x2] = td;
- }
+ if (before)
+ return false;
}
- }
+ });
- return grid;
- }
+ if (before)
+ return !posX;
+ });
- function trimRow(table, tr, td, new_tr) {
- var grid = getTableGrid(table), cpos = getCellPos(grid, td);
- var cells, lastElm;
-
- // Time to crop away some
- if (new_tr.cells.length != tr.childNodes.length) {
- cells = tr.childNodes;
- lastElm = null;
-
- for (var x=0; td = getCell(grid, cpos.rowindex, x); x++) {
- var remove = true;
- var sd = getColRowSpan(td);
-
- // Remove due to rowspan
- if (inArray(cells, td)) {
- new_tr.childNodes[x]._delete = true;
- } else if ((lastElm == null || td != lastElm) && sd.colspan > 1) { // Remove due to colspan
- for (var i=x; i<x+td.colSpan; i++)
- new_tr.childNodes[i]._delete = true;
- }
+ each(grid, function(row, y) {
+ var cell = row[posX].elm, rowSpan, colSpan;
- if ((lastElm == null || td != lastElm) && sd.rowspan > 1)
- td.rowSpan = sd.rowspan + 1;
+ if (cell != lastCell) {
+ colSpan = getSpanVal(cell, 'colspan');
+ rowSpan = getSpanVal(cell, 'rowspan');
- lastElm = td;
- }
+ if (colSpan == 1) {
+ if (!before) {
+ dom.insertAfter(cloneCell(cell), cell);
+ fillLeftDown(posX, y, rowSpan - 1, colSpan);
+ } else {
+ cell.parentNode.insertBefore(cloneCell(cell), cell);
+ fillLeftDown(posX, y, rowSpan - 1, colSpan);
+ }
+ } else
+ cell.colSpan++;
- deleteMarked(tableElm);
+ lastCell = cell;
}
- }
+ });
+ };
- function prevElm(node, name) {
- while ((node = node.previousSibling) != null) {
- if (node.nodeName == name)
- return node;
- }
+ function deleteCols() {
+ var cols = [];
- return null;
- }
+ // Get selected column indexes
+ each(grid, function(row, y) {
+ each(row, function(cell, x) {
+ if (isCellSelected(cell) && tinymce.inArray(cols, x) === -1) {
+ each(grid, function(row) {
+ var cell = row[x].elm, colSpan;
- function nextElm(node, names) {
- var namesAr = names.split(',');
+ colSpan = getSpanVal(cell, 'colspan');
- while ((node = node.nextSibling) != null) {
- for (var i=0; i<namesAr.length; i++) {
- if (node.nodeName.toLowerCase() == namesAr[i].toLowerCase() )
- return node;
+ if (colSpan > 1)
+ cell.colSpan = colSpan - 1;
+ else
+ dom.remove(cell);
+ });
+
+ cols.push(x);
}
- }
+ });
+ });
- return null;
- }
+ cleanup();
+ };
- function deleteMarked(tbl) {
- if (tbl.rows == 0)
- return;
+ function deleteRows() {
+ var rows;
- var tr = tbl.rows[0];
- do {
- var next = nextElm(tr, "TR");
+ function deleteRow(tr) {
+ var nextTr, pos, lastCell;
- // Delete row
- if (tr._delete) {
- tr.parentNode.removeChild(tr);
- continue;
- }
+ nextTr = dom.getNext(tr, 'tr');
- // Delete cells
- var td = tr.cells[0];
- if (td.cells > 1) {
- do {
- var nexttd = nextElm(td, "TD,TH");
+ // Move down row spanned cells
+ each(tr.cells, function(cell) {
+ var rowSpan = getSpanVal(cell, 'rowspan');
- if (td._delete)
- td.parentNode.removeChild(td);
- } while ((td = nexttd) != null);
+ if (rowSpan > 1) {
+ cell.rowSpan = rowSpan - 1;
+ pos = getPos(cell);
+ fillLeftDown(pos.x, pos.y, 1, 1);
}
- } while ((tr = next) != null);
- }
+ });
- function addRows(td_elm, tr_elm, rowspan) {
- // Add rows
- td_elm.rowSpan = 1;
- var trNext = nextElm(tr_elm, "TR");
- for (var i=1; i<rowspan && trNext; i++) {
- var newTD = doc.createElement("td");
+ // Delete cells
+ pos = getPos(tr.cells[0]);
+ each(grid[pos.y], function(cell) {
+ var rowSpan;
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
+ cell = cell.elm;
- if (tinymce.isIE)
- trNext.insertBefore(newTD, trNext.cells(td_elm.cellIndex));
- else
- trNext.insertBefore(newTD, trNext.cells[td_elm.cellIndex]);
+ if (cell != lastCell) {
+ rowSpan = getSpanVal(cell, 'rowspan');
- trNext = nextElm(trNext, "TR");
- }
- }
+ if (rowSpan <= 1)
+ dom.remove(cell);
+ else
+ cell.rowSpan = rowSpan - 1;
- function copyRow(doc, table, tr) {
- var grid = getTableGrid(table);
- var newTR = tr.cloneNode(false);
- var cpos = getCellPos(grid, tr.cells[0]);
- var lastCell = null;
- var tableBorder = inst.dom.getAttrib(table, "border");
- var tdElm = null;
-
- for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
- var newTD = null;
-
- if (lastCell != tdElm) {
- for (var i=0; i<tr.cells.length; i++) {
- if (tdElm == tr.cells[i]) {
- newTD = tdElm.cloneNode(true);
- break;
- }
- }
+ lastCell = cell;
}
+ });
+ };
- if (newTD == null) {
- newTD = doc.createElement("td");
+ // Get selected rows and move selection out of scope
+ rows = getSelectedRows();
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
- }
+ // Delete all selected rows
+ each(rows.reverse(), function(tr) {
+ deleteRow(tr);
+ });
- // Reset col/row span
- newTD.colSpan = 1;
- newTD.rowSpan = 1;
+ cleanup();
+ };
- newTR.appendChild(newTD);
+ function cutRows() {
+ var rows = getSelectedRows();
- lastCell = tdElm;
- }
+ dom.remove(rows);
+ cleanup();
- return newTR;
- }
+ return rows;
+ };
- // ---- Commands -----
+ function copyRows() {
+ var rows = getSelectedRows();
- // Handle commands
- switch (command) {
- case "mceTableMoveToNextRow":
- var nextCell = getNextCell(tableElm, tdElm);
+ each(rows, function(row, i) {
+ rows[i] = row.cloneNode(true);
+ });
- if (!nextCell) {
- inst.execCommand("mceTableInsertRowAfter", tdElm);
- nextCell = getNextCell(tableElm, tdElm);
- }
+ return rows;
+ };
- inst.selection.select(nextCell);
- inst.selection.collapse(true);
+ function pasteRows(rows, before) {
+ var selectedRows = getSelectedRows(),
+ targetRow = selectedRows[before ? 0 : selectedRows.length - 1],
+ targetCellCount = targetRow.cells.length;
- return true;
+ // Calc target cell count
+ each(grid, function(row) {
+ var match;
- case "mceTableRowProps":
- if (trElm == null)
- return true;
+ targetCellCount = 0;
+ each(row, function(cell, x) {
+ if (cell.real)
+ targetCellCount += cell.colspan;
- if (user_interface) {
- inst.windowManager.open({
- url : url + '/row.htm',
- width : 400 + parseInt(inst.getLang('table.rowprops_delta_width', 0)),
- height : 295 + parseInt(inst.getLang('table.rowprops_delta_height', 0)),
- inline : 1
- }, {
- plugin_url : url
- });
- }
+ if (cell.elm.parentNode == targetRow)
+ match = 1;
+ });
- return true;
+ if (match)
+ return false;
+ });
- case "mceTableCellProps":
- if (tdElm == null)
- return true;
+ if (!before)
+ rows.reverse();
- if (user_interface) {
- inst.windowManager.open({
- url : url + '/cell.htm',
- width : 400 + parseInt(inst.getLang('table.cellprops_delta_width', 0)),
- height : 295 + parseInt(inst.getLang('table.cellprops_delta_height', 0)),
- inline : 1
- }, {
- plugin_url : url
- });
- }
+ each(rows, function(row) {
+ var cellCount = row.cells.length, cell;
- return true;
+ // Remove col/rowspans
+ for (i = 0; i < cellCount; i++) {
+ cell = row.cells[i];
+ cell.colSpan = cell.rowSpan = 1;
+ }
- case "mceInsertTable":
- if (user_interface) {
- inst.windowManager.open({
- url : url + '/table.htm',
- width : 400 + parseInt(inst.getLang('table.table_delta_width', 0)),
- height : 320 + parseInt(inst.getLang('table.table_delta_height', 0)),
- inline : 1
- }, {
- plugin_url : url,
- action : value ? value.action : 0
- });
- }
+ // Needs more cells
+ for (i = cellCount; i < targetCellCount; i++)
+ row.appendChild(cloneCell(row.cells[cellCount - 1]));
- return true;
+ // Needs less cells
+ for (i = targetCellCount; i < cellCount; i++)
+ dom.remove(row.cells[i]);
- case "mceTableDelete":
- var table = inst.dom.getParent(inst.selection.getNode(), "table");
- if (table) {
- table.parentNode.removeChild(table);
- inst.execCommand('mceRepaint');
- }
- return true;
-
- case "mceTableSplitCells":
- case "mceTableMergeCells":
- case "mceTableInsertRowBefore":
- case "mceTableInsertRowAfter":
- case "mceTableDeleteRow":
- case "mceTableInsertColBefore":
- case "mceTableInsertColAfter":
- case "mceTableDeleteCol":
- case "mceTableCutRow":
- case "mceTableCopyRow":
- case "mceTablePasteRowBefore":
- case "mceTablePasteRowAfter":
- // No table just return (invalid command)
- if (!tableElm)
- return true;
-
- // Table has a tbody use that reference
- // Changed logic by ApTest 2005.07.12 (www.aptest.com)
- // Now lookk at the focused element and take its parentNode. That will be a tbody or a table.
- if (trElm && tableElm != trElm.parentNode)
- tableElm = trElm.parentNode;
-
- if (tableElm && trElm) {
- switch (command) {
- case "mceTableCutRow":
- if (!trElm || !tdElm)
- return true;
-
- inst.tableRowClipboard = copyRow(doc, tableElm, trElm);
- inst.execCommand("mceTableDeleteRow");
- break;
-
- case "mceTableCopyRow":
- if (!trElm || !tdElm)
- return true;
-
- inst.tableRowClipboard = copyRow(doc, tableElm, trElm);
- break;
-
- case "mceTablePasteRowBefore":
- if (!trElm || !tdElm)
- return true;
-
- var newTR = inst.tableRowClipboard.cloneNode(true);
-
- var prevTR = prevElm(trElm, "TR");
- if (prevTR != null)
- trimRow(tableElm, prevTR, prevTR.cells[0], newTR);
-
- trElm.parentNode.insertBefore(newTR, trElm);
- break;
-
- case "mceTablePasteRowAfter":
- if (!trElm || !tdElm)
- return true;
-
- var nextTR = nextElm(trElm, "TR");
- var newTR = inst.tableRowClipboard.cloneNode(true);
-
- trimRow(tableElm, trElm, tdElm, newTR);
-
- if (nextTR == null)
- trElm.parentNode.appendChild(newTR);
- else
- nextTR.parentNode.insertBefore(newTR, nextTR);
-
- break;
-
- case "mceTableInsertRowBefore":
- if (!trElm || !tdElm)
- return true;
-
- var grid = getTableGrid(tableElm);
- var cpos = getCellPos(grid, tdElm);
- var newTR = doc.createElement("tr");
- var lastTDElm = null;
-
- cpos.rowindex--;
- if (cpos.rowindex < 0)
- cpos.rowindex = 0;
-
- // Create cells
- for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
- if (tdElm != lastTDElm) {
- var sd = getColRowSpan(tdElm);
-
- if (sd['rowspan'] == 1) {
- var newTD = doc.createElement("td");
-
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
-
- newTD.colSpan = tdElm.colSpan;
-
- newTR.appendChild(newTD);
- } else
- tdElm.rowSpan = sd['rowspan'] + 1;
-
- lastTDElm = tdElm;
- }
- }
+ // Add before/after
+ if (before)
+ targetRow.parentNode.insertBefore(row, targetRow);
+ else
+ dom.insertAfter(row, targetRow);
+ });
+ };
- trElm.parentNode.insertBefore(newTR, trElm);
- select(0, 1);
- break;
+ function getPos(target) {
+ var pos;
- case "mceTableInsertRowAfter":
- if (!trElm || !tdElm)
- return true;
+ each(grid, function(row, y) {
+ each(row, function(cell, x) {
+ if (cell.elm == target) {
+ pos = {x : x, y : y};
+ return false;
+ }
+ });
- var grid = getTableGrid(tableElm);
- var cpos = getCellPos(grid, tdElm);
- var newTR = doc.createElement("tr");
- var lastTDElm = null;
+ return !pos;
+ });
- // Create cells
- for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
- if (tdElm != lastTDElm) {
- var sd = getColRowSpan(tdElm);
+ return pos;
+ };
- if (sd['rowspan'] == 1) {
- var newTD = doc.createElement("td");
+ function setStartCell(cell) {
+ startPos = getPos(cell);
+ };
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
+ function findEndPos() {
+ var pos, maxX, maxY;
- newTD.colSpan = tdElm.colSpan;
+ maxX = maxY = 0;
- newTR.appendChild(newTD);
- } else
- tdElm.rowSpan = sd['rowspan'] + 1;
+ each(grid, function(row, y) {
+ each(row, function(cell, x) {
+ var colSpan, rowSpan;
- lastTDElm = tdElm;
- }
- }
+ if (isCellSelected(cell)) {
+ cell = grid[y][x];
- if (newTR.hasChildNodes()) {
- var nextTR = nextElm(trElm, "TR");
- if (nextTR)
- nextTR.parentNode.insertBefore(newTR, nextTR);
- else
- tableElm.appendChild(newTR);
- }
+ if (x > maxX)
+ maxX = x;
- select(0, 1);
- break;
+ if (y > maxY)
+ maxY = y;
- case "mceTableDeleteRow":
- if (!trElm || !tdElm)
- return true;
+ if (cell.real) {
+ colSpan = cell.colspan - 1;
+ rowSpan = cell.rowspan - 1;
- var grid = getTableGrid(tableElm);
- var cpos = getCellPos(grid, tdElm);
+ if (colSpan) {
+ if (x + colSpan > maxX)
+ maxX = x + colSpan;
+ }
- // Only one row, remove whole table
- if (grid.length == 1 && tableElm.nodeName == 'TBODY') {
- inst.dom.remove(inst.dom.getParent(tableElm, "table"));
- return true;
- }
+ if (rowSpan) {
+ if (y + rowSpan > maxY)
+ maxY = y + rowSpan;
+ }
+ }
+ }
+ });
+ });
- // Move down row spanned cells
- var cells = trElm.cells;
- var nextTR = nextElm(trElm, "TR");
- for (var x=0; x<cells.length; x++) {
- if (cells[x].rowSpan > 1) {
- var newTD = cells[x].cloneNode(true);
- var sd = getColRowSpan(cells[x]);
+ return {x : maxX, y : maxY};
+ };
- newTD.rowSpan = sd.rowspan - 1;
+ function setEndCell(cell) {
+ var startX, startY, endX, endY, maxX, maxY, colSpan, rowSpan;
- var nextTD = nextTR.cells[x];
+ endPos = getPos(cell);
- if (nextTD == null)
- nextTR.appendChild(newTD);
- else
- nextTR.insertBefore(newTD, nextTD);
- }
- }
+ if (startPos && endPos) {
+ // Get start/end positions
+ startX = Math.min(startPos.x, endPos.x);
+ startY = Math.min(startPos.y, endPos.y);
+ endX = Math.max(startPos.x, endPos.x);
+ endY = Math.max(startPos.y, endPos.y);
- // Delete cells
- var lastTDElm = null;
- for (var x=0; tdElm = getCell(grid, cpos.rowindex, x); x++) {
- if (tdElm != lastTDElm) {
- var sd = getColRowSpan(tdElm);
+ // Expand end positon to include spans
+ maxX = endX;
+ maxY = endY;
- if (sd.rowspan > 1) {
- tdElm.rowSpan = sd.rowspan - 1;
- } else {
- trElm = tdElm.parentNode;
+ // Expand startX
+ for (y = startY; y <= maxY; y++) {
+ cell = grid[y][startX];
- if (trElm.parentNode)
- trElm._delete = true;
- }
+ if (!cell.real) {
+ if (startX - (cell.colspan - 1) < startX)
+ startX -= cell.colspan - 1;
+ }
+ }
- lastTDElm = tdElm;
- }
- }
+ // Expand startY
+ for (x = startX; x <= maxX; x++) {
+ cell = grid[startY][x];
- deleteMarked(tableElm);
+ if (!cell.real) {
+ if (startY - (cell.rowspan - 1) < startY)
+ startY -= cell.rowspan - 1;
+ }
+ }
- select(0, -1);
- break;
+ // Find max X, Y
+ for (y = startY; y <= endY; y++) {
+ for (x = startX; x <= endX; x++) {
+ cell = grid[y][x];
- case "mceTableInsertColBefore":
- if (!trElm || !tdElm)
- return true;
+ if (cell.real) {
+ colSpan = cell.colspan - 1;
+ rowSpan = cell.rowspan - 1;
- var grid = getTableGrid(inst.dom.getParent(tableElm, "table"));
- var cpos = getCellPos(grid, tdElm);
- var lastTDElm = null;
+ if (colSpan) {
+ if (x + colSpan > maxX)
+ maxX = x + colSpan;
+ }
- for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) {
- if (tdElm != lastTDElm) {
- var sd = getColRowSpan(tdElm);
+ if (rowSpan) {
+ if (y + rowSpan > maxY)
+ maxY = y + rowSpan;
+ }
+ }
+ }
+ }
- if (sd['colspan'] == 1) {
- var newTD = doc.createElement(tdElm.nodeName);
+ // Remove current selection
+ dom.removeClass(dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
+ // Add new selection
+ for (y = startY; y <= maxY; y++) {
+ for (x = startX; x <= maxX; x++)
+ dom.addClass(grid[y][x].elm, 'mceSelected');
+ }
+ }
+ };
+
+ // Expose to public
+ tinymce.extend(this, {
+ deleteTable : deleteTable,
+ split : split,
+ merge : merge,
+ insertRow : insertRow,
+ insertCol : insertCol,
+ deleteCols : deleteCols,
+ deleteRows : deleteRows,
+ cutRows : cutRows,
+ copyRows : copyRows,
+ pasteRows : pasteRows,
+ getPos : getPos,
+ setStartCell : setStartCell,
+ setEndCell : setEndCell
+ });
+ };
- newTD.rowSpan = tdElm.rowSpan;
+ tinymce.create('tinymce.plugins.TablePlugin', {
+ init : function(ed, url) {
+ var winMan, clipboardRows;
- tdElm.parentNode.insertBefore(newTD, tdElm);
- } else
- tdElm.colSpan++;
+ function createTableGrid(node) {
+ var selection = ed.selection, tblElm = ed.dom.getParent(node || selection.getNode(), 'table');
- lastTDElm = tdElm;
- }
- }
+ if (tblElm)
+ return new TableGrid(tblElm, ed.dom, selection);
+ };
- select();
- break;
+ function cleanup() {
+ // Restore selection possibilities
+ ed.getBody().style.webkitUserSelect = '';
+ ed.dom.removeClass(ed.dom.select('td.mceSelected,th.mceSelected'), 'mceSelected');
+ };
- case "mceTableInsertColAfter":
- if (!trElm || !tdElm)
- return true;
+ // Register buttons
+ each([
+ ['table', 'table.desc', 'mceInsertTable', true],
+ ['delete_table', 'table.del', 'mceTableDelete'],
+ ['delete_col', 'table.delete_col_desc', 'mceTableDeleteCol'],
+ ['delete_row', 'table.delete_row_desc', 'mceTableDeleteRow'],
+ ['col_after', 'table.col_after_desc', 'mceTableInsertColAfter'],
+ ['col_before', 'table.col_before_desc', 'mceTableInsertColBefore'],
+ ['row_after', 'table.row_after_desc', 'mceTableInsertRowAfter'],
+ ['row_before', 'table.row_before_desc', 'mceTableInsertRowBefore'],
+ ['row_props', 'table.row_desc', 'mceTableRowProps', true],
+ ['cell_props', 'table.cell_desc', 'mceTableCellProps', true],
+ ['split_cells', 'table.split_cells_desc', 'mceTableSplitCells', true],
+ ['merge_cells', 'table.merge_cells_desc', 'mceTableMergeCells', true]
+ ], function(c) {
+ ed.addButton(c[0], {title : c[1], cmd : c[2], ui : c[3]});
+ });
- var grid = getTableGrid(inst.dom.getParent(tableElm, "table"));
- var cpos = getCellPos(grid, tdElm);
- var lastTDElm = null;
+ // Select whole table is a table border is clicked
+ if (!tinymce.isIE) {
+ ed.onClick.add(function(ed, e) {
+ e = e.target;
- for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) {
- if (tdElm != lastTDElm) {
- var sd = getColRowSpan(tdElm);
+ if (e.nodeName === 'TABLE')
+ ed.selection.select(e);
+ });
+ }
- if (sd['colspan'] == 1) {
- var newTD = doc.createElement(tdElm.nodeName);
+ // Handle node change updates
+ ed.onNodeChange.add(function(ed, cm, n) {
+ var p;
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
+ n = ed.selection.getStart();
+ p = ed.dom.getParent(n, 'td,th,caption');
+ cm.setActive('table', n.nodeName === 'TABLE' || !!p);
- newTD.rowSpan = tdElm.rowSpan;
+ // Disable table tools if we are in caption
+ if (p && p.nodeName === 'CAPTION')
+ p = 0;
- var nextTD = nextElm(tdElm, "TD,TH");
- if (nextTD == null)
- tdElm.parentNode.appendChild(newTD);
- else
- nextTD.parentNode.insertBefore(newTD, nextTD);
- } else
- tdElm.colSpan++;
+ cm.setDisabled('delete_table', !p);
+ cm.setDisabled('delete_col', !p);
+ cm.setDisabled('delete_table', !p);
+ cm.setDisabled('delete_row', !p);
+ cm.setDisabled('col_after', !p);
+ cm.setDisabled('col_before', !p);
+ cm.setDisabled('row_after', !p);
+ cm.setDisabled('row_before', !p);
+ cm.setDisabled('row_props', !p);
+ cm.setDisabled('cell_props', !p);
+ cm.setDisabled('split_cells', !p);
+ cm.setDisabled('merge_cells', !p);
+ });
- lastTDElm = tdElm;
- }
- }
+ ed.onInit.add(function(ed) {
+ var startTable, startCell, dom = ed.dom, tableGrid;
- select(1);
- break;
+ winMan = ed.windowManager;
- case "mceTableDeleteCol":
- if (!trElm || !tdElm)
- return true;
+ // Add cell selection logic
+ ed.onMouseDown.add(function(ed, e) {
+ if (e.button != 2) {
+ cleanup();
- var grid = getTableGrid(tableElm);
- var cpos = getCellPos(grid, tdElm);
- var lastTDElm = null;
+ startCell = dom.getParent(e.target, 'td,th');
+ startTable = dom.getParent(startCell, 'table');
+ }
+ });
- // Only one col, remove whole table
- if ((grid.length > 1 && grid[0].length <= 1) && tableElm.nodeName == 'TBODY') {
- inst.dom.remove(inst.dom.getParent(tableElm, "table"));
- return true;
- }
+ dom.bind(ed.getDoc(), 'mouseover', function(e) {
+ var sel, table, target = e.target;
- // Delete cells
- for (var y=0; tdElm = getCell(grid, y, cpos.cellindex); y++) {
- if (tdElm != lastTDElm) {
- var sd = getColRowSpan(tdElm);
+ if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
+ table = dom.getParent(target, 'table');
+ if (table == startTable) {
+ if (!tableGrid) {
+ tableGrid = createTableGrid(table);
+ tableGrid.setStartCell(startCell);
- if (sd['colspan'] > 1)
- tdElm.colSpan = sd['colspan'] - 1;
- else {
- if (tdElm.parentNode)
- tdElm.parentNode.removeChild(tdElm);
- }
+ ed.getBody().style.webkitUserSelect = 'none';
+ }
- lastTDElm = tdElm;
- }
- }
+ tableGrid.setEndCell(target);
+ }
- select(-1);
- break;
+ // Remove current selection
+ sel = ed.selection.getSel();
- case "mceTableSplitCells":
- if (!trElm || !tdElm)
- return true;
+ if (sel.removeAllRanges)
+ sel.removeAllRanges();
+ else
+ sel.empty();
- var spandata = getColRowSpan(tdElm);
+ e.preventDefault();
+ }
+ });
- var colspan = spandata["colspan"];
- var rowspan = spandata["rowspan"];
+ ed.onMouseUp.add(function(ed, e) {
+ var rng, sel = ed.selection, selectedCells, nativeSel = sel.getSel(), walker, node, lastNode, endNode;
- // Needs splitting
- if (colspan > 1 || rowspan > 1) {
- // Generate cols
- tdElm.colSpan = 1;
- for (var i=1; i<colspan; i++) {
- var newTD = doc.createElement("td");
+ // Move selection to startCell
+ if (startCell) {
+ if (tableGrid)
+ ed.getBody().style.webkitUserSelect = '';
- if (!tinymce.isIE)
- newTD.innerHTML = '<br mce_bogus="1"/>';
+ function setPoint(node, start) {
+ var walker = new tinymce.dom.TreeWalker(node, node);
- trElm.insertBefore(newTD, nextElm(tdElm, "TD,TH"));
+ do {
+ // Text node
+ if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
+ if (start)
+ rng.setStart(node, 0);
+ else
+ rng.setEnd(node, node.nodeValue.length);
- if (rowspan > 1)
- addRows(newTD, trElm, rowspan);
+ return;
}
- addRows(tdElm, trElm, rowspan);
- }
-
- // Apply visual aids
- tableElm = inst.dom.getParent(inst.selection.getNode(), "table");
- break;
-
- case "mceTableMergeCells":
- var rows = [];
- var sel = inst.selection.getSel();
- var grid = getTableGrid(tableElm);
-
- if (tinymce.isIE || sel.rangeCount == 1) {
- if (user_interface) {
- // Setup template
- var sp = getColRowSpan(tdElm);
-
- inst.windowManager.open({
- url : url + '/merge_cells.htm',
- width : 240 + parseInt(inst.getLang('table.merge_cells_delta_width', 0)),
- height : 110 + parseInt(inst.getLang('table.merge_cells_delta_height', 0)),
- inline : 1
- }, {
- action : "update",
- numcols : sp.colspan,
- numrows : sp.rowspan,
- plugin_url : url
- });
-
- return true;
- } else {
- var numRows = parseInt(value['numrows']);
- var numCols = parseInt(value['numcols']);
- var cpos = getCellPos(grid, tdElm);
-
- if (("" + numRows) == "NaN")
- numRows = 1;
-
- if (("" + numCols) == "NaN")
- numCols = 1;
-
- // Get rows and cells
- var tRows = tableElm.rows;
- for (var y=cpos.rowindex; y<grid.length; y++) {
- var rowCells = [];
-
- for (var x=cpos.cellindex; x<grid[y].length; x++) {
- var td = getCell(grid, y, x);
-
- if (td && !inArray(rows, td) && !inArray(rowCells, td)) {
- var cp = getCellPos(grid, td);
-
- // Within range
- if (cp.cellindex < cpos.cellindex+numCols && cp.rowindex < cpos.rowindex+numRows)
- rowCells[rowCells.length] = td;
- }
- }
-
- if (rowCells.length > 0)
- rows[rows.length] = rowCells;
-
- var td = getCell(grid, cpos.rowindex, cpos.cellindex);
- each(ed.dom.select('br', td), function(e, i) {
- if (i > 0 && ed.dom.getAttrib('mce_bogus'))
- ed.dom.remove(e);
- });
- }
+ // BR element
+ if (node.nodeName == 'BR') {
+ if (start)
+ rng.setStartBefore(node);
+ else
+ rng.setEndBefore(node);
- //return true;
+ return;
}
- } else {
- var cells = [];
- var sel = inst.selection.getSel();
- var lastTR = null;
- var curRow = null;
- var x1 = -1, y1 = -1, x2, y2;
-
- // Only one cell selected, whats the point?
- if (sel.rangeCount < 2)
- return true;
-
- // Get all selected cells
- for (var i=0; i<sel.rangeCount; i++) {
- var rng = sel.getRangeAt(i);
- var tdElm = rng.startContainer.childNodes[rng.startOffset];
-
- if (!tdElm)
+ } while (node = (start ? walker.next() : walker.prev()));
+ };
+
+ // Try to expand text selection as much as we can only Gecko supports cell selection
+ selectedCells = dom.select('td.mceSelected,th.mceSelected');
+ if (selectedCells.length > 0) {
+ rng = dom.createRng();
+ node = selectedCells[0];
+ endNode = selectedCells[selectedCells.length - 1];
+
+ setPoint(node, 1);
+ walker = new tinymce.dom.TreeWalker(node, dom.getParent(selectedCells[0], 'table'));
+
+ do {
+ if (node.nodeName == 'TD' || node.nodeName == 'TH') {
+ if (!dom.hasClass(node, 'mceSelected'))
break;
- if (tdElm.nodeName == "TD" || tdElm.nodeName == "TH")
- cells[cells.length] = tdElm;
+ lastNode = node;
}
+ } while (node = walker.next());
- // Get rows and cells
- var tRows = tableElm.rows;
- for (var y=0; y<tRows.length; y++) {
- var rowCells = [];
+ setPoint(lastNode);
- for (var x=0; x<tRows[y].cells.length; x++) {
- var td = tRows[y].cells[x];
+ sel.setRng(rng);
+ }
- for (var i=0; i<cells.length; i++) {
- if (td == cells[i]) {
- rowCells[rowCells.length] = td;
- }
- }
- }
+ ed.nodeChanged();
+ startCell = tableGrid = startTable = null;
+ }
+ });
- if (rowCells.length > 0)
- rows[rows.length] = rowCells;
- }
+ ed.onKeyUp.add(function(ed, e) {
+ cleanup();
+ });
- // Find selected cells in grid and box
- var curRow = [];
- var lastTR = null;
- for (var y=0; y<grid.length; y++) {
- for (var x=0; x<grid[y].length; x++) {
- grid[y][x]._selected = false;
-
- for (var i=0; i<cells.length; i++) {
- if (grid[y][x] == cells[i]) {
- // Get start pos
- if (x1 == -1) {
- x1 = x;
- y1 = y;
- }
-
- // Get end pos
- x2 = x;
- y2 = y;
-
- grid[y][x]._selected = true;
- }
- }
- }
- }
+ // Add context menu
+ if (ed && ed.plugins.contextmenu) {
+ ed.plugins.contextmenu.onContextMenu.add(function(th, m, e) {
+ var sm, se = ed.selection, el = se.getNode() || ed.getBody();
- // Is there gaps, if so deny
- for (var y=y1; y<=y2; y++) {
- for (var x=x1; x<=x2; x++) {
- if (!grid[y][x]._selected) {
- alert("Invalid selection for merge.");
- return true;
- }
- }
- }
+ if (ed.dom.getParent(e, 'td') || ed.dom.getParent(e, 'th')) {
+ m.removeAll();
+
+ if (el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) {
+ m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
+ m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
+ m.addSeparator();
}
- // Validate selection and get total rowspan and colspan
- var rowSpan = 1, colSpan = 1;
+ if (el.nodeName == 'IMG' && el.className.indexOf('mceItem') == -1) {
+ m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
+ m.addSeparator();
+ }
- // Validate horizontal and get total colspan
- var lastRowSpan = -1;
- for (var y=0; y<rows.length; y++) {
- var rowColSpan = 0;
+ m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable', value : {action : 'insert'}});
+ m.add({title : 'table.props_desc', icon : 'table_props', cmd : 'mceInsertTable'});
+ m.add({title : 'table.del', icon : 'delete_table', cmd : 'mceTableDelete'});
+ m.addSeparator();
- for (var x=0; x<rows[y].length; x++) {
- var sd = getColRowSpan(rows[y][x]);
+ // Cell menu
+ sm = m.addMenu({title : 'table.cell'});
+ sm.add({title : 'table.cell_desc', icon : 'cell_props', cmd : 'mceTableCellProps'});
+ sm.add({title : 'table.split_cells_desc', icon : 'split_cells', cmd : 'mceTableSplitCells'});
+ sm.add({title : 'table.merge_cells_desc', icon : 'merge_cells', cmd : 'mceTableMergeCells'});
- rowColSpan += sd['colspan'];
+ // Row menu
+ sm = m.addMenu({title : 'table.row'});
+ sm.add({title : 'table.row_desc', icon : 'row_props', cmd : 'mceTableRowProps'});
+ sm.add({title : 'table.row_before_desc', icon : 'row_before', cmd : 'mceTableInsertRowBefore'});
+ sm.add({title : 'table.row_after_desc', icon : 'row_after', cmd : 'mceTableInsertRowAfter'});
+ sm.add({title : 'table.delete_row_desc', icon : 'delete_row', cmd : 'mceTableDeleteRow'});
+ sm.addSeparator();
+ sm.add({title : 'table.cut_row_desc', icon : 'cut', cmd : 'mceTableCutRow'});
+ sm.add({title : 'table.copy_row_desc', icon : 'copy', cmd : 'mceTableCopyRow'});
+ sm.add({title : 'table.paste_row_before_desc', icon : 'paste', cmd : 'mceTablePasteRowBefore'}).setDisabled(!clipboardRows);
+ sm.add({title : 'table.paste_row_after_desc', icon : 'paste', cmd : 'mceTablePasteRowAfter'}).setDisabled(!clipboardRows);
- if (lastRowSpan != -1 && sd['rowspan'] != lastRowSpan) {
- alert("Invalid selection for merge.");
- return true;
- }
+ // Column menu
+ sm = m.addMenu({title : 'table.col'});
+ sm.add({title : 'table.col_before_desc', icon : 'col_before', cmd : 'mceTableInsertColBefore'});
+ sm.add({title : 'table.col_after_desc', icon : 'col_after', cmd : 'mceTableInsertColAfter'});
+ sm.add({title : 'table.delete_col_desc', icon : 'delete_col', cmd : 'mceTableDeleteCol'});
+ } else
+ m.add({title : 'table.desc', icon : 'table', cmd : 'mceInsertTable'});
+ });
+ }
- lastRowSpan = sd['rowspan'];
- }
+ // Fixes an issue on Gecko where it's impossible to place the caret behind a table
+ // This fix will force a paragraph element after the table but only when the forced_root_block setting is enabled
+ if (!tinymce.isIE) {
+ function fixTableCaretPos() {
+ var last;
- if (rowColSpan > colSpan)
- colSpan = rowColSpan;
+ // Skip empty text nodes form the end
+ for (last = ed.getBody().lastChild; last && last.nodeType == 3 && !last.nodeValue.length; last = last.previousSibling) ;
- lastRowSpan = -1;
- }
+ if (last && last.nodeName == 'TABLE')
+ ed.dom.add(ed.getBody(), 'p', null, '<br mce_bogus="1" />');
+ };
+
+ // Fixes an bug where it's impossible to place the caret before a table in Gecko
+ // this fix solves it by detecting when the caret is at the beginning of such a table
+ // and then manually moves the caret infront of the table
+ if (tinymce.isGecko) {
+ ed.onKeyDown.add(function(ed, e) {
+ var rng, table, dom = ed.dom;
+
+ // On gecko it's not possible to place the caret before a table
+ if (e.keyCode == 37 || e.keyCode == 38) {
+ rng = ed.selection.getRng();
+ table = dom.getParent(rng.startContainer, 'table');
- // Validate vertical and get total rowspan
- var lastColSpan = -1;
- for (var x=0; x<rows[0].length; x++) {
- var colRowSpan = 0;
+ if (table && ed.getBody().firstChild == table) {
+ if (isAtStart(rng, table)) {
+ rng = dom.createRng();
- for (var y=0; y<rows.length; y++) {
- var sd = getColRowSpan(rows[y][x]);
+ rng.setStartBefore(table);
+ rng.setEndBefore(table);
- colRowSpan += sd['rowspan'];
+ ed.selection.setRng(rng);
- if (lastColSpan != -1 && sd['colspan'] != lastColSpan) {
- alert("Invalid selection for merge.");
- return true;
+ e.preventDefault();
}
-
- lastColSpan = sd['colspan'];
}
+ }
+ });
+ }
- if (colRowSpan > rowSpan)
- rowSpan = colRowSpan;
+ ed.onKeyUp.add(fixTableCaretPos);
+ ed.onSetContent.add(fixTableCaretPos);
+ ed.onVisualAid.add(fixTableCaretPos);
- lastColSpan = -1;
- }
+ ed.onPreProcess.add(function(ed, o) {
+ var last = o.node.lastChild;
- // Setup td
- tdElm = rows[0][0];
- tdElm.rowSpan = rowSpan;
- tdElm.colSpan = colSpan;
+ if (last && last.childNodes.length == 1 && last.firstChild.nodeName == 'BR')
+ ed.dom.remove(last);
+ });
- // Merge cells
- for (var y=0; y<rows.length; y++) {
- for (var x=0; x<rows[y].length; x++) {
- var html = rows[y][x].innerHTML;
- var chk = html.replace(/[ \t\r\n]/g, "");
+ fixTableCaretPos();
+ }
+ });
- if (chk != "<br/>" && chk != "<br>" && chk != '<br mce_bogus="1"/>' && (x+y > 0))
- tdElm.innerHTML += html;
+ // Register action commands
+ each({
+ mceTableSplitCells : function(grid) {
+ grid.split();
+ },
- // Not current cell
- if (rows[y][x] != tdElm && !rows[y][x]._deleted) {
- var cpos = getCellPos(grid, rows[y][x]);
- var tr = rows[y][x].parentNode;
+ mceTableMergeCells : function(grid) {
+ var rowSpan, colSpan, cell;
- tr.removeChild(rows[y][x]);
- rows[y][x]._deleted = true;
+ cell = ed.dom.getParent(ed.selection.getNode(), 'th,td');
+ if (cell) {
+ rowSpan = cell.rowSpan;
+ colSpan = cell.colSpan;
+ }
- // Empty TR, remove it
- if (!tr.hasChildNodes()) {
- tr.parentNode.removeChild(tr);
+ if (!ed.dom.select('td.mceSelected,th.mceSelected').length) {
+ winMan.open({
+ url : url + '/merge_cells.htm',
+ width : 240 + parseInt(ed.getLang('table.merge_cells_delta_width', 0)),
+ height : 110 + parseInt(ed.getLang('table.merge_cells_delta_height', 0)),
+ inline : 1
+ }, {
+ rows : rowSpan,
+ cols : colSpan,
+ onaction : function(data) {
+ grid.merge(cell, data.cols, data.rows);
+ },
+ plugin_url : url
+ });
+ } else
+ grid.merge();
+ },
- var lastCell = null;
- for (var x=0; cellElm = getCell(grid, cpos.rowindex, x); x++) {
- if (cellElm != lastCell && cellElm.rowSpan > 1)
- cellElm.rowSpan--;
+ mceTableInsertRowBefore : function(grid) {
+ grid.insertRow(true);
+ },
- lastCell = cellElm;
- }
+ mceTableInsertRowAfter : function(grid) {
+ grid.insertRow();
+ },
- if (tdElm.rowSpan > 1)
- tdElm.rowSpan--;
- }
- }
- }
- }
+ mceTableInsertColBefore : function(grid) {
+ grid.insertCol(true);
+ },
- // Remove all but one bogus br
- each(ed.dom.select('br', tdElm), function(e, i) {
- if (i > 0 && ed.dom.getAttrib(e, 'mce_bogus'))
- ed.dom.remove(e);
- });
+ mceTableInsertColAfter : function(grid) {
+ grid.insertCol();
+ },
- break;
- }
+ mceTableDeleteCol : function(grid) {
+ grid.deleteCols();
+ },
- tableElm = inst.dom.getParent(inst.selection.getNode(), "table");
- inst.addVisual(tableElm);
- inst.nodeChanged();
- }
+ mceTableDeleteRow : function(grid) {
+ grid.deleteRows();
+ },
- return true;
- }
+ mceTableCutRow : function(grid) {
+ clipboardRows = grid.cutRows();
+ },
+
+ mceTableCopyRow : function(grid) {
+ clipboardRows = grid.copyRows();
+ },
- // Pass to next handler in chain
- return false;
+ mceTablePasteRowBefore : function(grid) {
+ grid.pasteRows(clipboardRows, true);
+ },
+
+ mceTablePasteRowAfter : function(grid) {
+ grid.pasteRows(clipboardRows);
+ },
+
+ mceTableDelete : function(grid) {
+ grid.deleteTable();
+ }
+ }, function(func, name) {
+ ed.addCommand(name, function() {
+ var grid = createTableGrid();
+
+ if (grid) {
+ func(grid);
+ ed.execCommand('mceRepaint');
+ cleanup();
+ }
+ });
+ });
+
+ // Register dialog commands
+ each({
+ mceInsertTable : function(val) {
+ winMan.open({
+ url : url + '/table.htm',
+ width : 400 + parseInt(ed.getLang('table.table_delta_width', 0)),
+ height : 320 + parseInt(ed.getLang('table.table_delta_height', 0)),
+ inline : 1
+ }, {
+ plugin_url : url,
+ action : val ? val.action : 0
+ });
+ },
+
+ mceTableRowProps : function() {
+ winMan.open({
+ url : url + '/row.htm',
+ width : 400 + parseInt(ed.getLang('table.rowprops_delta_width', 0)),
+ height : 295 + parseInt(ed.getLang('table.rowprops_delta_height', 0)),
+ inline : 1
+ }, {
+ plugin_url : url
+ });
+ },
+
+ mceTableCellProps : function() {
+ winMan.open({
+ url : url + '/cell.htm',
+ width : 400 + parseInt(ed.getLang('table.cellprops_delta_width', 0)),
+ height : 295 + parseInt(ed.getLang('table.cellprops_delta_height', 0)),
+ inline : 1
+ }, {
+ plugin_url : url
+ });
+ }
+ }, function(func, name) {
+ ed.addCommand(name, function(ui, val) {
+ func(val);
+ });
+ });
}
});
// Register plugin
tinymce.PluginManager.add('table', tinymce.plugins.TablePlugin);
-})(); \ No newline at end of file
+})(tinymce); \ No newline at end of file
diff --git a/program/js/tiny_mce/plugins/table/js/cell.js b/program/js/tiny_mce/plugins/table/js/cell.js
index f23b06751..f24619172 100644
--- a/program/js/tiny_mce/plugins/table/js/cell.js
+++ b/program/js/tiny_mce/plugins/table/js/cell.js
@@ -11,7 +11,7 @@ function init() {
document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor')
var inst = ed;
- var tdElm = ed.dom.getParent(ed.selection.getNode(), "td,th");
+ var tdElm = ed.dom.getParent(ed.selection.getStart(), "td,th");
var formObj = document.forms[0];
var st = ed.dom.parseStyle(ed.dom.getAttrib(tdElm, "style"));
@@ -34,38 +34,55 @@ function init() {
addClassesToList('class', 'table_cell_styles');
TinyMCE_EditableSelects.init();
- formObj.bordercolor.value = bordercolor;
- formObj.bgcolor.value = bgcolor;
- formObj.backgroundimage.value = backgroundimage;
- formObj.width.value = width;
- formObj.height.value = height;
- formObj.id.value = id;
- formObj.lang.value = lang;
- formObj.style.value = ed.dom.serializeStyle(st);
- selectByValue(formObj, 'align', align);
- selectByValue(formObj, 'valign', valign);
- selectByValue(formObj, 'class', className, true, true);
- selectByValue(formObj, 'celltype', celltype);
- selectByValue(formObj, 'dir', dir);
- selectByValue(formObj, 'scope', scope);
-
- // Resize some elements
- if (isVisible('backgroundimagebrowser'))
- document.getElementById('backgroundimage').style.width = '180px';
-
- updateColor('bordercolor_pick', 'bordercolor');
- updateColor('bgcolor_pick', 'bgcolor');
+ if (!ed.dom.hasClass(tdElm, 'mceSelected')) {
+ formObj.bordercolor.value = bordercolor;
+ formObj.bgcolor.value = bgcolor;
+ formObj.backgroundimage.value = backgroundimage;
+ formObj.width.value = width;
+ formObj.height.value = height;
+ formObj.id.value = id;
+ formObj.lang.value = lang;
+ formObj.style.value = ed.dom.serializeStyle(st);
+ selectByValue(formObj, 'align', align);
+ selectByValue(formObj, 'valign', valign);
+ selectByValue(formObj, 'class', className, true, true);
+ selectByValue(formObj, 'celltype', celltype);
+ selectByValue(formObj, 'dir', dir);
+ selectByValue(formObj, 'scope', scope);
+
+ // Resize some elements
+ if (isVisible('backgroundimagebrowser'))
+ document.getElementById('backgroundimage').style.width = '180px';
+
+ updateColor('bordercolor_pick', 'bordercolor');
+ updateColor('bgcolor_pick', 'bgcolor');
+ } else
+ tinyMCEPopup.dom.hide('action');
}
function updateAction() {
var el, inst = ed, tdElm, trElm, tableElm, formObj = document.forms[0];
tinyMCEPopup.restoreSelection();
- el = ed.selection.getNode();
+ el = ed.selection.getStart();
tdElm = ed.dom.getParent(el, "td,th");
trElm = ed.dom.getParent(el, "tr");
tableElm = ed.dom.getParent(el, "table");
+ // Cell is selected
+ if (ed.dom.hasClass(tdElm, 'mceSelected')) {
+ // Update all selected sells
+ tinymce.each(ed.dom.select('td.mceSelected,th.mceSelected'), function(td) {
+ updateCell(td);
+ });
+
+ ed.addVisual();
+ ed.nodeChanged();
+ inst.execCommand('mceEndUndoLevel');
+ tinyMCEPopup.close();
+ return;
+ }
+
ed.execCommand('mceBeginUndoLevel');
switch (getSelectValue(formObj, 'action')) {
diff --git a/program/js/tiny_mce/plugins/table/js/merge_cells.js b/program/js/tiny_mce/plugins/table/js/merge_cells.js
index 31d6df0ab..7ee4bf040 100644
--- a/program/js/tiny_mce/plugins/table/js/merge_cells.js
+++ b/program/js/tiny_mce/plugins/table/js/merge_cells.js
@@ -1,29 +1,27 @@
tinyMCEPopup.requireLangPack();
-function init() {
- var f = document.forms[0], v;
+var MergeCellsDialog = {
+ init : function() {
+ var f = document.forms[0];
- tinyMCEPopup.resizeToInnerSize();
+ f.numcols.value = tinyMCEPopup.getWindowArg('cols', 1);
+ f.numrows.value = tinyMCEPopup.getWindowArg('rows', 1);
+ },
- f.numcols.value = tinyMCEPopup.getWindowArg('numcols', 1);
- f.numrows.value = tinyMCEPopup.getWindowArg('numrows', 1);
-}
+ merge : function() {
+ var func, f = document.forms[0];
-function mergeCells() {
- var args = [], f = document.forms[0];
+ tinyMCEPopup.restoreSelection();
- tinyMCEPopup.restoreSelection();
+ func = tinyMCEPopup.getWindowArg('onaction');
- if (!AutoValidator.validate(f)) {
- tinyMCEPopup.alert(tinyMCEPopup.getLang('invalid_data'));
- return false;
- }
-
- args["numcols"] = f.numcols.value;
- args["numrows"] = f.numrows.value;
+ func({
+ cols : f.numcols.value,
+ rows : f.numrows.value
+ });
- tinyMCEPopup.execCommand("mceTableMergeCells", false, args);
- tinyMCEPopup.close();
-}
+ tinyMCEPopup.close();
+ }
+};
-tinyMCEPopup.onInit.add(init);
+tinyMCEPopup.onInit.add(MergeCellsDialog.init, MergeCellsDialog);
diff --git a/program/js/tiny_mce/plugins/table/js/row.js b/program/js/tiny_mce/plugins/table/js/row.js
index d25f635f6..7e188c3f0 100644
--- a/program/js/tiny_mce/plugins/table/js/row.js
+++ b/program/js/tiny_mce/plugins/table/js/row.js
@@ -8,7 +8,7 @@ function init() {
var inst = tinyMCEPopup.editor;
var dom = inst.dom;
- var trElm = dom.getParent(inst.selection.getNode(), "tr");
+ var trElm = dom.getParent(inst.selection.getStart(), "tr");
var formObj = document.forms[0];
var st = dom.parseStyle(dom.getAttrib(trElm, "style"));
@@ -24,27 +24,32 @@ function init() {
var lang = dom.getAttrib(trElm, 'lang');
var dir = dom.getAttrib(trElm, 'dir');
- // Setup form
- addClassesToList('class', 'table_row_styles');
- TinyMCE_EditableSelects.init();
-
- formObj.bgcolor.value = bgcolor;
- formObj.backgroundimage.value = backgroundimage;
- formObj.height.value = height;
- formObj.id.value = id;
- formObj.lang.value = lang;
- formObj.style.value = dom.serializeStyle(st);
- selectByValue(formObj, 'align', align);
- selectByValue(formObj, 'valign', valign);
- selectByValue(formObj, 'class', className, true, true);
selectByValue(formObj, 'rowtype', rowtype);
- selectByValue(formObj, 'dir', dir);
-
- // Resize some elements
- if (isVisible('backgroundimagebrowser'))
- document.getElementById('backgroundimage').style.width = '180px';
- updateColor('bgcolor_pick', 'bgcolor');
+ // Any cells selected
+ if (dom.select('td.mceSelected,th.mceSelected', trElm).length == 0) {
+ // Setup form
+ addClassesToList('class', 'table_row_styles');
+ TinyMCE_EditableSelects.init();
+
+ formObj.bgcolor.value = bgcolor;
+ formObj.backgroundimage.value = backgroundimage;
+ formObj.height.value = height;
+ formObj.id.value = id;
+ formObj.lang.value = lang;
+ formObj.style.value = dom.serializeStyle(st);
+ selectByValue(formObj, 'align', align);
+ selectByValue(formObj, 'valign', valign);
+ selectByValue(formObj, 'class', className, true, true);
+ selectByValue(formObj, 'dir', dir);
+
+ // Resize some elements
+ if (isVisible('backgroundimagebrowser'))
+ document.getElementById('backgroundimage').style.width = '180px';
+
+ updateColor('bgcolor_pick', 'bgcolor');
+ } else
+ tinyMCEPopup.dom.hide('action');
}
function updateAction() {
@@ -52,8 +57,28 @@ function updateAction() {
var action = getSelectValue(formObj, 'action');
tinyMCEPopup.restoreSelection();
- trElm = dom.getParent(inst.selection.getNode(), "tr");
- tableElm = dom.getParent(inst.selection.getNode(), "table");
+ trElm = dom.getParent(inst.selection.getStart(), "tr");
+ tableElm = dom.getParent(inst.selection.getStart(), "table");
+
+ // Update all selected rows
+ if (dom.select('td.mceSelected,th.mceSelected', trElm).length > 0) {
+ tinymce.each(tableElm.rows, function(tr) {
+ var i;
+
+ for (i = 0; i < tr.cells.length; i++) {
+ if (dom.hasClass(tr.cells[i], 'mceSelected')) {
+ updateRow(tr, true);
+ return;
+ }
+ }
+ });
+
+ inst.addVisual();
+ inst.nodeChanged();
+ inst.execCommand('mceEndUndoLevel');
+ tinyMCEPopup.close();
+ return;
+ }
inst.execCommand('mceBeginUndoLevel');
diff --git a/program/js/tiny_mce/plugins/table/js/table.js b/program/js/tiny_mce/plugins/table/js/table.js
index 182589d69..f4b0862ef 100644
--- a/program/js/tiny_mce/plugins/table/js/table.js
+++ b/program/js/tiny_mce/plugins/table/js/table.js
@@ -82,7 +82,7 @@ function insertTable() {
capEl = elm.ownerDocument.createElement('caption');
if (!tinymce.isIE)
- capEl.innerHTML = '<br mce_bogus="1"/>';
+ capEl.innerHTML = '<br _mce_bogus="1"/>';
elm.insertBefore(capEl, elm.firstChild);
}
@@ -151,6 +151,7 @@ function insertTable() {
html += makeAttrib('border', border);
html += makeAttrib('cellpadding', cellpadding);
html += makeAttrib('cellspacing', cellspacing);
+ html += makeAttrib('_mce_new', '1');
if (width && inst.settings.inline_styles) {
if (style)
@@ -186,7 +187,7 @@ function insertTable() {
if (caption) {
if (!tinymce.isIE)
- html += '<caption><br mce_bogus="1"/></caption>';
+ html += '<caption><br _mce_bogus="1"/></caption>';
else
html += '<caption></caption>';
}
@@ -196,7 +197,7 @@ function insertTable() {
for (var x=0; x<cols; x++) {
if (!tinymce.isIE)
- html += '<td><br mce_bogus="1"/></td>';
+ html += '<td><br _mce_bogus="1"/></td>';
else
html += '<td></td>';
}
@@ -210,9 +211,10 @@ function insertTable() {
// Move table
if (inst.settings.fix_table_elements) {
- var bm = inst.selection.getBookmark(), patt = '';
+ var patt = '';
- inst.execCommand('mceInsertContent', false, '<br class="_mce_marker" />');
+ inst.focus();
+ inst.selection.setContent('<br class="_mce_marker" />');
tinymce.each('h1,h2,h3,h4,h5,h6,p'.split(','), function(n) {
if (patt)
@@ -225,12 +227,19 @@ function insertTable() {
inst.dom.split(inst.dom.getParent(n, 'h1,h2,h3,h4,h5,h6,p'), n);
});
- dom.setOuterHTML(dom.select('._mce_marker')[0], html);
-
- inst.selection.moveToBookmark(bm);
+ dom.setOuterHTML(dom.select('br._mce_marker')[0], html);
} else
inst.execCommand('mceInsertContent', false, html);
+ tinymce.each(dom.select('table[_mce_new]'), function(node) {
+ var td = dom.select('td', node);
+
+ inst.selection.select(td[0], true);
+ inst.selection.collapse();
+
+ dom.setAttrib(node, '_mce_new', '');
+ });
+
inst.addVisual();
inst.execCommand('mceEndUndoLevel');
diff --git a/program/js/tiny_mce/plugins/table/merge_cells.htm b/program/js/tiny_mce/plugins/table/merge_cells.htm
index 25d42eb65..9736ed8c0 100644
--- a/program/js/tiny_mce/plugins/table/merge_cells.htm
+++ b/program/js/tiny_mce/plugins/table/merge_cells.htm
@@ -8,7 +8,7 @@
<script type="text/javascript" src="js/merge_cells.js"></script>
</head>
<body style="margin: 8px">
-<form onsubmit="mergeCells();return false;" action="#">
+<form onsubmit="MergeCellsDialog.merge();return false;" action="#">
<fieldset>
<legend>{#table_dlg.merge_cells_title}</legend>
<table border="0" cellpadding="0" cellspacing="3" width="100%">
@@ -24,13 +24,8 @@
</fieldset>
<div class="mceActionPanel">
- <div style="float: left">
- <input type="submit" id="insert" name="insert" value="{#update}" />
- </div>
-
- <div style="float: right">
- <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
- </div>
+ <input type="submit" id="insert" name="insert" value="{#update}" />
+ <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
</div>
</form>
</body>
diff --git a/program/js/tiny_mce/plugins/table/row.htm b/program/js/tiny_mce/plugins/table/row.htm
index 07ca13c98..092e6c827 100644
--- a/program/js/tiny_mce/plugins/table/row.htm
+++ b/program/js/tiny_mce/plugins/table/row.htm
@@ -147,13 +147,8 @@
</select>
</div>
- <div style="float: left">
- <div><input type="submit" id="insert" name="insert" value="{#update}" /></div>
- </div>
-
- <div style="float: right">
- <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
- </div>
+ <input type="submit" id="insert" name="insert" value="{#update}" />
+ <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
</div>
</form>
</body>
diff --git a/program/js/tiny_mce/plugins/table/table.htm b/program/js/tiny_mce/plugins/table/table.htm
index 37e615970..f26903922 100644
--- a/program/js/tiny_mce/plugins/table/table.htm
+++ b/program/js/tiny_mce/plugins/table/table.htm
@@ -179,13 +179,8 @@
</div>
<div class="mceActionPanel">
- <div style="float: left">
- <input type="submit" id="insert" name="insert" value="{#insert}" />
- </div>
-
- <div style="float: right">
- <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
- </div>
+ <input type="submit" id="insert" name="insert" value="{#insert}" />
+ <input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />
</div>
</form>
</body>