Ticket #10021: fix_ckeditor_table_js.diff

File fix_ckeditor_table_js.diff, 13.8 KB (added by Stephen, 9 years ago)
Line 
1Index: ckeditor/plugins/table/dialogs/table.js
2===================================================================
3@@ -222,6 +222,40 @@
4                                        if ( !table.getAttribute( 'style' ) )
5                                                table.removeAttribute( 'style' );
6                                }
7+                               
8+        //////////////////////////// Patched By Stephen ////////////////////////////
9+
10+                               for ( row = 0; row < table.$.rows.length; row++ ) {
11+                                 for (index = 0, len = table.$.rows[ row ].cells.length; index < len; ++index) {
12+                                         newCell = new CKEDITOR.dom.element( table.$.rows[ row ].cells[ index ] );
13+                                         if(table.getStyle('border-width')){
14+                                           newCell.setStyle('border-width', table.getStyle('border-width'));
15+                                         }
16+                                   else{
17+                                           newCell.removeStyle('border');
18+                                         }             
19+                                   if(table.getAttribute('cellPadding')>0){
20+                                     newCell.setStyle('padding', table.getAttribute('cellPadding')+'px');
21+                                   }
22+                                         else{
23+                                           newCell.removeStyle('padding');
24+                                         }
25+                                         if(table.getStyle('border-color')){
26+                                           newCell.setStyle('border-color', table.getStyle('border-color'));
27+                                         }
28+                                         else{
29+                                           newCell.removeStyle('border-color');
30+                                         }
31+                                         if(table.getStyle('border-style')){
32+                                           newCell.setStyle('border-style', table.getStyle('border-style')); 
33+                                         }
34+                                         else{
35+                                           newCell.removeStyle('border-style');
36+                                         }
37+                                       }
38+                               }
39+        table.removeAttribute('cellPadding');
40+        //////////////////////////// Patched By Stephen ////////////////////////////
41 
42                                // Insert the table element if we're creating one.
43                                if ( !this._.selectedElement ) {
44@@ -331,20 +365,134 @@
45                                                        controlStyle: 'width:3em',
46                                                        validate: CKEDITOR.dialog.validate[ 'number' ]( editor.lang.table.invalidBorder ),
47                                                        setup: function( selectedTable ) {
48-                                                               this.setValue( selectedTable.getAttribute( 'border' ) || '' );
49+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
50+                                                               //this.setValue( selectedTable.getAttribute( 'border' ) || '' );
51+                                                               if(selectedTable.getStyle('border-width')){
52+                                                                 this.setValue(selectedTable.getStyle('border-width').replace('px', ''));
53+                                                               }
54+                                                               else if(selectedTable.getAttribute('border')){
55+                                                                 this.setValue(selectedTable.getAttribute('border'));
56+                                                                 selectedTable.setStyle('border-style', 'solid');
57+                                                               }
58+                                                               else{
59+                                                                 this.setValue('');
60+                                                               }
61+                                                               ////////////////////////////// Patched By Stephen //////////////////////////////////
62                                                        },
63                                                        commit: function( data, selectedTable ) {
64-                                                               if ( this.getValue() )
65-                                                                       selectedTable.setAttribute( 'border', this.getValue() );
66-                                                               else
67-                                                                       selectedTable.removeAttribute( 'border' );
68+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
69+                                                               //if ( this.getValue() ) // removed
70+                                                               //      selectedTable.setAttribute( 'border', this.getValue() ); // removed
71+                                                               //else // removed
72+                                                               //      selectedTable.removeAttribute( 'border' ); // removed
73+                                             if(this.getValue()){
74+                                               if(this.getValue()>0){
75+                                                       selectedTable.setStyle('border-width', this.getValue()+'px');
76+                                               }
77+                                               else{
78+                                                 selectedTable.removeStyle('border');
79+                                               }
80+                                             }
81+                                             else{
82+                                               selectedTable.removeStyle('border');
83+                                             }
84+                                             selectedTable.removeAttribute('border');
85+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
86+                                                       }
87+                                               },
88+
89+
90+
91+              ////////////////////////////// Patched By Stephen //////////////////////////////////
92+                                                       {
93+                                                       id: 'cmbBorderstyle',
94+                                                       type: 'select',
95+                                                       requiredContent: 'table{border-style}',
96+                                                       'default': 'solid',
97+                                                       label: editor.lang.common.borderstyle,
98+                                                       items: [
99+                                                               [ editor.lang.common.notSet, '' ],
100+                                                               [ editor.lang.common.borderstyleNone, 'none' ],
101+                                                               [ editor.lang.common.borderstyleSolid, 'solid' ],
102+                                                               [ editor.lang.common.borderstyleDotted, 'dotted' ],
103+                                                               [ editor.lang.common.borderstyleDashed, 'dashed' ],
104+                                                               [ editor.lang.common.borderstyleHidden, 'hidden' ],
105+                                                               [ editor.lang.common.borderstyleDouble, 'double' ],
106+                                                               [ editor.lang.common.borderstyleGroove, 'groove' ],
107+                                                               [ editor.lang.common.borderstyleRidge, 'ridge' ],
108+                                                               [ editor.lang.common.borderstyleInset, 'inset' ],
109+                                                               [ editor.lang.common.borderstyleOutset, 'outset' ],
110+                                                               [ editor.lang.common.borderstyleInitial, 'initial' ],
111+                                                               [ editor.lang.common.borderstyleInherit, 'inherit' ]
112+                                                               ],
113+                                                       setup: function( selectedTable ) {
114+                                                         if(this.getValue(selectedTable.getStyle('border-style'))){
115+                                                           this.setValue(selectedTable.getStyle('border-style'));
116+                                                         }
117+                                                         //else{
118+                                                         //  this.setValue('solid');
119+                                                         //}
120+                                                       },
121+                                                       commit: function( data, selectedTable ) {
122+                                                         if (this.getValue()){
123+                                                           selectedTable.setStyle('border-style', this.getValue());
124+                                                         }
125+                                                         else {
126+                                                           selectedTable.setStyle('border-style', '');
127+                                                         }
128+                                                       }
129+                                               },
130+                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
131+
132+
133+
134+
135+                                                 ////////////////////////////// Patched By Stephen //////////////////////////////////
136+                                           {
137+                                                       type: 'text',
138+                                                       id: 'txtBordercolor',
139+                                                       requiredContent: 'table',
140+                                                       controlStyle: 'width:6em',
141+                                                       'default': '#cccccc',
142+                                                       label: editor.lang.table.tablebordercolor,
143+                                                       setup: function( selectedTable ) {
144+                                                               if(selectedTable.getStyle('border-color')){
145+                                                                 this.setValue(selectedTable.getStyle('border-color'));
146+                                                               }
147+                                                               else if(selectedTable.getAttribute('bordercolor')){
148+                                                                 this.setValue(selectedTable.getAttribute('bordercolor'));
149+                                                                 selectedTable.removeAttribute('bordercolor');
150+                                                               }
151+                                                               else{
152+                                                                 this.setValue('');
153+                                                               }
154+                                                       },
155+                                                       commit: function( data, selectedTable ) {
156+                                             if(this.getValue()){
157+                                                     selectedTable.setStyle('border-color', this.getValue()); 
158+                                             }
159+                                             else{
160+                                               selectedTable.removeStyle('border-color');
161+                                             }
162                                                        }
163                                                },
164+                                               ////////////////////////////// Patched By Stephen //////////////////////////////////
165+
166+
167+
168+
169+
170+
171+
172+
173                                                        {
174                                                        id: 'cmbAlign',
175                                                        type: 'select',
176                                                        requiredContent: 'table[align]',
177-                                                       'default': '',
178+                                                       ////////////////////////////// Patched By Stephen //////////////////////////////////
179+                                                       //'default': '',
180+                                                       'default': 'center',
181+                                                       ////////////////////////////// Patched By Stephen //////////////////////////////////
182                                                        label: editor.lang.common.align,
183                                                        items: [
184                                                                [ editor.lang.common.notSet, '' ],
185@@ -353,13 +501,52 @@
186                                                                [ editor.lang.common.alignRight, 'right' ]
187                                                                ],
188                                                        setup: function( selectedTable ) {
189-                                                               this.setValue( selectedTable.getAttribute( 'align' ) || '' );
190+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
191+                                                               //this.setValue( selectedTable.getAttribute( 'align' ) || '' );
192+                                                               if(selectedTable.getStyle('float')){
193+                                                                 this.setValue(selectedTable.getStyle('float'));
194+                                                               }
195+                                                               else if(selectedTable.getStyle('margin-left')){
196+                                                                 this.setValue('center');
197+                                                               }
198+                                                               else if(selectedTable.getAttribute('align')){
199+                                                                 this.setValue(selectedTable.getAttribute('align'));
200+                                                               }
201+                                                               else{
202+                                                                 this.setValue('');
203+                                                               }
204+                                                               ////////////////////////////// Patched By Stephen //////////////////////////////////
205                                                        },
206                                                        commit: function( data, selectedTable ) {
207-                                                               if ( this.getValue() )
208-                                                                       selectedTable.setAttribute( 'align', this.getValue() );
209-                                                               else
210-                                                                       selectedTable.removeAttribute( 'align' );
211+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
212+                                                               //if ( this.getValue() )
213+                                                               //      selectedTable.setAttribute( 'align', this.getValue() );
214+                                                               //else
215+                                                               //      selectedTable.removeAttribute( 'align' );
216+                                                               if(this.getValue()){
217+                                                                 if(this.getValue()=='left'){
218+                                                                   selectedTable.setStyle('float', 'left');
219+                                                                   selectedTable.removeStyle('margin-left');
220+                                                                   selectedTable.removeStyle('margin-right');
221+                                                                 }
222+                                                                 else if(this.getValue()=='right'){
223+                                                                   selectedTable.setStyle('float', 'right');
224+                                                                   selectedTable.removeStyle('margin-left');
225+                                                                   selectedTable.removeStyle('margin-right');
226+                                                                 }
227+                                                                 else if(this.getValue()=='center'){
228+                                                                   selectedTable.setStyle('margin-left', 'auto');
229+                                                                   selectedTable.setStyle('margin-right', 'auto');
230+                                                                   selectedTable.removeStyle('float');
231+                                                                 }
232+                                                               }
233+                                                               else{
234+                                                                 selectedTable.removeStyle('margin-left');
235+                                                                 selectedTable.removeStyle('margin-right');
236+                                                                 selectedTable.removeStyle('float');
237+                                                               }
238+                                                               selectedTable.removeAttribute('align');
239+                                                               ////////////////////////////// Patched By Stephen //////////////////////////////////
240                                                        }
241                                                }
242                                                ]
243@@ -432,16 +619,46 @@
244                                                        requiredContent: 'table[cellspacing]',
245                                                        controlStyle: 'width:3em',
246                                                        label: editor.lang.table.cellSpace,
247-                                                       'default': editor.filter.check( 'table[cellspacing]' ) ? 1 : 0,
248+                                                       ////////////////////////////// Patched By Stephen //////////////////////////////////
249+                                                       //'default': editor.filter.check( 'table[cellspacing]' ) ? 1 : 0,
250+                                                       'default': editor.filter.check( 'table[cellspacing]' ) ? 0 : 0,
251+                                                       ////////////////////////////// Patched By Stephen //////////////////////////////////
252                                                        validate: CKEDITOR.dialog.validate.number( editor.lang.table.invalidCellSpacing ),
253                                                        setup: function( selectedTable ) {
254-                                                               this.setValue( selectedTable.getAttribute( 'cellSpacing' ) || '' );
255+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
256+                                                               //this.setValue( selectedTable.getAttribute( 'cellSpacing' ) || '' );
257+                                                               if(selectedTable.getStyle('border-spacing')){
258+                                                                 this.setValue(selectedTable.getStyle('border-spacing').replace('px',''));
259+                                                               }
260+                                                               else if(selectedTable.getAttribute('cellspacing')){
261+                                                                 this.setValue(selectedTable.getAttribute('cellspacing'));
262+                                                               }
263+                                                               else{
264+                                                                 this.setValue(''); 
265+                                                               }
266+                                                               ////////////////////////////// Patched By Stephen //////////////////////////////////
267                                                        },
268                                                        commit: function( data, selectedTable ) {
269-                                                               if ( this.getValue() )
270-                                                                       selectedTable.setAttribute( 'cellSpacing', this.getValue() );
271-                                                               else
272-                                                                       selectedTable.removeAttribute( 'cellSpacing' );
273+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
274+                                                               //if ( this.getValue() )
275+                                                               //      selectedTable.setAttribute( 'cellSpacing', this.getValue() );
276+                                                               //else
277+                                                               //      selectedTable.removeAttribute( 'cellSpacing' );
278+                                                               if(this.getValue()){
279+                                                                 if(this.getValue()>0){
280+                                                                   selectedTable.setStyle('border-collapse', 'separate');
281+                                                                 }
282+                                                                 else{
283+                                                                   selectedTable.setStyle('border-collapse', 'collapse');
284+                                                                 }
285+                                                                 selectedTable.setStyle('border-spacing', this.getValue()+'px');
286+                                                               }
287+                                                               else{
288+                                                                 selectedTable.setStyle('border-collapse', 'collapse');
289+                                                                 selectedTable.removeStyle('border-spacing');
290+                                                               }
291+                                                               selectedTable.removeAttribute('cellSpacing');
292+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
293                                                        }
294                                                },
295                                                        {
296@@ -450,10 +667,42 @@
297                                                        requiredContent: 'table[cellpadding]',
298                                                        controlStyle: 'width:3em',
299                                                        label: editor.lang.table.cellPad,
300-                                                       'default': editor.filter.check( 'table[cellpadding]' ) ? 1 : 0,
301+                                                       ////////////////////////////// Patched By Stephen //////////////////////////////////
302+                                                       //'default': editor.filter.check( 'table[cellpadding]' ) ? 1 : 0,
303+                                                       'default': editor.filter.check( 'table[cellpadding]' ) ? 4 : 0,
304+                                                       ////////////////////////////// Patched By Stephen //////////////////////////////////
305                                                        validate: CKEDITOR.dialog.validate.number( editor.lang.table.invalidCellPadding ),
306                                                        setup: function( selectedTable ) {
307-                                                               this.setValue( selectedTable.getAttribute( 'cellPadding' ) || '' );
308+                                                         ////////////////////////////// Patched By Stephen //////////////////////////////////
309+                                             if(selectedTable.getAttribute('cellpadding')){
310+                                               this.setValue(selectedTable.getAttribute('cellpadding'));
311+                                             }
312+                                             else if(selectedTable.getElementsByTag('tbody').getItem(0)){
313+                                               var cellpadding=0;
314+                                                                 var tbody = selectedTable.getElementsByTag('tbody').getItem(0);
315+                                                                 var theRow = tbody.getElementsByTag('tr').getItem(0);
316+                                                                 var td = theRow.getChild(0);
317+                                                                 if(td.getStyle('padding')){
318+                                                                   this.setValue(td.getStyle('padding').replace('px',''));
319+                                                                 }
320+                                                                 else{
321+                                                                   if(selectedTable.getElementsByTag('thead').getItem(0)){
322+                                                                     var thead = selectedTable.getElementsByTag('thead').getItem(0);
323+                                                                     var thead = tbody.getElementsByTag('tr').getItem(0);
324+                                                                     var th = theRow.getChild(0);
325+                                                                     if(th.getStyle('padding')){
326+                                                                       this.setValue(th.getStyle('padding').replace('px',''));
327+                                                                     }
328+                                                                     else{
329+                                                                       this.setValue('');
330+                                                                     }
331+                                                                   }
332+                                                                   else{
333+                                                                     this.setValue('');
334+                                                                   }
335+                                                                 }
336+                                                               }
337+                                                               ////////////////////////////// Patched By Stephen //////////////////////////////////
338                                                        },
339                                                        commit: function( data, selectedTable ) {
340                                                                if ( this.getValue() )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy