JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / iframe / dialogs / iframe.js
1 /*\r
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 (function()\r
7 {\r
8         // Map 'true' and 'false' values to match W3C's specifications\r
9         // http://www.w3.org/TR/REC-html40/present/frames.html#h-16.5\r
10         var checkboxValues =\r
11         {\r
12                 scrolling : { 'true' : 'yes', 'false' : 'no' },\r
13                 frameborder : { 'true' : '1', 'false' : '0' }\r
14         };\r
15 \r
16         function loadValue( iframeNode )\r
17         {\r
18                 var isCheckbox = this instanceof CKEDITOR.ui.dialog.checkbox;\r
19                 if ( iframeNode.hasAttribute( this.id ) )\r
20                 {\r
21                         var value = iframeNode.getAttribute( this.id );\r
22                         if ( isCheckbox )\r
23                                 this.setValue( checkboxValues[ this.id ][ 'true' ] == value.toLowerCase() );\r
24                         else\r
25                                 this.setValue( value );\r
26                 }\r
27         }\r
28 \r
29         function commitValue( iframeNode )\r
30         {\r
31                 var isRemove = this.getValue() === '',\r
32                         isCheckbox = this instanceof CKEDITOR.ui.dialog.checkbox,\r
33                         value = this.getValue();\r
34                 if ( isRemove )\r
35                         iframeNode.removeAttribute( this.att || this.id );\r
36                 else if ( isCheckbox )\r
37                         iframeNode.setAttribute( this.id, checkboxValues[ this.id ][ value ] );\r
38                 else\r
39                         iframeNode.setAttribute( this.att || this.id, value );\r
40         }\r
41 \r
42         CKEDITOR.dialog.add( 'iframe', function( editor )\r
43         {\r
44                 var iframeLang = editor.lang.iframe,\r
45                         commonLang = editor.lang.common,\r
46                         dialogadvtab = editor.plugins.dialogadvtab;\r
47                 return {\r
48                         title : iframeLang.title,\r
49                         minWidth : 350,\r
50                         minHeight : 260,\r
51                         onShow : function()\r
52                         {\r
53                                 // Clear previously saved elements.\r
54                                 this.fakeImage = this.iframeNode = null;\r
55 \r
56                                 var fakeImage = this.getSelectedElement();\r
57                                 if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'iframe' )\r
58                                 {\r
59                                         this.fakeImage = fakeImage;\r
60 \r
61                                         var iframeNode = editor.restoreRealElement( fakeImage );\r
62                                         this.iframeNode = iframeNode;\r
63 \r
64                                         this.setupContent( iframeNode );\r
65                                 }\r
66                         },\r
67                         onOk : function()\r
68                         {\r
69                                 var iframeNode;\r
70                                 if ( !this.fakeImage )\r
71                                         iframeNode = new CKEDITOR.dom.element( 'iframe' );\r
72                                 else\r
73                                         iframeNode = this.iframeNode;\r
74 \r
75                                 // A subset of the specified attributes/styles\r
76                                 // should also be applied on the fake element to\r
77                                 // have better visual effect. (#5240)\r
78                                 var extraStyles = {}, extraAttributes = {};\r
79                                 this.commitContent( iframeNode, extraStyles, extraAttributes );\r
80 \r
81                                 // Refresh the fake image.\r
82                                 var newFakeImage = editor.createFakeElement( iframeNode, 'cke_iframe', 'iframe', true );\r
83                                 newFakeImage.setAttributes( extraAttributes );\r
84                                 newFakeImage.setStyles( extraStyles );\r
85                                 if ( this.fakeImage )\r
86                                 {\r
87                                         newFakeImage.replace( this.fakeImage );\r
88                                         editor.getSelection().selectElement( newFakeImage );\r
89                                 }\r
90                                 else\r
91                                         editor.insertElement( newFakeImage );\r
92                         },\r
93                         contents : [\r
94                                 {\r
95                                         id : 'info',\r
96                                         label : commonLang.generalTab,\r
97                                         accessKey : 'I',\r
98                                         elements :\r
99                                         [\r
100                                                 {\r
101                                                         type : 'vbox',\r
102                                                         padding : 0,\r
103                                                         children :\r
104                                                         [\r
105                                                                 {\r
106                                                                         id : 'src',\r
107                                                                         type : 'text',\r
108                                                                         label : commonLang.url,\r
109                                                                         required : true,\r
110                                                                         validate : CKEDITOR.dialog.validate.notEmpty( iframeLang.noUrl ),\r
111                                                                         setup : loadValue,\r
112                                                                         commit : commitValue\r
113                                                                 }\r
114                                                         ]\r
115                                                 },\r
116                                                 {\r
117                                                         type : 'hbox',\r
118                                                         children :\r
119                                                         [\r
120                                                                 {\r
121                                                                         id : 'width',\r
122                                                                         type : 'text',\r
123                                                                         style : 'width:100%',\r
124                                                                         labelLayout : 'vertical',\r
125                                                                         label : commonLang.width,\r
126                                                                         validate : CKEDITOR.dialog.validate.htmlLength( commonLang.invalidHtmlLength.replace( '%1', commonLang.width ) ),\r
127                                                                         setup : loadValue,\r
128                                                                         commit : commitValue\r
129                                                                 },\r
130                                                                 {\r
131                                                                         id : 'height',\r
132                                                                         type : 'text',\r
133                                                                         style : 'width:100%',\r
134                                                                         labelLayout : 'vertical',\r
135                                                                         label : commonLang.height,\r
136                                                                         validate : CKEDITOR.dialog.validate.htmlLength( commonLang.invalidHtmlLength.replace( '%1', commonLang.height ) ),\r
137                                                                         setup : loadValue,\r
138                                                                         commit : commitValue\r
139                                                                 },\r
140                                                                 {\r
141                                                                         id : 'align',\r
142                                                                         type : 'select',\r
143                                                                         'default' : '',\r
144                                                                         items :\r
145                                                                         [\r
146                                                                                 [ commonLang.notSet , '' ],\r
147                                                                                 [ commonLang.alignLeft , 'left' ],\r
148                                                                                 [ commonLang.alignRight , 'right' ],\r
149                                                                                 [ commonLang.alignTop , 'top' ],\r
150                                                                                 [ commonLang.alignMiddle , 'middle' ],\r
151                                                                                 [ commonLang.alignBottom , 'bottom' ]\r
152                                                                         ],\r
153                                                                         style : 'width:100%',\r
154                                                                         labelLayout : 'vertical',\r
155                                                                         label : commonLang.align,\r
156                                                                         setup : function( iframeNode, fakeImage )\r
157                                                                         {\r
158                                                                                 loadValue.apply( this, arguments );\r
159                                                                                 if ( fakeImage )\r
160                                                                                 {\r
161                                                                                         var fakeImageAlign = fakeImage.getAttribute( 'align' );\r
162                                                                                         this.setValue( fakeImageAlign && fakeImageAlign.toLowerCase() || '' );\r
163                                                                                 }\r
164                                                                         },\r
165                                                                         commit : function( iframeNode, extraStyles, extraAttributes )\r
166                                                                         {\r
167                                                                                 commitValue.apply( this, arguments );\r
168                                                                                 if ( this.getValue() )\r
169                                                                                         extraAttributes.align = this.getValue();\r
170                                                                         }\r
171                                                                 }\r
172                                                         ]\r
173                                                 },\r
174                                                 {\r
175                                                         type : 'hbox',\r
176                                                         widths : [ '50%', '50%' ],\r
177                                                         children :\r
178                                                         [\r
179                                                                 {\r
180                                                                         id : 'scrolling',\r
181                                                                         type : 'checkbox',\r
182                                                                         label : iframeLang.scrolling,\r
183                                                                         setup : loadValue,\r
184                                                                         commit : commitValue\r
185                                                                 },\r
186                                                                 {\r
187                                                                         id : 'frameborder',\r
188                                                                         type : 'checkbox',\r
189                                                                         label : iframeLang.border,\r
190                                                                         setup : loadValue,\r
191                                                                         commit : commitValue\r
192                                                                 }\r
193                                                         ]\r
194                                                 },\r
195                                                 {\r
196                                                         type : 'hbox',\r
197                                                         widths : [ '50%', '50%' ],\r
198                                                         children :\r
199                                                         [\r
200                                                                 {\r
201                                                                         id : 'name',\r
202                                                                         type : 'text',\r
203                                                                         label : commonLang.name,\r
204                                                                         setup : loadValue,\r
205                                                                         commit : commitValue\r
206                                                                 },\r
207                                                                 {\r
208                                                                         id : 'title',\r
209                                                                         type : 'text',\r
210                                                                         label : commonLang.advisoryTitle,\r
211                                                                         setup : loadValue,\r
212                                                                         commit : commitValue\r
213                                                                 }\r
214                                                         ]\r
215                                                 },\r
216                                                 {\r
217                                                         id : 'longdesc',\r
218                                                         type : 'text',\r
219                                                         label : commonLang.longDescr,\r
220                                                         setup : loadValue,\r
221                                                         commit : commitValue\r
222                                                 }\r
223                                         ]\r
224                                 },\r
225                                 dialogadvtab && dialogadvtab.createAdvancedTab( editor, { id:1, classes:1, styles:1 })\r
226                         ]\r
227                 };\r
228         });\r
229 })();\r