]> git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blame - sources/plugins/dialog/plugin.js
Update to 4.7.3
[perso/Immae/Projets/packagist/ludivine-ckeditor-component.git] / sources / plugins / dialog / plugin.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/**\r
7 * @fileOverview The floating dialog plugin.\r
8 */\r
9\r
10/**\r
11 * No resize for this dialog.\r
12 *\r
13 * @readonly\r
14 * @property {Number} [=0]\r
15 * @member CKEDITOR\r
16 */\r
17CKEDITOR.DIALOG_RESIZE_NONE = 0;\r
18\r
19/**\r
20 * Only allow horizontal resizing for this dialog, disable vertical resizing.\r
21 *\r
22 * @readonly\r
23 * @property {Number} [=1]\r
24 * @member CKEDITOR\r
25 */\r
26CKEDITOR.DIALOG_RESIZE_WIDTH = 1;\r
27\r
28/**\r
29 * Only allow vertical resizing for this dialog, disable horizontal resizing.\r
30 *\r
31 * @readonly\r
32 * @property {Number} [=2]\r
33 * @member CKEDITOR\r
34 */\r
35CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;\r
36\r
37/**\r
38 * Allow the dialog to be resized in both directions.\r
39 *\r
40 * @readonly\r
41 * @property {Number} [=3]\r
42 * @member CKEDITOR\r
43 */\r
44CKEDITOR.DIALOG_RESIZE_BOTH = 3;\r
45\r
46/**\r
47 * Dialog state when idle.\r
48 *\r
49 * @readonly\r
50 * @property {Number} [=1]\r
51 * @member CKEDITOR\r
52 */\r
53CKEDITOR.DIALOG_STATE_IDLE = 1;\r
54\r
55/**\r
56 * Dialog state when busy.\r
57 *\r
58 * @readonly\r
59 * @property {Number} [=2]\r
60 * @member CKEDITOR\r
61 */\r
62CKEDITOR.DIALOG_STATE_BUSY = 2;\r
63\r
64( function() {\r
65 var cssLength = CKEDITOR.tools.cssLength;\r
66\r
67 function isTabVisible( tabId ) {\r
68 return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;\r
69 }\r
70\r
71 function getPreviousVisibleTab() {\r
72 var tabId = this._.currentTabId,\r
73 length = this._.tabIdList.length,\r
74 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;\r
75\r
76 for ( var i = tabIndex - 1; i > tabIndex - length; i-- ) {\r
77 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )\r
78 return this._.tabIdList[ i % length ];\r
79 }\r
80\r
81 return null;\r
82 }\r
83\r
84 function getNextVisibleTab() {\r
85 var tabId = this._.currentTabId,\r
86 length = this._.tabIdList.length,\r
87 tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );\r
88\r
89 for ( var i = tabIndex + 1; i < tabIndex + length; i++ ) {\r
90 if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )\r
91 return this._.tabIdList[ i % length ];\r
92 }\r
93\r
94 return null;\r
95 }\r
96\r
97\r
98 function clearOrRecoverTextInputValue( container, isRecover ) {\r
99 var inputs = container.$.getElementsByTagName( 'input' );\r
100 for ( var i = 0, length = inputs.length; i < length; i++ ) {\r
101 var item = new CKEDITOR.dom.element( inputs[ i ] );\r
102\r
103 if ( item.getAttribute( 'type' ).toLowerCase() == 'text' ) {\r
104 if ( isRecover ) {\r
105 item.setAttribute( 'value', item.getCustomData( 'fake_value' ) || '' );\r
106 item.removeCustomData( 'fake_value' );\r
107 } else {\r
108 item.setCustomData( 'fake_value', item.getAttribute( 'value' ) );\r
109 item.setAttribute( 'value', '' );\r
110 }\r
111 }\r
112 }\r
113 }\r
114\r
115 // Handle dialog element validation state UI changes.\r
116 function handleFieldValidated( isValid, msg ) {\r
117 var input = this.getInputElement();\r
118 if ( input )\r
119 isValid ? input.removeAttribute( 'aria-invalid' ) : input.setAttribute( 'aria-invalid', true );\r
120\r
121 if ( !isValid ) {\r
122 if ( this.select )\r
123 this.select();\r
124 else\r
125 this.focus();\r
126 }\r
127\r
128 msg && alert( msg ); // jshint ignore:line\r
129\r
130 this.fire( 'validated', { valid: isValid, msg: msg } );\r
131 }\r
132\r
133 function resetField() {\r
134 var input = this.getInputElement();\r
135 input && input.removeAttribute( 'aria-invalid' );\r
136 }\r
137\r
138 var templateSource = '<div class="cke_reset_all {editorId} {editorDialogClass} {hidpi}' +\r
139 '" dir="{langDir}"' +\r
140 ' lang="{langCode}"' +\r
141 ' role="dialog"' +\r
142 ' aria-labelledby="cke_dialog_title_{id}"' +\r
143 '>' +\r
144 '<table class="cke_dialog ' + CKEDITOR.env.cssClass + ' cke_{langDir}"' +\r
145 ' style="position:absolute" role="presentation">' +\r
146 '<tr><td role="presentation">' +\r
147 '<div class="cke_dialog_body" role="presentation">' +\r
148 '<div id="cke_dialog_title_{id}" class="cke_dialog_title" role="presentation"></div>' +\r
149 '<a id="cke_dialog_close_button_{id}" class="cke_dialog_close_button" href="javascript:void(0)" title="{closeTitle}" role="button"><span class="cke_label">X</span></a>' +\r
150 '<div id="cke_dialog_tabs_{id}" class="cke_dialog_tabs" role="tablist"></div>' +\r
151 '<table class="cke_dialog_contents" role="presentation">' +\r
152 '<tr>' +\r
153 '<td id="cke_dialog_contents_{id}" class="cke_dialog_contents_body" role="presentation"></td>' +\r
154 '</tr>' +\r
155 '<tr>' +\r
156 '<td id="cke_dialog_footer_{id}" class="cke_dialog_footer" role="presentation"></td>' +\r
157 '</tr>' +\r
158 '</table>' +\r
159 '</div>' +\r
160 '</td></tr>' +\r
161 '</table>' +\r
162 '</div>';\r
163\r
164 function buildDialog( editor ) {\r
165 var element = CKEDITOR.dom.element.createFromHtml( CKEDITOR.addTemplate( 'dialog', templateSource ).output( {\r
166 id: CKEDITOR.tools.getNextNumber(),\r
167 editorId: editor.id,\r
168 langDir: editor.lang.dir,\r
169 langCode: editor.langCode,\r
170 editorDialogClass: 'cke_editor_' + editor.name.replace( /\./g, '\\.' ) + '_dialog',\r
171 closeTitle: editor.lang.common.close,\r
172 hidpi: CKEDITOR.env.hidpi ? 'cke_hidpi' : ''\r
173 } ) );\r
174\r
175 // TODO: Change this to getById(), so it'll support custom templates.\r
176 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),\r
177 title = body.getChild( 0 ),\r
178 close = body.getChild( 1 );\r
179\r
1794320d 180 // Don't allow dragging on dialog (http://dev.ckeditor.com/ticket/13184).\r
c63493c8
IB
181 editor.plugins.clipboard && CKEDITOR.plugins.clipboard.preventDefaultDropOnElement( body );\r
182\r
1794320d 183 // IFrame shim for dialog that masks activeX in IE. (http://dev.ckeditor.com/ticket/7619)\r
c63493c8
IB
184 if ( CKEDITOR.env.ie && !CKEDITOR.env.quirks && !CKEDITOR.env.edge ) {\r
185 var src = 'javascript:void(function(){' + encodeURIComponent( 'document.open();(' + CKEDITOR.tools.fixDomain + ')();document.close();' ) + '}())', // jshint ignore:line\r
186 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +\r
187 ' frameBorder="0"' +\r
188 ' class="cke_iframe_shim"' +\r
189 ' src="' + src + '"' +\r
190 ' tabIndex="-1"' +\r
191 '></iframe>' );\r
192 iframe.appendTo( body.getParent() );\r
193 }\r
194\r
195 // Make the Title and Close Button unselectable.\r
196 title.unselectable();\r
197 close.unselectable();\r
198\r
199 return {\r
200 element: element,\r
201 parts: {\r
202 dialog: element.getChild( 0 ),\r
203 title: title,\r
204 close: close,\r
205 tabs: body.getChild( 2 ),\r
206 contents: body.getChild( [ 3, 0, 0, 0 ] ),\r
207 footer: body.getChild( [ 3, 0, 1, 0 ] )\r
208 }\r
209 };\r
210 }\r
211\r
212 /**\r
213 * This is the base class for runtime dialog objects. An instance of this\r
214 * class represents a single named dialog for a single editor instance.\r
215 *\r
216 * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );\r
217 *\r
218 * @class\r
219 * @constructor Creates a dialog class instance.\r
220 * @param {Object} editor The editor which created the dialog.\r
221 * @param {String} dialogName The dialog's registered name.\r
222 */\r
223 CKEDITOR.dialog = function( editor, dialogName ) {\r
224 // Load the dialog definition.\r
225 var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],\r
226 defaultDefinition = CKEDITOR.tools.clone( defaultDialogDefinition ),\r
227 buttonsOrder = editor.config.dialog_buttonsOrder || 'OS',\r
228 dir = editor.lang.dir,\r
229 tabsToRemove = {},\r
230 i, processed, stopPropagation;\r
231\r
1794320d 232 if ( ( buttonsOrder == 'OS' && CKEDITOR.env.mac ) || // The buttons in MacOS Apps are in reverse order (http://dev.ckeditor.com/ticket/4750)\r
c63493c8
IB
233 ( buttonsOrder == 'rtl' && dir == 'ltr' ) || ( buttonsOrder == 'ltr' && dir == 'rtl' ) )\r
234 defaultDefinition.buttons.reverse();\r
235\r
236\r
237 // Completes the definition with the default values.\r
238 definition = CKEDITOR.tools.extend( definition( editor ), defaultDefinition );\r
239\r
240 // Clone a functionally independent copy for this dialog.\r
241 definition = CKEDITOR.tools.clone( definition );\r
242\r
243 // Create a complex definition object, extending it with the API\r
244 // functions.\r
245 definition = new definitionObject( this, definition );\r
246\r
247 var themeBuilt = buildDialog( editor );\r
248\r
249 // Initialize some basic parameters.\r
250 this._ = {\r
251 editor: editor,\r
252 element: themeBuilt.element,\r
253 name: dialogName,\r
254 contentSize: { width: 0, height: 0 },\r
255 size: { width: 0, height: 0 },\r
256 contents: {},\r
257 buttons: {},\r
258 accessKeyMap: {},\r
259\r
260 // Initialize the tab and page map.\r
261 tabs: {},\r
262 tabIdList: [],\r
263 currentTabId: null,\r
264 currentTabIndex: null,\r
265 pageCount: 0,\r
266 lastTab: null,\r
267 tabBarMode: false,\r
268\r
269 // Initialize the tab order array for input widgets.\r
270 focusList: [],\r
271 currentFocusIndex: 0,\r
272 hasFocus: false\r
273 };\r
274\r
275 this.parts = themeBuilt.parts;\r
276\r
277 CKEDITOR.tools.setTimeout( function() {\r
278 editor.fire( 'ariaWidget', this.parts.contents );\r
279 }, 0, this );\r
280\r
281 // Set the startup styles for the dialog, avoiding it enlarging the\r
282 // page size on the dialog creation.\r
283 var startStyles = {\r
284 position: CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',\r
285 top: 0,\r
286 visibility: 'hidden'\r
287 };\r
288\r
289 startStyles[ dir == 'rtl' ? 'right' : 'left' ] = 0;\r
290 this.parts.dialog.setStyles( startStyles );\r
291\r
292\r
293 // Call the CKEDITOR.event constructor to initialize this instance.\r
294 CKEDITOR.event.call( this );\r
295\r
296 // Fire the "dialogDefinition" event, making it possible to customize\r
297 // the dialog definition.\r
298 this.definition = definition = CKEDITOR.fire( 'dialogDefinition', {\r
299 name: dialogName,\r
300 definition: definition\r
301 }, editor ).definition;\r
302\r
303 // Cache tabs that should be removed.\r
304 if ( !( 'removeDialogTabs' in editor._ ) && editor.config.removeDialogTabs ) {\r
305 var removeContents = editor.config.removeDialogTabs.split( ';' );\r
306\r
307 for ( i = 0; i < removeContents.length; i++ ) {\r
308 var parts = removeContents[ i ].split( ':' );\r
309 if ( parts.length == 2 ) {\r
310 var removeDialogName = parts[ 0 ];\r
311 if ( !tabsToRemove[ removeDialogName ] )\r
312 tabsToRemove[ removeDialogName ] = [];\r
313 tabsToRemove[ removeDialogName ].push( parts[ 1 ] );\r
314 }\r
315 }\r
316 editor._.removeDialogTabs = tabsToRemove;\r
317 }\r
318\r
319 // Remove tabs of this dialog.\r
320 if ( editor._.removeDialogTabs && ( tabsToRemove = editor._.removeDialogTabs[ dialogName ] ) ) {\r
321 for ( i = 0; i < tabsToRemove.length; i++ )\r
322 definition.removeContents( tabsToRemove[ i ] );\r
323 }\r
324\r
325 // Initialize load, show, hide, ok and cancel events.\r
326 if ( definition.onLoad )\r
327 this.on( 'load', definition.onLoad );\r
328\r
329 if ( definition.onShow )\r
330 this.on( 'show', definition.onShow );\r
331\r
332 if ( definition.onHide )\r
333 this.on( 'hide', definition.onHide );\r
334\r
335 if ( definition.onOk ) {\r
336 this.on( 'ok', function( evt ) {\r
1794320d 337 // Dialog confirm might probably introduce content changes (http://dev.ckeditor.com/ticket/5415).\r
c63493c8
IB
338 editor.fire( 'saveSnapshot' );\r
339 setTimeout( function() {\r
340 editor.fire( 'saveSnapshot' );\r
341 }, 0 );\r
342 if ( definition.onOk.call( this, evt ) === false )\r
343 evt.data.hide = false;\r
344 } );\r
345 }\r
346\r
347 // Set default dialog state.\r
348 this.state = CKEDITOR.DIALOG_STATE_IDLE;\r
349\r
350 if ( definition.onCancel ) {\r
351 this.on( 'cancel', function( evt ) {\r
352 if ( definition.onCancel.call( this, evt ) === false )\r
353 evt.data.hide = false;\r
354 } );\r
355 }\r
356\r
357 var me = this;\r
358\r
359 // Iterates over all items inside all content in the dialog, calling a\r
360 // function for each of them.\r
361 var iterContents = function( func ) {\r
362 var contents = me._.contents,\r
363 stop = false;\r
364\r
365 for ( var i in contents ) {\r
366 for ( var j in contents[ i ] ) {\r
367 stop = func.call( this, contents[ i ][ j ] );\r
368 if ( stop )\r
369 return;\r
370 }\r
371 }\r
372 };\r
373\r
374 this.on( 'ok', function( evt ) {\r
375 iterContents( function( item ) {\r
376 if ( item.validate ) {\r
377 var retval = item.validate( this ),\r
378 invalid = ( typeof retval == 'string' ) || retval === false;\r
379\r
380 if ( invalid ) {\r
381 evt.data.hide = false;\r
382 evt.stop();\r
383 }\r
384\r
385 handleFieldValidated.call( item, !invalid, typeof retval == 'string' ? retval : undefined );\r
386 return invalid;\r
387 }\r
388 } );\r
389 }, this, null, 0 );\r
390\r
391 this.on( 'cancel', function( evt ) {\r
392 iterContents( function( item ) {\r
393 if ( item.isChanged() ) {\r
394 if ( !editor.config.dialog_noConfirmCancel && !confirm( editor.lang.common.confirmCancel ) ) // jshint ignore:line\r
395 evt.data.hide = false;\r
396 return true;\r
397 }\r
398 } );\r
399 }, this, null, 0 );\r
400\r
401 this.parts.close.on( 'click', function( evt ) {\r
402 if ( this.fire( 'cancel', { hide: true } ).hide !== false )\r
403 this.hide();\r
404 evt.data.preventDefault();\r
405 }, this );\r
406\r
407 // Sort focus list according to tab order definitions.\r
408 function setupFocus() {\r
409 var focusList = me._.focusList;\r
410 focusList.sort( function( a, b ) {\r
411 // Mimics browser tab order logics;\r
412 if ( a.tabIndex != b.tabIndex )\r
413 return b.tabIndex - a.tabIndex;\r
414 // Sort is not stable in some browsers,\r
415 // fall-back the comparator to 'focusIndex';\r
416 else\r
417 return a.focusIndex - b.focusIndex;\r
418 } );\r
419\r
420 var size = focusList.length;\r
421 for ( var i = 0; i < size; i++ )\r
422 focusList[ i ].focusIndex = i;\r
423 }\r
424\r
425 // Expects 1 or -1 as an offset, meaning direction of the offset change.\r
426 function changeFocus( offset ) {\r
427 var focusList = me._.focusList;\r
428 offset = offset || 0;\r
429\r
430 if ( focusList.length < 1 )\r
431 return;\r
432\r
433 var startIndex = me._.currentFocusIndex;\r
434\r
435 if ( me._.tabBarMode && offset < 0 ) {\r
436 // If we are in tab mode, we need to mimic that we started tabbing back from the first\r
437 // focusList (so it will go to the last one).\r
438 startIndex = 0;\r
439 }\r
440\r
441 // Trigger the 'blur' event of any input element before anything,\r
442 // since certain UI updates may depend on it.\r
443 try {\r
444 focusList[ startIndex ].getInputElement().$.blur();\r
445 } catch ( e ) {}\r
446\r
447 var currentIndex = startIndex,\r
448 hasTabs = me._.pageCount > 1;\r
449\r
450 do {\r
451 currentIndex = currentIndex + offset;\r
452\r
453 if ( hasTabs && !me._.tabBarMode && ( currentIndex == focusList.length || currentIndex == -1 ) ) {\r
1794320d 454 // If the dialog was not in tab mode, then focus the first tab (http://dev.ckeditor.com/ticket/13027).\r
c63493c8
IB
455 me._.tabBarMode = true;\r
456 me._.tabs[ me._.currentTabId ][ 0 ].focus();\r
457 me._.currentFocusIndex = -1;\r
458\r
459 // Early return, in order to avoid accessing focusList[ -1 ].\r
460 return;\r
461 }\r
462\r
463 currentIndex = ( currentIndex + focusList.length ) % focusList.length;\r
464\r
465 if ( currentIndex == startIndex ) {\r
466 break;\r
467 }\r
468 } while ( offset && !focusList[ currentIndex ].isFocusable() );\r
469\r
470 focusList[ currentIndex ].focus();\r
471\r
472 // Select whole field content.\r
473 if ( focusList[ currentIndex ].type == 'text' )\r
474 focusList[ currentIndex ].select();\r
475 }\r
476\r
477 this.changeFocus = changeFocus;\r
478\r
479\r
480 function keydownHandler( evt ) {\r
481 // If I'm not the top dialog, ignore.\r
482 if ( me != CKEDITOR.dialog._.currentTop )\r
483 return;\r
484\r
485 var keystroke = evt.data.getKeystroke(),\r
486 rtl = editor.lang.dir == 'rtl',\r
487 arrowKeys = [ 37, 38, 39, 40 ],\r
488 button;\r
489\r
490 processed = stopPropagation = 0;\r
491\r
492 if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 ) {\r
493 var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );\r
494 changeFocus( shiftPressed ? -1 : 1 );\r
495 processed = 1;\r
496 } else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 ) {\r
497 // Alt-F10 puts focus into the current tab item in the tab bar.\r
498 me._.tabBarMode = true;\r
499 me._.tabs[ me._.currentTabId ][ 0 ].focus();\r
500 me._.currentFocusIndex = -1;\r
501 processed = 1;\r
502 } else if ( CKEDITOR.tools.indexOf( arrowKeys, keystroke ) != -1 && me._.tabBarMode ) {\r
503 // Array with key codes that activate previous tab.\r
504 var prevKeyCodes = [\r
505 // Depending on the lang dir: right or left key\r
506 rtl ? 39 : 37,\r
507 // Top/bot arrow: actually for both cases it's the same.\r
508 38\r
509 ],\r
510 nextId = CKEDITOR.tools.indexOf( prevKeyCodes, keystroke ) != -1 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );\r
511\r
512 me.selectPage( nextId );\r
513 me._.tabs[ nextId ][ 0 ].focus();\r
514 processed = 1;\r
515 } else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode ) {\r
516 this.selectPage( this._.currentTabId );\r
517 this._.tabBarMode = false;\r
518 this._.currentFocusIndex = -1;\r
519 changeFocus( 1 );\r
520 processed = 1;\r
521 }\r
522 // If user presses enter key in a text box, it implies clicking OK for the dialog.\r
523 else if ( keystroke == 13 /*ENTER*/ ) {\r
524 // Don't do that for a target that handles ENTER.\r
525 var target = evt.data.getTarget();\r
526 if ( !target.is( 'a', 'button', 'select', 'textarea' ) && ( !target.is( 'input' ) || target.$.type != 'button' ) ) {\r
527 button = this.getButton( 'ok' );\r
528 button && CKEDITOR.tools.setTimeout( button.click, 0, button );\r
529 processed = 1;\r
530 }\r
1794320d 531 stopPropagation = 1; // Always block the propagation (http://dev.ckeditor.com/ticket/4269)\r
c63493c8
IB
532 } else if ( keystroke == 27 /*ESC*/ ) {\r
533 button = this.getButton( 'cancel' );\r
534\r
535 // If there's a Cancel button, click it, else just fire the cancel event and hide the dialog.\r
536 if ( button )\r
537 CKEDITOR.tools.setTimeout( button.click, 0, button );\r
538 else {\r
539 if ( this.fire( 'cancel', { hide: true } ).hide !== false )\r
540 this.hide();\r
541 }\r
1794320d 542 stopPropagation = 1; // Always block the propagation (http://dev.ckeditor.com/ticket/4269)\r
c63493c8
IB
543 } else {\r
544 return;\r
545 }\r
546\r
547 keypressHandler( evt );\r
548 }\r
549\r
550 function keypressHandler( evt ) {\r
551 if ( processed )\r
552 evt.data.preventDefault( 1 );\r
553 else if ( stopPropagation )\r
554 evt.data.stopPropagation();\r
555 }\r
556\r
557 var dialogElement = this._.element;\r
558\r
559 editor.focusManager.add( dialogElement, 1 );\r
560\r
561 // Add the dialog keyboard handlers.\r
562 this.on( 'show', function() {\r
563 dialogElement.on( 'keydown', keydownHandler, this );\r
564\r
565 // Some browsers instead, don't cancel key events in the keydown, but in the\r
1794320d 566 // keypress. So we must do a longer trip in those cases. (http://dev.ckeditor.com/ticket/4531,http://dev.ckeditor.com/ticket/8985)\r
c63493c8
IB
567 if ( CKEDITOR.env.gecko )\r
568 dialogElement.on( 'keypress', keypressHandler, this );\r
569\r
570 } );\r
571 this.on( 'hide', function() {\r
572 dialogElement.removeListener( 'keydown', keydownHandler );\r
573 if ( CKEDITOR.env.gecko )\r
574 dialogElement.removeListener( 'keypress', keypressHandler );\r
575\r
576 // Reset fields state when closing dialog.\r
577 iterContents( function( item ) {\r
578 resetField.apply( item );\r
579 } );\r
580 } );\r
581 this.on( 'iframeAdded', function( evt ) {\r
582 var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );\r
583 doc.on( 'keydown', keydownHandler, this, null, 0 );\r
584 } );\r
585\r
586 // Auto-focus logic in dialog.\r
587 this.on( 'show', function() {\r
588 // Setup tabIndex on showing the dialog instead of on loading\r
589 // to allow dynamic tab order happen in dialog definition.\r
590 setupFocus();\r
591\r
592 var hasTabs = me._.pageCount > 1;\r
593\r
594 if ( editor.config.dialog_startupFocusTab && hasTabs ) {\r
595 me._.tabBarMode = true;\r
596 me._.tabs[ me._.currentTabId ][ 0 ].focus();\r
597 me._.currentFocusIndex = -1;\r
598 } else if ( !this._.hasFocus ) {\r
599 // http://dev.ckeditor.com/ticket/13114#comment:4.\r
600 this._.currentFocusIndex = hasTabs ? -1 : this._.focusList.length - 1;\r
601\r
602 // Decide where to put the initial focus.\r
603 if ( definition.onFocus ) {\r
604 var initialFocus = definition.onFocus.call( this );\r
605 // Focus the field that the user specified.\r
606 initialFocus && initialFocus.focus();\r
607 }\r
608 // Focus the first field in layout order.\r
609 else {\r
610 changeFocus( 1 );\r
611 }\r
612 }\r
613 }, this, null, 0xffffffff );\r
614\r
1794320d 615 // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (http://dev.ckeditor.com/ticket/2661).\r
c63493c8
IB
616 // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.\r
617 if ( CKEDITOR.env.ie6Compat ) {\r
618 this.on( 'load', function() {\r
619 var outer = this.getElement(),\r
620 inner = outer.getFirst();\r
621 inner.remove();\r
622 inner.appendTo( outer );\r
623 }, this );\r
624 }\r
625\r
626 initDragAndDrop( this );\r
627 initResizeHandles( this );\r
628\r
629 // Insert the title.\r
630 ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );\r
631\r
632 // Insert the tabs and contents.\r
633 for ( i = 0; i < definition.contents.length; i++ ) {\r
634 var page = definition.contents[ i ];\r
635 page && this.addPage( page );\r
636 }\r
637\r
638 this.parts.tabs.on( 'click', function( evt ) {\r
639 var target = evt.data.getTarget();\r
640 // If we aren't inside a tab, bail out.\r
641 if ( target.hasClass( 'cke_dialog_tab' ) ) {\r
642 // Get the ID of the tab, without the 'cke_' prefix and the unique number suffix.\r
643 var id = target.$.id;\r
644 this.selectPage( id.substring( 4, id.lastIndexOf( '_' ) ) );\r
645\r
646 if ( this._.tabBarMode ) {\r
647 this._.tabBarMode = false;\r
648 this._.currentFocusIndex = -1;\r
649 changeFocus( 1 );\r
650 }\r
651 evt.data.preventDefault();\r
652 }\r
653 }, this );\r
654\r
655 // Insert buttons.\r
656 var buttonsHtml = [],\r
657 buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this, {\r
658 type: 'hbox',\r
659 className: 'cke_dialog_footer_buttons',\r
660 widths: [],\r
661 children: definition.buttons\r
662 }, buttonsHtml ).getChild();\r
663 this.parts.footer.setHtml( buttonsHtml.join( '' ) );\r
664\r
665 for ( i = 0; i < buttons.length; i++ )\r
666 this._.buttons[ buttons[ i ].id ] = buttons[ i ];\r
667\r
668 /**\r
669 * Current state of the dialog. Use the {@link #setState} method to update it.\r
670 * See the {@link #event-state} event to know more.\r
671 *\r
672 * @readonly\r
673 * @property {Number} [state=CKEDITOR.DIALOG_STATE_IDLE]\r
674 */\r
675 };\r
676\r
677 // Focusable interface. Use it via dialog.addFocusable.\r
678 function Focusable( dialog, element, index ) {\r
679 this.element = element;\r
680 this.focusIndex = index;\r
681 // TODO: support tabIndex for focusables.\r
682 this.tabIndex = 0;\r
683 this.isFocusable = function() {\r
684 return !element.getAttribute( 'disabled' ) && element.isVisible();\r
685 };\r
686 this.focus = function() {\r
687 dialog._.currentFocusIndex = this.focusIndex;\r
688 this.element.focus();\r
689 };\r
690 // Bind events\r
691 element.on( 'keydown', function( e ) {\r
692 if ( e.data.getKeystroke() in { 32: 1, 13: 1 } )\r
693 this.fire( 'click' );\r
694 } );\r
695 element.on( 'focus', function() {\r
696 this.fire( 'mouseover' );\r
697 } );\r
698 element.on( 'blur', function() {\r
699 this.fire( 'mouseout' );\r
700 } );\r
701 }\r
702\r
703 // Re-layout the dialog on window resize.\r
704 function resizeWithWindow( dialog ) {\r
705 var win = CKEDITOR.document.getWindow();\r
706 function resizeHandler() {\r
707 dialog.layout();\r
708 }\r
709 win.on( 'resize', resizeHandler );\r
710 dialog.on( 'hide', function() {\r
711 win.removeListener( 'resize', resizeHandler );\r
712 } );\r
713 }\r
714\r
715 CKEDITOR.dialog.prototype = {\r
716 destroy: function() {\r
717 this.hide();\r
718 this._.element.remove();\r
719 },\r
720\r
721 /**\r
722 * Resizes the dialog.\r
723 *\r
724 * dialogObj.resize( 800, 640 );\r
725 *\r
726 * @method\r
727 * @param {Number} width The width of the dialog in pixels.\r
728 * @param {Number} height The height of the dialog in pixels.\r
729 */\r
730 resize: ( function() {\r
731 return function( width, height ) {\r
732 if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )\r
733 return;\r
734\r
735 CKEDITOR.dialog.fire( 'resize', {\r
736 dialog: this,\r
737 width: width,\r
738 height: height\r
739 }, this._.editor );\r
740\r
741 this.fire( 'resize', {\r
742 width: width,\r
743 height: height\r
744 }, this._.editor );\r
745\r
746 var contents = this.parts.contents;\r
747 contents.setStyles( {\r
748 width: width + 'px',\r
749 height: height + 'px'\r
750 } );\r
751\r
752 // Update dialog position when dimension get changed in RTL.\r
753 if ( this._.editor.lang.dir == 'rtl' && this._.position )\r
754 this._.position.x = CKEDITOR.document.getWindow().getViewPaneSize().width - this._.contentSize.width - parseInt( this._.element.getFirst().getStyle( 'right' ), 10 );\r
755\r
756 this._.contentSize = { width: width, height: height };\r
757 };\r
758 } )(),\r
759\r
760 /**\r
761 * Gets the current size of the dialog in pixels.\r
762 *\r
763 * var width = dialogObj.getSize().width;\r
764 *\r
765 * @returns {Object}\r
766 * @returns {Number} return.width\r
767 * @returns {Number} return.height\r
768 */\r
769 getSize: function() {\r
770 var element = this._.element.getFirst();\r
771 return { width: element.$.offsetWidth || 0, height: element.$.offsetHeight || 0 };\r
772 },\r
773\r
774 /**\r
775 * Moves the dialog to an `(x, y)` coordinate relative to the window.\r
776 *\r
777 * dialogObj.move( 10, 40 );\r
778 *\r
779 * @method\r
780 * @param {Number} x The target x-coordinate.\r
781 * @param {Number} y The target y-coordinate.\r
782 * @param {Boolean} save Flag indicate whether the dialog position should be remembered on next open up.\r
783 */\r
784 move: function( x, y, save ) {\r
785\r
786 // The dialog may be fixed positioned or absolute positioned. Ask the\r
787 // browser what is the current situation first.\r
788 var element = this._.element.getFirst(), rtl = this._.editor.lang.dir == 'rtl';\r
789 var isFixed = element.getComputedStyle( 'position' ) == 'fixed';\r
790\r
1794320d 791 // (http://dev.ckeditor.com/ticket/8888) In some cases of a very small viewport, dialog is incorrectly\r
c63493c8
IB
792 // positioned in IE7. It also happens that it remains sticky and user cannot\r
793 // scroll down/up to reveal dialog's content below/above the viewport; this is\r
794 // cumbersome.\r
795 // The only way to fix this is to move mouse out of the browser and\r
796 // go back to see that dialog position is automagically fixed. No events,\r
797 // no style change - pure magic. This is a IE7 rendering issue, which can be\r
798 // fixed with dummy style redraw on each move.\r
799 if ( CKEDITOR.env.ie )\r
800 element.setStyle( 'zoom', '100%' );\r
801\r
802 if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )\r
803 return;\r
804\r
805 // Save the current position.\r
806 this._.position = { x: x, y: y };\r
807\r
808 // If not fixed positioned, add scroll position to the coordinates.\r
809 if ( !isFixed ) {\r
810 var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();\r
811 x += scrollPosition.x;\r
812 y += scrollPosition.y;\r
813 }\r
814\r
815 // Translate coordinate for RTL.\r
816 if ( rtl ) {\r
817 var dialogSize = this.getSize(), viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize();\r
818 x = viewPaneSize.width - dialogSize.width - x;\r
819 }\r
820\r
821 var styles = { 'top': ( y > 0 ? y : 0 ) + 'px' };\r
822 styles[ rtl ? 'right' : 'left' ] = ( x > 0 ? x : 0 ) + 'px';\r
823\r
824 element.setStyles( styles );\r
825\r
826 save && ( this._.moved = 1 );\r
827 },\r
828\r
829 /**\r
830 * Gets the dialog's position in the window.\r
831 *\r
832 * var dialogX = dialogObj.getPosition().x;\r
833 *\r
834 * @returns {Object}\r
835 * @returns {Number} return.x\r
836 * @returns {Number} return.y\r
837 */\r
838 getPosition: function() {\r
839 return CKEDITOR.tools.extend( {}, this._.position );\r
840 },\r
841\r
842 /**\r
843 * Shows the dialog box.\r
844 *\r
845 * dialogObj.show();\r
846 */\r
847 show: function() {\r
848 // Insert the dialog's element to the root document.\r
849 var element = this._.element;\r
850 var definition = this.definition;\r
851 if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )\r
852 element.appendTo( CKEDITOR.document.getBody() );\r
853 else\r
854 element.setStyle( 'display', 'block' );\r
855\r
856 // First, set the dialog to an appropriate size.\r
857 this.resize(\r
858 this._.contentSize && this._.contentSize.width || definition.width || definition.minWidth,\r
859 this._.contentSize && this._.contentSize.height || definition.height || definition.minHeight\r
860 );\r
861\r
862 // Reset all inputs back to their default value.\r
863 this.reset();\r
864\r
1794320d
IB
865 // Selects the first tab if no tab is already selected.\r
866 if ( this._.currentTabId === null ) {\r
867 this.selectPage( this.definition.contents[ 0 ].id );\r
868 }\r
c63493c8
IB
869\r
870 // Set z-index.\r
871 if ( CKEDITOR.dialog._.currentZIndex === null )\r
872 CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;\r
873 this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );\r
874\r
875 // Maintain the dialog ordering and dialog cover.\r
876 if ( CKEDITOR.dialog._.currentTop === null ) {\r
877 CKEDITOR.dialog._.currentTop = this;\r
878 this._.parentDialog = null;\r
879 showCover( this._.editor );\r
880\r
881 } else {\r
882 this._.parentDialog = CKEDITOR.dialog._.currentTop;\r
883 var parentElement = this._.parentDialog.getElement().getFirst();\r
884 parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );\r
885 CKEDITOR.dialog._.currentTop = this;\r
886 }\r
887\r
888 element.on( 'keydown', accessKeyDownHandler );\r
889 element.on( 'keyup', accessKeyUpHandler );\r
890\r
891 // Reset the hasFocus state.\r
892 this._.hasFocus = false;\r
893\r
894 for ( var i in definition.contents ) {\r
895 if ( !definition.contents[ i ] )\r
896 continue;\r
897\r
898 var content = definition.contents[ i ],\r
899 tab = this._.tabs[ content.id ],\r
900 requiredContent = content.requiredContent,\r
901 enableElements = 0;\r
902\r
903 if ( !tab )\r
904 continue;\r
905\r
906 for ( var j in this._.contents[ content.id ] ) {\r
907 var elem = this._.contents[ content.id ][ j ];\r
908\r
909 if ( elem.type == 'hbox' || elem.type == 'vbox' || !elem.getInputElement() )\r
910 continue;\r
911\r
912 if ( elem.requiredContent && !this._.editor.activeFilter.check( elem.requiredContent ) )\r
913 elem.disable();\r
914 else {\r
915 elem.enable();\r
916 enableElements++;\r
917 }\r
918 }\r
919\r
920 if ( !enableElements || ( requiredContent && !this._.editor.activeFilter.check( requiredContent ) ) )\r
921 tab[ 0 ].addClass( 'cke_dialog_tab_disabled' );\r
922 else\r
923 tab[ 0 ].removeClass( 'cke_dialog_tab_disabled' );\r
924 }\r
925\r
926 CKEDITOR.tools.setTimeout( function() {\r
927 this.layout();\r
928 resizeWithWindow( this );\r
929\r
930 this.parts.dialog.setStyle( 'visibility', '' );\r
931\r
932 // Execute onLoad for the first show.\r
933 this.fireOnce( 'load', {} );\r
934 CKEDITOR.ui.fire( 'ready', this );\r
935\r
936 this.fire( 'show', {} );\r
937 this._.editor.fire( 'dialogShow', this );\r
938\r
939 if ( !this._.parentDialog )\r
940 this._.editor.focusManager.lock();\r
941\r
942 // Save the initial values of the dialog.\r
943 this.foreach( function( contentObj ) {\r
944 contentObj.setInitValue && contentObj.setInitValue();\r
945 } );\r
946\r
947 }, 100, this );\r
948 },\r
949\r
950 /**\r
951 * Rearrange the dialog to its previous position or the middle of the window.\r
952 *\r
953 * @since 3.5\r
954 */\r
955 layout: function() {\r
956 var el = this.parts.dialog;\r
957 var dialogSize = this.getSize();\r
958 var win = CKEDITOR.document.getWindow(),\r
959 viewSize = win.getViewPaneSize();\r
960\r
961 var posX = ( viewSize.width - dialogSize.width ) / 2,\r
962 posY = ( viewSize.height - dialogSize.height ) / 2;\r
963\r
964 // Switch to absolute position when viewport is smaller than dialog size.\r
965 if ( !CKEDITOR.env.ie6Compat ) {\r
966 if ( dialogSize.height + ( posY > 0 ? posY : 0 ) > viewSize.height || dialogSize.width + ( posX > 0 ? posX : 0 ) > viewSize.width ) {\r
967 el.setStyle( 'position', 'absolute' );\r
968 } else {\r
969 el.setStyle( 'position', 'fixed' );\r
970 }\r
971 }\r
972\r
973 this.move( this._.moved ? this._.position.x : posX, this._.moved ? this._.position.y : posY );\r
974 },\r
975\r
976 /**\r
977 * Executes a function for each UI element.\r
978 *\r
979 * @param {Function} fn Function to execute for each UI element.\r
980 * @returns {CKEDITOR.dialog} The current dialog object.\r
981 */\r
982 foreach: function( fn ) {\r
983 for ( var i in this._.contents ) {\r
984 for ( var j in this._.contents[ i ] ) {\r
985 fn.call( this, this._.contents[i][j] );\r
986 }\r
987 }\r
988\r
989 return this;\r
990 },\r
991\r
992 /**\r
993 * Resets all input values in the dialog.\r
994 *\r
995 * dialogObj.reset();\r
996 *\r
997 * @method\r
998 * @chainable\r
999 */\r
1000 reset: ( function() {\r
1001 var fn = function( widget ) {\r
1002 if ( widget.reset )\r
1003 widget.reset( 1 );\r
1004 };\r
1005 return function() {\r
1006 this.foreach( fn );\r
1007 return this;\r
1008 };\r
1009 } )(),\r
1010\r
1011\r
1012 /**\r
1013 * Calls the {@link CKEDITOR.dialog.definition.uiElement#setup} method of each\r
1014 * of the UI elements, with the arguments passed through it.\r
1015 * It is usually being called when the dialog is opened, to put the initial value inside the field.\r
1016 *\r
1017 * dialogObj.setupContent();\r
1018 *\r
1019 * var timestamp = ( new Date() ).valueOf();\r
1020 * dialogObj.setupContent( timestamp );\r
1021 */\r
1022 setupContent: function() {\r
1023 var args = arguments;\r
1024 this.foreach( function( widget ) {\r
1025 if ( widget.setup )\r
1026 widget.setup.apply( widget, args );\r
1027 } );\r
1028 },\r
1029\r
1030 /**\r
1031 * Calls the {@link CKEDITOR.dialog.definition.uiElement#commit} method of each\r
1032 * of the UI elements, with the arguments passed through it.\r
1033 * It is usually being called when the user confirms the dialog, to process the values.\r
1034 *\r
1035 * dialogObj.commitContent();\r
1036 *\r
1037 * var timestamp = ( new Date() ).valueOf();\r
1038 * dialogObj.commitContent( timestamp );\r
1039 */\r
1040 commitContent: function() {\r
1041 var args = arguments;\r
1042 this.foreach( function( widget ) {\r
1794320d 1043 // Make sure IE triggers "change" event on last focused input before closing the dialog. (http://dev.ckeditor.com/ticket/7915)\r
c63493c8
IB
1044 if ( CKEDITOR.env.ie && this._.currentFocusIndex == widget.focusIndex )\r
1045 widget.getInputElement().$.blur();\r
1046\r
1047 if ( widget.commit )\r
1048 widget.commit.apply( widget, args );\r
1049 } );\r
1050 },\r
1051\r
1052 /**\r
1053 * Hides the dialog box.\r
1054 *\r
1055 * dialogObj.hide();\r
1056 */\r
1057 hide: function() {\r
1058 if ( !this.parts.dialog.isVisible() )\r
1059 return;\r
1060\r
1061 this.fire( 'hide', {} );\r
1062 this._.editor.fire( 'dialogHide', this );\r
1063 // Reset the tab page.\r
1064 this.selectPage( this._.tabIdList[ 0 ] );\r
1065 var element = this._.element;\r
1066 element.setStyle( 'display', 'none' );\r
1067 this.parts.dialog.setStyle( 'visibility', 'hidden' );\r
1068 // Unregister all access keys associated with this dialog.\r
1069 unregisterAccessKey( this );\r
1070\r
1071 // Close any child(top) dialogs first.\r
1072 while ( CKEDITOR.dialog._.currentTop != this )\r
1073 CKEDITOR.dialog._.currentTop.hide();\r
1074\r
1075 // Maintain dialog ordering and remove cover if needed.\r
1076 if ( !this._.parentDialog )\r
1077 hideCover( this._.editor );\r
1078 else {\r
1079 var parentElement = this._.parentDialog.getElement().getFirst();\r
1080 parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );\r
1081 }\r
1082 CKEDITOR.dialog._.currentTop = this._.parentDialog;\r
1083\r
1084 // Deduct or clear the z-index.\r
1085 if ( !this._.parentDialog ) {\r
1086 CKEDITOR.dialog._.currentZIndex = null;\r
1087\r
1088 // Remove access key handlers.\r
1089 element.removeListener( 'keydown', accessKeyDownHandler );\r
1090 element.removeListener( 'keyup', accessKeyUpHandler );\r
1091\r
1092 var editor = this._.editor;\r
1093 editor.focus();\r
1094\r
1794320d 1095 // Give a while before unlock, waiting for focus to return to the editable. (http://dev.ckeditor.com/ticket/172)\r
c63493c8
IB
1096 setTimeout( function() {\r
1097 editor.focusManager.unlock();\r
1098\r
1794320d 1099 // Fixed iOS focus issue (http://dev.ckeditor.com/ticket/12381).\r
c63493c8
IB
1100 // Keep in mind that editor.focus() does not work in this case.\r
1101 if ( CKEDITOR.env.iOS ) {\r
1102 editor.window.focus();\r
1103 }\r
1104 }, 0 );\r
1105\r
1106 } else {\r
1107 CKEDITOR.dialog._.currentZIndex -= 10;\r
1108 }\r
1109\r
1110 delete this._.parentDialog;\r
1111 // Reset the initial values of the dialog.\r
1112 this.foreach( function( contentObj ) {\r
1113 contentObj.resetInitValue && contentObj.resetInitValue();\r
1114 } );\r
1115\r
1794320d 1116 // Reset dialog state back to IDLE, if busy (http://dev.ckeditor.com/ticket/13213).\r
c63493c8
IB
1117 this.setState( CKEDITOR.DIALOG_STATE_IDLE );\r
1118 },\r
1119\r
1120 /**\r
1121 * Adds a tabbed page into the dialog.\r
1122 *\r
1123 * @param {Object} contents Content definition.\r
1124 */\r
1125 addPage: function( contents ) {\r
1126 if ( contents.requiredContent && !this._.editor.filter.check( contents.requiredContent ) )\r
1127 return;\r
1128\r
1129 var pageHtml = [],\r
1130 titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',\r
1131 vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this, {\r
1132 type: 'vbox',\r
1133 className: 'cke_dialog_page_contents',\r
1134 children: contents.elements,\r
1135 expand: !!contents.expand,\r
1136 padding: contents.padding,\r
1137 style: contents.style || 'width: 100%;'\r
1138 }, pageHtml );\r
1139\r
1140 var contentMap = this._.contents[ contents.id ] = {},\r
1141 cursor,\r
1142 children = vbox.getChild(),\r
1143 enabledFields = 0;\r
1144\r
1145 while ( ( cursor = children.shift() ) ) {\r
1146 // Count all allowed fields.\r
1147 if ( !cursor.notAllowed && cursor.type != 'hbox' && cursor.type != 'vbox' )\r
1148 enabledFields++;\r
1149\r
1150 contentMap[ cursor.id ] = cursor;\r
1151 if ( typeof cursor.getChild == 'function' )\r
1152 children.push.apply( children, cursor.getChild() );\r
1153 }\r
1154\r
1155 // If all fields are disabled (because they are not allowed) hide this tab.\r
1156 if ( !enabledFields )\r
1157 contents.hidden = true;\r
1158\r
1159 // Create the HTML for the tab and the content block.\r
1160 var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );\r
1161 page.setAttribute( 'role', 'tabpanel' );\r
1162\r
1163 var env = CKEDITOR.env;\r
1164 var tabId = 'cke_' + contents.id + '_' + CKEDITOR.tools.getNextNumber(),\r
1165 tab = CKEDITOR.dom.element.createFromHtml( [\r
1166 '<a class="cke_dialog_tab"',\r
1167 ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),\r
1168 titleHtml,\r
1169 ( !!contents.hidden ? ' style="display:none"' : '' ),\r
1170 ' id="', tabId, '"',\r
1171 env.gecko && !env.hc ? '' : ' href="javascript:void(0)"',\r
1172 ' tabIndex="-1"',\r
1173 ' hidefocus="true"',\r
1174 ' role="tab">',\r
1175 contents.label,\r
1176 '</a>'\r
1177 ].join( '' ) );\r
1178\r
1179 page.setAttribute( 'aria-labelledby', tabId );\r
1180\r
1181 // Take records for the tabs and elements created.\r
1182 this._.tabs[ contents.id ] = [ tab, page ];\r
1183 this._.tabIdList.push( contents.id );\r
1184 !contents.hidden && this._.pageCount++;\r
1185 this._.lastTab = tab;\r
1186 this.updateStyle();\r
1187\r
1188 // Attach the DOM nodes.\r
1189\r
1190 page.setAttribute( 'name', contents.id );\r
1191 page.appendTo( this.parts.contents );\r
1192\r
1193 tab.unselectable();\r
1194 this.parts.tabs.append( tab );\r
1195\r
1196 // Add access key handlers if access key is defined.\r
1197 if ( contents.accessKey ) {\r
1198 registerAccessKey( this, this, 'CTRL+' + contents.accessKey, tabAccessKeyDown, tabAccessKeyUp );\r
1199 this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;\r
1200 }\r
1201 },\r
1202\r
1203 /**\r
1204 * Activates a tab page in the dialog by its id.\r
1205 *\r
1206 * dialogObj.selectPage( 'tab_1' );\r
1207 *\r
1208 * @param {String} id The id of the dialog tab to be activated.\r
1209 */\r
1210 selectPage: function( id ) {\r
1211 if ( this._.currentTabId == id )\r
1212 return;\r
1213\r
1214 if ( this._.tabs[ id ][ 0 ].hasClass( 'cke_dialog_tab_disabled' ) )\r
1215 return;\r
1216\r
1217 // If event was canceled - do nothing.\r
1218 if ( this.fire( 'selectPage', { page: id, currentPage: this._.currentTabId } ) === false )\r
1219 return;\r
1220\r
1221 // Hide the non-selected tabs and pages.\r
1222 for ( var i in this._.tabs ) {\r
1223 var tab = this._.tabs[ i ][ 0 ],\r
1224 page = this._.tabs[ i ][ 1 ];\r
1225 if ( i != id ) {\r
1226 tab.removeClass( 'cke_dialog_tab_selected' );\r
1227 page.hide();\r
1228 }\r
1229 page.setAttribute( 'aria-hidden', i != id );\r
1230 }\r
1231\r
1232 var selected = this._.tabs[ id ];\r
1233 selected[ 0 ].addClass( 'cke_dialog_tab_selected' );\r
1234\r
1235 // [IE] an invisible input[type='text'] will enlarge it's width\r
1236 // if it's value is long when it shows, so we clear it's value\r
1794320d 1237 // before it shows and then recover it (http://dev.ckeditor.com/ticket/5649)\r
c63493c8
IB
1238 if ( CKEDITOR.env.ie6Compat || CKEDITOR.env.ie7Compat ) {\r
1239 clearOrRecoverTextInputValue( selected[ 1 ] );\r
1240 selected[ 1 ].show();\r
1241 setTimeout( function() {\r
1242 clearOrRecoverTextInputValue( selected[ 1 ], 1 );\r
1243 }, 0 );\r
1244 } else {\r
1245 selected[ 1 ].show();\r
1246 }\r
1247\r
1248 this._.currentTabId = id;\r
1249 this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );\r
1250 },\r
1251\r
1252 /**\r
1253 * Dialog state-specific style updates.\r
1254 */\r
1255 updateStyle: function() {\r
1256 // If only a single page shown, a different style is used in the central pane.\r
1257 this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );\r
1258 },\r
1259\r
1260 /**\r
1261 * Hides a page's tab away from the dialog.\r
1262 *\r
1263 * dialog.hidePage( 'tab_3' );\r
1264 *\r
1265 * @param {String} id The page's Id.\r
1266 */\r
1267 hidePage: function( id ) {\r
1268 var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];\r
1269 if ( !tab || this._.pageCount == 1 || !tab.isVisible() )\r
1270 return;\r
1271 // Switch to other tab first when we're hiding the active tab.\r
1272 else if ( id == this._.currentTabId )\r
1273 this.selectPage( getPreviousVisibleTab.call( this ) );\r
1274\r
1275 tab.hide();\r
1276 this._.pageCount--;\r
1277 this.updateStyle();\r
1278 },\r
1279\r
1280 /**\r
1281 * Unhides a page's tab.\r
1282 *\r
1283 * dialog.showPage( 'tab_2' );\r
1284 *\r
1285 * @param {String} id The page's Id.\r
1286 */\r
1287 showPage: function( id ) {\r
1288 var tab = this._.tabs[ id ] && this._.tabs[ id ][ 0 ];\r
1289 if ( !tab )\r
1290 return;\r
1291 tab.show();\r
1292 this._.pageCount++;\r
1293 this.updateStyle();\r
1294 },\r
1295\r
1296 /**\r
1297 * Gets the root DOM element of the dialog.\r
1298 *\r
1299 * var dialogElement = dialogObj.getElement().getFirst();\r
1300 * dialogElement.setStyle( 'padding', '5px' );\r
1301 *\r
1302 * @returns {CKEDITOR.dom.element} The `<span>` element containing this dialog.\r
1303 */\r
1304 getElement: function() {\r
1305 return this._.element;\r
1306 },\r
1307\r
1308 /**\r
1309 * Gets the name of the dialog.\r
1310 *\r
1311 * var dialogName = dialogObj.getName();\r
1312 *\r
1313 * @returns {String} The name of this dialog.\r
1314 */\r
1315 getName: function() {\r
1316 return this._.name;\r
1317 },\r
1318\r
1319 /**\r
1320 * Gets a dialog UI element object from a dialog page.\r
1321 *\r
1322 * dialogObj.getContentElement( 'tabId', 'elementId' ).setValue( 'Example' );\r
1323 *\r
1324 * @param {String} pageId id of dialog page.\r
1325 * @param {String} elementId id of UI element.\r
1326 * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.\r
1327 */\r
1328 getContentElement: function( pageId, elementId ) {\r
1329 var page = this._.contents[ pageId ];\r
1330 return page && page[ elementId ];\r
1331 },\r
1332\r
1333 /**\r
1334 * Gets the value of a dialog UI element.\r
1335 *\r
1336 * alert( dialogObj.getValueOf( 'tabId', 'elementId' ) );\r
1337 *\r
1338 * @param {String} pageId id of dialog page.\r
1339 * @param {String} elementId id of UI element.\r
1340 * @returns {Object} The value of the UI element.\r
1341 */\r
1342 getValueOf: function( pageId, elementId ) {\r
1343 return this.getContentElement( pageId, elementId ).getValue();\r
1344 },\r
1345\r
1346 /**\r
1347 * Sets the value of a dialog UI element.\r
1348 *\r
1349 * dialogObj.setValueOf( 'tabId', 'elementId', 'Example' );\r
1350 *\r
1351 * @param {String} pageId id of the dialog page.\r
1352 * @param {String} elementId id of the UI element.\r
1353 * @param {Object} value The new value of the UI element.\r
1354 */\r
1355 setValueOf: function( pageId, elementId, value ) {\r
1356 return this.getContentElement( pageId, elementId ).setValue( value );\r
1357 },\r
1358\r
1359 /**\r
1360 * Gets the UI element of a button in the dialog's button row.\r
1361 *\r
1362 * @returns {CKEDITOR.ui.dialog.button} The button object.\r
1363 *\r
1364 * @param {String} id The id of the button.\r
1365 */\r
1366 getButton: function( id ) {\r
1367 return this._.buttons[ id ];\r
1368 },\r
1369\r
1370 /**\r
1371 * Simulates a click to a dialog button in the dialog's button row.\r
1372 *\r
1373 * @returns The return value of the dialog's `click` event.\r
1374 *\r
1375 * @param {String} id The id of the button.\r
1376 */\r
1377 click: function( id ) {\r
1378 return this._.buttons[ id ].click();\r
1379 },\r
1380\r
1381 /**\r
1382 * Disables a dialog button.\r
1383 *\r
1384 * @param {String} id The id of the button.\r
1385 */\r
1386 disableButton: function( id ) {\r
1387 return this._.buttons[ id ].disable();\r
1388 },\r
1389\r
1390 /**\r
1391 * Enables a dialog button.\r
1392 *\r
1393 * @param {String} id The id of the button.\r
1394 */\r
1395 enableButton: function( id ) {\r
1396 return this._.buttons[ id ].enable();\r
1397 },\r
1398\r
1399 /**\r
1400 * Gets the number of pages in the dialog.\r
1401 *\r
1402 * @returns {Number} Page count.\r
1403 */\r
1404 getPageCount: function() {\r
1405 return this._.pageCount;\r
1406 },\r
1407\r
1408 /**\r
1409 * Gets the editor instance which opened this dialog.\r
1410 *\r
1411 * @returns {CKEDITOR.editor} Parent editor instances.\r
1412 */\r
1413 getParentEditor: function() {\r
1414 return this._.editor;\r
1415 },\r
1416\r
1417 /**\r
1418 * Gets the element that was selected when opening the dialog, if any.\r
1419 *\r
1420 * @returns {CKEDITOR.dom.element} The element that was selected, or `null`.\r
1421 */\r
1422 getSelectedElement: function() {\r
1423 return this.getParentEditor().getSelection().getSelectedElement();\r
1424 },\r
1425\r
1426 /**\r
1427 * Adds element to dialog's focusable list.\r
1428 *\r
1429 * @param {CKEDITOR.dom.element} element\r
1430 * @param {Number} [index]\r
1431 */\r
1432 addFocusable: function( element, index ) {\r
1433 if ( typeof index == 'undefined' ) {\r
1434 index = this._.focusList.length;\r
1435 this._.focusList.push( new Focusable( this, element, index ) );\r
1436 } else {\r
1437 this._.focusList.splice( index, 0, new Focusable( this, element, index ) );\r
1438 for ( var i = index + 1; i < this._.focusList.length; i++ )\r
1439 this._.focusList[ i ].focusIndex++;\r
1440 }\r
1441 },\r
1442\r
1443 /**\r
1444 * Sets the dialog {@link #property-state}.\r
1445 *\r
1446 * @since 4.5\r
1447 * @param {Number} state Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.\r
1448 */\r
1449 setState: function( state ) {\r
1450 var oldState = this.state;\r
1451\r
1452 if ( oldState == state ) {\r
1453 return;\r
1454 }\r
1455\r
1456 this.state = state;\r
1457\r
1458 if ( state == CKEDITOR.DIALOG_STATE_BUSY ) {\r
1459 // Insert the spinner on demand.\r
1460 if ( !this.parts.spinner ) {\r
1461 var dir = this.getParentEditor().lang.dir,\r
1462 spinnerDef = {\r
1463 attributes: {\r
1464 'class': 'cke_dialog_spinner'\r
1465 },\r
1466 styles: {\r
1467 'float': dir == 'rtl' ? 'right' : 'left'\r
1468 }\r
1469 };\r
1470\r
1471 spinnerDef.styles[ 'margin-' + ( dir == 'rtl' ? 'left' : 'right' ) ] = '8px';\r
1472\r
1473 this.parts.spinner = CKEDITOR.document.createElement( 'div', spinnerDef );\r
1474\r
1475 this.parts.spinner.setHtml( '&#8987;' );\r
1476 this.parts.spinner.appendTo( this.parts.title, 1 );\r
1477 }\r
1478\r
1479 // Finally, show the spinner.\r
1480 this.parts.spinner.show();\r
1481\r
1482 this.getButton( 'ok' ).disable();\r
1483 } else if ( state == CKEDITOR.DIALOG_STATE_IDLE ) {\r
1484 // Hide the spinner. But don't do anything if there is no spinner yet.\r
1485 this.parts.spinner && this.parts.spinner.hide();\r
1486\r
1487 this.getButton( 'ok' ).enable();\r
1488 }\r
1489\r
1490 this.fire( 'state', state );\r
1491 }\r
1492 };\r
1493\r
1494 CKEDITOR.tools.extend( CKEDITOR.dialog, {\r
1495 /**\r
1496 * Registers a dialog.\r
1497 *\r
1498 * // Full sample plugin, which does not only register a dialog window but also adds an item to the context menu.\r
1499 * // To open the dialog window, choose "Open dialog" in the context menu.\r
1500 * CKEDITOR.plugins.add( 'myplugin', {\r
1501 * init: function( editor ) {\r
1502 * editor.addCommand( 'mydialog',new CKEDITOR.dialogCommand( 'mydialog' ) );\r
1503 *\r
1504 * if ( editor.contextMenu ) {\r
1505 * editor.addMenuGroup( 'mygroup', 10 );\r
1506 * editor.addMenuItem( 'My Dialog', {\r
1507 * label: 'Open dialog',\r
1508 * command: 'mydialog',\r
1509 * group: 'mygroup'\r
1510 * } );\r
1511 * editor.contextMenu.addListener( function( element ) {\r
1512 * return { 'My Dialog': CKEDITOR.TRISTATE_OFF };\r
1513 * } );\r
1514 * }\r
1515 *\r
1516 * CKEDITOR.dialog.add( 'mydialog', function( api ) {\r
1517 * // CKEDITOR.dialog.definition\r
1518 * var dialogDefinition = {\r
1519 * title: 'Sample dialog',\r
1520 * minWidth: 390,\r
1521 * minHeight: 130,\r
1522 * contents: [\r
1523 * {\r
1524 * id: 'tab1',\r
1525 * label: 'Label',\r
1526 * title: 'Title',\r
1527 * expand: true,\r
1528 * padding: 0,\r
1529 * elements: [\r
1530 * {\r
1531 * type: 'html',\r
1532 * html: '<p>This is some sample HTML content.</p>'\r
1533 * },\r
1534 * {\r
1535 * type: 'textarea',\r
1536 * id: 'textareaId',\r
1537 * rows: 4,\r
1538 * cols: 40\r
1539 * }\r
1540 * ]\r
1541 * }\r
1542 * ],\r
1543 * buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ],\r
1544 * onOk: function() {\r
1545 * // "this" is now a CKEDITOR.dialog object.\r
1546 * // Accessing dialog elements:\r
1547 * var textareaObj = this.getContentElement( 'tab1', 'textareaId' );\r
1548 * alert( "You have entered: " + textareaObj.getValue() );\r
1549 * }\r
1550 * };\r
1551 *\r
1552 * return dialogDefinition;\r
1553 * } );\r
1554 * }\r
1555 * } );\r
1556 *\r
1557 * CKEDITOR.replace( 'editor1', { extraPlugins: 'myplugin' } );\r
1558 *\r
1559 * @static\r
1560 * @param {String} name The dialog's name.\r
1561 * @param {Function/String} dialogDefinition\r
1562 * A function returning the dialog's definition, or the URL to the `.js` file holding the function.\r
1563 * The function should accept an argument `editor` which is the current editor instance, and\r
1564 * return an object conforming to {@link CKEDITOR.dialog.definition}.\r
1565 * @see CKEDITOR.dialog.definition\r
1566 */\r
1567 add: function( name, dialogDefinition ) {\r
1568 // Avoid path registration from multiple instances override definition.\r
1569 if ( !this._.dialogDefinitions[ name ] || typeof dialogDefinition == 'function' )\r
1570 this._.dialogDefinitions[ name ] = dialogDefinition;\r
1571 },\r
1572\r
1573 /**\r
1574 * @static\r
1575 * @todo\r
1576 */\r
1577 exists: function( name ) {\r
1578 return !!this._.dialogDefinitions[ name ];\r
1579 },\r
1580\r
1581 /**\r
1582 * @static\r
1583 * @todo\r
1584 */\r
1585 getCurrent: function() {\r
1586 return CKEDITOR.dialog._.currentTop;\r
1587 },\r
1588\r
1589 /**\r
1590 * Check whether tab wasn't removed by {@link CKEDITOR.config#removeDialogTabs}.\r
1591 *\r
1592 * @since 4.1\r
1593 * @static\r
1594 * @param {CKEDITOR.editor} editor\r
1595 * @param {String} dialogName\r
1596 * @param {String} tabName\r
1597 * @returns {Boolean}\r
1598 */\r
1599 isTabEnabled: function( editor, dialogName, tabName ) {\r
1600 var cfg = editor.config.removeDialogTabs;\r
1601\r
1602 return !( cfg && cfg.match( new RegExp( '(?:^|;)' + dialogName + ':' + tabName + '(?:$|;)', 'i' ) ) );\r
1603 },\r
1604\r
1605 /**\r
1606 * The default OK button for dialogs. Fires the `ok` event and closes the dialog if the event succeeds.\r
1607 *\r
1608 * @static\r
1609 * @method\r
1610 */\r
1611 okButton: ( function() {\r
1612 var retval = function( editor, override ) {\r
1613 override = override || {};\r
1614 return CKEDITOR.tools.extend( {\r
1615 id: 'ok',\r
1616 type: 'button',\r
1617 label: editor.lang.common.ok,\r
1618 'class': 'cke_dialog_ui_button_ok',\r
1619 onClick: function( evt ) {\r
1620 var dialog = evt.data.dialog;\r
1621 if ( dialog.fire( 'ok', { hide: true } ).hide !== false )\r
1622 dialog.hide();\r
1623 }\r
1624 }, override, true );\r
1625 };\r
1626 retval.type = 'button';\r
1627 retval.override = function( override ) {\r
1628 return CKEDITOR.tools.extend( function( editor ) {\r
1629 return retval( editor, override );\r
1630 }, { type: 'button' }, true );\r
1631 };\r
1632 return retval;\r
1633 } )(),\r
1634\r
1635 /**\r
1636 * The default cancel button for dialogs. Fires the `cancel` event and\r
1637 * closes the dialog if no UI element value changed.\r
1638 *\r
1639 * @static\r
1640 * @method\r
1641 */\r
1642 cancelButton: ( function() {\r
1643 var retval = function( editor, override ) {\r
1644 override = override || {};\r
1645 return CKEDITOR.tools.extend( {\r
1646 id: 'cancel',\r
1647 type: 'button',\r
1648 label: editor.lang.common.cancel,\r
1649 'class': 'cke_dialog_ui_button_cancel',\r
1650 onClick: function( evt ) {\r
1651 var dialog = evt.data.dialog;\r
1652 if ( dialog.fire( 'cancel', { hide: true } ).hide !== false )\r
1653 dialog.hide();\r
1654 }\r
1655 }, override, true );\r
1656 };\r
1657 retval.type = 'button';\r
1658 retval.override = function( override ) {\r
1659 return CKEDITOR.tools.extend( function( editor ) {\r
1660 return retval( editor, override );\r
1661 }, { type: 'button' }, true );\r
1662 };\r
1663 return retval;\r
1664 } )(),\r
1665\r
1666 /**\r
1667 * Registers a dialog UI element.\r
1668 *\r
1669 * @static\r
1670 * @param {String} typeName The name of the UI element.\r
1671 * @param {Function} builder The function to build the UI element.\r
1672 */\r
1673 addUIElement: function( typeName, builder ) {\r
1674 this._.uiElementBuilders[ typeName ] = builder;\r
1675 }\r
1676 } );\r
1677\r
1678 CKEDITOR.dialog._ = {\r
1679 uiElementBuilders: {},\r
1680\r
1681 dialogDefinitions: {},\r
1682\r
1683 currentTop: null,\r
1684\r
1685 currentZIndex: null\r
1686 };\r
1687\r
1688 // "Inherit" (copy actually) from CKEDITOR.event.\r
1689 CKEDITOR.event.implementOn( CKEDITOR.dialog );\r
1690 CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype );\r
1691\r
1692 var defaultDialogDefinition = {\r
1693 resizable: CKEDITOR.DIALOG_RESIZE_BOTH,\r
1694 minWidth: 600,\r
1695 minHeight: 400,\r
1696 buttons: [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]\r
1697 };\r
1698\r
1699 // Tool function used to return an item from an array based on its id\r
1700 // property.\r
1701 var getById = function( array, id, recurse ) {\r
1702 for ( var i = 0, item;\r
1703 ( item = array[ i ] ); i++ ) {\r
1704 if ( item.id == id )\r
1705 return item;\r
1706 if ( recurse && item[ recurse ] ) {\r
1707 var retval = getById( item[ recurse ], id, recurse );\r
1708 if ( retval )\r
1709 return retval;\r
1710 }\r
1711 }\r
1712 return null;\r
1713 };\r
1714\r
1715 // Tool function used to add an item into an array.\r
1716 var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound ) {\r
1717 if ( nextSiblingId ) {\r
1718 for ( var i = 0, item;\r
1719 ( item = array[ i ] ); i++ ) {\r
1720 if ( item.id == nextSiblingId ) {\r
1721 array.splice( i, 0, newItem );\r
1722 return newItem;\r
1723 }\r
1724\r
1725 if ( recurse && item[ recurse ] ) {\r
1726 var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );\r
1727 if ( retval )\r
1728 return retval;\r
1729 }\r
1730 }\r
1731\r
1732 if ( nullIfNotFound )\r
1733 return null;\r
1734 }\r
1735\r
1736 array.push( newItem );\r
1737 return newItem;\r
1738 };\r
1739\r
1740 // Tool function used to remove an item from an array based on its id.\r
1741 var removeById = function( array, id, recurse ) {\r
1742 for ( var i = 0, item;\r
1743 ( item = array[ i ] ); i++ ) {\r
1744 if ( item.id == id )\r
1745 return array.splice( i, 1 );\r
1746 if ( recurse && item[ recurse ] ) {\r
1747 var retval = removeById( item[ recurse ], id, recurse );\r
1748 if ( retval )\r
1749 return retval;\r
1750 }\r
1751 }\r
1752 return null;\r
1753 };\r
1754\r
1755 /**\r
1756 * This class is not really part of the API. It is the `definition` property value\r
1757 * passed to `dialogDefinition` event handlers.\r
1758 *\r
1759 * CKEDITOR.on( 'dialogDefinition', function( evt ) {\r
1760 * var definition = evt.data.definition;\r
1761 * var content = definition.getContents( 'page1' );\r
1762 * // ...\r
1763 * } );\r
1764 *\r
1765 * @private\r
1766 * @class CKEDITOR.dialog.definitionObject\r
1767 * @extends CKEDITOR.dialog.definition\r
1768 * @constructor Creates a definitionObject class instance.\r
1769 */\r
1770 var definitionObject = function( dialog, dialogDefinition ) {\r
1771 // TODO : Check if needed.\r
1772 this.dialog = dialog;\r
1773\r
1774 // Transform the contents entries in contentObjects.\r
1775 var contents = dialogDefinition.contents;\r
1776 for ( var i = 0, content;\r
1777 ( content = contents[ i ] ); i++ )\r
1778 contents[ i ] = content && new contentObject( dialog, content );\r
1779\r
1780 CKEDITOR.tools.extend( this, dialogDefinition );\r
1781 };\r
1782\r
1783 definitionObject.prototype = {\r
1784 /**\r
1785 * Gets a content definition.\r
1786 *\r
1787 * @param {String} id The id of the content definition.\r
1788 * @returns {CKEDITOR.dialog.definition.content} The content definition matching id.\r
1789 */\r
1790 getContents: function( id ) {\r
1791 return getById( this.contents, id );\r
1792 },\r
1793\r
1794 /**\r
1795 * Gets a button definition.\r
1796 *\r
1797 * @param {String} id The id of the button definition.\r
1798 * @returns {CKEDITOR.dialog.definition.button} The button definition matching id.\r
1799 */\r
1800 getButton: function( id ) {\r
1801 return getById( this.buttons, id );\r
1802 },\r
1803\r
1804 /**\r
1805 * Adds a content definition object under this dialog definition.\r
1806 *\r
1807 * @param {CKEDITOR.dialog.definition.content} contentDefinition The\r
1808 * content definition.\r
1809 * @param {String} [nextSiblingId] The id of an existing content\r
1810 * definition which the new content definition will be inserted\r
1811 * before. Omit if the new content definition is to be inserted as\r
1812 * the last item.\r
1813 * @returns {CKEDITOR.dialog.definition.content} The inserted content definition.\r
1814 */\r
1815 addContents: function( contentDefinition, nextSiblingId ) {\r
1816 return addById( this.contents, contentDefinition, nextSiblingId );\r
1817 },\r
1818\r
1819 /**\r
1820 * Adds a button definition object under this dialog definition.\r
1821 *\r
1822 * @param {CKEDITOR.dialog.definition.button} buttonDefinition The\r
1823 * button definition.\r
1824 * @param {String} [nextSiblingId] The id of an existing button\r
1825 * definition which the new button definition will be inserted\r
1826 * before. Omit if the new button definition is to be inserted as\r
1827 * the last item.\r
1828 * @returns {CKEDITOR.dialog.definition.button} The inserted button definition.\r
1829 */\r
1830 addButton: function( buttonDefinition, nextSiblingId ) {\r
1831 return addById( this.buttons, buttonDefinition, nextSiblingId );\r
1832 },\r
1833\r
1834 /**\r
1835 * Removes a content definition from this dialog definition.\r
1836 *\r
1837 * @param {String} id The id of the content definition to be removed.\r
1838 * @returns {CKEDITOR.dialog.definition.content} The removed content definition.\r
1839 */\r
1840 removeContents: function( id ) {\r
1841 removeById( this.contents, id );\r
1842 },\r
1843\r
1844 /**\r
1845 * Removes a button definition from the dialog definition.\r
1846 *\r
1847 * @param {String} id The id of the button definition to be removed.\r
1848 * @returns {CKEDITOR.dialog.definition.button} The removed button definition.\r
1849 */\r
1850 removeButton: function( id ) {\r
1851 removeById( this.buttons, id );\r
1852 }\r
1853 };\r
1854\r
1855 /**\r
1856 * This class is not really part of the API. It is the template of the\r
1857 * objects representing content pages inside the\r
1858 * CKEDITOR.dialog.definitionObject.\r
1859 *\r
1860 * CKEDITOR.on( 'dialogDefinition', function( evt ) {\r
1861 * var definition = evt.data.definition;\r
1862 * var content = definition.getContents( 'page1' );\r
1863 * content.remove( 'textInput1' );\r
1864 * // ...\r
1865 * } );\r
1866 *\r
1867 * @private\r
1868 * @class CKEDITOR.dialog.definition.contentObject\r
1869 * @constructor Creates a contentObject class instance.\r
1870 */\r
1871 function contentObject( dialog, contentDefinition ) {\r
1872 this._ = {\r
1873 dialog: dialog\r
1874 };\r
1875\r
1876 CKEDITOR.tools.extend( this, contentDefinition );\r
1877 }\r
1878\r
1879 contentObject.prototype = {\r
1880 /**\r
1881 * Gets a UI element definition under the content definition.\r
1882 *\r
1883 * @param {String} id The id of the UI element definition.\r
1884 * @returns {CKEDITOR.dialog.definition.uiElement}\r
1885 */\r
1886 get: function( id ) {\r
1887 return getById( this.elements, id, 'children' );\r
1888 },\r
1889\r
1890 /**\r
1891 * Adds a UI element definition to the content definition.\r
1892 *\r
1893 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition The\r
1894 * UI elemnet definition to be added.\r
1895 * @param {String} nextSiblingId The id of an existing UI element\r
1896 * definition which the new UI element definition will be inserted\r
1897 * before. Omit if the new button definition is to be inserted as\r
1898 * the last item.\r
1899 * @returns {CKEDITOR.dialog.definition.uiElement} The element definition inserted.\r
1900 */\r
1901 add: function( elementDefinition, nextSiblingId ) {\r
1902 return addById( this.elements, elementDefinition, nextSiblingId, 'children' );\r
1903 },\r
1904\r
1905 /**\r
1906 * Removes a UI element definition from the content definition.\r
1907 *\r
1908 * @param {String} id The id of the UI element definition to be removed.\r
1909 * @returns {CKEDITOR.dialog.definition.uiElement} The element definition removed.\r
1910 */\r
1911 remove: function( id ) {\r
1912 removeById( this.elements, id, 'children' );\r
1913 }\r
1914 };\r
1915\r
1916 function initDragAndDrop( dialog ) {\r
1917 var lastCoords = null,\r
1918 abstractDialogCoords = null,\r
1919 editor = dialog.getParentEditor(),\r
1920 magnetDistance = editor.config.dialog_magnetDistance,\r
1921 margins = CKEDITOR.skin.margins || [ 0, 0, 0, 0 ];\r
1922\r
1923 if ( typeof magnetDistance == 'undefined' )\r
1924 magnetDistance = 20;\r
1925\r
1926 function mouseMoveHandler( evt ) {\r
1927 var dialogSize = dialog.getSize(),\r
1928 viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),\r
1929 x = evt.data.$.screenX,\r
1930 y = evt.data.$.screenY,\r
1931 dx = x - lastCoords.x,\r
1932 dy = y - lastCoords.y,\r
1933 realX, realY;\r
1934\r
1935 lastCoords = { x: x, y: y };\r
1936 abstractDialogCoords.x += dx;\r
1937 abstractDialogCoords.y += dy;\r
1938\r
1939 if ( abstractDialogCoords.x + margins[ 3 ] < magnetDistance )\r
1940 realX = -margins[ 3 ];\r
1941 else if ( abstractDialogCoords.x - margins[ 1 ] > viewPaneSize.width - dialogSize.width - magnetDistance )\r
1942 realX = viewPaneSize.width - dialogSize.width + ( editor.lang.dir == 'rtl' ? 0 : margins[ 1 ] );\r
1943 else\r
1944 realX = abstractDialogCoords.x;\r
1945\r
1946 if ( abstractDialogCoords.y + margins[ 0 ] < magnetDistance )\r
1947 realY = -margins[ 0 ];\r
1948 else if ( abstractDialogCoords.y - margins[ 2 ] > viewPaneSize.height - dialogSize.height - magnetDistance )\r
1949 realY = viewPaneSize.height - dialogSize.height + margins[ 2 ];\r
1950 else\r
1951 realY = abstractDialogCoords.y;\r
1952\r
1953 dialog.move( realX, realY, 1 );\r
1954\r
1955 evt.data.preventDefault();\r
1956 }\r
1957\r
1958 function mouseUpHandler() {\r
1959 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );\r
1960 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );\r
1961\r
1962 if ( CKEDITOR.env.ie6Compat ) {\r
1963 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
1964 coverDoc.removeListener( 'mousemove', mouseMoveHandler );\r
1965 coverDoc.removeListener( 'mouseup', mouseUpHandler );\r
1966 }\r
1967 }\r
1968\r
1969 dialog.parts.title.on( 'mousedown', function( evt ) {\r
1970 lastCoords = { x: evt.data.$.screenX, y: evt.data.$.screenY };\r
1971\r
1972 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );\r
1973 CKEDITOR.document.on( 'mouseup', mouseUpHandler );\r
1974 abstractDialogCoords = dialog.getPosition();\r
1975\r
1976 if ( CKEDITOR.env.ie6Compat ) {\r
1977 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
1978 coverDoc.on( 'mousemove', mouseMoveHandler );\r
1979 coverDoc.on( 'mouseup', mouseUpHandler );\r
1980 }\r
1981\r
1982 evt.data.preventDefault();\r
1983 }, dialog );\r
1984 }\r
1985\r
1986 function initResizeHandles( dialog ) {\r
1987 var def = dialog.definition,\r
1988 resizable = def.resizable;\r
1989\r
1990 if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE )\r
1991 return;\r
1992\r
1993 var editor = dialog.getParentEditor();\r
1994 var wrapperWidth, wrapperHeight, viewSize, origin, startSize, dialogCover;\r
1995\r
1996 var mouseDownFn = CKEDITOR.tools.addFunction( function( $event ) {\r
1997 startSize = dialog.getSize();\r
1998\r
1999 var content = dialog.parts.contents,\r
2000 iframeDialog = content.$.getElementsByTagName( 'iframe' ).length;\r
2001\r
2002 // Shim to help capturing "mousemove" over iframe.\r
2003 if ( iframeDialog ) {\r
2004 dialogCover = CKEDITOR.dom.element.createFromHtml( '<div class="cke_dialog_resize_cover" style="height: 100%; position: absolute; width: 100%;"></div>' );\r
2005 content.append( dialogCover );\r
2006 }\r
2007\r
2008 // Calculate the offset between content and chrome size.\r
2009 wrapperHeight = startSize.height - dialog.parts.contents.getSize( 'height', !( CKEDITOR.env.gecko || CKEDITOR.env.ie && CKEDITOR.env.quirks ) );\r
2010 wrapperWidth = startSize.width - dialog.parts.contents.getSize( 'width', 1 );\r
2011\r
2012 origin = { x: $event.screenX, y: $event.screenY };\r
2013\r
2014 viewSize = CKEDITOR.document.getWindow().getViewPaneSize();\r
2015\r
2016 CKEDITOR.document.on( 'mousemove', mouseMoveHandler );\r
2017 CKEDITOR.document.on( 'mouseup', mouseUpHandler );\r
2018\r
2019 if ( CKEDITOR.env.ie6Compat ) {\r
2020 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
2021 coverDoc.on( 'mousemove', mouseMoveHandler );\r
2022 coverDoc.on( 'mouseup', mouseUpHandler );\r
2023 }\r
2024\r
2025 $event.preventDefault && $event.preventDefault();\r
2026 } );\r
2027\r
2028 // Prepend the grip to the dialog.\r
2029 dialog.on( 'load', function() {\r
2030 var direction = '';\r
2031 if ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH )\r
2032 direction = ' cke_resizer_horizontal';\r
2033 else if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT )\r
2034 direction = ' cke_resizer_vertical';\r
2035 var resizer = CKEDITOR.dom.element.createFromHtml(\r
2036 '<div' +\r
2037 ' class="cke_resizer' + direction + ' cke_resizer_' + editor.lang.dir + '"' +\r
2038 ' title="' + CKEDITOR.tools.htmlEncode( editor.lang.common.resize ) + '"' +\r
2039 ' onmousedown="CKEDITOR.tools.callFunction(' + mouseDownFn + ', event )">' +\r
2040 // BLACK LOWER RIGHT TRIANGLE (ltr)\r
2041 // BLACK LOWER LEFT TRIANGLE (rtl)\r
2042 ( editor.lang.dir == 'ltr' ? '\u25E2' : '\u25E3' ) +\r
2043 '</div>' );\r
2044 dialog.parts.footer.append( resizer, 1 );\r
2045 } );\r
2046 editor.on( 'destroy', function() {\r
2047 CKEDITOR.tools.removeFunction( mouseDownFn );\r
2048 } );\r
2049\r
2050 function mouseMoveHandler( evt ) {\r
2051 var rtl = editor.lang.dir == 'rtl',\r
2052 dx = ( evt.data.$.screenX - origin.x ) * ( rtl ? -1 : 1 ),\r
2053 dy = evt.data.$.screenY - origin.y,\r
2054 width = startSize.width,\r
2055 height = startSize.height,\r
2056 internalWidth = width + dx * ( dialog._.moved ? 1 : 2 ),\r
2057 internalHeight = height + dy * ( dialog._.moved ? 1 : 2 ),\r
2058 element = dialog._.element.getFirst(),\r
2059 right = rtl && element.getComputedStyle( 'right' ),\r
2060 position = dialog.getPosition();\r
2061\r
2062 if ( position.y + internalHeight > viewSize.height )\r
2063 internalHeight = viewSize.height - position.y;\r
2064\r
2065 if ( ( rtl ? right : position.x ) + internalWidth > viewSize.width )\r
2066 internalWidth = viewSize.width - ( rtl ? right : position.x );\r
2067\r
2068 // Make sure the dialog will not be resized to the wrong side when it's in the leftmost position for RTL.\r
2069 if ( ( resizable == CKEDITOR.DIALOG_RESIZE_WIDTH || resizable == CKEDITOR.DIALOG_RESIZE_BOTH ) )\r
2070 width = Math.max( def.minWidth || 0, internalWidth - wrapperWidth );\r
2071\r
2072 if ( resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT || resizable == CKEDITOR.DIALOG_RESIZE_BOTH )\r
2073 height = Math.max( def.minHeight || 0, internalHeight - wrapperHeight );\r
2074\r
2075 dialog.resize( width, height );\r
2076\r
2077 if ( !dialog._.moved )\r
2078 dialog.layout();\r
2079\r
2080 evt.data.preventDefault();\r
2081 }\r
2082\r
2083 function mouseUpHandler() {\r
2084 CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );\r
2085 CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );\r
2086\r
2087 if ( dialogCover ) {\r
2088 dialogCover.remove();\r
2089 dialogCover = null;\r
2090 }\r
2091\r
2092 if ( CKEDITOR.env.ie6Compat ) {\r
2093 var coverDoc = currentCover.getChild( 0 ).getFrameDocument();\r
2094 coverDoc.removeListener( 'mouseup', mouseUpHandler );\r
2095 coverDoc.removeListener( 'mousemove', mouseMoveHandler );\r
2096 }\r
2097 }\r
2098 }\r
2099\r
2100 var resizeCover;\r
2101 // Caching resuable covers and allowing only one cover\r
2102 // on screen.\r
2103 var covers = {},\r
2104 currentCover;\r
2105\r
2106 function cancelEvent( ev ) {\r
2107 ev.data.preventDefault( 1 );\r
2108 }\r
2109\r
2110 function showCover( editor ) {\r
2111 var win = CKEDITOR.document.getWindow(),\r
2112 config = editor.config,\r
2113 skinName = ( CKEDITOR.skinName || editor.config.skin ),\r
2114 backgroundColorStyle = config.dialog_backgroundCoverColor || ( skinName == 'moono-lisa' ? 'black' : 'white' ),\r
2115 backgroundCoverOpacity = config.dialog_backgroundCoverOpacity,\r
2116 baseFloatZIndex = config.baseFloatZIndex,\r
2117 coverKey = CKEDITOR.tools.genKey( backgroundColorStyle, backgroundCoverOpacity, baseFloatZIndex ),\r
2118 coverElement = covers[ coverKey ];\r
2119\r
2120 if ( !coverElement ) {\r
2121 var html = [\r
2122 '<div tabIndex="-1" style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),\r
2123 '; z-index: ', baseFloatZIndex,\r
2124 '; top: 0px; left: 0px; ',\r
2125 ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),\r
2126 '" class="cke_dialog_background_cover">'\r
2127 ];\r
2128\r
2129 if ( CKEDITOR.env.ie6Compat ) {\r
2130 // Support for custom document.domain in IE.\r
2131 var iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';\r
2132\r
2133 html.push( '<iframe' +\r
2134 ' hidefocus="true"' +\r
2135 ' frameborder="0"' +\r
2136 ' id="cke_dialog_background_iframe"' +\r
2137 ' src="javascript:' );\r
2138\r
2139 html.push( 'void((function(){' + encodeURIComponent(\r
2140 'document.open();' +\r
2141 // Support for custom document.domain in IE.\r
2142 '(' + CKEDITOR.tools.fixDomain + ')();' +\r
2143 'document.write( \'' + iframeHtml + '\' );' +\r
2144 'document.close();'\r
2145 ) + '})())' );\r
2146\r
2147 html.push( '"' +\r
2148 ' style="' +\r
2149 'position:absolute;' +\r
2150 'left:0;' +\r
2151 'top:0;' +\r
2152 'width:100%;' +\r
2153 'height: 100%;' +\r
2154 'filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +\r
2155 '</iframe>' );\r
2156 }\r
2157\r
2158 html.push( '</div>' );\r
2159\r
2160 coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );\r
2161 coverElement.setOpacity( backgroundCoverOpacity !== undefined ? backgroundCoverOpacity : 0.5 );\r
2162\r
2163 coverElement.on( 'keydown', cancelEvent );\r
2164 coverElement.on( 'keypress', cancelEvent );\r
2165 coverElement.on( 'keyup', cancelEvent );\r
2166\r
2167 coverElement.appendTo( CKEDITOR.document.getBody() );\r
2168 covers[ coverKey ] = coverElement;\r
2169 } else {\r
2170 coverElement.show();\r
2171 }\r
2172\r
2173 // Makes the dialog cover a focus holder as well.\r
2174 editor.focusManager.add( coverElement );\r
2175\r
2176 currentCover = coverElement;\r
2177 var resizeFunc = function() {\r
2178 var size = win.getViewPaneSize();\r
2179 coverElement.setStyles( {\r
2180 width: size.width + 'px',\r
2181 height: size.height + 'px'\r
2182 } );\r
2183 };\r
2184\r
2185 var scrollFunc = function() {\r
2186 var pos = win.getScrollPosition(),\r
2187 cursor = CKEDITOR.dialog._.currentTop;\r
2188 coverElement.setStyles( {\r
2189 left: pos.x + 'px',\r
2190 top: pos.y + 'px'\r
2191 } );\r
2192\r
2193 if ( cursor ) {\r
2194 do {\r
2195 var dialogPos = cursor.getPosition();\r
2196 cursor.move( dialogPos.x, dialogPos.y );\r
2197 } while ( ( cursor = cursor._.parentDialog ) );\r
2198 }\r
2199 };\r
2200\r
2201 resizeCover = resizeFunc;\r
2202 win.on( 'resize', resizeFunc );\r
2203 resizeFunc();\r
1794320d 2204 // Using Safari/Mac, focus must be kept where it is (http://dev.ckeditor.com/ticket/7027)\r
c63493c8
IB
2205 if ( !( CKEDITOR.env.mac && CKEDITOR.env.webkit ) )\r
2206 coverElement.focus();\r
2207\r
2208 if ( CKEDITOR.env.ie6Compat ) {\r
2209 // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.\r
2210 // So we need to invent a really funny way to make it work.\r
2211 var myScrollHandler = function() {\r
2212 scrollFunc();\r
2213 arguments.callee.prevScrollHandler.apply( this, arguments );\r
2214 };\r
2215 win.$.setTimeout( function() {\r
2216 myScrollHandler.prevScrollHandler = window.onscroll ||\r
2217 function() {};\r
2218 window.onscroll = myScrollHandler;\r
2219 }, 0 );\r
2220 scrollFunc();\r
2221 }\r
2222 }\r
2223\r
2224 function hideCover( editor ) {\r
2225 if ( !currentCover )\r
2226 return;\r
2227\r
2228 editor.focusManager.remove( currentCover );\r
2229 var win = CKEDITOR.document.getWindow();\r
2230 currentCover.hide();\r
2231 win.removeListener( 'resize', resizeCover );\r
2232\r
2233 if ( CKEDITOR.env.ie6Compat ) {\r
2234 win.$.setTimeout( function() {\r
2235 var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;\r
2236 window.onscroll = prevScrollHandler || null;\r
2237 }, 0 );\r
2238 }\r
2239 resizeCover = null;\r
2240 }\r
2241\r
2242 function removeCovers() {\r
2243 for ( var coverId in covers )\r
2244 covers[ coverId ].remove();\r
2245 covers = {};\r
2246 }\r
2247\r
2248 var accessKeyProcessors = {};\r
2249\r
2250 var accessKeyDownHandler = function( evt ) {\r
2251 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,\r
2252 alt = evt.data.$.altKey,\r
2253 shift = evt.data.$.shiftKey,\r
2254 key = String.fromCharCode( evt.data.$.keyCode ),\r
2255 keyProcessor = accessKeyProcessors[ ( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '' ) + ( shift ? 'SHIFT+' : '' ) + key ];\r
2256\r
2257 if ( !keyProcessor || !keyProcessor.length )\r
2258 return;\r
2259\r
2260 keyProcessor = keyProcessor[ keyProcessor.length - 1 ];\r
2261 keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );\r
2262 evt.data.preventDefault();\r
2263 };\r
2264\r
2265 var accessKeyUpHandler = function( evt ) {\r
2266 var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,\r
2267 alt = evt.data.$.altKey,\r
2268 shift = evt.data.$.shiftKey,\r
2269 key = String.fromCharCode( evt.data.$.keyCode ),\r
2270 keyProcessor = accessKeyProcessors[ ( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '' ) + ( shift ? 'SHIFT+' : '' ) + key ];\r
2271\r
2272 if ( !keyProcessor || !keyProcessor.length )\r
2273 return;\r
2274\r
2275 keyProcessor = keyProcessor[ keyProcessor.length - 1 ];\r
2276 if ( keyProcessor.keyup ) {\r
2277 keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );\r
2278 evt.data.preventDefault();\r
2279 }\r
2280 };\r
2281\r
2282 var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc ) {\r
2283 var procList = accessKeyProcessors[ key ] || ( accessKeyProcessors[ key ] = [] );\r
2284 procList.push( {\r
2285 uiElement: uiElement,\r
2286 dialog: dialog,\r
2287 key: key,\r
2288 keyup: upFunc || uiElement.accessKeyUp,\r
2289 keydown: downFunc || uiElement.accessKeyDown\r
2290 } );\r
2291 };\r
2292\r
2293 var unregisterAccessKey = function( obj ) {\r
2294 for ( var i in accessKeyProcessors ) {\r
2295 var list = accessKeyProcessors[ i ];\r
2296 for ( var j = list.length - 1; j >= 0; j-- ) {\r
2297 if ( list[ j ].dialog == obj || list[ j ].uiElement == obj )\r
2298 list.splice( j, 1 );\r
2299 }\r
2300 if ( list.length === 0 )\r
2301 delete accessKeyProcessors[ i ];\r
2302 }\r
2303 };\r
2304\r
2305 var tabAccessKeyUp = function( dialog, key ) {\r
2306 if ( dialog._.accessKeyMap[ key ] )\r
2307 dialog.selectPage( dialog._.accessKeyMap[ key ] );\r
2308 };\r
2309\r
2310 var tabAccessKeyDown = function() {};\r
2311\r
2312 ( function() {\r
2313 CKEDITOR.ui.dialog = {\r
2314 /**\r
2315 * The base class of all dialog UI elements.\r
2316 *\r
2317 * @class CKEDITOR.ui.dialog.uiElement\r
2318 * @constructor Creates a uiElement class instance.\r
2319 * @param {CKEDITOR.dialog} dialog Parent dialog object.\r
2320 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition Element\r
2321 * definition.\r
2322 *\r
2323 * Accepted fields:\r
2324 *\r
2325 * * `id` (Required) The id of the UI element. See {@link CKEDITOR.dialog#getContentElement}.\r
2326 * * `type` (Required) The type of the UI element. The\r
2327 * value to this field specifies which UI element class will be used to\r
2328 * generate the final widget.\r
2329 * * `title` (Optional) The popup tooltip for the UI\r
2330 * element.\r
2331 * * `hidden` (Optional) A flag that tells if the element\r
2332 * should be initially visible.\r
2333 * * `className` (Optional) Additional CSS class names\r
2334 * to add to the UI element. Separated by space.\r
2335 * * `style` (Optional) Additional CSS inline styles\r
2336 * to add to the UI element. A semicolon (;) is required after the last\r
2337 * style declaration.\r
2338 * * `accessKey` (Optional) The alphanumeric access key\r
2339 * for this element. Access keys are automatically prefixed by CTRL.\r
2340 * * `on*` (Optional) Any UI element definition field that\r
2341 * starts with `on` followed immediately by a capital letter and\r
2342 * probably more letters is an event handler. Event handlers may be further\r
2343 * divided into registered event handlers and DOM event handlers. Please\r
2344 * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and\r
2345 * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more information.\r
2346 *\r
2347 * @param {Array} htmlList\r
2348 * List of HTML code to be added to the dialog's content area.\r
2349 * @param {Function/String} [nodeNameArg='div']\r
2350 * A function returning a string, or a simple string for the node name for\r
2351 * the root DOM node.\r
2352 * @param {Function/Object} [stylesArg={}]\r
2353 * A function returning an object, or a simple object for CSS styles applied\r
2354 * to the DOM node.\r
2355 * @param {Function/Object} [attributesArg={}]\r
2356 * A fucntion returning an object, or a simple object for attributes applied\r
2357 * to the DOM node.\r
2358 * @param {Function/String} [contentsArg='']\r
2359 * A function returning a string, or a simple string for the HTML code inside\r
2360 * the root DOM node. Default is empty string.\r
2361 */\r
2362 uiElement: function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg ) {\r
2363 if ( arguments.length < 4 )\r
2364 return;\r
2365\r
2366 var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',\r
2367 html = [ '<', nodeName, ' ' ],\r
2368 styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},\r
2369 attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},\r
2370 innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',\r
2371 domId = this.domId = attributes.id || CKEDITOR.tools.getNextId() + '_uiElement',\r
2372 i;\r
2373\r
2374 if ( elementDefinition.requiredContent && !dialog.getParentEditor().filter.check( elementDefinition.requiredContent ) ) {\r
2375 styles.display = 'none';\r
2376 this.notAllowed = true;\r
2377 }\r
2378\r
2379 // Set the id, a unique id is required for getElement() to work.\r
2380 attributes.id = domId;\r
2381\r
2382 // Set the type and definition CSS class names.\r
2383 var classes = {};\r
2384 if ( elementDefinition.type )\r
2385 classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;\r
2386 if ( elementDefinition.className )\r
2387 classes[ elementDefinition.className ] = 1;\r
2388 if ( elementDefinition.disabled )\r
2389 classes.cke_disabled = 1;\r
2390\r
2391 var attributeClasses = ( attributes[ 'class' ] && attributes[ 'class' ].split ) ? attributes[ 'class' ].split( ' ' ) : [];\r
2392 for ( i = 0; i < attributeClasses.length; i++ ) {\r
2393 if ( attributeClasses[ i ] )\r
2394 classes[ attributeClasses[ i ] ] = 1;\r
2395 }\r
2396 var finalClasses = [];\r
2397 for ( i in classes )\r
2398 finalClasses.push( i );\r
2399 attributes[ 'class' ] = finalClasses.join( ' ' );\r
2400\r
2401 // Set the popup tooltop.\r
2402 if ( elementDefinition.title )\r
2403 attributes.title = elementDefinition.title;\r
2404\r
2405 // Write the inline CSS styles.\r
2406 var styleStr = ( elementDefinition.style || '' ).split( ';' );\r
2407\r
2408 // Element alignment support.\r
2409 if ( elementDefinition.align ) {\r
2410 var align = elementDefinition.align;\r
2411 styles[ 'margin-left' ] = align == 'left' ? 0 : 'auto';\r
2412 styles[ 'margin-right' ] = align == 'right' ? 0 : 'auto';\r
2413 }\r
2414\r
2415 for ( i in styles )\r
2416 styleStr.push( i + ':' + styles[ i ] );\r
2417 if ( elementDefinition.hidden )\r
2418 styleStr.push( 'display:none' );\r
2419 for ( i = styleStr.length - 1; i >= 0; i-- ) {\r
2420 if ( styleStr[ i ] === '' )\r
2421 styleStr.splice( i, 1 );\r
2422 }\r
2423 if ( styleStr.length > 0 )\r
2424 attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );\r
2425\r
2426 // Write the attributes.\r
2427 for ( i in attributes )\r
2428 html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[ i ] ) + '" ' );\r
2429\r
2430 // Write the content HTML.\r
2431 html.push( '>', innerHTML, '</', nodeName, '>' );\r
2432\r
2433 // Add contents to the parent HTML array.\r
2434 htmlList.push( html.join( '' ) );\r
2435\r
2436 ( this._ || ( this._ = {} ) ).dialog = dialog;\r
2437\r
2438 // Override isChanged if it is defined in element definition.\r
2439 if ( typeof elementDefinition.isChanged == 'boolean' )\r
2440 this.isChanged = function() {\r
2441 return elementDefinition.isChanged;\r
2442 };\r
2443 if ( typeof elementDefinition.isChanged == 'function' )\r
2444 this.isChanged = elementDefinition.isChanged;\r
2445\r
2446 // Overload 'get(set)Value' on definition.\r
2447 if ( typeof elementDefinition.setValue == 'function' ) {\r
2448 this.setValue = CKEDITOR.tools.override( this.setValue, function( org ) {\r
2449 return function( val ) {\r
2450 org.call( this, elementDefinition.setValue.call( this, val ) );\r
2451 };\r
2452 } );\r
2453 }\r
2454\r
2455 if ( typeof elementDefinition.getValue == 'function' ) {\r
2456 this.getValue = CKEDITOR.tools.override( this.getValue, function( org ) {\r
2457 return function() {\r
2458 return elementDefinition.getValue.call( this, org.call( this ) );\r
2459 };\r
2460 } );\r
2461 }\r
2462\r
2463 // Add events.\r
2464 CKEDITOR.event.implementOn( this );\r
2465\r
2466 this.registerEvents( elementDefinition );\r
2467 if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )\r
2468 registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );\r
2469\r
2470 var me = this;\r
2471 dialog.on( 'load', function() {\r
2472 var input = me.getInputElement();\r
2473 if ( input ) {\r
2474 var focusClass = me.type in { 'checkbox': 1, 'ratio': 1 } && CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? 'cke_dialog_ui_focused' : '';\r
2475 input.on( 'focus', function() {\r
2476 dialog._.tabBarMode = false;\r
2477 dialog._.hasFocus = true;\r
2478 me.fire( 'focus' );\r
2479 focusClass && this.addClass( focusClass );\r
2480\r
2481 } );\r
2482\r
2483 input.on( 'blur', function() {\r
2484 me.fire( 'blur' );\r
2485 focusClass && this.removeClass( focusClass );\r
2486 } );\r
2487 }\r
2488 } );\r
2489\r
2490 // Completes this object with everything we have in the\r
2491 // definition.\r
2492 CKEDITOR.tools.extend( this, elementDefinition );\r
2493\r
2494 // Register the object as a tab focus if it can be included.\r
2495 if ( this.keyboardFocusable ) {\r
2496 this.tabIndex = elementDefinition.tabIndex || 0;\r
2497\r
2498 this.focusIndex = dialog._.focusList.push( this ) - 1;\r
2499 this.on( 'focus', function() {\r
2500 dialog._.currentFocusIndex = me.focusIndex;\r
2501 } );\r
2502 }\r
2503 },\r
2504\r
2505 /**\r
2506 * Horizontal layout box for dialog UI elements, auto-expends to available width of container.\r
2507 *\r
2508 * @class CKEDITOR.ui.dialog.hbox\r
2509 * @extends CKEDITOR.ui.dialog.uiElement\r
2510 * @constructor Creates a hbox class instance.\r
2511 * @param {CKEDITOR.dialog} dialog Parent dialog object.\r
2512 * @param {Array} childObjList\r
2513 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this container.\r
2514 * @param {Array} childHtmlList\r
2515 * Array of HTML code that correspond to the HTML output of all the\r
2516 * objects in childObjList.\r
2517 * @param {Array} htmlList\r
2518 * Array of HTML code that this element will output to.\r
2519 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition\r
2520 * The element definition. Accepted fields:\r
2521 *\r
2522 * * `widths` (Optional) The widths of child cells.\r
2523 * * `height` (Optional) The height of the layout.\r
2524 * * `padding` (Optional) The padding width inside child cells.\r
2525 * * `align` (Optional) The alignment of the whole layout.\r
2526 */\r
2527 hbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {\r
2528 if ( arguments.length < 4 )\r
2529 return;\r
2530\r
2531 this._ || ( this._ = {} );\r
2532\r
2533 var children = this._.children = childObjList,\r
2534 widths = elementDefinition && elementDefinition.widths || null,\r
2535 height = elementDefinition && elementDefinition.height || null,\r
2536 styles = {},\r
2537 i;\r
2538 /** @ignore */\r
2539 var innerHTML = function() {\r
2540 var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];\r
2541 for ( i = 0; i < childHtmlList.length; i++ ) {\r
2542 var className = 'cke_dialog_ui_hbox_child',\r
2543 styles = [];\r
2544 if ( i === 0 ) {\r
2545 className = 'cke_dialog_ui_hbox_first';\r
2546 }\r
2547 if ( i == childHtmlList.length - 1 ) {\r
2548 className = 'cke_dialog_ui_hbox_last';\r
2549 }\r
2550\r
2551 html.push( '<td class="', className, '" role="presentation" ' );\r
2552 if ( widths ) {\r
2553 if ( widths[ i ] ) {\r
2554 styles.push( 'width:' + cssLength( widths[i] ) );\r
2555 }\r
2556 } else {\r
2557 styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );\r
2558 }\r
2559 if ( height ) {\r
2560 styles.push( 'height:' + cssLength( height ) );\r
2561 }\r
2562 if ( elementDefinition && elementDefinition.padding !== undefined ) {\r
2563 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );\r
2564 }\r
1794320d 2565 // In IE Quirks alignment has to be done on table cells. (http://dev.ckeditor.com/ticket/7324)\r
c63493c8
IB
2566 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align ) {\r
2567 styles.push( 'text-align:' + children[ i ].align );\r
2568 }\r
2569 if ( styles.length > 0 ) {\r
2570 html.push( 'style="' + styles.join( '; ' ) + '" ' );\r
2571 }\r
2572 html.push( '>', childHtmlList[ i ], '</td>' );\r
2573 }\r
2574 html.push( '</tr></tbody>' );\r
2575 return html.join( '' );\r
2576 };\r
2577\r
2578 var attribs = { role: 'presentation' };\r
2579 elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );\r
2580\r
2581 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'hbox' }, htmlList, 'table', styles, attribs, innerHTML );\r
2582 },\r
2583\r
2584 /**\r
2585 * Vertical layout box for dialog UI elements.\r
2586 *\r
2587 * @class CKEDITOR.ui.dialog.vbox\r
2588 * @extends CKEDITOR.ui.dialog.hbox\r
2589 * @constructor Creates a vbox class instance.\r
2590 * @param {CKEDITOR.dialog} dialog Parent dialog object.\r
2591 * @param {Array} childObjList\r
2592 * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this container.\r
2593 * @param {Array} childHtmlList\r
2594 * Array of HTML code that correspond to the HTML output of all the\r
2595 * objects in childObjList.\r
2596 * @param {Array} htmlList Array of HTML code that this element will output to.\r
2597 * @param {CKEDITOR.dialog.definition.uiElement} elementDefinition\r
2598 * The element definition. Accepted fields:\r
2599 *\r
2600 * * `width` (Optional) The width of the layout.\r
2601 * * `heights` (Optional) The heights of individual cells.\r
2602 * * `align` (Optional) The alignment of the layout.\r
2603 * * `padding` (Optional) The padding width inside child cells.\r
2604 * * `expand` (Optional) Whether the layout should expand\r
2605 * vertically to fill its container.\r
2606 */\r
2607 vbox: function( dialog, childObjList, childHtmlList, htmlList, elementDefinition ) {\r
2608 if ( arguments.length < 3 )\r
2609 return;\r
2610\r
2611 this._ || ( this._ = {} );\r
2612\r
2613 var children = this._.children = childObjList,\r
2614 width = elementDefinition && elementDefinition.width || null,\r
2615 heights = elementDefinition && elementDefinition.heights || null;\r
2616 /** @ignore */\r
2617 var innerHTML = function() {\r
2618 var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];\r
2619 html.push( 'style="' );\r
2620 if ( elementDefinition && elementDefinition.expand )\r
2621 html.push( 'height:100%;' );\r
2622 html.push( 'width:' + cssLength( width || '100%' ), ';' );\r
2623\r
1794320d 2624 // (http://dev.ckeditor.com/ticket/10123) Temp fix for dialog broken layout in latest webkit.\r
c63493c8
IB
2625 if ( CKEDITOR.env.webkit )\r
2626 html.push( 'float:none;' );\r
2627\r
2628 html.push( '"' );\r
2629 html.push( 'align="', CKEDITOR.tools.htmlEncode(\r
2630 ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );\r
2631\r
2632 html.push( '><tbody>' );\r
2633 for ( var i = 0; i < childHtmlList.length; i++ ) {\r
2634 var styles = [];\r
2635 html.push( '<tr><td role="presentation" ' );\r
2636 if ( width )\r
2637 styles.push( 'width:' + cssLength( width || '100%' ) );\r
2638 if ( heights )\r
2639 styles.push( 'height:' + cssLength( heights[ i ] ) );\r
2640 else if ( elementDefinition && elementDefinition.expand )\r
2641 styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );\r
2642 if ( elementDefinition && elementDefinition.padding !== undefined )\r
2643 styles.push( 'padding:' + cssLength( elementDefinition.padding ) );\r
1794320d 2644 // In IE Quirks alignment has to be done on table cells. (http://dev.ckeditor.com/ticket/7324)\r
c63493c8
IB
2645 if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && children[ i ].align )\r
2646 styles.push( 'text-align:' + children[ i ].align );\r
2647 if ( styles.length > 0 )\r
2648 html.push( 'style="', styles.join( '; ' ), '" ' );\r
2649 html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[ i ], '</td></tr>' );\r
2650 }\r
2651 html.push( '</tbody></table>' );\r
2652 return html.join( '' );\r
2653 };\r
2654 CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type: 'vbox' }, htmlList, 'div', null, { role: 'presentation' }, innerHTML );\r
2655 }\r
2656 };\r
2657 } )();\r
2658\r
2659 /** @class CKEDITOR.ui.dialog.uiElement */\r
2660 CKEDITOR.ui.dialog.uiElement.prototype = {\r
2661 /**\r
2662 * Gets the root DOM element of this dialog UI object.\r
2663 *\r
2664 * uiElement.getElement().hide();\r
2665 *\r
2666 * @returns {CKEDITOR.dom.element} Root DOM element of UI object.\r
2667 */\r
2668 getElement: function() {\r
2669 return CKEDITOR.document.getById( this.domId );\r
2670 },\r
2671\r
2672 /**\r
2673 * Gets the DOM element that the user inputs values.\r
2674 *\r
2675 * This function is used by {@link #setValue}, {@link #getValue} and {@link #focus}. It should\r
2676 * be overrided in child classes where the input element isn't the root\r
2677 * element.\r
2678 *\r
2679 * var rawValue = textInput.getInputElement().$.value;\r
2680 *\r
2681 * @returns {CKEDITOR.dom.element} The element where the user input values.\r
2682 */\r
2683 getInputElement: function() {\r
2684 return this.getElement();\r
2685 },\r
2686\r
2687 /**\r
2688 * Gets the parent dialog object containing this UI element.\r
2689 *\r
2690 * var dialog = uiElement.getDialog();\r
2691 *\r
2692 * @returns {CKEDITOR.dialog} Parent dialog object.\r
2693 */\r
2694 getDialog: function() {\r
2695 return this._.dialog;\r
2696 },\r
2697\r
2698 /**\r
2699 * Sets the value of this dialog UI object.\r
2700 *\r
2701 * uiElement.setValue( 'Dingo' );\r
2702 *\r
2703 * @chainable\r
2704 * @param {Object} value The new value.\r
2705 * @param {Boolean} noChangeEvent Internal commit, to supress `change` event on this element.\r
2706 */\r
2707 setValue: function( value, noChangeEvent ) {\r
2708 this.getInputElement().setValue( value );\r
2709 !noChangeEvent && this.fire( 'change', { value: value } );\r
2710 return this;\r
2711 },\r
2712\r
2713 /**\r
2714 * Gets the current value of this dialog UI object.\r
2715 *\r
2716 * var myValue = uiElement.getValue();\r
2717 *\r
2718 * @returns {Object} The current value.\r
2719 */\r
2720 getValue: function() {\r
2721 return this.getInputElement().getValue();\r
2722 },\r
2723\r
2724 /**\r
2725 * Tells whether the UI object's value has changed.\r
2726 *\r
2727 * if ( uiElement.isChanged() )\r
2728 * confirm( 'Value changed! Continue?' );\r
2729 *\r
2730 * @returns {Boolean} `true` if changed, `false` if not changed.\r
2731 */\r
2732 isChanged: function() {\r
2733 // Override in input classes.\r
2734 return false;\r
2735 },\r
2736\r
2737 /**\r
2738 * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.\r
2739 *\r
2740 * focus : function() {\r
2741 * this.selectParentTab();\r
2742 * // do something else.\r
2743 * }\r
2744 *\r
2745 * @chainable\r
2746 */\r
2747 selectParentTab: function() {\r
2748 var element = this.getInputElement(),\r
2749 cursor = element,\r
2750 tabId;\r
2751 while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 ) {\r
2752\r
2753 }\r
2754\r
2755 // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).\r
2756 if ( !cursor )\r
2757 return this;\r
2758\r
2759 tabId = cursor.getAttribute( 'name' );\r
2760 // Avoid duplicate select.\r
2761 if ( this._.dialog._.currentTabId != tabId )\r
2762 this._.dialog.selectPage( tabId );\r
2763 return this;\r
2764 },\r
2765\r
2766 /**\r
2767 * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.\r
2768 *\r
2769 * uiElement.focus();\r
2770 *\r
2771 * @chainable\r
2772 */\r
2773 focus: function() {\r
2774 this.selectParentTab().getInputElement().focus();\r
2775 return this;\r
2776 },\r
2777\r
2778 /**\r
2779 * Registers the `on*` event handlers defined in the element definition.\r
2780 *\r
2781 * The default behavior of this function is:\r
2782 *\r
2783 * 1. If the on* event is defined in the class's eventProcesors list,\r
2784 * then the registration is delegated to the corresponding function\r
2785 * in the eventProcessors list.\r
2786 * 2. If the on* event is not defined in the eventProcessors list, then\r
2787 * register the event handler under the corresponding DOM event of\r
2788 * the UI element's input DOM element (as defined by the return value\r
2789 * of {@link #getInputElement}).\r
2790 *\r
2791 * This function is only called at UI element instantiation, but can\r
2792 * be overridded in child classes if they require more flexibility.\r
2793 *\r
2794 * @chainable\r
2795 * @param {CKEDITOR.dialog.definition.uiElement} definition The UI element\r
2796 * definition.\r
2797 */\r
2798 registerEvents: function( definition ) {\r
2799 var regex = /^on([A-Z]\w+)/,\r
2800 match;\r
2801\r
2802 var registerDomEvent = function( uiElement, dialog, eventName, func ) {\r
2803 dialog.on( 'load', function() {\r
2804 uiElement.getInputElement().on( eventName, func, uiElement );\r
2805 } );\r
2806 };\r
2807\r
2808 for ( var i in definition ) {\r
2809 if ( !( match = i.match( regex ) ) )\r
2810 continue;\r
2811 if ( this.eventProcessors[ i ] )\r
2812 this.eventProcessors[ i ].call( this, this._.dialog, definition[ i ] );\r
2813 else\r
2814 registerDomEvent( this, this._.dialog, match[ 1 ].toLowerCase(), definition[ i ] );\r
2815 }\r
2816\r
2817 return this;\r
2818 },\r
2819\r
2820 /**\r
2821 * The event processor list used by\r
2822 * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element\r
2823 * instantiation. The default list defines three `on*` events:\r
2824 *\r
2825 * 1. `onLoad` - Called when the element's parent dialog opens for the\r
2826 * first time.\r
2827 * 2. `onShow` - Called whenever the element's parent dialog opens.\r
2828 * 3. `onHide` - Called whenever the element's parent dialog closes.\r
2829 *\r
2830 * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick\r
2831 * // handlers in the UI element's definitions.\r
2832 * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},\r
2833 * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,\r
2834 * { onClick : function( dialog, func ) { this.on( 'click', func ); } },\r
2835 * true\r
2836 * );\r
2837 *\r
2838 * @property {Object}\r
2839 */\r
2840 eventProcessors: {\r
2841 onLoad: function( dialog, func ) {\r
2842 dialog.on( 'load', func, this );\r
2843 },\r
2844\r
2845 onShow: function( dialog, func ) {\r
2846 dialog.on( 'show', func, this );\r
2847 },\r
2848\r
2849 onHide: function( dialog, func ) {\r
2850 dialog.on( 'hide', func, this );\r
2851 }\r
2852 },\r
2853\r
2854 /**\r
2855 * The default handler for a UI element's access key down event, which\r
2856 * tries to put focus to the UI element.\r
2857 *\r
2858 * Can be overridded in child classes for more sophisticaed behavior.\r
2859 *\r
2860 * @param {CKEDITOR.dialog} dialog The parent dialog object.\r
2861 * @param {String} key The key combination pressed. Since access keys\r
2862 * are defined to always include the `CTRL` key, its value should always\r
2863 * include a `'CTRL+'` prefix.\r
2864 */\r
2865 accessKeyDown: function() {\r
2866 this.focus();\r
2867 },\r
2868\r
2869 /**\r
2870 * The default handler for a UI element's access key up event, which\r
2871 * does nothing.\r
2872 *\r
2873 * Can be overridded in child classes for more sophisticated behavior.\r
2874 *\r
2875 * @param {CKEDITOR.dialog} dialog The parent dialog object.\r
2876 * @param {String} key The key combination pressed. Since access keys\r
2877 * are defined to always include the `CTRL` key, its value should always\r
2878 * include a `'CTRL+'` prefix.\r
2879 */\r
2880 accessKeyUp: function() {},\r
2881\r
2882 /**\r
2883 * Disables a UI element.\r
2884 */\r
2885 disable: function() {\r
2886 var element = this.getElement(),\r
2887 input = this.getInputElement();\r
2888 input.setAttribute( 'disabled', 'true' );\r
2889 element.addClass( 'cke_disabled' );\r
2890 },\r
2891\r
2892 /**\r
2893 * Enables a UI element.\r
2894 */\r
2895 enable: function() {\r
2896 var element = this.getElement(),\r
2897 input = this.getInputElement();\r
2898 input.removeAttribute( 'disabled' );\r
2899 element.removeClass( 'cke_disabled' );\r
2900 },\r
2901\r
2902 /**\r
2903 * Determines whether an UI element is enabled or not.\r
2904 *\r
2905 * @returns {Boolean} Whether the UI element is enabled.\r
2906 */\r
2907 isEnabled: function() {\r
2908 return !this.getElement().hasClass( 'cke_disabled' );\r
2909 },\r
2910\r
2911 /**\r
2912 * Determines whether an UI element is visible or not.\r
2913 *\r
2914 * @returns {Boolean} Whether the UI element is visible.\r
2915 */\r
2916 isVisible: function() {\r
2917 return this.getInputElement().isVisible();\r
2918 },\r
2919\r
2920 /**\r
2921 * Determines whether an UI element is focus-able or not.\r
2922 * Focus-able is defined as being both visible and enabled.\r
2923 *\r
2924 * @returns {Boolean} Whether the UI element can be focused.\r
2925 */\r
2926 isFocusable: function() {\r
2927 if ( !this.isEnabled() || !this.isVisible() )\r
2928 return false;\r
2929 return true;\r
2930 }\r
2931 };\r
2932\r
2933 /** @class CKEDITOR.ui.dialog.hbox */\r
2934 CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement(), {\r
2935 /**\r
2936 * Gets a child UI element inside this container.\r
2937 *\r
2938 * var checkbox = hbox.getChild( [0,1] );\r
2939 * checkbox.setValue( true );\r
2940 *\r
2941 * @param {Array/Number} indices An array or a single number to indicate the child's\r
2942 * position in the container's descendant tree. Omit to get all the children in an array.\r
2943 * @returns {Array/CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container\r
2944 * if no argument given, or the specified UI element if indices is given.\r
2945 */\r
2946 getChild: function( indices ) {\r
2947 // If no arguments, return a clone of the children array.\r
2948 if ( arguments.length < 1 )\r
2949 return this._.children.concat();\r
2950\r
2951 // If indices isn't array, make it one.\r
2952 if ( !indices.splice )\r
2953 indices = [ indices ];\r
2954\r
2955 // Retrieve the child element according to tree position.\r
2956 if ( indices.length < 2 )\r
2957 return this._.children[ indices[ 0 ] ];\r
2958 else\r
2959 return ( this._.children[ indices[ 0 ] ] && this._.children[ indices[ 0 ] ].getChild ) ? this._.children[ indices[ 0 ] ].getChild( indices.slice( 1, indices.length ) ) : null;\r
2960 }\r
2961 }, true );\r
2962\r
2963 CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();\r
2964\r
2965 ( function() {\r
2966 var commonBuilder = {\r
2967 build: function( dialog, elementDefinition, output ) {\r
2968 var children = elementDefinition.children,\r
2969 child,\r
2970 childHtmlList = [],\r
2971 childObjList = [];\r
2972 for ( var i = 0;\r
2973 ( i < children.length && ( child = children[ i ] ) ); i++ ) {\r
2974 var childHtml = [];\r
2975 childHtmlList.push( childHtml );\r
2976 childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );\r
2977 }\r
2978 return new CKEDITOR.ui.dialog[ elementDefinition.type ]( dialog, childObjList, childHtmlList, output, elementDefinition );\r
2979 }\r
2980 };\r
2981\r
2982 CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );\r
2983 CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );\r
2984 } )();\r
2985\r
2986 /**\r
2987 * Generic dialog command. It opens a specific dialog when executed.\r
2988 *\r
1794320d 2989 * // Register the "link" command which opens the "link" dialog.\r
c63493c8
IB
2990 * editor.addCommand( 'link', new CKEDITOR.dialogCommand( 'link' ) );\r
2991 *\r
2992 * @class\r
2993 * @constructor Creates a dialogCommand class instance.\r
2994 * @extends CKEDITOR.commandDefinition\r
2995 * @param {String} dialogName The name of the dialog to open when executing\r
2996 * this command.\r
2997 * @param {Object} [ext] Additional command definition's properties.\r
1794320d
IB
2998 * @param {String} [ext.tabId] You can provide additional property (`tabId`) if you wish to open the dialog on a specific tabId.\r
2999 *\r
3000 * // Open the dialog on the 'keystroke' tabId.\r
3001 * editor.addCommand( 'keystroke', new CKEDITOR.dialogCommand( 'a11yHelp', { tabId: 'keystroke' } ) );\r
c63493c8
IB
3002 */\r
3003 CKEDITOR.dialogCommand = function( dialogName, ext ) {\r
3004 this.dialogName = dialogName;\r
3005 CKEDITOR.tools.extend( this, ext, true );\r
3006 };\r
3007\r
3008 CKEDITOR.dialogCommand.prototype = {\r
3009 exec: function( editor ) {\r
1794320d
IB
3010 var tabId = this.tabId;\r
3011 editor.openDialog( this.dialogName, function( dialog ) {\r
3012 // Select different tab if it's provided (#830).\r
3013 if ( tabId ) {\r
3014 dialog.selectPage( tabId );\r
3015 }\r
3016 } );\r
c63493c8
IB
3017 },\r
3018\r
3019 // Dialog commands just open a dialog ui, thus require no undo logic,\r
3020 // undo support should dedicate to specific dialog implementation.\r
3021 canUndo: false,\r
3022\r
3023 editorFocus: 1\r
3024 };\r
3025\r
3026 ( function() {\r
3027 var notEmptyRegex = /^([a]|[^a])+$/,\r
3028 integerRegex = /^\d*$/,\r
3029 numberRegex = /^\d*(?:\.\d+)?$/,\r
3030 htmlLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|\%)?)?$/,\r
3031 cssLengthRegex = /^(((\d*(\.\d+))|(\d*))(px|em|ex|in|cm|mm|pt|pc|\%)?)?$/i,\r
3032 inlineStyleRegex = /^(\s*[\w-]+\s*:\s*[^:;]+(?:;|$))*$/;\r
3033\r
3034 CKEDITOR.VALIDATE_OR = 1;\r
3035 CKEDITOR.VALIDATE_AND = 2;\r
3036\r
3037 CKEDITOR.dialog.validate = {\r
3038 functions: function() {\r
3039 var args = arguments;\r
3040 return function() {\r
3041 /**\r
3042 * It's important for validate functions to be able to accept the value\r
3043 * as argument in addition to this.getValue(), so that it is possible to\r
3044 * combine validate functions together to make more sophisticated\r
3045 * validators.\r
3046 */\r
3047 var value = this && this.getValue ? this.getValue() : args[ 0 ];\r
3048\r
3049 var msg,\r
3050 relation = CKEDITOR.VALIDATE_AND,\r
3051 functions = [],\r
3052 i;\r
3053\r
3054 for ( i = 0; i < args.length; i++ ) {\r
3055 if ( typeof args[ i ] == 'function' )\r
3056 functions.push( args[ i ] );\r
3057 else\r
3058 break;\r
3059 }\r
3060\r
3061 if ( i < args.length && typeof args[ i ] == 'string' ) {\r
3062 msg = args[ i ];\r
3063 i++;\r
3064 }\r
3065\r
3066 if ( i < args.length && typeof args[ i ] == 'number' )\r
3067 relation = args[ i ];\r
3068\r
3069 var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );\r
3070 for ( i = 0; i < functions.length; i++ ) {\r
3071 if ( relation == CKEDITOR.VALIDATE_AND )\r
3072 passed = passed && functions[ i ]( value );\r
3073 else\r
3074 passed = passed || functions[ i ]( value );\r
3075 }\r
3076\r
3077 return !passed ? msg : true;\r
3078 };\r
3079 },\r
3080\r
3081 regex: function( regex, msg ) {\r
3082 /*\r
3083 * Can be greatly shortened by deriving from functions validator if code size\r
3084 * turns out to be more important than performance.\r
3085 */\r
3086 return function() {\r
3087 var value = this && this.getValue ? this.getValue() : arguments[ 0 ];\r
3088 return !regex.test( value ) ? msg : true;\r
3089 };\r
3090 },\r
3091\r
3092 notEmpty: function( msg ) {\r
3093 return this.regex( notEmptyRegex, msg );\r
3094 },\r
3095\r
3096 integer: function( msg ) {\r
3097 return this.regex( integerRegex, msg );\r
3098 },\r
3099\r
3100 'number': function( msg ) {\r
3101 return this.regex( numberRegex, msg );\r
3102 },\r
3103\r
3104 'cssLength': function( msg ) {\r
3105 return this.functions( function( val ) {\r
3106 return cssLengthRegex.test( CKEDITOR.tools.trim( val ) );\r
3107 }, msg );\r
3108 },\r
3109\r
3110 'htmlLength': function( msg ) {\r
3111 return this.functions( function( val ) {\r
3112 return htmlLengthRegex.test( CKEDITOR.tools.trim( val ) );\r
3113 }, msg );\r
3114 },\r
3115\r
3116 'inlineStyle': function( msg ) {\r
3117 return this.functions( function( val ) {\r
3118 return inlineStyleRegex.test( CKEDITOR.tools.trim( val ) );\r
3119 }, msg );\r
3120 },\r
3121\r
3122 equals: function( value, msg ) {\r
3123 return this.functions( function( val ) {\r
3124 return val == value;\r
3125 }, msg );\r
3126 },\r
3127\r
3128 notEqual: function( value, msg ) {\r
3129 return this.functions( function( val ) {\r
3130 return val != value;\r
3131 }, msg );\r
3132 }\r
3133 };\r
3134\r
3135 CKEDITOR.on( 'instanceDestroyed', function( evt ) {\r
3136 // Remove dialog cover on last instance destroy.\r
3137 if ( CKEDITOR.tools.isEmpty( CKEDITOR.instances ) ) {\r
3138 var currentTopDialog;\r
3139 while ( ( currentTopDialog = CKEDITOR.dialog._.currentTop ) )\r
3140 currentTopDialog.hide();\r
3141 removeCovers();\r
3142 }\r
3143\r
3144 var dialogs = evt.editor._.storedDialogs;\r
3145 for ( var name in dialogs )\r
3146 dialogs[ name ].destroy();\r
3147\r
3148 } );\r
3149\r
3150 } )();\r
3151\r
3152 // Extend the CKEDITOR.editor class with dialog specific functions.\r
3153 CKEDITOR.tools.extend( CKEDITOR.editor.prototype, {\r
3154 /**\r
3155 * Loads and opens a registered dialog.\r
3156 *\r
3157 * CKEDITOR.instances.editor1.openDialog( 'smiley' );\r
3158 *\r
3159 * @member CKEDITOR.editor\r
3160 * @param {String} dialogName The registered name of the dialog.\r
3161 * @param {Function} callback The function to be invoked after dialog instance created.\r
3162 * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed.\r
3163 * `null` if the dialog name is not registered.\r
3164 * @see CKEDITOR.dialog#add\r
3165 */\r
3166 openDialog: function( dialogName, callback ) {\r
3167 var dialog = null, dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];\r
3168\r
3169 if ( CKEDITOR.dialog._.currentTop === null )\r
3170 showCover( this );\r
3171\r
3172 // If the dialogDefinition is already loaded, open it immediately.\r
3173 if ( typeof dialogDefinitions == 'function' ) {\r
3174 var storedDialogs = this._.storedDialogs || ( this._.storedDialogs = {} );\r
3175\r
3176 dialog = storedDialogs[ dialogName ] || ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );\r
3177\r
3178 callback && callback.call( dialog, dialog );\r
3179 dialog.show();\r
3180\r
3181 } else if ( dialogDefinitions == 'failed' ) {\r
3182 hideCover( this );\r
3183 throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );\r
3184 } else if ( typeof dialogDefinitions == 'string' ) {\r
3185\r
3186 CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ),\r
3187 function() {\r
3188 var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];\r
3189 // In case of plugin error, mark it as loading failed.\r
3190 if ( typeof dialogDefinition != 'function' )\r
3191 CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';\r
3192\r
3193 this.openDialog( dialogName, callback );\r
3194 }, this, 0, 1 );\r
3195 }\r
3196\r
3197 CKEDITOR.skin.loadPart( 'dialog' );\r
3198\r
3199 return dialog;\r
3200 }\r
3201 } );\r
3202} )();\r
3203\r
3204CKEDITOR.plugins.add( 'dialog', {\r
3205 requires: 'dialogui',\r
3206 init: function( editor ) {\r
3207 editor.on( 'doubleclick', function( evt ) {\r
3208 if ( evt.data.dialog )\r
3209 editor.openDialog( evt.data.dialog );\r
3210 }, null, null, 999 );\r
3211 }\r
3212} );\r
3213\r
3214// Dialog related configurations.\r
3215\r
3216/**\r
3217 * The color of the dialog background cover. It should be a valid CSS color string.\r
3218 *\r
3219 * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';\r
3220 *\r
3221 * @cfg {String} [dialog_backgroundCoverColor='white']\r
3222 * @member CKEDITOR.config\r
3223 */\r
3224\r
3225/**\r
3226 * The opacity of the dialog background cover. It should be a number within the\r
3227 * range `[0.0, 1.0]`.\r
3228 *\r
3229 * config.dialog_backgroundCoverOpacity = 0.7;\r
3230 *\r
3231 * @cfg {Number} [dialog_backgroundCoverOpacity=0.5]\r
3232 * @member CKEDITOR.config\r
3233 */\r
3234\r
3235/**\r
3236 * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.\r
3237 *\r
3238 * config.dialog_startupFocusTab = true;\r
3239 *\r
3240 * @cfg {Boolean} [dialog_startupFocusTab=false]\r
3241 * @member CKEDITOR.config\r
3242 */\r
3243\r
3244/**\r
3245 * The distance of magnetic borders used in moving and resizing dialogs,\r
3246 * measured in pixels.\r
3247 *\r
3248 * config.dialog_magnetDistance = 30;\r
3249 *\r
3250 * @cfg {Number} [dialog_magnetDistance=20]\r
3251 * @member CKEDITOR.config\r
3252 */\r
3253\r
3254/**\r
3255 * The guideline to follow when generating the dialog buttons. There are 3 possible options:\r
3256 *\r
3257 * * `'OS'` - the buttons will be displayed in the default order of the user's OS;\r
3258 * * `'ltr'` - for Left-To-Right order;\r
3259 * * `'rtl'` - for Right-To-Left order.\r
3260 *\r
3261 * Example:\r
3262 *\r
3263 * config.dialog_buttonsOrder = 'rtl';\r
3264 *\r
3265 * @since 3.5\r
3266 * @cfg {String} [dialog_buttonsOrder='OS']\r
3267 * @member CKEDITOR.config\r
3268 */\r
3269\r
3270/**\r
3271 * The dialog contents to removed. It's a string composed by dialog name and tab name with a colon between them.\r
3272 *\r
3273 * Separate each pair with semicolon (see example).\r
3274 *\r
3275 * **Note:** All names are case-sensitive.\r
3276 *\r
3277 * **Note:** Be cautious when specifying dialog tabs that are mandatory,\r
3278 * like `'info'`, dialog functionality might be broken because of this!\r
3279 *\r
3280 * config.removeDialogTabs = 'flash:advanced;image:Link';\r
3281 *\r
3282 * @since 3.5\r
3283 * @cfg {String} [removeDialogTabs='']\r
3284 * @member CKEDITOR.config\r
3285 */\r
3286\r
3287/**\r
3288 * Tells if user should not be asked to confirm close, if any dialog field was modified.\r
3289 * By default it is set to `false` meaning that the confirmation dialog will be shown.\r
3290 *\r
3291 * config.dialog_noConfirmCancel = true;\r
3292 *\r
3293 * @since 4.3\r
3294 * @cfg {Boolean} [dialog_noConfirmCancel=false]\r
3295 * @member CKEDITOR.config\r
3296 */\r
3297\r
3298/**\r
3299 * Event fired when a dialog definition is about to be used to create a dialog into\r
3300 * an editor instance. This event makes it possible to customize the definition\r
3301 * before creating it.\r
3302 *\r
3303 * Note that this event is called only the first time a specific dialog is\r
3304 * opened. Successive openings will use the cached dialog, and this event will\r
3305 * not get fired.\r
3306 *\r
3307 * @event dialogDefinition\r
3308 * @member CKEDITOR\r
3309 * @param {CKEDITOR.dialog.definition} data The dialog defination that\r
3310 * is being loaded.\r
3311 * @param {CKEDITOR.editor} editor The editor instance that will use the dialog.\r
3312 */\r
3313\r
3314/**\r
3315 * Event fired when a tab is going to be selected in a dialog.\r
3316 *\r
3317 * @event selectPage\r
3318 * @member CKEDITOR.dialog\r
3319 * @param data\r
3320 * @param {String} data.page The id of the page that it's gonna be selected.\r
3321 * @param {String} data.currentPage The id of the current page.\r
3322 */\r
3323\r
3324/**\r
3325 * Event fired when the user tries to dismiss a dialog.\r
3326 *\r
3327 * @event cancel\r
3328 * @member CKEDITOR.dialog\r
3329 * @param data\r
3330 * @param {Boolean} data.hide Whether the event should proceed or not.\r
3331 */\r
3332\r
3333/**\r
3334 * Event fired when the user tries to confirm a dialog.\r
3335 *\r
3336 * @event ok\r
3337 * @member CKEDITOR.dialog\r
3338 * @param data\r
3339 * @param {Boolean} data.hide Whether the event should proceed or not.\r
3340 */\r
3341\r
3342/**\r
3343 * Event fired when a dialog is shown.\r
3344 *\r
3345 * @event show\r
3346 * @member CKEDITOR.dialog\r
3347 */\r
3348\r
3349/**\r
3350 * Event fired when a dialog is shown.\r
3351 *\r
3352 * @event dialogShow\r
3353 * @member CKEDITOR.editor\r
3354 * @param {CKEDITOR.editor} editor This editor instance.\r
3355 * @param {CKEDITOR.dialog} data The opened dialog instance.\r
3356 */\r
3357\r
3358/**\r
3359 * Event fired when a dialog is hidden.\r
3360 *\r
3361 * @event hide\r
3362 * @member CKEDITOR.dialog\r
3363 */\r
3364\r
3365/**\r
3366 * Event fired when a dialog is hidden.\r
3367 *\r
3368 * @event dialogHide\r
3369 * @member CKEDITOR.editor\r
3370 * @param {CKEDITOR.editor} editor This editor instance.\r
3371 * @param {CKEDITOR.dialog} data The hidden dialog instance.\r
3372 */\r
3373\r
3374/**\r
3375 * Event fired when a dialog is being resized. The event is fired on\r
3376 * both the {@link CKEDITOR.dialog} object and the dialog instance\r
3377 * since 3.5.3, previously it was only available in the global object.\r
3378 *\r
3379 * @static\r
3380 * @event resize\r
3381 * @member CKEDITOR.dialog\r
3382 * @param data\r
3383 * @param {CKEDITOR.dialog} data.dialog The dialog being resized (if\r
3384 * it is fired on the dialog itself, this parameter is not sent).\r
3385 * @param {String} data.skin The skin name.\r
3386 * @param {Number} data.width The new width.\r
3387 * @param {Number} data.height The new height.\r
3388 */\r
3389\r
3390/**\r
3391 * Event fired when a dialog is being resized. The event is fired on\r
3392 * both the {@link CKEDITOR.dialog} object and the dialog instance\r
3393 * since 3.5.3, previously it was only available in the global object.\r
3394 *\r
3395 * @since 3.5\r
3396 * @event resize\r
3397 * @member CKEDITOR.dialog\r
3398 * @param data\r
3399 * @param {Number} data.width The new width.\r
3400 * @param {Number} data.height The new height.\r
3401 */\r
3402\r
3403/**\r
3404 * Event fired when the dialog state changes, usually by {@link CKEDITOR.dialog#setState}.\r
3405 *\r
3406 * @since 4.5\r
3407 * @event state\r
3408 * @member CKEDITOR.dialog\r
3409 * @param data\r
3410 * @param {Number} data The new state. Either {@link CKEDITOR#DIALOG_STATE_IDLE} or {@link CKEDITOR#DIALOG_STATE_BUSY}.\r
3411 */\r