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