Bugfix : la localisation des zpt ne fonctionnait plus. « request » était mal initiali...
[ckeditor.git] / skins / ckeditor / _source / plugins / dialogadvtab / plugin.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
5
6 (function()
7 {
8
9 function setupAdvParams( element )
10 {
11 var attrName = this.att;
12
13 var value = element && element.hasAttribute( attrName ) && element.getAttribute( attrName ) || '';
14
15 if ( value !== undefined )
16 this.setValue( value );
17 }
18
19 function commitAdvParams()
20 {
21 // Dialogs may use different parameters in the commit list, so, by
22 // definition, we take the first CKEDITOR.dom.element available.
23 var element;
24
25 for ( var i = 0 ; i < arguments.length ; i++ )
26 {
27 if ( arguments[ i ] instanceof CKEDITOR.dom.element )
28 {
29 element = arguments[ i ];
30 break;
31 }
32 }
33
34 if ( element )
35 {
36 var attrName = this.att,
37 value = this.getValue();
38
39 if ( value )
40 element.setAttribute( attrName, value );
41 else
42 element.removeAttribute( attrName, value );
43 }
44 }
45
46 CKEDITOR.plugins.add( 'dialogadvtab',
47 {
48 /**
49 *
50 * @param tabConfig
51 * id, dir, classes, styles
52 */
53 createAdvancedTab : function( editor, tabConfig )
54 {
55 if ( !tabConfig )
56 tabConfig = { id:1, dir:1, classes:1, styles:1 };
57
58 var lang = editor.lang.common;
59
60 var result =
61 {
62 id : 'advanced',
63 label : lang.advancedTab,
64 title : lang.advancedTab,
65 elements :
66 [
67 {
68 type : 'vbox',
69 padding : 1,
70 children : []
71 }
72 ]
73 };
74
75 var contents = [];
76
77 if ( tabConfig.id || tabConfig.dir )
78 {
79 if ( tabConfig.id )
80 {
81 contents.push(
82 {
83 id : 'advId',
84 att : 'id',
85 type : 'text',
86 label : lang.id,
87 setup : setupAdvParams,
88 commit : commitAdvParams
89 });
90 }
91
92 if ( tabConfig.dir )
93 {
94 contents.push(
95 {
96 id : 'advLangDir',
97 att : 'dir',
98 type : 'select',
99 label : lang.langDir,
100 'default' : '',
101 style : 'width:100%',
102 items :
103 [
104 [ lang.notSet, '' ],
105 [ lang.langDirLTR, 'ltr' ],
106 [ lang.langDirRTL, 'rtl' ]
107 ],
108 setup : setupAdvParams,
109 commit : commitAdvParams
110 });
111 }
112
113 result.elements[ 0 ].children.push(
114 {
115 type : 'hbox',
116 widths : [ '50%', '50%' ],
117 children : [].concat( contents )
118 });
119 }
120
121 if ( tabConfig.styles || tabConfig.classes )
122 {
123 contents = [];
124
125 if ( tabConfig.styles )
126 {
127 contents.push(
128 {
129 id : 'advStyles',
130 att : 'style',
131 type : 'text',
132 label : lang.styles,
133 'default' : '',
134
135 onChange : function(){},
136
137 getStyle : function( name, defaultValue )
138 {
139 var match = this.getValue().match( new RegExp( name + '\\s*:\\s*([^;]*)', 'i') );
140 return match ? match[ 1 ] : defaultValue;
141 },
142
143 updateStyle : function( name, value )
144 {
145 var styles = this.getValue();
146
147 // Remove the current value.
148 if ( styles )
149 {
150 styles = styles
151 .replace( new RegExp( '\\s*' + name + '\s*:[^;]*(?:$|;\s*)', 'i' ), '' )
152 .replace( /^[;\s]+/, '' )
153 .replace( /\s+$/, '' );
154 }
155
156 if ( value )
157 {
158 styles && !(/;\s*$/).test( styles ) && ( styles += '; ' );
159 styles += name + ': ' + value;
160 }
161
162 this.setValue( styles, 1 );
163
164 },
165
166 setup : setupAdvParams,
167
168 commit : commitAdvParams
169
170 });
171 }
172
173 if ( tabConfig.classes )
174 {
175 contents.push(
176 {
177 type : 'hbox',
178 widths : [ '45%', '55%' ],
179 children :
180 [
181 {
182 id : 'advCSSClasses',
183 att : 'class',
184 type : 'text',
185 label : lang.cssClasses,
186 'default' : '',
187 setup : setupAdvParams,
188 commit : commitAdvParams
189
190 }
191 ]
192 });
193 }
194
195 result.elements[ 0 ].children.push(
196 {
197 type : 'hbox',
198 widths : [ '50%', '50%' ],
199 children : [].concat( contents )
200 });
201 }
202
203 return result;
204 }
205 });
206
207 })();