JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-4.0_full
[ckeditor.git] / plugins / table / dialogs / table.js
index 12541f3..c74303c 100644 (file)
@@ -1,9 +1,20 @@
-/*\r
-Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.\r
-For licensing, see LICENSE.html or http://ckeditor.com/license\r
-*/\r
-\r
-(function(){var a=CKEDITOR.tools.cssLength,b=function(f){var g=this.id;if(!f.info)f.info={};f.info[g]=this.getValue();};function c(f){var g=0,h=0;for(var i=0,j,k=f.$.rows.length;i<k;i++){j=f.$.rows[i],g=0;for(var l=0,m,n=j.cells.length;l<n;l++){m=j.cells[l];g+=m.colSpan;}g>h&&(h=g);}return h;};function d(f){return function(){var g=this.getValue(),h=!!(CKEDITOR.dialog.validate.integer()(g)&&g>0);if(!h){alert(f);this.select();}return h;};};function e(f,g){var h=function(j){return new CKEDITOR.dom.element(j,f.document);},i=f.plugins.dialogadvtab;return{title:f.lang.table.title,minWidth:310,minHeight:CKEDITOR.env.ie?310:280,onLoad:function(){var j=this,k=j.getContentElement('advanced','advStyles');if(k)k.on('change',function(l){var m=this.getStyle('width',''),n=j.getContentElement('info','txtWidth');n&&n.setValue(m,true);var o=this.getStyle('height',''),p=j.getContentElement('info','txtHeight');p&&p.setValue(o,true);});},onShow:function(){var r=this;var j=f.getSelection(),k=j.getRanges(),l=null,m=r.getContentElement('info','txtRows'),n=r.getContentElement('info','txtCols'),o=r.getContentElement('info','txtWidth'),p=r.getContentElement('info','txtHeight');if(g=='tableProperties'){if(l=j.getSelectedElement())l=l.getAscendant('table',true);else if(k.length>0){if(CKEDITOR.env.webkit)k[0].shrink(CKEDITOR.NODE_ELEMENT);var q=k[0].getCommonAncestor(true);l=q.getAscendant('table',true);}r._.selectedElement=l;}if(l){r.setupContent(l);m&&m.disable();n&&n.disable();}else{m&&m.enable();n&&n.enable();}o&&o.onChange();p&&p.onChange();},onOk:function(){var j=f.getSelection(),k=this._.selectedElement&&j.createBookmarks(),l=this._.selectedElement||h('table'),m=this,n={};this.commitContent(n,l);if(n.info){var o=n.info;if(!this._.selectedElement){var p=l.append(h('tbody')),q=parseInt(o.txtRows,10)||0,r=parseInt(o.txtCols,10)||0;for(var s=0;s<q;s++){var t=p.append(h('tr'));for(var u=0;u<r;u++){var v=t.append(h('td'));if(!CKEDITOR.env.ie)v.append(h('br'));}}}var w=o.selHeaders;if(!l.$.tHead&&(w=='row'||w=='both')){var x=new CKEDITOR.dom.element(l.$.createTHead());p=l.getElementsByTag('tbody').getItem(0);var y=p.getElementsByTag('tr').getItem(0);for(s=0;s<y.getChildCount();s++){var z=y.getChild(s);if(z.type==CKEDITOR.NODE_ELEMENT&&!z.data('cke-bookmark')){z.renameNode('th');z.setAttribute('scope','col');}}x.append(y.remove());}if(l.$.tHead!==null&&!(w=='row'||w=='both')){x=new CKEDITOR.dom.element(l.$.tHead);p=l.getElementsByTag('tbody').getItem(0);var A=p.getFirst();while(x.getChildCount()>0){y=x.getFirst();\r
-for(s=0;s<y.getChildCount();s++){var B=y.getChild(s);if(B.type==CKEDITOR.NODE_ELEMENT){B.renameNode('td');B.removeAttribute('scope');}}y.insertBefore(A);}x.remove();}if(!this.hasColumnHeaders&&(w=='col'||w=='both'))for(t=0;t<l.$.rows.length;t++){B=new CKEDITOR.dom.element(l.$.rows[t].cells[0]);B.renameNode('th');B.setAttribute('scope','row');}if(this.hasColumnHeaders&&!(w=='col'||w=='both'))for(s=0;s<l.$.rows.length;s++){t=new CKEDITOR.dom.element(l.$.rows[s]);if(t.getParent().getName()=='tbody'){B=new CKEDITOR.dom.element(t.$.cells[0]);B.renameNode('td');B.removeAttribute('scope');}}o.txtHeight?l.setStyle('height',o.txtHeight):l.removeStyle('height');o.txtWidth?l.setStyle('width',o.txtWidth):l.removeStyle('width');if(!l.getAttribute('style'))l.removeAttribute('style');}if(!this._.selectedElement){f.insertElement(l);setTimeout(function(){var C=new CKEDITOR.dom.element(l.$.rows[0].cells[0]),D=new CKEDITOR.dom.range(f.document);D.moveToPosition(C,CKEDITOR.POSITION_AFTER_START);D.select(1);},0);}else try{j.selectBookmarks(k);}catch(C){}},contents:[{id:'info',label:f.lang.table.title,elements:[{type:'hbox',widths:[null,null],styles:['vertical-align:top'],children:[{type:'vbox',padding:0,children:[{type:'text',id:'txtRows','default':3,label:f.lang.table.rows,required:true,controlStyle:'width:5em',validate:d(f.lang.table.invalidRows),setup:function(j){this.setValue(j.$.rows.length);},commit:b},{type:'text',id:'txtCols','default':2,label:f.lang.table.columns,required:true,controlStyle:'width:5em',validate:d(f.lang.table.invalidCols),setup:function(j){this.setValue(c(j));},commit:b},{type:'html',html:'&nbsp;'},{type:'select',id:'selHeaders','default':'',label:f.lang.table.headers,items:[[f.lang.table.headersNone,''],[f.lang.table.headersRow,'row'],[f.lang.table.headersColumn,'col'],[f.lang.table.headersBoth,'both']],setup:function(j){var k=this.getDialog();k.hasColumnHeaders=true;for(var l=0;l<j.$.rows.length;l++){var m=j.$.rows[l].cells[0];if(m&&m.nodeName.toLowerCase()!='th'){k.hasColumnHeaders=false;break;}}if(j.$.tHead!==null)this.setValue(k.hasColumnHeaders?'both':'row');else this.setValue(k.hasColumnHeaders?'col':'');},commit:b},{type:'text',id:'txtBorder','default':1,label:f.lang.table.border,controlStyle:'width:3em',validate:CKEDITOR.dialog.validate.number(f.lang.table.invalidBorder),setup:function(j){this.setValue(j.getAttribute('border')||'');},commit:function(j,k){if(this.getValue())k.setAttribute('border',this.getValue());else k.removeAttribute('border');\r
-}},{id:'cmbAlign',type:'select','default':'',label:f.lang.common.align,items:[[f.lang.common.notSet,''],[f.lang.common.alignLeft,'left'],[f.lang.common.alignCenter,'center'],[f.lang.common.alignRight,'right']],setup:function(j){this.setValue(j.getAttribute('align')||'');},commit:function(j,k){if(this.getValue())k.setAttribute('align',this.getValue());else k.removeAttribute('align');}}]},{type:'vbox',padding:0,children:[{type:'hbox',widths:['5em'],children:[{type:'text',id:'txtWidth',controlStyle:'width:5em',label:f.lang.common.width,title:f.lang.common.cssLengthTooltip,'default':500,getValue:a,validate:CKEDITOR.dialog.validate.cssLength(f.lang.common.invalidCssLength.replace('%1',f.lang.common.width)),onChange:function(){var j=this.getDialog().getContentElement('advanced','advStyles');j&&j.updateStyle('width',this.getValue());},setup:function(j){var k=j.getStyle('width');k&&this.setValue(k);},commit:b}]},{type:'hbox',widths:['5em'],children:[{type:'text',id:'txtHeight',controlStyle:'width:5em',label:f.lang.common.height,title:f.lang.common.cssLengthTooltip,'default':'',getValue:a,validate:CKEDITOR.dialog.validate.cssLength(f.lang.common.invalidCssLength.replace('%1',f.lang.common.height)),onChange:function(){var j=this.getDialog().getContentElement('advanced','advStyles');j&&j.updateStyle('height',this.getValue());},setup:function(j){var k=j.getStyle('height');k&&this.setValue(k);},commit:b}]},{type:'html',html:'&nbsp;'},{type:'text',id:'txtCellSpace',controlStyle:'width:3em',label:f.lang.table.cellSpace,'default':1,validate:CKEDITOR.dialog.validate.number(f.lang.table.invalidCellSpacing),setup:function(j){this.setValue(j.getAttribute('cellSpacing')||'');},commit:function(j,k){if(this.getValue())k.setAttribute('cellSpacing',this.getValue());else k.removeAttribute('cellSpacing');}},{type:'text',id:'txtCellPad',controlStyle:'width:3em',label:f.lang.table.cellPad,'default':1,validate:CKEDITOR.dialog.validate.number(f.lang.table.invalidCellPadding),setup:function(j){this.setValue(j.getAttribute('cellPadding')||'');},commit:function(j,k){if(this.getValue())k.setAttribute('cellPadding',this.getValue());else k.removeAttribute('cellPadding');}}]}]},{type:'html',align:'right',html:''},{type:'vbox',padding:0,children:[{type:'text',id:'txtCaption',label:f.lang.table.caption,setup:function(j){var n=this;n.enable();var k=j.getElementsByTag('caption');if(k.count()>0){var l=k.getItem(0),m=l.getFirst(CKEDITOR.dom.walker.nodeType(CKEDITOR.NODE_ELEMENT));if(m&&!m.equals(l.getBogus())){n.disable();\r
-n.setValue(l.getText());return;}l=CKEDITOR.tools.trim(l.getText());n.setValue(l);}},commit:function(j,k){if(!this.isEnabled())return;var l=this.getValue(),m=k.getElementsByTag('caption');if(l){if(m.count()>0){m=m.getItem(0);m.setHtml('');}else{m=new CKEDITOR.dom.element('caption',f.document);if(k.getChildCount())m.insertBefore(k.getFirst());else m.appendTo(k);}m.append(new CKEDITOR.dom.text(l,f.document));}else if(m.count()>0)for(var n=m.count()-1;n>=0;n--)m.getItem(n).remove();}},{type:'text',id:'txtSummary',label:f.lang.table.summary,setup:function(j){this.setValue(j.getAttribute('summary')||'');},commit:function(j,k){if(this.getValue())k.setAttribute('summary',this.getValue());else k.removeAttribute('summary');}}]}]},i&&i.createAdvancedTab(f)]};};CKEDITOR.dialog.add('table',function(f){return e(f,'table');});CKEDITOR.dialog.add('tableProperties',function(f){return e(f,'tableProperties');});})();\r
+/*
+ Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
+ For licensing, see LICENSE.html or http://ckeditor.com/license
+*/
+(function(){function r(a){for(var f=0,l=0,k=0,m,e=a.$.rows.length;k<e;k++){m=a.$.rows[k];for(var d=f=0,c,b=m.cells.length;d<b;d++)c=m.cells[d],f+=c.colSpan;f>l&&(l=f)}return l}function o(a){return function(){var f=this.getValue(),f=!!(CKEDITOR.dialog.validate.integer()(f)&&0<f);f||(alert(a),this.select());return f}}function n(a,f){var l=function(e){return new CKEDITOR.dom.element(e,a.document)},n=a.editable(),m=a.plugins.dialogadvtab;return{title:a.lang.table.title,minWidth:310,minHeight:CKEDITOR.env.ie?
+310:280,onLoad:function(){var e=this,a=e.getContentElement("advanced","advStyles");if(a)a.on("change",function(){var a=this.getStyle("width",""),b=e.getContentElement("info","txtWidth");b&&b.setValue(a,!0);a=this.getStyle("height","");(b=e.getContentElement("info","txtHeight"))&&b.setValue(a,!0)})},onShow:function(){var e=a.getSelection(),d=e.getRanges(),c,b=this.getContentElement("info","txtRows"),h=this.getContentElement("info","txtCols"),p=this.getContentElement("info","txtWidth"),g=this.getContentElement("info",
+"txtHeight");"tableProperties"==f&&((e=e.getSelectedElement())&&e.is("table")?c=e:0<d.length&&(CKEDITOR.env.webkit&&d[0].shrink(CKEDITOR.NODE_ELEMENT),c=a.elementPath(d[0].getCommonAncestor(!0)).contains("table",1)),this._.selectedElement=c);c?(this.setupContent(c),b&&b.disable(),h&&h.disable()):(b&&b.enable(),h&&h.enable());p&&p.onChange();g&&g.onChange()},onOk:function(){var e=a.getSelection(),d=this._.selectedElement&&e.createBookmarks(),c=this._.selectedElement||l("table"),b={};this.commitContent(b,
+c);if(b.info){b=b.info;if(!this._.selectedElement)for(var h=c.append(l("tbody")),f=parseInt(b.txtRows,10)||0,g=parseInt(b.txtCols,10)||0,i=0;i<f;i++)for(var j=h.append(l("tr")),k=0;k<g;k++){var m=j.append(l("td"));CKEDITOR.env.ie||m.append(l("br"))}f=b.selHeaders;if(!c.$.tHead&&("row"==f||"both"==f)){j=new CKEDITOR.dom.element(c.$.createTHead());h=c.getElementsByTag("tbody").getItem(0);h=h.getElementsByTag("tr").getItem(0);for(i=0;i<h.getChildCount();i++)g=h.getChild(i),g.type==CKEDITOR.NODE_ELEMENT&&
+!g.data("cke-bookmark")&&(g.renameNode("th"),g.setAttribute("scope","col"));j.append(h.remove())}if(null!==c.$.tHead&&!("row"==f||"both"==f)){j=new CKEDITOR.dom.element(c.$.tHead);h=c.getElementsByTag("tbody").getItem(0);for(k=h.getFirst();0<j.getChildCount();){h=j.getFirst();for(i=0;i<h.getChildCount();i++)g=h.getChild(i),g.type==CKEDITOR.NODE_ELEMENT&&(g.renameNode("td"),g.removeAttribute("scope"));h.insertBefore(k)}j.remove()}if(!this.hasColumnHeaders&&("col"==f||"both"==f))for(j=0;j<c.$.rows.length;j++)g=
+new CKEDITOR.dom.element(c.$.rows[j].cells[0]),g.renameNode("th"),g.setAttribute("scope","row");if(this.hasColumnHeaders&&!("col"==f||"both"==f))for(i=0;i<c.$.rows.length;i++)j=new CKEDITOR.dom.element(c.$.rows[i]),"tbody"==j.getParent().getName()&&(g=new CKEDITOR.dom.element(j.$.cells[0]),g.renameNode("td"),g.removeAttribute("scope"));b.txtHeight?c.setStyle("height",b.txtHeight):c.removeStyle("height");b.txtWidth?c.setStyle("width",b.txtWidth):c.removeStyle("width");c.getAttribute("style")||c.removeAttribute("style")}if(this._.selectedElement)try{e.selectBookmarks(d)}catch(n){}else a.insertElement(c),
+setTimeout(function(){var e=new CKEDITOR.dom.element(c.$.rows[0].cells[0]),b=a.createRange();b.moveToPosition(e,CKEDITOR.POSITION_AFTER_START);b.select()},0)},contents:[{id:"info",label:a.lang.table.title,elements:[{type:"hbox",widths:[null,null],styles:["vertical-align:top"],children:[{type:"vbox",padding:0,children:[{type:"text",id:"txtRows","default":3,label:a.lang.table.rows,required:!0,controlStyle:"width:5em",validate:o(a.lang.table.invalidRows),setup:function(e){this.setValue(e.$.rows.length)},
+commit:k},{type:"text",id:"txtCols","default":2,label:a.lang.table.columns,required:!0,controlStyle:"width:5em",validate:o(a.lang.table.invalidCols),setup:function(e){this.setValue(r(e))},commit:k},{type:"html",html:"&nbsp;"},{type:"select",id:"selHeaders","default":"",label:a.lang.table.headers,items:[[a.lang.table.headersNone,""],[a.lang.table.headersRow,"row"],[a.lang.table.headersColumn,"col"],[a.lang.table.headersBoth,"both"]],setup:function(e){var a=this.getDialog();a.hasColumnHeaders=!0;for(var c=
+0;c<e.$.rows.length;c++){var b=e.$.rows[c].cells[0];if(b&&"th"!=b.nodeName.toLowerCase()){a.hasColumnHeaders=!1;break}}null!==e.$.tHead?this.setValue(a.hasColumnHeaders?"both":"row"):this.setValue(a.hasColumnHeaders?"col":"")},commit:k},{type:"text",id:"txtBorder","default":1,label:a.lang.table.border,controlStyle:"width:3em",validate:CKEDITOR.dialog.validate.number(a.lang.table.invalidBorder),setup:function(a){this.setValue(a.getAttribute("border")||"")},commit:function(a,d){this.getValue()?d.setAttribute("border",
+this.getValue()):d.removeAttribute("border")}},{id:"cmbAlign",type:"select","default":"",label:a.lang.common.align,items:[[a.lang.common.notSet,""],[a.lang.common.alignLeft,"left"],[a.lang.common.alignCenter,"center"],[a.lang.common.alignRight,"right"]],setup:function(a){this.setValue(a.getAttribute("align")||"")},commit:function(a,d){this.getValue()?d.setAttribute("align",this.getValue()):d.removeAttribute("align")}}]},{type:"vbox",padding:0,children:[{type:"hbox",widths:["5em"],children:[{type:"text",
+id:"txtWidth",controlStyle:"width:5em",label:a.lang.common.width,title:a.lang.common.cssLengthTooltip,"default":500>n.getSize("width")?"100%":500,getValue:q,validate:CKEDITOR.dialog.validate.cssLength(a.lang.common.invalidCssLength.replace("%1",a.lang.common.width)),onChange:function(){var a=this.getDialog().getContentElement("advanced","advStyles");a&&a.updateStyle("width",this.getValue())},setup:function(a){(a=a.getStyle("width"))&&this.setValue(a)},commit:k}]},{type:"hbox",widths:["5em"],children:[{type:"text",
+id:"txtHeight",controlStyle:"width:5em",label:a.lang.common.height,title:a.lang.common.cssLengthTooltip,"default":"",getValue:q,validate:CKEDITOR.dialog.validate.cssLength(a.lang.common.invalidCssLength.replace("%1",a.lang.common.height)),onChange:function(){var a=this.getDialog().getContentElement("advanced","advStyles");a&&a.updateStyle("height",this.getValue())},setup:function(a){(a=a.getStyle("height"))&&this.setValue(a)},commit:k}]},{type:"html",html:"&nbsp;"},{type:"text",id:"txtCellSpace",
+controlStyle:"width:3em",label:a.lang.table.cellSpace,"default":1,validate:CKEDITOR.dialog.validate.number(a.lang.table.invalidCellSpacing),setup:function(a){this.setValue(a.getAttribute("cellSpacing")||"")},commit:function(a,d){this.getValue()?d.setAttribute("cellSpacing",this.getValue()):d.removeAttribute("cellSpacing")}},{type:"text",id:"txtCellPad",controlStyle:"width:3em",label:a.lang.table.cellPad,"default":1,validate:CKEDITOR.dialog.validate.number(a.lang.table.invalidCellPadding),setup:function(a){this.setValue(a.getAttribute("cellPadding")||
+"")},commit:function(a,d){this.getValue()?d.setAttribute("cellPadding",this.getValue()):d.removeAttribute("cellPadding")}}]}]},{type:"html",align:"right",html:""},{type:"vbox",padding:0,children:[{type:"text",id:"txtCaption",label:a.lang.table.caption,setup:function(a){this.enable();a=a.getElementsByTag("caption");if(0<a.count()){var a=a.getItem(0),d=a.getFirst(CKEDITOR.dom.walker.nodeType(CKEDITOR.NODE_ELEMENT));d&&!d.equals(a.getBogus())?(this.disable(),this.setValue(a.getText())):(a=CKEDITOR.tools.trim(a.getText()),
+this.setValue(a))}},commit:function(e,d){if(this.isEnabled()){var c=this.getValue(),b=d.getElementsByTag("caption");if(c)0<b.count()?(b=b.getItem(0),b.setHtml("")):(b=new CKEDITOR.dom.element("caption",a.document),d.getChildCount()?b.insertBefore(d.getFirst()):b.appendTo(d)),b.append(new CKEDITOR.dom.text(c,a.document));else if(0<b.count())for(c=b.count()-1;0<=c;c--)b.getItem(c).remove()}}},{type:"text",id:"txtSummary",label:a.lang.table.summary,setup:function(a){this.setValue(a.getAttribute("summary")||
+"")},commit:function(a,d){this.getValue()?d.setAttribute("summary",this.getValue()):d.removeAttribute("summary")}}]}]},m&&m.createAdvancedTab(a)]}}var q=CKEDITOR.tools.cssLength,k=function(a){var f=this.id;a.info||(a.info={});a.info[f]=this.getValue()};CKEDITOR.dialog.add("table",function(a){return n(a,"table")});CKEDITOR.dialog.add("tableProperties",function(a){return n(a,"tableProperties")})})();
\ No newline at end of file