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