1 | /*
|
---|
2 | Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
|
---|
3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
4 | */
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * @fileOverview The floating dialog plugin.
|
---|
8 | */
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * No resize for this dialog.
|
---|
12 | * @constant
|
---|
13 | */
|
---|
14 | CKEDITOR.DIALOG_RESIZE_NONE = 0;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Only allow horizontal resizing for this dialog, disable vertical resizing.
|
---|
18 | * @constant
|
---|
19 | */
|
---|
20 | CKEDITOR.DIALOG_RESIZE_WIDTH = 1;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Only allow vertical resizing for this dialog, disable horizontal resizing.
|
---|
24 | * @constant
|
---|
25 | */
|
---|
26 | CKEDITOR.DIALOG_RESIZE_HEIGHT = 2;
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * Allow the dialog to be resized in both directions.
|
---|
30 | * @constant
|
---|
31 | */
|
---|
32 | CKEDITOR.DIALOG_RESIZE_BOTH = 3;
|
---|
33 |
|
---|
34 | (function()
|
---|
35 | {
|
---|
36 | function isTabVisible( tabId )
|
---|
37 | {
|
---|
38 | return !!this._.tabs[ tabId ][ 0 ].$.offsetHeight;
|
---|
39 | }
|
---|
40 |
|
---|
41 | function getPreviousVisibleTab()
|
---|
42 | {
|
---|
43 | var tabId = this._.currentTabId,
|
---|
44 | length = this._.tabIdList.length,
|
---|
45 | tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId ) + length;
|
---|
46 |
|
---|
47 | for ( var i = tabIndex - 1 ; i > tabIndex - length ; i-- )
|
---|
48 | {
|
---|
49 | if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
|
---|
50 | return this._.tabIdList[ i % length ];
|
---|
51 | }
|
---|
52 |
|
---|
53 | return null;
|
---|
54 | }
|
---|
55 |
|
---|
56 | function getNextVisibleTab()
|
---|
57 | {
|
---|
58 | var tabId = this._.currentTabId,
|
---|
59 | length = this._.tabIdList.length,
|
---|
60 | tabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, tabId );
|
---|
61 |
|
---|
62 | for ( var i = tabIndex + 1 ; i < tabIndex + length ; i++ )
|
---|
63 | {
|
---|
64 | if ( isTabVisible.call( this, this._.tabIdList[ i % length ] ) )
|
---|
65 | return this._.tabIdList[ i % length ];
|
---|
66 | }
|
---|
67 |
|
---|
68 | return null;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * This is the base class for runtime dialog objects. An instance of this
|
---|
73 | * class represents a single named dialog for a single editor instance.
|
---|
74 | * @param {Object} editor The editor which created the dialog.
|
---|
75 | * @param {String} dialogName The dialog's registered name.
|
---|
76 | * @constructor
|
---|
77 | * @example
|
---|
78 | * var dialogObj = new CKEDITOR.dialog( editor, 'smiley' );
|
---|
79 | */
|
---|
80 | CKEDITOR.dialog = function( editor, dialogName )
|
---|
81 | {
|
---|
82 | // Load the dialog definition.
|
---|
83 | var definition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ];
|
---|
84 |
|
---|
85 | // Completes the definition with the default values.
|
---|
86 | definition = CKEDITOR.tools.extend( definition( editor ), defaultDialogDefinition );
|
---|
87 |
|
---|
88 | // Clone a functionally independent copy for this dialog.
|
---|
89 | definition = CKEDITOR.tools.clone( definition );
|
---|
90 |
|
---|
91 | // Create a complex definition object, extending it with the API
|
---|
92 | // functions.
|
---|
93 | definition = new definitionObject( this, definition );
|
---|
94 |
|
---|
95 |
|
---|
96 | var doc = CKEDITOR.document;
|
---|
97 |
|
---|
98 | var themeBuilt = editor.theme.buildDialog( editor );
|
---|
99 |
|
---|
100 | // Initialize some basic parameters.
|
---|
101 | this._ =
|
---|
102 | {
|
---|
103 | editor : editor,
|
---|
104 | element : themeBuilt.element,
|
---|
105 | name : dialogName,
|
---|
106 | contentSize : { width : 0, height : 0 },
|
---|
107 | size : { width : 0, height : 0 },
|
---|
108 | updateSize : false,
|
---|
109 | contents : {},
|
---|
110 | buttons : {},
|
---|
111 | accessKeyMap : {},
|
---|
112 |
|
---|
113 | // Initialize the tab and page map.
|
---|
114 | tabs : {},
|
---|
115 | tabIdList : [],
|
---|
116 | currentTabId : null,
|
---|
117 | currentTabIndex : null,
|
---|
118 | pageCount : 0,
|
---|
119 | lastTab : null,
|
---|
120 | tabBarMode : false,
|
---|
121 |
|
---|
122 | // Initialize the tab order array for input widgets.
|
---|
123 | focusList : [],
|
---|
124 | currentFocusIndex : 0,
|
---|
125 | hasFocus : false
|
---|
126 | };
|
---|
127 |
|
---|
128 | this.parts = themeBuilt.parts;
|
---|
129 |
|
---|
130 | CKEDITOR.tools.setTimeout( function()
|
---|
131 | {
|
---|
132 | editor.fire( 'ariaWidget', this.parts.contents );
|
---|
133 | },
|
---|
134 | 0, this );
|
---|
135 |
|
---|
136 | // Set the startup styles for the dialog, avoiding it enlarging the
|
---|
137 | // page size on the dialog creation.
|
---|
138 | this.parts.dialog.setStyles(
|
---|
139 | {
|
---|
140 | position : CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed',
|
---|
141 | top : 0,
|
---|
142 | left: 0,
|
---|
143 | visibility : 'hidden'
|
---|
144 | });
|
---|
145 |
|
---|
146 | // Call the CKEDITOR.event constructor to initialize this instance.
|
---|
147 | CKEDITOR.event.call( this );
|
---|
148 |
|
---|
149 | // Fire the "dialogDefinition" event, making it possible to customize
|
---|
150 | // the dialog definition.
|
---|
151 | this.definition = definition = CKEDITOR.fire( 'dialogDefinition',
|
---|
152 | {
|
---|
153 | name : dialogName,
|
---|
154 | definition : definition
|
---|
155 | }
|
---|
156 | , editor ).definition;
|
---|
157 | // Initialize load, show, hide, ok and cancel events.
|
---|
158 | if ( definition.onLoad )
|
---|
159 | this.on( 'load', definition.onLoad );
|
---|
160 |
|
---|
161 | if ( definition.onShow )
|
---|
162 | this.on( 'show', definition.onShow );
|
---|
163 |
|
---|
164 | if ( definition.onHide )
|
---|
165 | this.on( 'hide', definition.onHide );
|
---|
166 |
|
---|
167 | if ( definition.onOk )
|
---|
168 | {
|
---|
169 | this.on( 'ok', function( evt )
|
---|
170 | {
|
---|
171 | if ( definition.onOk.call( this, evt ) === false )
|
---|
172 | evt.data.hide = false;
|
---|
173 | });
|
---|
174 | }
|
---|
175 |
|
---|
176 | if ( definition.onCancel )
|
---|
177 | {
|
---|
178 | this.on( 'cancel', function( evt )
|
---|
179 | {
|
---|
180 | if ( definition.onCancel.call( this, evt ) === false )
|
---|
181 | evt.data.hide = false;
|
---|
182 | });
|
---|
183 | }
|
---|
184 |
|
---|
185 | var me = this;
|
---|
186 |
|
---|
187 | // Iterates over all items inside all content in the dialog, calling a
|
---|
188 | // function for each of them.
|
---|
189 | var iterContents = function( func )
|
---|
190 | {
|
---|
191 | var contents = me._.contents,
|
---|
192 | stop = false;
|
---|
193 |
|
---|
194 | for ( var i in contents )
|
---|
195 | if ( ! ( i in Object.prototype ) )
|
---|
196 | {
|
---|
197 | for ( var j in contents[i] )
|
---|
198 | if ( ! ( j in Object.prototype ) )
|
---|
199 | {
|
---|
200 | stop = func.call( this, contents[i][j] );
|
---|
201 | if ( stop )
|
---|
202 | return;
|
---|
203 | }
|
---|
204 | }
|
---|
205 | };
|
---|
206 |
|
---|
207 | this.on( 'ok', function( evt )
|
---|
208 | {
|
---|
209 | iterContents( function( item )
|
---|
210 | {
|
---|
211 | if ( item.validate )
|
---|
212 | {
|
---|
213 | var isValid = item.validate( this );
|
---|
214 |
|
---|
215 | if ( typeof isValid == 'string' )
|
---|
216 | {
|
---|
217 | alert( isValid );
|
---|
218 | isValid = false;
|
---|
219 | }
|
---|
220 |
|
---|
221 | if ( isValid === false )
|
---|
222 | {
|
---|
223 | if ( item.select )
|
---|
224 | item.select();
|
---|
225 | else
|
---|
226 | item.focus();
|
---|
227 |
|
---|
228 | evt.data.hide = false;
|
---|
229 | evt.stop();
|
---|
230 | return true;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | });
|
---|
234 | }, this, null, 0 );
|
---|
235 |
|
---|
236 | this.on( 'cancel', function( evt )
|
---|
237 | {
|
---|
238 | iterContents( function( item )
|
---|
239 | {
|
---|
240 | if ( item.isChanged() )
|
---|
241 | {
|
---|
242 | if ( !confirm( editor.lang.common.confirmCancel ) )
|
---|
243 | evt.data.hide = false;
|
---|
244 | return true;
|
---|
245 | }
|
---|
246 | });
|
---|
247 | }, this, null, 0 );
|
---|
248 |
|
---|
249 | this.parts.close.on( 'click', function( evt )
|
---|
250 | {
|
---|
251 | if ( this.fire( 'cancel', { hide : true } ).hide !== false )
|
---|
252 | this.hide();
|
---|
253 | }, this );
|
---|
254 |
|
---|
255 | // Sort focus list according to tab order definitions.
|
---|
256 | function setupFocus()
|
---|
257 | {
|
---|
258 | var focusList = me._.focusList;
|
---|
259 | focusList.sort( function( a, b )
|
---|
260 | {
|
---|
261 | // Mimics browser tab order logics;
|
---|
262 | if ( a.tabIndex != b.tabIndex )
|
---|
263 | return b.tabIndex - a.tabIndex;
|
---|
264 | // Sort is not stable in some browsers,
|
---|
265 | // fall-back the comparator to 'focusIndex';
|
---|
266 | else
|
---|
267 | return a.focusIndex - b.focusIndex;
|
---|
268 | });
|
---|
269 |
|
---|
270 | var size = focusList.length;
|
---|
271 | for ( var i = 0; i < size; i++ )
|
---|
272 | focusList[ i ].focusIndex = i;
|
---|
273 | }
|
---|
274 |
|
---|
275 | function changeFocus( forward )
|
---|
276 | {
|
---|
277 | var focusList = me._.focusList,
|
---|
278 | offset = forward ? 1 : -1;
|
---|
279 | if ( focusList.length < 1 )
|
---|
280 | return;
|
---|
281 |
|
---|
282 | var current = me._.currentFocusIndex;
|
---|
283 |
|
---|
284 | // Trigger the 'blur' event of any input element before anything,
|
---|
285 | // since certain UI updates may depend on it.
|
---|
286 | try
|
---|
287 | {
|
---|
288 | focusList[ current ].getInputElement().$.blur();
|
---|
289 | }
|
---|
290 | catch( e ){}
|
---|
291 |
|
---|
292 | var startIndex = ( current + offset + focusList.length ) % focusList.length,
|
---|
293 | currentIndex = startIndex;
|
---|
294 | while ( !focusList[ currentIndex ].isFocusable() )
|
---|
295 | {
|
---|
296 | currentIndex = ( currentIndex + offset + focusList.length ) % focusList.length;
|
---|
297 | if ( currentIndex == startIndex )
|
---|
298 | break;
|
---|
299 | }
|
---|
300 | focusList[ currentIndex ].focus();
|
---|
301 |
|
---|
302 | // Select whole field content.
|
---|
303 | if ( focusList[ currentIndex ].type == 'text' )
|
---|
304 | focusList[ currentIndex ].select();
|
---|
305 | }
|
---|
306 |
|
---|
307 | this.changeFocus = changeFocus;
|
---|
308 |
|
---|
309 | var processed;
|
---|
310 |
|
---|
311 | function focusKeydownHandler( evt )
|
---|
312 | {
|
---|
313 | // If I'm not the top dialog, ignore.
|
---|
314 | if ( me != CKEDITOR.dialog._.currentTop )
|
---|
315 | return;
|
---|
316 |
|
---|
317 | var keystroke = evt.data.getKeystroke();
|
---|
318 |
|
---|
319 | processed = 0;
|
---|
320 | if ( keystroke == 9 || keystroke == CKEDITOR.SHIFT + 9 )
|
---|
321 | {
|
---|
322 | var shiftPressed = ( keystroke == CKEDITOR.SHIFT + 9 );
|
---|
323 |
|
---|
324 | // Handling Tab and Shift-Tab.
|
---|
325 | if ( me._.tabBarMode )
|
---|
326 | {
|
---|
327 | // Change tabs.
|
---|
328 | var nextId = shiftPressed ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me );
|
---|
329 | me.selectPage( nextId );
|
---|
330 | me._.tabs[ nextId ][ 0 ].focus();
|
---|
331 | }
|
---|
332 | else
|
---|
333 | {
|
---|
334 | // Change the focus of inputs.
|
---|
335 | changeFocus( !shiftPressed );
|
---|
336 | }
|
---|
337 |
|
---|
338 | processed = 1;
|
---|
339 | }
|
---|
340 | else if ( keystroke == CKEDITOR.ALT + 121 && !me._.tabBarMode && me.getPageCount() > 1 )
|
---|
341 | {
|
---|
342 | // Alt-F10 puts focus into the current tab item in the tab bar.
|
---|
343 | me._.tabBarMode = true;
|
---|
344 | me._.tabs[ me._.currentTabId ][ 0 ].focus();
|
---|
345 | processed = 1;
|
---|
346 | }
|
---|
347 | else if ( ( keystroke == 37 || keystroke == 39 ) && me._.tabBarMode )
|
---|
348 | {
|
---|
349 | // Arrow keys - used for changing tabs.
|
---|
350 | nextId = ( keystroke == 37 ? getPreviousVisibleTab.call( me ) : getNextVisibleTab.call( me ) );
|
---|
351 | me.selectPage( nextId );
|
---|
352 | me._.tabs[ nextId ][ 0 ].focus();
|
---|
353 | processed = 1;
|
---|
354 | }
|
---|
355 | else if ( ( keystroke == 13 || keystroke == 32 ) && me._.tabBarMode )
|
---|
356 | {
|
---|
357 | this.selectPage( this._.currentTabId );
|
---|
358 | this._.tabBarMode = false;
|
---|
359 | this._.currentFocusIndex = -1;
|
---|
360 | changeFocus( true );
|
---|
361 | processed = 1;
|
---|
362 | }
|
---|
363 |
|
---|
364 | if ( processed )
|
---|
365 | {
|
---|
366 | evt.stop();
|
---|
367 | evt.data.preventDefault();
|
---|
368 | }
|
---|
369 | }
|
---|
370 |
|
---|
371 | function focusKeyPressHandler( evt )
|
---|
372 | {
|
---|
373 | processed && evt.data.preventDefault();
|
---|
374 | }
|
---|
375 |
|
---|
376 | var dialogElement = this._.element;
|
---|
377 | // Add the dialog keyboard handlers.
|
---|
378 | this.on( 'show', function()
|
---|
379 | {
|
---|
380 | dialogElement.on( 'keydown', focusKeydownHandler, this, null, 0 );
|
---|
381 | // Some browsers instead, don't cancel key events in the keydown, but in the
|
---|
382 | // keypress. So we must do a longer trip in those cases. (#4531)
|
---|
383 | if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
|
---|
384 | dialogElement.on( 'keypress', focusKeyPressHandler, this );
|
---|
385 |
|
---|
386 | if ( CKEDITOR.env.ie6Compat )
|
---|
387 | {
|
---|
388 | var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
|
---|
389 | coverDoc.on( 'keydown', focusKeydownHandler, this, null, 0 );
|
---|
390 | }
|
---|
391 | } );
|
---|
392 | this.on( 'hide', function()
|
---|
393 | {
|
---|
394 | dialogElement.removeListener( 'keydown', focusKeydownHandler );
|
---|
395 | if ( CKEDITOR.env.opera || ( CKEDITOR.env.gecko && CKEDITOR.env.mac ) )
|
---|
396 | dialogElement.removeListener( 'keypress', focusKeyPressHandler );
|
---|
397 | } );
|
---|
398 | this.on( 'iframeAdded', function( evt )
|
---|
399 | {
|
---|
400 | var doc = new CKEDITOR.dom.document( evt.data.iframe.$.contentWindow.document );
|
---|
401 | doc.on( 'keydown', focusKeydownHandler, this, null, 0 );
|
---|
402 | } );
|
---|
403 |
|
---|
404 | // Auto-focus logic in dialog.
|
---|
405 | this.on( 'show', function()
|
---|
406 | {
|
---|
407 | // Setup tabIndex on showing the dialog instead of on loading
|
---|
408 | // to allow dynamic tab order happen in dialog definition.
|
---|
409 | setupFocus();
|
---|
410 |
|
---|
411 | if ( editor.config.dialog_startupFocusTab
|
---|
412 | && me._.tabIdList.length > 1 )
|
---|
413 | {
|
---|
414 | me._.tabBarMode = true;
|
---|
415 | me._.tabs[ me._.currentTabId ][ 0 ].focus();
|
---|
416 | }
|
---|
417 | else if ( !this._.hasFocus )
|
---|
418 | {
|
---|
419 | this._.currentFocusIndex = -1;
|
---|
420 |
|
---|
421 | // Decide where to put the initial focus.
|
---|
422 | if ( definition.onFocus )
|
---|
423 | {
|
---|
424 | var initialFocus = definition.onFocus.call( this );
|
---|
425 | // Focus the field that the user specified.
|
---|
426 | initialFocus && initialFocus.focus();
|
---|
427 | }
|
---|
428 | // Focus the first field in layout order.
|
---|
429 | else
|
---|
430 | changeFocus( true );
|
---|
431 |
|
---|
432 | /*
|
---|
433 | * IE BUG: If the initial focus went into a non-text element (e.g. button),
|
---|
434 | * then IE would still leave the caret inside the editing area.
|
---|
435 | */
|
---|
436 | if ( this._.editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
|
---|
437 | {
|
---|
438 | var $selection = editor.document.$.selection,
|
---|
439 | $range = $selection.createRange();
|
---|
440 |
|
---|
441 | if ( $range )
|
---|
442 | {
|
---|
443 | if ( $range.parentElement && $range.parentElement().ownerDocument == editor.document.$
|
---|
444 | || $range.item && $range.item( 0 ).ownerDocument == editor.document.$ )
|
---|
445 | {
|
---|
446 | var $myRange = document.body.createTextRange();
|
---|
447 | $myRange.moveToElementText( this.getElement().getFirst().$ );
|
---|
448 | $myRange.collapse( true );
|
---|
449 | $myRange.select();
|
---|
450 | }
|
---|
451 | }
|
---|
452 | }
|
---|
453 | }
|
---|
454 | }, this, null, 0xffffffff );
|
---|
455 |
|
---|
456 | // IE6 BUG: Text fields and text areas are only half-rendered the first time the dialog appears in IE6 (#2661).
|
---|
457 | // This is still needed after [2708] and [2709] because text fields in hidden TR tags are still broken.
|
---|
458 | if ( CKEDITOR.env.ie6Compat )
|
---|
459 | {
|
---|
460 | this.on( 'load', function( evt )
|
---|
461 | {
|
---|
462 | var outer = this.getElement(),
|
---|
463 | inner = outer.getFirst();
|
---|
464 | inner.remove();
|
---|
465 | inner.appendTo( outer );
|
---|
466 | }, this );
|
---|
467 | }
|
---|
468 |
|
---|
469 | initDragAndDrop( this );
|
---|
470 | initResizeHandles( this );
|
---|
471 |
|
---|
472 | // Insert the title.
|
---|
473 | ( new CKEDITOR.dom.text( definition.title, CKEDITOR.document ) ).appendTo( this.parts.title );
|
---|
474 |
|
---|
475 | // Insert the tabs and contents.
|
---|
476 | for ( var i = 0 ; i < definition.contents.length ; i++ )
|
---|
477 | this.addPage( definition.contents[i] );
|
---|
478 |
|
---|
479 | this.parts['tabs'].on( 'click', function( evt )
|
---|
480 | {
|
---|
481 | var target = evt.data.getTarget();
|
---|
482 | // If we aren't inside a tab, bail out.
|
---|
483 | if ( target.hasClass( 'cke_dialog_tab' ) )
|
---|
484 | {
|
---|
485 | var id = target.$.id;
|
---|
486 | this.selectPage( id.substr( 0, id.lastIndexOf( '_' ) ) );
|
---|
487 | if ( this._.tabBarMode )
|
---|
488 | {
|
---|
489 | this._.tabBarMode = false;
|
---|
490 | this._.currentFocusIndex = -1;
|
---|
491 | changeFocus( true );
|
---|
492 | }
|
---|
493 | evt.data.preventDefault();
|
---|
494 | }
|
---|
495 | }, this );
|
---|
496 |
|
---|
497 | // Insert buttons.
|
---|
498 | var buttonsHtml = [],
|
---|
499 | buttons = CKEDITOR.dialog._.uiElementBuilders.hbox.build( this,
|
---|
500 | {
|
---|
501 | type : 'hbox',
|
---|
502 | className : 'cke_dialog_footer_buttons',
|
---|
503 | widths : [],
|
---|
504 | children : definition.buttons
|
---|
505 | }, buttonsHtml ).getChild();
|
---|
506 | this.parts.footer.setHtml( buttonsHtml.join( '' ) );
|
---|
507 |
|
---|
508 | for ( i = 0 ; i < buttons.length ; i++ )
|
---|
509 | this._.buttons[ buttons[i].id ] = buttons[i];
|
---|
510 | };
|
---|
511 |
|
---|
512 | // Focusable interface. Use it via dialog.addFocusable.
|
---|
513 | function Focusable( dialog, element, index )
|
---|
514 | {
|
---|
515 | this.element = element;
|
---|
516 | this.focusIndex = index;
|
---|
517 | // TODO: support tabIndex for focusables.
|
---|
518 | this.tabIndex = 0;
|
---|
519 | this.isFocusable = function()
|
---|
520 | {
|
---|
521 | return !element.getAttribute( 'disabled' ) && element.isVisible();
|
---|
522 | };
|
---|
523 | this.focus = function()
|
---|
524 | {
|
---|
525 | dialog._.currentFocusIndex = this.focusIndex;
|
---|
526 | this.element.focus();
|
---|
527 | };
|
---|
528 | // Bind events
|
---|
529 | element.on( 'keydown', function( e )
|
---|
530 | {
|
---|
531 | if ( e.data.getKeystroke() in { 32:1, 13:1 } )
|
---|
532 | this.fire( 'click' );
|
---|
533 | } );
|
---|
534 | element.on( 'focus', function()
|
---|
535 | {
|
---|
536 | this.fire( 'mouseover' );
|
---|
537 | } );
|
---|
538 | element.on( 'blur', function()
|
---|
539 | {
|
---|
540 | this.fire( 'mouseout' );
|
---|
541 | } );
|
---|
542 | }
|
---|
543 |
|
---|
544 | CKEDITOR.dialog.prototype =
|
---|
545 | {
|
---|
546 | /**
|
---|
547 | * Resizes the dialog.
|
---|
548 | * @param {Number} width The width of the dialog in pixels.
|
---|
549 | * @param {Number} height The height of the dialog in pixels.
|
---|
550 | * @function
|
---|
551 | * @example
|
---|
552 | * dialogObj.resize( 800, 640 );
|
---|
553 | */
|
---|
554 | resize : (function()
|
---|
555 | {
|
---|
556 | return function( width, height )
|
---|
557 | {
|
---|
558 | if ( this._.contentSize && this._.contentSize.width == width && this._.contentSize.height == height )
|
---|
559 | return;
|
---|
560 |
|
---|
561 | CKEDITOR.dialog.fire( 'resize',
|
---|
562 | {
|
---|
563 | dialog : this,
|
---|
564 | skin : this._.editor.skinName,
|
---|
565 | width : width,
|
---|
566 | height : height
|
---|
567 | }, this._.editor );
|
---|
568 |
|
---|
569 | this._.contentSize = { width : width, height : height };
|
---|
570 | this._.updateSize = true;
|
---|
571 | };
|
---|
572 | })(),
|
---|
573 |
|
---|
574 | /**
|
---|
575 | * Gets the current size of the dialog in pixels.
|
---|
576 | * @returns {Object} An object with "width" and "height" properties.
|
---|
577 | * @example
|
---|
578 | * var width = dialogObj.getSize().width;
|
---|
579 | */
|
---|
580 | getSize : function()
|
---|
581 | {
|
---|
582 | if ( !this._.updateSize )
|
---|
583 | return this._.size;
|
---|
584 | var element = this._.element.getFirst();
|
---|
585 | var size = this._.size = { width : element.$.offsetWidth || 0, height : element.$.offsetHeight || 0};
|
---|
586 |
|
---|
587 | // If either the offsetWidth or offsetHeight is 0, the element isn't visible.
|
---|
588 | this._.updateSize = !size.width || !size.height;
|
---|
589 |
|
---|
590 | return size;
|
---|
591 | },
|
---|
592 |
|
---|
593 | /**
|
---|
594 | * Moves the dialog to an (x, y) coordinate relative to the window.
|
---|
595 | * @function
|
---|
596 | * @param {Number} x The target x-coordinate.
|
---|
597 | * @param {Number} y The target y-coordinate.
|
---|
598 | * @example
|
---|
599 | * dialogObj.move( 10, 40 );
|
---|
600 | */
|
---|
601 | move : (function()
|
---|
602 | {
|
---|
603 | var isFixed;
|
---|
604 | return function( x, y )
|
---|
605 | {
|
---|
606 | // The dialog may be fixed positioned or absolute positioned. Ask the
|
---|
607 | // browser what is the current situation first.
|
---|
608 | var element = this._.element.getFirst();
|
---|
609 | if ( isFixed === undefined )
|
---|
610 | isFixed = element.getComputedStyle( 'position' ) == 'fixed';
|
---|
611 |
|
---|
612 | if ( isFixed && this._.position && this._.position.x == x && this._.position.y == y )
|
---|
613 | return;
|
---|
614 |
|
---|
615 | // Save the current position.
|
---|
616 | this._.position = { x : x, y : y };
|
---|
617 |
|
---|
618 | // If not fixed positioned, add scroll position to the coordinates.
|
---|
619 | if ( !isFixed )
|
---|
620 | {
|
---|
621 | var scrollPosition = CKEDITOR.document.getWindow().getScrollPosition();
|
---|
622 | x += scrollPosition.x;
|
---|
623 | y += scrollPosition.y;
|
---|
624 | }
|
---|
625 |
|
---|
626 | element.setStyles(
|
---|
627 | {
|
---|
628 | 'left' : ( x > 0 ? x : 0 ) + 'px',
|
---|
629 | 'top' : ( y > 0 ? y : 0 ) + 'px'
|
---|
630 | });
|
---|
631 | };
|
---|
632 | })(),
|
---|
633 |
|
---|
634 | /**
|
---|
635 | * Gets the dialog's position in the window.
|
---|
636 | * @returns {Object} An object with "x" and "y" properties.
|
---|
637 | * @example
|
---|
638 | * var dialogX = dialogObj.getPosition().x;
|
---|
639 | */
|
---|
640 | getPosition : function(){ return CKEDITOR.tools.extend( {}, this._.position ); },
|
---|
641 |
|
---|
642 | /**
|
---|
643 | * Shows the dialog box.
|
---|
644 | * @example
|
---|
645 | * dialogObj.show();
|
---|
646 | */
|
---|
647 | show : function()
|
---|
648 | {
|
---|
649 | var editor = this._.editor;
|
---|
650 | if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
|
---|
651 | {
|
---|
652 | var selection = editor.getSelection();
|
---|
653 | selection && selection.lock();
|
---|
654 | }
|
---|
655 |
|
---|
656 | // Insert the dialog's element to the root document.
|
---|
657 | var element = this._.element;
|
---|
658 | var definition = this.definition;
|
---|
659 | if ( !( element.getParent() && element.getParent().equals( CKEDITOR.document.getBody() ) ) )
|
---|
660 | element.appendTo( CKEDITOR.document.getBody() );
|
---|
661 | else
|
---|
662 | return;
|
---|
663 |
|
---|
664 | // FIREFOX BUG: Fix vanishing caret for Firefox 2 or Gecko 1.8.
|
---|
665 | if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 )
|
---|
666 | {
|
---|
667 | var dialogElement = this.parts.dialog;
|
---|
668 | dialogElement.setStyle( 'position', 'absolute' );
|
---|
669 | setTimeout( function()
|
---|
670 | {
|
---|
671 | dialogElement.setStyle( 'position', 'fixed' );
|
---|
672 | }, 0 );
|
---|
673 | }
|
---|
674 |
|
---|
675 |
|
---|
676 | // First, set the dialog to an appropriate size.
|
---|
677 | this.resize( definition.minWidth, definition.minHeight );
|
---|
678 |
|
---|
679 | // Select the first tab by default.
|
---|
680 | this.selectPage( this.definition.contents[0].id );
|
---|
681 |
|
---|
682 | // Reset all inputs back to their default value.
|
---|
683 | this.reset();
|
---|
684 |
|
---|
685 | // Set z-index.
|
---|
686 | if ( CKEDITOR.dialog._.currentZIndex === null )
|
---|
687 | CKEDITOR.dialog._.currentZIndex = this._.editor.config.baseFloatZIndex;
|
---|
688 | this._.element.getFirst().setStyle( 'z-index', CKEDITOR.dialog._.currentZIndex += 10 );
|
---|
689 |
|
---|
690 | // Maintain the dialog ordering and dialog cover.
|
---|
691 | // Also register key handlers if first dialog.
|
---|
692 | if ( CKEDITOR.dialog._.currentTop === null )
|
---|
693 | {
|
---|
694 | CKEDITOR.dialog._.currentTop = this;
|
---|
695 | this._.parentDialog = null;
|
---|
696 | addCover( this._.editor );
|
---|
697 |
|
---|
698 | element.on( 'keydown', accessKeyDownHandler );
|
---|
699 | element.on( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
|
---|
700 |
|
---|
701 | // Prevent some keys from bubbling up. (#4269)
|
---|
702 | for ( var event in { keyup :1, keydown :1, keypress :1 } )
|
---|
703 | if ( ! ( event in Object.prototype ) )
|
---|
704 | element.on( event, preventKeyBubbling );
|
---|
705 | }
|
---|
706 | else
|
---|
707 | {
|
---|
708 | this._.parentDialog = CKEDITOR.dialog._.currentTop;
|
---|
709 | var parentElement = this._.parentDialog.getElement().getFirst();
|
---|
710 | parentElement.$.style.zIndex -= Math.floor( this._.editor.config.baseFloatZIndex / 2 );
|
---|
711 | CKEDITOR.dialog._.currentTop = this;
|
---|
712 | }
|
---|
713 |
|
---|
714 | // Register the Esc hotkeys.
|
---|
715 | registerAccessKey( this, this, '\x1b', null, function()
|
---|
716 | {
|
---|
717 | this.getButton( 'cancel' ) && this.getButton( 'cancel' ).click();
|
---|
718 | } );
|
---|
719 |
|
---|
720 | // Reset the hasFocus state.
|
---|
721 | this._.hasFocus = false;
|
---|
722 |
|
---|
723 | // Rearrange the dialog to the middle of the window.
|
---|
724 | CKEDITOR.tools.setTimeout( function()
|
---|
725 | {
|
---|
726 | var viewSize = CKEDITOR.document.getWindow().getViewPaneSize();
|
---|
727 | var dialogSize = this.getSize();
|
---|
728 |
|
---|
729 | // We're using definition size for initial position because of
|
---|
730 | // offten corrupted data in offsetWidth at this point. (#4084)
|
---|
731 | this.move( ( viewSize.width - definition.minWidth ) / 2, ( viewSize.height - dialogSize.height ) / 2 );
|
---|
732 |
|
---|
733 | this.parts.dialog.setStyle( 'visibility', '' );
|
---|
734 |
|
---|
735 | // Execute onLoad for the first show.
|
---|
736 | this.fireOnce( 'load', {} );
|
---|
737 | this.fire( 'show', {} );
|
---|
738 | this._.editor.fire( 'dialogShow', this );
|
---|
739 |
|
---|
740 | // Save the initial values of the dialog.
|
---|
741 | this.foreach( function( contentObj ) { contentObj.setInitValue && contentObj.setInitValue(); } );
|
---|
742 |
|
---|
743 | },
|
---|
744 | 100, this );
|
---|
745 | },
|
---|
746 |
|
---|
747 | /**
|
---|
748 | * Executes a function for each UI element.
|
---|
749 | * @param {Function} fn Function to execute for each UI element.
|
---|
750 | * @returns {CKEDITOR.dialog} The current dialog object.
|
---|
751 | */
|
---|
752 | foreach : function( fn )
|
---|
753 | {
|
---|
754 | for ( var i in this._.contents )
|
---|
755 | if ( ! ( i in Object.prototype ) )
|
---|
756 | {
|
---|
757 | for ( var j in this._.contents[i] )
|
---|
758 | fn( this._.contents[i][j]);
|
---|
759 | }
|
---|
760 | return this;
|
---|
761 | },
|
---|
762 |
|
---|
763 | /**
|
---|
764 | * Resets all input values in the dialog.
|
---|
765 | * @example
|
---|
766 | * dialogObj.reset();
|
---|
767 | * @returns {CKEDITOR.dialog} The current dialog object.
|
---|
768 | */
|
---|
769 | reset : (function()
|
---|
770 | {
|
---|
771 | var fn = function( widget ){ if ( widget.reset ) widget.reset(); };
|
---|
772 | return function(){ this.foreach( fn ); return this; };
|
---|
773 | })(),
|
---|
774 |
|
---|
775 | setupContent : function()
|
---|
776 | {
|
---|
777 | var args = arguments;
|
---|
778 | this.foreach( function( widget )
|
---|
779 | {
|
---|
780 | if ( widget.setup )
|
---|
781 | widget.setup.apply( widget, args );
|
---|
782 | });
|
---|
783 | },
|
---|
784 |
|
---|
785 | commitContent : function()
|
---|
786 | {
|
---|
787 | var args = arguments;
|
---|
788 | this.foreach( function( widget )
|
---|
789 | {
|
---|
790 | if ( widget.commit )
|
---|
791 | widget.commit.apply( widget, args );
|
---|
792 | });
|
---|
793 | },
|
---|
794 |
|
---|
795 | /**
|
---|
796 | * Hides the dialog box.
|
---|
797 | * @example
|
---|
798 | * dialogObj.hide();
|
---|
799 | */
|
---|
800 | hide : function()
|
---|
801 | {
|
---|
802 | this.fire( 'hide', {} );
|
---|
803 | this._.editor.fire( 'dialogHide', this );
|
---|
804 |
|
---|
805 | // Remove the dialog's element from the root document.
|
---|
806 | var element = this._.element;
|
---|
807 | if ( !element.getParent() )
|
---|
808 | return;
|
---|
809 |
|
---|
810 | element.remove();
|
---|
811 | this.parts.dialog.setStyle( 'visibility', 'hidden' );
|
---|
812 |
|
---|
813 | // Unregister all access keys associated with this dialog.
|
---|
814 | unregisterAccessKey( this );
|
---|
815 |
|
---|
816 | // Maintain dialog ordering and remove cover if needed.
|
---|
817 | if ( !this._.parentDialog )
|
---|
818 | removeCover();
|
---|
819 | else
|
---|
820 | {
|
---|
821 | var parentElement = this._.parentDialog.getElement().getFirst();
|
---|
822 | parentElement.setStyle( 'z-index', parseInt( parentElement.$.style.zIndex, 10 ) + Math.floor( this._.editor.config.baseFloatZIndex / 2 ) );
|
---|
823 | }
|
---|
824 | CKEDITOR.dialog._.currentTop = this._.parentDialog;
|
---|
825 |
|
---|
826 | // Deduct or clear the z-index.
|
---|
827 | if ( !this._.parentDialog )
|
---|
828 | {
|
---|
829 | CKEDITOR.dialog._.currentZIndex = null;
|
---|
830 |
|
---|
831 | // Remove access key handlers.
|
---|
832 | element.removeListener( 'keydown', accessKeyDownHandler );
|
---|
833 | element.removeListener( CKEDITOR.env.opera ? 'keypress' : 'keyup', accessKeyUpHandler );
|
---|
834 |
|
---|
835 | // Remove bubbling-prevention handler. (#4269)
|
---|
836 | for ( var event in { keyup :1, keydown :1, keypress :1 } )
|
---|
837 | if ( ! ( event in Object.prototype ) )
|
---|
838 | element.removeListener( event, preventKeyBubbling );
|
---|
839 |
|
---|
840 | var editor = this._.editor;
|
---|
841 | editor.focus();
|
---|
842 |
|
---|
843 | if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
|
---|
844 | {
|
---|
845 | var selection = editor.getSelection();
|
---|
846 | selection && selection.unlock( true );
|
---|
847 | }
|
---|
848 | }
|
---|
849 | else
|
---|
850 | CKEDITOR.dialog._.currentZIndex -= 10;
|
---|
851 |
|
---|
852 |
|
---|
853 | // Reset the initial values of the dialog.
|
---|
854 | this.foreach( function( contentObj ) { contentObj.resetInitValue && contentObj.resetInitValue(); } );
|
---|
855 | },
|
---|
856 |
|
---|
857 | /**
|
---|
858 | * Adds a tabbed page into the dialog.
|
---|
859 | * @param {Object} contents Content definition.
|
---|
860 | * @example
|
---|
861 | */
|
---|
862 | addPage : function( contents )
|
---|
863 | {
|
---|
864 | var pageHtml = [],
|
---|
865 | titleHtml = contents.label ? ' title="' + CKEDITOR.tools.htmlEncode( contents.label ) + '"' : '',
|
---|
866 | elements = contents.elements,
|
---|
867 | vbox = CKEDITOR.dialog._.uiElementBuilders.vbox.build( this,
|
---|
868 | {
|
---|
869 | type : 'vbox',
|
---|
870 | className : 'cke_dialog_page_contents',
|
---|
871 | children : contents.elements,
|
---|
872 | expand : !!contents.expand,
|
---|
873 | padding : contents.padding,
|
---|
874 | style : contents.style || 'width: 100%; height: 100%;'
|
---|
875 | }, pageHtml );
|
---|
876 |
|
---|
877 | // Create the HTML for the tab and the content block.
|
---|
878 | var page = CKEDITOR.dom.element.createFromHtml( pageHtml.join( '' ) );
|
---|
879 | page.setAttribute( 'role', 'tabpanel' );
|
---|
880 |
|
---|
881 | var env = CKEDITOR.env;
|
---|
882 | var tabId = contents.id + '_' + CKEDITOR.tools.getNextNumber(),
|
---|
883 | tab = CKEDITOR.dom.element.createFromHtml( [
|
---|
884 | '<a class="cke_dialog_tab"',
|
---|
885 | ( this._.pageCount > 0 ? ' cke_last' : 'cke_first' ),
|
---|
886 | titleHtml,
|
---|
887 | ( !!contents.hidden ? ' style="display:none"' : '' ),
|
---|
888 | ' id="', tabId, '"',
|
---|
889 | env.gecko && env.version >= 10900 && !env.hc ? '' : ' href="javascript:void(0)"',
|
---|
890 | ' tabIndex="-1"',
|
---|
891 | ' hidefocus="true"',
|
---|
892 | ' role="tab">',
|
---|
893 | contents.label,
|
---|
894 | '</a>'
|
---|
895 | ].join( '' ) );
|
---|
896 |
|
---|
897 | page.setAttribute( 'aria-labelledby', tabId );
|
---|
898 |
|
---|
899 | // Take records for the tabs and elements created.
|
---|
900 | this._.tabs[ contents.id ] = [ tab, page ];
|
---|
901 | this._.tabIdList.push( contents.id );
|
---|
902 | !contents.hidden && this._.pageCount++;
|
---|
903 | this._.lastTab = tab;
|
---|
904 | this.updateStyle();
|
---|
905 |
|
---|
906 | var contentMap = this._.contents[ contents.id ] = {},
|
---|
907 | cursor,
|
---|
908 | children = vbox.getChild();
|
---|
909 |
|
---|
910 | while ( ( cursor = children.shift() ) )
|
---|
911 | {
|
---|
912 | contentMap[ cursor.id ] = cursor;
|
---|
913 | if ( typeof( cursor.getChild ) == 'function' )
|
---|
914 | children.push.apply( children, cursor.getChild() );
|
---|
915 | }
|
---|
916 |
|
---|
917 | // Attach the DOM nodes.
|
---|
918 |
|
---|
919 | page.setAttribute( 'name', contents.id );
|
---|
920 | page.appendTo( this.parts.contents );
|
---|
921 |
|
---|
922 | tab.unselectable();
|
---|
923 | this.parts.tabs.append( tab );
|
---|
924 |
|
---|
925 | // Add access key handlers if access key is defined.
|
---|
926 | if ( contents.accessKey )
|
---|
927 | {
|
---|
928 | registerAccessKey( this, this, 'CTRL+' + contents.accessKey,
|
---|
929 | tabAccessKeyDown, tabAccessKeyUp );
|
---|
930 | this._.accessKeyMap[ 'CTRL+' + contents.accessKey ] = contents.id;
|
---|
931 | }
|
---|
932 | },
|
---|
933 |
|
---|
934 | /**
|
---|
935 | * Activates a tab page in the dialog by its id.
|
---|
936 | * @param {String} id The id of the dialog tab to be activated.
|
---|
937 | * @example
|
---|
938 | * dialogObj.selectPage( 'tab_1' );
|
---|
939 | */
|
---|
940 | selectPage : function( id )
|
---|
941 | {
|
---|
942 | // Hide the non-selected tabs and pages.
|
---|
943 | for ( var i in this._.tabs )
|
---|
944 | if ( ! ( i in Object.prototype ) )
|
---|
945 | {
|
---|
946 | var tab = this._.tabs[i][0],
|
---|
947 | page = this._.tabs[i][1];
|
---|
948 | if ( i != id )
|
---|
949 | {
|
---|
950 | tab.removeClass( 'cke_dialog_tab_selected' );
|
---|
951 | page.hide();
|
---|
952 | }
|
---|
953 | page.setAttribute( 'aria-hidden', i != id );
|
---|
954 | }
|
---|
955 |
|
---|
956 | var selected = this._.tabs[id];
|
---|
957 | selected[0].addClass( 'cke_dialog_tab_selected' );
|
---|
958 | selected[1].show();
|
---|
959 | this._.currentTabId = id;
|
---|
960 | this._.currentTabIndex = CKEDITOR.tools.indexOf( this._.tabIdList, id );
|
---|
961 | },
|
---|
962 |
|
---|
963 | // Dialog state-specific style updates.
|
---|
964 | updateStyle : function()
|
---|
965 | {
|
---|
966 | // If only a single page shown, a different style is used in the central pane.
|
---|
967 | this.parts.dialog[ ( this._.pageCount === 1 ? 'add' : 'remove' ) + 'Class' ]( 'cke_single_page' );
|
---|
968 | },
|
---|
969 |
|
---|
970 | /**
|
---|
971 | * Hides a page's tab away from the dialog.
|
---|
972 | * @param {String} id The page's Id.
|
---|
973 | * @example
|
---|
974 | * dialog.hidePage( 'tab_3' );
|
---|
975 | */
|
---|
976 | hidePage : function( id )
|
---|
977 | {
|
---|
978 | var tab = this._.tabs[id] && this._.tabs[id][0];
|
---|
979 | if ( !tab || this._.pageCount == 1 )
|
---|
980 | return;
|
---|
981 | // Switch to other tab first when we're hiding the active tab.
|
---|
982 | else if ( id == this._.currentTabId )
|
---|
983 | this.selectPage( getPreviousVisibleTab.call( this ) );
|
---|
984 |
|
---|
985 | tab.hide();
|
---|
986 | this._.pageCount--;
|
---|
987 | this.updateStyle();
|
---|
988 | },
|
---|
989 |
|
---|
990 | /**
|
---|
991 | * Unhides a page's tab.
|
---|
992 | * @param {String} id The page's Id.
|
---|
993 | * @example
|
---|
994 | * dialog.showPage( 'tab_2' );
|
---|
995 | */
|
---|
996 | showPage : function( id )
|
---|
997 | {
|
---|
998 | var tab = this._.tabs[id] && this._.tabs[id][0];
|
---|
999 | if ( !tab )
|
---|
1000 | return;
|
---|
1001 | tab.show();
|
---|
1002 | this._.pageCount++;
|
---|
1003 | this.updateStyle();
|
---|
1004 | },
|
---|
1005 |
|
---|
1006 | /**
|
---|
1007 | * Gets the root DOM element of the dialog.
|
---|
1008 | * @returns {CKEDITOR.dom.element} The <span> element containing this dialog.
|
---|
1009 | * @example
|
---|
1010 | * var dialogElement = dialogObj.getElement().getFirst();
|
---|
1011 | * dialogElement.setStyle( 'padding', '5px' );
|
---|
1012 | */
|
---|
1013 | getElement : function()
|
---|
1014 | {
|
---|
1015 | return this._.element;
|
---|
1016 | },
|
---|
1017 |
|
---|
1018 | /**
|
---|
1019 | * Gets the name of the dialog.
|
---|
1020 | * @returns {String} The name of this dialog.
|
---|
1021 | * @example
|
---|
1022 | * var dialogName = dialogObj.getName();
|
---|
1023 | */
|
---|
1024 | getName : function()
|
---|
1025 | {
|
---|
1026 | return this._.name;
|
---|
1027 | },
|
---|
1028 |
|
---|
1029 | /**
|
---|
1030 | * Gets a dialog UI element object from a dialog page.
|
---|
1031 | * @param {String} pageId id of dialog page.
|
---|
1032 | * @param {String} elementId id of UI element.
|
---|
1033 | * @example
|
---|
1034 | * @returns {CKEDITOR.ui.dialog.uiElement} The dialog UI element.
|
---|
1035 | */
|
---|
1036 | getContentElement : function( pageId, elementId )
|
---|
1037 | {
|
---|
1038 | var page = this._.contents[ pageId ];
|
---|
1039 | return page && page[ elementId ];
|
---|
1040 | },
|
---|
1041 |
|
---|
1042 | /**
|
---|
1043 | * Gets the value of a dialog UI element.
|
---|
1044 | * @param {String} pageId id of dialog page.
|
---|
1045 | * @param {String} elementId id of UI element.
|
---|
1046 | * @example
|
---|
1047 | * @returns {Object} The value of the UI element.
|
---|
1048 | */
|
---|
1049 | getValueOf : function( pageId, elementId )
|
---|
1050 | {
|
---|
1051 | return this.getContentElement( pageId, elementId ).getValue();
|
---|
1052 | },
|
---|
1053 |
|
---|
1054 | /**
|
---|
1055 | * Sets the value of a dialog UI element.
|
---|
1056 | * @param {String} pageId id of the dialog page.
|
---|
1057 | * @param {String} elementId id of the UI element.
|
---|
1058 | * @param {Object} value The new value of the UI element.
|
---|
1059 | * @example
|
---|
1060 | */
|
---|
1061 | setValueOf : function( pageId, elementId, value )
|
---|
1062 | {
|
---|
1063 | return this.getContentElement( pageId, elementId ).setValue( value );
|
---|
1064 | },
|
---|
1065 |
|
---|
1066 | /**
|
---|
1067 | * Gets the UI element of a button in the dialog's button row.
|
---|
1068 | * @param {String} id The id of the button.
|
---|
1069 | * @example
|
---|
1070 | * @returns {CKEDITOR.ui.dialog.button} The button object.
|
---|
1071 | */
|
---|
1072 | getButton : function( id )
|
---|
1073 | {
|
---|
1074 | return this._.buttons[ id ];
|
---|
1075 | },
|
---|
1076 |
|
---|
1077 | /**
|
---|
1078 | * Simulates a click to a dialog button in the dialog's button row.
|
---|
1079 | * @param {String} id The id of the button.
|
---|
1080 | * @example
|
---|
1081 | * @returns The return value of the dialog's "click" event.
|
---|
1082 | */
|
---|
1083 | click : function( id )
|
---|
1084 | {
|
---|
1085 | return this._.buttons[ id ].click();
|
---|
1086 | },
|
---|
1087 |
|
---|
1088 | /**
|
---|
1089 | * Disables a dialog button.
|
---|
1090 | * @param {String} id The id of the button.
|
---|
1091 | * @example
|
---|
1092 | */
|
---|
1093 | disableButton : function( id )
|
---|
1094 | {
|
---|
1095 | return this._.buttons[ id ].disable();
|
---|
1096 | },
|
---|
1097 |
|
---|
1098 | /**
|
---|
1099 | * Enables a dialog button.
|
---|
1100 | * @param {String} id The id of the button.
|
---|
1101 | * @example
|
---|
1102 | */
|
---|
1103 | enableButton : function( id )
|
---|
1104 | {
|
---|
1105 | return this._.buttons[ id ].enable();
|
---|
1106 | },
|
---|
1107 |
|
---|
1108 | /**
|
---|
1109 | * Gets the number of pages in the dialog.
|
---|
1110 | * @returns {Number} Page count.
|
---|
1111 | */
|
---|
1112 | getPageCount : function()
|
---|
1113 | {
|
---|
1114 | return this._.pageCount;
|
---|
1115 | },
|
---|
1116 |
|
---|
1117 | /**
|
---|
1118 | * Gets the editor instance which opened this dialog.
|
---|
1119 | * @returns {CKEDITOR.editor} Parent editor instances.
|
---|
1120 | */
|
---|
1121 | getParentEditor : function()
|
---|
1122 | {
|
---|
1123 | return this._.editor;
|
---|
1124 | },
|
---|
1125 |
|
---|
1126 | /**
|
---|
1127 | * Gets the element that was selected when opening the dialog, if any.
|
---|
1128 | * @returns {CKEDITOR.dom.element} The element that was selected, or null.
|
---|
1129 | */
|
---|
1130 | getSelectedElement : function()
|
---|
1131 | {
|
---|
1132 | return this.getParentEditor().getSelection().getSelectedElement();
|
---|
1133 | },
|
---|
1134 |
|
---|
1135 | /**
|
---|
1136 | * Adds element to dialog's focusable list.
|
---|
1137 | *
|
---|
1138 | * @param {CKEDITOR.dom.element} element
|
---|
1139 | * @param {Number} [index]
|
---|
1140 | */
|
---|
1141 | addFocusable: function( element, index ) {
|
---|
1142 | if ( typeof index == 'undefined' )
|
---|
1143 | {
|
---|
1144 | index = this._.focusList.length;
|
---|
1145 | this._.focusList.push( new Focusable( this, element, index ) );
|
---|
1146 | }
|
---|
1147 | else
|
---|
1148 | {
|
---|
1149 | this._.focusList.splice( index, 0, new Focusable( this, element, index ) );
|
---|
1150 | for ( var i = index + 1 ; i < this._.focusList.length ; i++ )
|
---|
1151 | this._.focusList[ i ].focusIndex++;
|
---|
1152 | }
|
---|
1153 | }
|
---|
1154 | };
|
---|
1155 |
|
---|
1156 | CKEDITOR.tools.extend( CKEDITOR.dialog,
|
---|
1157 | /**
|
---|
1158 | * @lends CKEDITOR.dialog
|
---|
1159 | */
|
---|
1160 | {
|
---|
1161 | /**
|
---|
1162 | * Registers a dialog.
|
---|
1163 | * @param {String} name The dialog's name.
|
---|
1164 | * @param {Function|String} dialogDefinition
|
---|
1165 | * A function returning the dialog's definition, or the URL to the .js file holding the function.
|
---|
1166 | * The function should accept an argument "editor" which is the current editor instance, and
|
---|
1167 | * return an object conforming to {@link CKEDITOR.dialog.dialogDefinition}.
|
---|
1168 | * @example
|
---|
1169 | * @see CKEDITOR.dialog.dialogDefinition
|
---|
1170 | */
|
---|
1171 | add : function( name, dialogDefinition )
|
---|
1172 | {
|
---|
1173 | // Avoid path registration from multiple instances override definition.
|
---|
1174 | if ( !this._.dialogDefinitions[name]
|
---|
1175 | || typeof dialogDefinition == 'function' )
|
---|
1176 | this._.dialogDefinitions[name] = dialogDefinition;
|
---|
1177 | },
|
---|
1178 |
|
---|
1179 | exists : function( name )
|
---|
1180 | {
|
---|
1181 | return !!this._.dialogDefinitions[ name ];
|
---|
1182 | },
|
---|
1183 |
|
---|
1184 | getCurrent : function()
|
---|
1185 | {
|
---|
1186 | return CKEDITOR.dialog._.currentTop;
|
---|
1187 | },
|
---|
1188 |
|
---|
1189 | /**
|
---|
1190 | * The default OK button for dialogs. Fires the "ok" event and closes the dialog if the event succeeds.
|
---|
1191 | * @static
|
---|
1192 | * @field
|
---|
1193 | * @example
|
---|
1194 | * @type Function
|
---|
1195 | */
|
---|
1196 | okButton : (function()
|
---|
1197 | {
|
---|
1198 | var retval = function( editor, override )
|
---|
1199 | {
|
---|
1200 | override = override || {};
|
---|
1201 | return CKEDITOR.tools.extend( {
|
---|
1202 | id : 'ok',
|
---|
1203 | type : 'button',
|
---|
1204 | label : editor.lang.common.ok,
|
---|
1205 | 'class' : 'cke_dialog_ui_button_ok',
|
---|
1206 | onClick : function( evt )
|
---|
1207 | {
|
---|
1208 | var dialog = evt.data.dialog;
|
---|
1209 | if ( dialog.fire( 'ok', { hide : true } ).hide !== false )
|
---|
1210 | dialog.hide();
|
---|
1211 | }
|
---|
1212 | }, override, true );
|
---|
1213 | };
|
---|
1214 | retval.type = 'button';
|
---|
1215 | retval.override = function( override )
|
---|
1216 | {
|
---|
1217 | return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
|
---|
1218 | { type : 'button' }, true );
|
---|
1219 | };
|
---|
1220 | return retval;
|
---|
1221 | })(),
|
---|
1222 |
|
---|
1223 | /**
|
---|
1224 | * The default cancel button for dialogs. Fires the "cancel" event and closes the dialog if no UI element value changed.
|
---|
1225 | * @static
|
---|
1226 | * @field
|
---|
1227 | * @example
|
---|
1228 | * @type Function
|
---|
1229 | */
|
---|
1230 | cancelButton : (function()
|
---|
1231 | {
|
---|
1232 | var retval = function( editor, override )
|
---|
1233 | {
|
---|
1234 | override = override || {};
|
---|
1235 | return CKEDITOR.tools.extend( {
|
---|
1236 | id : 'cancel',
|
---|
1237 | type : 'button',
|
---|
1238 | label : editor.lang.common.cancel,
|
---|
1239 | 'class' : 'cke_dialog_ui_button_cancel',
|
---|
1240 | onClick : function( evt )
|
---|
1241 | {
|
---|
1242 | var dialog = evt.data.dialog;
|
---|
1243 | if ( dialog.fire( 'cancel', { hide : true } ).hide !== false )
|
---|
1244 | dialog.hide();
|
---|
1245 | }
|
---|
1246 | }, override, true );
|
---|
1247 | };
|
---|
1248 | retval.type = 'button';
|
---|
1249 | retval.override = function( override )
|
---|
1250 | {
|
---|
1251 | return CKEDITOR.tools.extend( function( editor ){ return retval( editor, override ); },
|
---|
1252 | { type : 'button' }, true );
|
---|
1253 | };
|
---|
1254 | return retval;
|
---|
1255 | })(),
|
---|
1256 |
|
---|
1257 | /**
|
---|
1258 | * Registers a dialog UI element.
|
---|
1259 | * @param {String} typeName The name of the UI element.
|
---|
1260 | * @param {Function} builder The function to build the UI element.
|
---|
1261 | * @example
|
---|
1262 | */
|
---|
1263 | addUIElement : function( typeName, builder )
|
---|
1264 | {
|
---|
1265 | this._.uiElementBuilders[ typeName ] = builder;
|
---|
1266 | }
|
---|
1267 | });
|
---|
1268 |
|
---|
1269 | CKEDITOR.dialog._ =
|
---|
1270 | {
|
---|
1271 | uiElementBuilders : {},
|
---|
1272 |
|
---|
1273 | dialogDefinitions : {},
|
---|
1274 |
|
---|
1275 | currentTop : null,
|
---|
1276 |
|
---|
1277 | currentZIndex : null
|
---|
1278 | };
|
---|
1279 |
|
---|
1280 | // "Inherit" (copy actually) from CKEDITOR.event.
|
---|
1281 | CKEDITOR.event.implementOn( CKEDITOR.dialog );
|
---|
1282 | CKEDITOR.event.implementOn( CKEDITOR.dialog.prototype, true );
|
---|
1283 |
|
---|
1284 | var defaultDialogDefinition =
|
---|
1285 | {
|
---|
1286 | resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
|
---|
1287 | minWidth : 600,
|
---|
1288 | minHeight : 400,
|
---|
1289 | buttons : [ CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton ]
|
---|
1290 | };
|
---|
1291 |
|
---|
1292 | // The buttons in MacOS Apps are in reverse order #4750
|
---|
1293 | CKEDITOR.env.mac && defaultDialogDefinition.buttons.reverse();
|
---|
1294 |
|
---|
1295 | // Tool function used to return an item from an array based on its id
|
---|
1296 | // property.
|
---|
1297 | var getById = function( array, id, recurse )
|
---|
1298 | {
|
---|
1299 | for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
|
---|
1300 | {
|
---|
1301 | if ( item.id == id )
|
---|
1302 | return item;
|
---|
1303 | if ( recurse && item[ recurse ] )
|
---|
1304 | {
|
---|
1305 | var retval = getById( item[ recurse ], id, recurse ) ;
|
---|
1306 | if ( retval )
|
---|
1307 | return retval;
|
---|
1308 | }
|
---|
1309 | }
|
---|
1310 | return null;
|
---|
1311 | };
|
---|
1312 |
|
---|
1313 | // Tool function used to add an item into an array.
|
---|
1314 | var addById = function( array, newItem, nextSiblingId, recurse, nullIfNotFound )
|
---|
1315 | {
|
---|
1316 | if ( nextSiblingId )
|
---|
1317 | {
|
---|
1318 | for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
|
---|
1319 | {
|
---|
1320 | if ( item.id == nextSiblingId )
|
---|
1321 | {
|
---|
1322 | array.splice( i, 0, newItem );
|
---|
1323 | return newItem;
|
---|
1324 | }
|
---|
1325 |
|
---|
1326 | if ( recurse && item[ recurse ] )
|
---|
1327 | {
|
---|
1328 | var retval = addById( item[ recurse ], newItem, nextSiblingId, recurse, true );
|
---|
1329 | if ( retval )
|
---|
1330 | return retval;
|
---|
1331 | }
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | if ( nullIfNotFound )
|
---|
1335 | return null;
|
---|
1336 | }
|
---|
1337 |
|
---|
1338 | array.push( newItem );
|
---|
1339 | return newItem;
|
---|
1340 | };
|
---|
1341 |
|
---|
1342 | // Tool function used to remove an item from an array based on its id.
|
---|
1343 | var removeById = function( array, id, recurse )
|
---|
1344 | {
|
---|
1345 | for ( var i = 0, item ; ( item = array[ i ] ) ; i++ )
|
---|
1346 | {
|
---|
1347 | if ( item.id == id )
|
---|
1348 | return array.splice( i, 1 );
|
---|
1349 | if ( recurse && item[ recurse ] )
|
---|
1350 | {
|
---|
1351 | var retval = removeById( item[ recurse ], id, recurse );
|
---|
1352 | if ( retval )
|
---|
1353 | return retval;
|
---|
1354 | }
|
---|
1355 | }
|
---|
1356 | return null;
|
---|
1357 | };
|
---|
1358 |
|
---|
1359 | /**
|
---|
1360 | * This class is not really part of the API. It is the "definition" property value
|
---|
1361 | * passed to "dialogDefinition" event handlers.
|
---|
1362 | * @constructor
|
---|
1363 | * @name CKEDITOR.dialog.dialogDefinitionObject
|
---|
1364 | * @extends CKEDITOR.dialog.dialogDefinition
|
---|
1365 | * @example
|
---|
1366 | * CKEDITOR.on( 'dialogDefinition', function( evt )
|
---|
1367 | * {
|
---|
1368 | * var definition = evt.data.definition;
|
---|
1369 | * var content = definition.getContents( 'page1' );
|
---|
1370 | * ...
|
---|
1371 | * } );
|
---|
1372 | */
|
---|
1373 | var definitionObject = function( dialog, dialogDefinition )
|
---|
1374 | {
|
---|
1375 | // TODO : Check if needed.
|
---|
1376 | this.dialog = dialog;
|
---|
1377 |
|
---|
1378 | // Transform the contents entries in contentObjects.
|
---|
1379 | var contents = dialogDefinition.contents;
|
---|
1380 | for ( var i = 0, content ; ( content = contents[i] ) ; i++ )
|
---|
1381 | contents[ i ] = new contentObject( dialog, content );
|
---|
1382 |
|
---|
1383 | CKEDITOR.tools.extend( this, dialogDefinition );
|
---|
1384 | };
|
---|
1385 |
|
---|
1386 | definitionObject.prototype =
|
---|
1387 | /** @lends CKEDITOR.dialog.dialogDefinitionObject.prototype */
|
---|
1388 | {
|
---|
1389 | /**
|
---|
1390 | * Gets a content definition.
|
---|
1391 | * @param {String} id The id of the content definition.
|
---|
1392 | * @returns {CKEDITOR.dialog.contentDefinition} The content definition
|
---|
1393 | * matching id.
|
---|
1394 | */
|
---|
1395 | getContents : function( id )
|
---|
1396 | {
|
---|
1397 | return getById( this.contents, id );
|
---|
1398 | },
|
---|
1399 |
|
---|
1400 | /**
|
---|
1401 | * Gets a button definition.
|
---|
1402 | * @param {String} id The id of the button definition.
|
---|
1403 | * @returns {CKEDITOR.dialog.buttonDefinition} The button definition
|
---|
1404 | * matching id.
|
---|
1405 | */
|
---|
1406 | getButton : function( id )
|
---|
1407 | {
|
---|
1408 | return getById( this.buttons, id );
|
---|
1409 | },
|
---|
1410 |
|
---|
1411 | /**
|
---|
1412 | * Adds a content definition object under this dialog definition.
|
---|
1413 | * @param {CKEDITOR.dialog.contentDefinition} contentDefinition The
|
---|
1414 | * content definition.
|
---|
1415 | * @param {String} [nextSiblingId] The id of an existing content
|
---|
1416 | * definition which the new content definition will be inserted
|
---|
1417 | * before. Omit if the new content definition is to be inserted as
|
---|
1418 | * the last item.
|
---|
1419 | * @returns {CKEDITOR.dialog.contentDefinition} The inserted content
|
---|
1420 | * definition.
|
---|
1421 | */
|
---|
1422 | addContents : function( contentDefinition, nextSiblingId )
|
---|
1423 | {
|
---|
1424 | return addById( this.contents, contentDefinition, nextSiblingId );
|
---|
1425 | },
|
---|
1426 |
|
---|
1427 | /**
|
---|
1428 | * Adds a button definition object under this dialog definition.
|
---|
1429 | * @param {CKEDITOR.dialog.buttonDefinition} buttonDefinition The
|
---|
1430 | * button definition.
|
---|
1431 | * @param {String} [nextSiblingId] The id of an existing button
|
---|
1432 | * definition which the new button definition will be inserted
|
---|
1433 | * before. Omit if the new button definition is to be inserted as
|
---|
1434 | * the last item.
|
---|
1435 | * @returns {CKEDITOR.dialog.buttonDefinition} The inserted button
|
---|
1436 | * definition.
|
---|
1437 | */
|
---|
1438 | addButton : function( buttonDefinition, nextSiblingId )
|
---|
1439 | {
|
---|
1440 | return addById( this.buttons, buttonDefinition, nextSiblingId );
|
---|
1441 | },
|
---|
1442 |
|
---|
1443 | /**
|
---|
1444 | * Removes a content definition from this dialog definition.
|
---|
1445 | * @param {String} id The id of the content definition to be removed.
|
---|
1446 | * @returns {CKEDITOR.dialog.contentDefinition} The removed content
|
---|
1447 | * definition.
|
---|
1448 | */
|
---|
1449 | removeContents : function( id )
|
---|
1450 | {
|
---|
1451 | removeById( this.contents, id );
|
---|
1452 | },
|
---|
1453 |
|
---|
1454 | /**
|
---|
1455 | * Removes a button definition from the dialog definition.
|
---|
1456 | * @param {String} id The id of the button definition to be removed.
|
---|
1457 | * @returns {CKEDITOR.dialog.buttonDefinition} The removed button
|
---|
1458 | * definition.
|
---|
1459 | */
|
---|
1460 | removeButton : function( id )
|
---|
1461 | {
|
---|
1462 | removeById( this.buttons, id );
|
---|
1463 | }
|
---|
1464 | };
|
---|
1465 |
|
---|
1466 | /**
|
---|
1467 | * This class is not really part of the API. It is the template of the
|
---|
1468 | * objects representing content pages inside the
|
---|
1469 | * CKEDITOR.dialog.dialogDefinitionObject.
|
---|
1470 | * @constructor
|
---|
1471 | * @name CKEDITOR.dialog.contentDefinitionObject
|
---|
1472 | * @example
|
---|
1473 | * CKEDITOR.on( 'dialogDefinition', function( evt )
|
---|
1474 | * {
|
---|
1475 | * var definition = evt.data.definition;
|
---|
1476 | * var content = definition.getContents( 'page1' );
|
---|
1477 | * content.remove( 'textInput1' );
|
---|
1478 | * ...
|
---|
1479 | * } );
|
---|
1480 | */
|
---|
1481 | function contentObject( dialog, contentDefinition )
|
---|
1482 | {
|
---|
1483 | this._ =
|
---|
1484 | {
|
---|
1485 | dialog : dialog
|
---|
1486 | };
|
---|
1487 |
|
---|
1488 | CKEDITOR.tools.extend( this, contentDefinition );
|
---|
1489 | }
|
---|
1490 |
|
---|
1491 | contentObject.prototype =
|
---|
1492 | /** @lends CKEDITOR.dialog.contentDefinitionObject.prototype */
|
---|
1493 | {
|
---|
1494 | /**
|
---|
1495 | * Gets a UI element definition under the content definition.
|
---|
1496 | * @param {String} id The id of the UI element definition.
|
---|
1497 | * @returns {CKEDITOR.dialog.uiElementDefinition}
|
---|
1498 | */
|
---|
1499 | get : function( id )
|
---|
1500 | {
|
---|
1501 | return getById( this.elements, id, 'children' );
|
---|
1502 | },
|
---|
1503 |
|
---|
1504 | /**
|
---|
1505 | * Adds a UI element definition to the content definition.
|
---|
1506 | * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition The
|
---|
1507 | * UI elemnet definition to be added.
|
---|
1508 | * @param {String} nextSiblingId The id of an existing UI element
|
---|
1509 | * definition which the new UI element definition will be inserted
|
---|
1510 | * before. Omit if the new button definition is to be inserted as
|
---|
1511 | * the last item.
|
---|
1512 | * @returns {CKEDITOR.dialog.uiElementDefinition} The element
|
---|
1513 | * definition inserted.
|
---|
1514 | */
|
---|
1515 | add : function( elementDefinition, nextSiblingId )
|
---|
1516 | {
|
---|
1517 | return addById( this.elements, elementDefinition, nextSiblingId, 'children' );
|
---|
1518 | },
|
---|
1519 |
|
---|
1520 | /**
|
---|
1521 | * Removes a UI element definition from the content definition.
|
---|
1522 | * @param {String} id The id of the UI element definition to be
|
---|
1523 | * removed.
|
---|
1524 | * @returns {CKEDITOR.dialog.uiElementDefinition} The element
|
---|
1525 | * definition removed.
|
---|
1526 | * @example
|
---|
1527 | */
|
---|
1528 | remove : function( id )
|
---|
1529 | {
|
---|
1530 | removeById( this.elements, id, 'children' );
|
---|
1531 | }
|
---|
1532 | };
|
---|
1533 |
|
---|
1534 | function initDragAndDrop( dialog )
|
---|
1535 | {
|
---|
1536 | var lastCoords = null,
|
---|
1537 | abstractDialogCoords = null,
|
---|
1538 | element = dialog.getElement().getFirst(),
|
---|
1539 | editor = dialog.getParentEditor(),
|
---|
1540 | magnetDistance = editor.config.dialog_magnetDistance,
|
---|
1541 | margins = editor.skin.margins || [ 0, 0, 0, 0 ];
|
---|
1542 |
|
---|
1543 | if ( typeof magnetDistance == 'undefined' )
|
---|
1544 | magnetDistance = 20;
|
---|
1545 |
|
---|
1546 | function mouseMoveHandler( evt )
|
---|
1547 | {
|
---|
1548 | var dialogSize = dialog.getSize(),
|
---|
1549 | viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
|
---|
1550 | x = evt.data.$.screenX,
|
---|
1551 | y = evt.data.$.screenY,
|
---|
1552 | dx = x - lastCoords.x,
|
---|
1553 | dy = y - lastCoords.y,
|
---|
1554 | realX, realY;
|
---|
1555 |
|
---|
1556 | lastCoords = { x : x, y : y };
|
---|
1557 | abstractDialogCoords.x += dx;
|
---|
1558 | abstractDialogCoords.y += dy;
|
---|
1559 |
|
---|
1560 | if ( abstractDialogCoords.x + margins[3] < magnetDistance )
|
---|
1561 | realX = - margins[3];
|
---|
1562 | else if ( abstractDialogCoords.x - margins[1] > viewPaneSize.width - dialogSize.width - magnetDistance )
|
---|
1563 | realX = viewPaneSize.width - dialogSize.width + margins[1];
|
---|
1564 | else
|
---|
1565 | realX = abstractDialogCoords.x;
|
---|
1566 |
|
---|
1567 | if ( abstractDialogCoords.y + margins[0] < magnetDistance )
|
---|
1568 | realY = - margins[0];
|
---|
1569 | else if ( abstractDialogCoords.y - margins[2] > viewPaneSize.height - dialogSize.height - magnetDistance )
|
---|
1570 | realY = viewPaneSize.height - dialogSize.height + margins[2];
|
---|
1571 | else
|
---|
1572 | realY = abstractDialogCoords.y;
|
---|
1573 |
|
---|
1574 | dialog.move( realX, realY );
|
---|
1575 |
|
---|
1576 | evt.data.preventDefault();
|
---|
1577 | }
|
---|
1578 |
|
---|
1579 | function mouseUpHandler( evt )
|
---|
1580 | {
|
---|
1581 | CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
|
---|
1582 | CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
|
---|
1583 |
|
---|
1584 | if ( CKEDITOR.env.ie6Compat )
|
---|
1585 | {
|
---|
1586 | var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
|
---|
1587 | coverDoc.removeListener( 'mousemove', mouseMoveHandler );
|
---|
1588 | coverDoc.removeListener( 'mouseup', mouseUpHandler );
|
---|
1589 | }
|
---|
1590 | }
|
---|
1591 |
|
---|
1592 | dialog.parts.title.on( 'mousedown', function( evt )
|
---|
1593 | {
|
---|
1594 | dialog._.updateSize = true;
|
---|
1595 |
|
---|
1596 | lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
|
---|
1597 |
|
---|
1598 | CKEDITOR.document.on( 'mousemove', mouseMoveHandler );
|
---|
1599 | CKEDITOR.document.on( 'mouseup', mouseUpHandler );
|
---|
1600 | abstractDialogCoords = dialog.getPosition();
|
---|
1601 |
|
---|
1602 | if ( CKEDITOR.env.ie6Compat )
|
---|
1603 | {
|
---|
1604 | var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
|
---|
1605 | coverDoc.on( 'mousemove', mouseMoveHandler );
|
---|
1606 | coverDoc.on( 'mouseup', mouseUpHandler );
|
---|
1607 | }
|
---|
1608 |
|
---|
1609 | evt.data.preventDefault();
|
---|
1610 | }, dialog );
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | function initResizeHandles( dialog )
|
---|
1614 | {
|
---|
1615 | var definition = dialog.definition,
|
---|
1616 | minWidth = definition.minWidth || 0,
|
---|
1617 | minHeight = definition.minHeight || 0,
|
---|
1618 | resizable = definition.resizable,
|
---|
1619 | margins = dialog.getParentEditor().skin.margins || [ 0, 0, 0, 0 ];
|
---|
1620 |
|
---|
1621 | function topSizer( coords, dy )
|
---|
1622 | {
|
---|
1623 | coords.y += dy;
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | function rightSizer( coords, dx )
|
---|
1627 | {
|
---|
1628 | coords.x2 += dx;
|
---|
1629 | }
|
---|
1630 |
|
---|
1631 | function bottomSizer( coords, dy )
|
---|
1632 | {
|
---|
1633 | coords.y2 += dy;
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | function leftSizer( coords, dx )
|
---|
1637 | {
|
---|
1638 | coords.x += dx;
|
---|
1639 | }
|
---|
1640 |
|
---|
1641 | var lastCoords = null,
|
---|
1642 | abstractDialogCoords = null,
|
---|
1643 | magnetDistance = dialog._.editor.config.magnetDistance,
|
---|
1644 | parts = [ 'tl', 't', 'tr', 'l', 'r', 'bl', 'b', 'br' ];
|
---|
1645 |
|
---|
1646 | function mouseDownHandler( evt )
|
---|
1647 | {
|
---|
1648 | var partName = evt.listenerData.part, size = dialog.getSize();
|
---|
1649 | abstractDialogCoords = dialog.getPosition();
|
---|
1650 | CKEDITOR.tools.extend( abstractDialogCoords,
|
---|
1651 | {
|
---|
1652 | x2 : abstractDialogCoords.x + size.width,
|
---|
1653 | y2 : abstractDialogCoords.y + size.height
|
---|
1654 | } );
|
---|
1655 | lastCoords = { x : evt.data.$.screenX, y : evt.data.$.screenY };
|
---|
1656 |
|
---|
1657 | CKEDITOR.document.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
|
---|
1658 | CKEDITOR.document.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
|
---|
1659 |
|
---|
1660 | if ( CKEDITOR.env.ie6Compat )
|
---|
1661 | {
|
---|
1662 | var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
|
---|
1663 | coverDoc.on( 'mousemove', mouseMoveHandler, dialog, { part : partName } );
|
---|
1664 | coverDoc.on( 'mouseup', mouseUpHandler, dialog, { part : partName } );
|
---|
1665 | }
|
---|
1666 |
|
---|
1667 | evt.data.preventDefault();
|
---|
1668 | }
|
---|
1669 |
|
---|
1670 | function mouseMoveHandler( evt )
|
---|
1671 | {
|
---|
1672 | var x = evt.data.$.screenX,
|
---|
1673 | y = evt.data.$.screenY,
|
---|
1674 | dx = x - lastCoords.x,
|
---|
1675 | dy = y - lastCoords.y,
|
---|
1676 | viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(),
|
---|
1677 | partName = evt.listenerData.part;
|
---|
1678 |
|
---|
1679 | if ( partName.search( 't' ) != -1 )
|
---|
1680 | topSizer( abstractDialogCoords, dy );
|
---|
1681 | if ( partName.search( 'l' ) != -1 )
|
---|
1682 | leftSizer( abstractDialogCoords, dx );
|
---|
1683 | if ( partName.search( 'b' ) != -1 )
|
---|
1684 | bottomSizer( abstractDialogCoords, dy );
|
---|
1685 | if ( partName.search( 'r' ) != -1 )
|
---|
1686 | rightSizer( abstractDialogCoords, dx );
|
---|
1687 |
|
---|
1688 | lastCoords = { x : x, y : y };
|
---|
1689 |
|
---|
1690 | var realX, realY, realX2, realY2;
|
---|
1691 |
|
---|
1692 | if ( abstractDialogCoords.x + margins[3] < magnetDistance )
|
---|
1693 | realX = - margins[3];
|
---|
1694 | else if ( partName.search( 'l' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
|
---|
1695 | realX = abstractDialogCoords.x2 - minWidth;
|
---|
1696 | else
|
---|
1697 | realX = abstractDialogCoords.x;
|
---|
1698 |
|
---|
1699 | if ( abstractDialogCoords.y + margins[0] < magnetDistance )
|
---|
1700 | realY = - margins[0];
|
---|
1701 | else if ( partName.search( 't' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
|
---|
1702 | realY = abstractDialogCoords.y2 - minHeight;
|
---|
1703 | else
|
---|
1704 | realY = abstractDialogCoords.y;
|
---|
1705 |
|
---|
1706 | if ( abstractDialogCoords.x2 - margins[1] > viewPaneSize.width - magnetDistance )
|
---|
1707 | realX2 = viewPaneSize.width + margins[1] ;
|
---|
1708 | else if ( partName.search( 'r' ) != -1 && abstractDialogCoords.x2 - abstractDialogCoords.x < minWidth + magnetDistance )
|
---|
1709 | realX2 = abstractDialogCoords.x + minWidth;
|
---|
1710 | else
|
---|
1711 | realX2 = abstractDialogCoords.x2;
|
---|
1712 |
|
---|
1713 | if ( abstractDialogCoords.y2 - margins[2] > viewPaneSize.height - magnetDistance )
|
---|
1714 | realY2= viewPaneSize.height + margins[2] ;
|
---|
1715 | else if ( partName.search( 'b' ) != -1 && abstractDialogCoords.y2 - abstractDialogCoords.y < minHeight + magnetDistance )
|
---|
1716 | realY2 = abstractDialogCoords.y + minHeight;
|
---|
1717 | else
|
---|
1718 | realY2 = abstractDialogCoords.y2 ;
|
---|
1719 |
|
---|
1720 | dialog.move( realX, realY );
|
---|
1721 | dialog.resize( realX2 - realX, realY2 - realY );
|
---|
1722 |
|
---|
1723 | evt.data.preventDefault();
|
---|
1724 | }
|
---|
1725 |
|
---|
1726 | function mouseUpHandler( evt )
|
---|
1727 | {
|
---|
1728 | CKEDITOR.document.removeListener( 'mouseup', mouseUpHandler );
|
---|
1729 | CKEDITOR.document.removeListener( 'mousemove', mouseMoveHandler );
|
---|
1730 |
|
---|
1731 | if ( CKEDITOR.env.ie6Compat )
|
---|
1732 | {
|
---|
1733 | var coverDoc = coverElement.getChild( 0 ).getFrameDocument();
|
---|
1734 | coverDoc.removeListener( 'mouseup', mouseUpHandler );
|
---|
1735 | coverDoc.removeListener( 'mousemove', mouseMoveHandler );
|
---|
1736 | }
|
---|
1737 | }
|
---|
1738 |
|
---|
1739 | // TODO : Simplify the resize logic, having just a single resize grip <div>.
|
---|
1740 | // var widthTest = /[lr]/,
|
---|
1741 | // heightTest = /[tb]/;
|
---|
1742 | // for ( var i = 0 ; i < parts.length ; i++ )
|
---|
1743 | // {
|
---|
1744 | // var element = dialog.parts[ parts[i] + '_resize' ];
|
---|
1745 | // if ( resizable == CKEDITOR.DIALOG_RESIZE_NONE ||
|
---|
1746 | // resizable == CKEDITOR.DIALOG_RESIZE_HEIGHT && widthTest.test( parts[i] ) ||
|
---|
1747 | // resizable == CKEDITOR.DIALOG_RESIZE_WIDTH && heightTest.test( parts[i] ) )
|
---|
1748 | // {
|
---|
1749 | // element.hide();
|
---|
1750 | // continue;
|
---|
1751 | // }
|
---|
1752 | // element.on( 'mousedown', mouseDownHandler, dialog, { part : parts[i] } );
|
---|
1753 | // }
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | var resizeCover;
|
---|
1757 | var coverElement;
|
---|
1758 |
|
---|
1759 | var addCover = function( editor )
|
---|
1760 | {
|
---|
1761 | var win = CKEDITOR.document.getWindow();
|
---|
1762 |
|
---|
1763 | if ( !coverElement )
|
---|
1764 | {
|
---|
1765 | var backgroundColorStyle = editor.config.dialog_backgroundCoverColor || 'white';
|
---|
1766 |
|
---|
1767 | var html = [
|
---|
1768 | '<div style="position: ', ( CKEDITOR.env.ie6Compat ? 'absolute' : 'fixed' ),
|
---|
1769 | '; z-index: ', editor.config.baseFloatZIndex,
|
---|
1770 | '; top: 0px; left: 0px; ',
|
---|
1771 | ( !CKEDITOR.env.ie6Compat ? 'background-color: ' + backgroundColorStyle : '' ),
|
---|
1772 | '" id="cke_dialog_background_cover">'
|
---|
1773 | ];
|
---|
1774 |
|
---|
1775 |
|
---|
1776 | if ( CKEDITOR.env.ie6Compat )
|
---|
1777 | {
|
---|
1778 | // Support for custom document.domain in IE.
|
---|
1779 | var isCustomDomain = CKEDITOR.env.isCustomDomain(),
|
---|
1780 | iframeHtml = '<html><body style=\\\'background-color:' + backgroundColorStyle + ';\\\'></body></html>';
|
---|
1781 |
|
---|
1782 | html.push(
|
---|
1783 | '<iframe' +
|
---|
1784 | ' hidefocus="true"' +
|
---|
1785 | ' frameborder="0"' +
|
---|
1786 | ' id="cke_dialog_background_iframe"' +
|
---|
1787 | ' src="javascript:' );
|
---|
1788 |
|
---|
1789 | html.push( 'void((function(){' +
|
---|
1790 | 'document.open();' +
|
---|
1791 | ( isCustomDomain ? 'document.domain=\'' + document.domain + '\';' : '' ) +
|
---|
1792 | 'document.write( \'' + iframeHtml + '\' );' +
|
---|
1793 | 'document.close();' +
|
---|
1794 | '})())' );
|
---|
1795 |
|
---|
1796 | html.push(
|
---|
1797 | '"' +
|
---|
1798 | ' style="' +
|
---|
1799 | 'position:absolute;' +
|
---|
1800 | 'left:0;' +
|
---|
1801 | 'top:0;' +
|
---|
1802 | 'width:100%;' +
|
---|
1803 | 'height: 100%;' +
|
---|
1804 | 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)">' +
|
---|
1805 | '</iframe>' );
|
---|
1806 | }
|
---|
1807 |
|
---|
1808 | html.push( '</div>' );
|
---|
1809 |
|
---|
1810 | coverElement = CKEDITOR.dom.element.createFromHtml( html.join( '' ) );
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | var element = coverElement;
|
---|
1814 |
|
---|
1815 | var resizeFunc = function()
|
---|
1816 | {
|
---|
1817 | var size = win.getViewPaneSize();
|
---|
1818 | element.setStyles(
|
---|
1819 | {
|
---|
1820 | width : size.width + 'px',
|
---|
1821 | height : size.height + 'px'
|
---|
1822 | } );
|
---|
1823 | };
|
---|
1824 |
|
---|
1825 | var scrollFunc = function()
|
---|
1826 | {
|
---|
1827 | var pos = win.getScrollPosition(),
|
---|
1828 | cursor = CKEDITOR.dialog._.currentTop;
|
---|
1829 | element.setStyles(
|
---|
1830 | {
|
---|
1831 | left : pos.x + 'px',
|
---|
1832 | top : pos.y + 'px'
|
---|
1833 | });
|
---|
1834 |
|
---|
1835 | do
|
---|
1836 | {
|
---|
1837 | var dialogPos = cursor.getPosition();
|
---|
1838 | cursor.move( dialogPos.x, dialogPos.y );
|
---|
1839 | } while ( ( cursor = cursor._.parentDialog ) );
|
---|
1840 | };
|
---|
1841 |
|
---|
1842 | resizeCover = resizeFunc;
|
---|
1843 | win.on( 'resize', resizeFunc );
|
---|
1844 | resizeFunc();
|
---|
1845 | if ( CKEDITOR.env.ie6Compat )
|
---|
1846 | {
|
---|
1847 | // IE BUG: win.$.onscroll assignment doesn't work.. it must be window.onscroll.
|
---|
1848 | // So we need to invent a really funny way to make it work.
|
---|
1849 | var myScrollHandler = function()
|
---|
1850 | {
|
---|
1851 | scrollFunc();
|
---|
1852 | arguments.callee.prevScrollHandler.apply( this, arguments );
|
---|
1853 | };
|
---|
1854 | win.$.setTimeout( function()
|
---|
1855 | {
|
---|
1856 | myScrollHandler.prevScrollHandler = window.onscroll || function(){};
|
---|
1857 | window.onscroll = myScrollHandler;
|
---|
1858 | }, 0 );
|
---|
1859 | scrollFunc();
|
---|
1860 | }
|
---|
1861 |
|
---|
1862 | var opacity = editor.config.dialog_backgroundCoverOpacity;
|
---|
1863 | element.setOpacity( typeof opacity != 'undefined' ? opacity : 0.5 );
|
---|
1864 |
|
---|
1865 | element.appendTo( CKEDITOR.document.getBody() );
|
---|
1866 | };
|
---|
1867 |
|
---|
1868 | var removeCover = function()
|
---|
1869 | {
|
---|
1870 | if ( !coverElement )
|
---|
1871 | return;
|
---|
1872 |
|
---|
1873 | var win = CKEDITOR.document.getWindow();
|
---|
1874 | coverElement.remove();
|
---|
1875 | win.removeListener( 'resize', resizeCover );
|
---|
1876 |
|
---|
1877 | if ( CKEDITOR.env.ie6Compat )
|
---|
1878 | {
|
---|
1879 | win.$.setTimeout( function()
|
---|
1880 | {
|
---|
1881 | var prevScrollHandler = window.onscroll && window.onscroll.prevScrollHandler;
|
---|
1882 | window.onscroll = prevScrollHandler || null;
|
---|
1883 | }, 0 );
|
---|
1884 | }
|
---|
1885 | resizeCover = null;
|
---|
1886 | };
|
---|
1887 |
|
---|
1888 | var accessKeyProcessors = {};
|
---|
1889 |
|
---|
1890 | var accessKeyDownHandler = function( evt )
|
---|
1891 | {
|
---|
1892 | var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
|
---|
1893 | alt = evt.data.$.altKey,
|
---|
1894 | shift = evt.data.$.shiftKey,
|
---|
1895 | key = String.fromCharCode( evt.data.$.keyCode ),
|
---|
1896 | keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
|
---|
1897 |
|
---|
1898 | if ( !keyProcessor || !keyProcessor.length )
|
---|
1899 | return;
|
---|
1900 |
|
---|
1901 | keyProcessor = keyProcessor[keyProcessor.length - 1];
|
---|
1902 | keyProcessor.keydown && keyProcessor.keydown.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
|
---|
1903 | evt.data.preventDefault();
|
---|
1904 | };
|
---|
1905 |
|
---|
1906 | var accessKeyUpHandler = function( evt )
|
---|
1907 | {
|
---|
1908 | var ctrl = evt.data.$.ctrlKey || evt.data.$.metaKey,
|
---|
1909 | alt = evt.data.$.altKey,
|
---|
1910 | shift = evt.data.$.shiftKey,
|
---|
1911 | key = String.fromCharCode( evt.data.$.keyCode ),
|
---|
1912 | keyProcessor = accessKeyProcessors[( ctrl ? 'CTRL+' : '' ) + ( alt ? 'ALT+' : '') + ( shift ? 'SHIFT+' : '' ) + key];
|
---|
1913 |
|
---|
1914 | if ( !keyProcessor || !keyProcessor.length )
|
---|
1915 | return;
|
---|
1916 |
|
---|
1917 | keyProcessor = keyProcessor[keyProcessor.length - 1];
|
---|
1918 | if ( keyProcessor.keyup )
|
---|
1919 | {
|
---|
1920 | keyProcessor.keyup.call( keyProcessor.uiElement, keyProcessor.dialog, keyProcessor.key );
|
---|
1921 | evt.data.preventDefault();
|
---|
1922 | }
|
---|
1923 | };
|
---|
1924 |
|
---|
1925 | var registerAccessKey = function( uiElement, dialog, key, downFunc, upFunc )
|
---|
1926 | {
|
---|
1927 | var procList = accessKeyProcessors[key] || ( accessKeyProcessors[key] = [] );
|
---|
1928 | procList.push( {
|
---|
1929 | uiElement : uiElement,
|
---|
1930 | dialog : dialog,
|
---|
1931 | key : key,
|
---|
1932 | keyup : upFunc || uiElement.accessKeyUp,
|
---|
1933 | keydown : downFunc || uiElement.accessKeyDown
|
---|
1934 | } );
|
---|
1935 | };
|
---|
1936 |
|
---|
1937 | var unregisterAccessKey = function( obj )
|
---|
1938 | {
|
---|
1939 | for ( var i in accessKeyProcessors )
|
---|
1940 | if ( ! ( i in Object.prototype ) )
|
---|
1941 | {
|
---|
1942 | var list = accessKeyProcessors[i];
|
---|
1943 | for ( var j = list.length - 1 ; j >= 0 ; j-- )
|
---|
1944 | {
|
---|
1945 | if ( list[j].dialog == obj || list[j].uiElement == obj )
|
---|
1946 | list.splice( j, 1 );
|
---|
1947 | }
|
---|
1948 | if ( list.length === 0 )
|
---|
1949 | delete accessKeyProcessors[i];
|
---|
1950 | }
|
---|
1951 | };
|
---|
1952 |
|
---|
1953 | var tabAccessKeyUp = function( dialog, key )
|
---|
1954 | {
|
---|
1955 | if ( dialog._.accessKeyMap[key] )
|
---|
1956 | dialog.selectPage( dialog._.accessKeyMap[key] );
|
---|
1957 | };
|
---|
1958 |
|
---|
1959 | var tabAccessKeyDown = function( dialog, key )
|
---|
1960 | {
|
---|
1961 | };
|
---|
1962 |
|
---|
1963 | // ESC, ENTER
|
---|
1964 | var preventKeyBubblingKeys = { 27 :1, 13 :1 };
|
---|
1965 | var preventKeyBubbling = function( e )
|
---|
1966 | {
|
---|
1967 | if ( e.data.getKeystroke() in preventKeyBubblingKeys )
|
---|
1968 | e.data.stopPropagation();
|
---|
1969 | };
|
---|
1970 |
|
---|
1971 | (function()
|
---|
1972 | {
|
---|
1973 | CKEDITOR.ui.dialog =
|
---|
1974 | {
|
---|
1975 | /**
|
---|
1976 | * The base class of all dialog UI elements.
|
---|
1977 | * @constructor
|
---|
1978 | * @param {CKEDITOR.dialog} dialog Parent dialog object.
|
---|
1979 | * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition Element
|
---|
1980 | * definition. Accepted fields:
|
---|
1981 | * <ul>
|
---|
1982 | * <li><strong>id</strong> (Required) The id of the UI element. See {@link
|
---|
1983 | * CKEDITOR.dialog#getContentElement}</li>
|
---|
1984 | * <li><strong>type</strong> (Required) The type of the UI element. The
|
---|
1985 | * value to this field specifies which UI element class will be used to
|
---|
1986 | * generate the final widget.</li>
|
---|
1987 | * <li><strong>title</strong> (Optional) The popup tooltip for the UI
|
---|
1988 | * element.</li>
|
---|
1989 | * <li><strong>hidden</strong> (Optional) A flag that tells if the element
|
---|
1990 | * should be initially visible.</li>
|
---|
1991 | * <li><strong>className</strong> (Optional) Additional CSS class names
|
---|
1992 | * to add to the UI element. Separated by space.</li>
|
---|
1993 | * <li><strong>style</strong> (Optional) Additional CSS inline styles
|
---|
1994 | * to add to the UI element. A semicolon (;) is required after the last
|
---|
1995 | * style declaration.</li>
|
---|
1996 | * <li><strong>accessKey</strong> (Optional) The alphanumeric access key
|
---|
1997 | * for this element. Access keys are automatically prefixed by CTRL.</li>
|
---|
1998 | * <li><strong>on*</strong> (Optional) Any UI element definition field that
|
---|
1999 | * starts with <em>on</em> followed immediately by a capital letter and
|
---|
2000 | * probably more letters is an event handler. Event handlers may be further
|
---|
2001 | * divided into registered event handlers and DOM event handlers. Please
|
---|
2002 | * refer to {@link CKEDITOR.ui.dialog.uiElement#registerEvents} and
|
---|
2003 | * {@link CKEDITOR.ui.dialog.uiElement#eventProcessors} for more
|
---|
2004 | * information.</li>
|
---|
2005 | * </ul>
|
---|
2006 | * @param {Array} htmlList
|
---|
2007 | * List of HTML code to be added to the dialog's content area.
|
---|
2008 | * @param {Function|String} nodeNameArg
|
---|
2009 | * A function returning a string, or a simple string for the node name for
|
---|
2010 | * the root DOM node. Default is 'div'.
|
---|
2011 | * @param {Function|Object} stylesArg
|
---|
2012 | * A function returning an object, or a simple object for CSS styles applied
|
---|
2013 | * to the DOM node. Default is empty object.
|
---|
2014 | * @param {Function|Object} attributesArg
|
---|
2015 | * A fucntion returning an object, or a simple object for attributes applied
|
---|
2016 | * to the DOM node. Default is empty object.
|
---|
2017 | * @param {Function|String} contentsArg
|
---|
2018 | * A function returning a string, or a simple string for the HTML code inside
|
---|
2019 | * the root DOM node. Default is empty string.
|
---|
2020 | * @example
|
---|
2021 | */
|
---|
2022 | uiElement : function( dialog, elementDefinition, htmlList, nodeNameArg, stylesArg, attributesArg, contentsArg )
|
---|
2023 | {
|
---|
2024 | if ( arguments.length < 4 )
|
---|
2025 | return;
|
---|
2026 |
|
---|
2027 | var nodeName = ( nodeNameArg.call ? nodeNameArg( elementDefinition ) : nodeNameArg ) || 'div',
|
---|
2028 | html = [ '<', nodeName, ' ' ],
|
---|
2029 | styles = ( stylesArg && stylesArg.call ? stylesArg( elementDefinition ) : stylesArg ) || {},
|
---|
2030 | attributes = ( attributesArg && attributesArg.call ? attributesArg( elementDefinition ) : attributesArg ) || {},
|
---|
2031 | innerHTML = ( contentsArg && contentsArg.call ? contentsArg.call( this, dialog, elementDefinition ) : contentsArg ) || '',
|
---|
2032 | domId = this.domId = attributes.id || CKEDITOR.tools.getNextNumber() + '_uiElement',
|
---|
2033 | id = this.id = elementDefinition.id,
|
---|
2034 | i;
|
---|
2035 |
|
---|
2036 | // Set the id, a unique id is required for getElement() to work.
|
---|
2037 | attributes.id = domId;
|
---|
2038 |
|
---|
2039 | // Set the type and definition CSS class names.
|
---|
2040 | var classes = {};
|
---|
2041 | if ( elementDefinition.type )
|
---|
2042 | classes[ 'cke_dialog_ui_' + elementDefinition.type ] = 1;
|
---|
2043 | if ( elementDefinition.className )
|
---|
2044 | classes[ elementDefinition.className ] = 1;
|
---|
2045 | var attributeClasses = ( attributes['class'] && attributes['class'].split ) ? attributes['class'].split( ' ' ) : [];
|
---|
2046 | for ( i = 0 ; i < attributeClasses.length ; i++ )
|
---|
2047 | {
|
---|
2048 | if ( attributeClasses[i] )
|
---|
2049 | classes[ attributeClasses[i] ] = 1;
|
---|
2050 | }
|
---|
2051 | var finalClasses = [];
|
---|
2052 | for ( i in classes )
|
---|
2053 | finalClasses.push( i );
|
---|
2054 | attributes['class'] = finalClasses.join( ' ' );
|
---|
2055 |
|
---|
2056 | // Set the popup tooltop.
|
---|
2057 | if ( elementDefinition.title )
|
---|
2058 | attributes.title = elementDefinition.title;
|
---|
2059 |
|
---|
2060 | // Write the inline CSS styles.
|
---|
2061 | var styleStr = ( elementDefinition.style || '' ).split( ';' );
|
---|
2062 | for ( i in styles )
|
---|
2063 | styleStr.push( i + ':' + styles[i] );
|
---|
2064 | if ( elementDefinition.hidden )
|
---|
2065 | styleStr.push( 'display:none' );
|
---|
2066 | for ( i = styleStr.length - 1 ; i >= 0 ; i-- )
|
---|
2067 | {
|
---|
2068 | if ( styleStr[i] === '' )
|
---|
2069 | styleStr.splice( i, 1 );
|
---|
2070 | }
|
---|
2071 | if ( styleStr.length > 0 )
|
---|
2072 | attributes.style = ( attributes.style ? ( attributes.style + '; ' ) : '' ) + styleStr.join( '; ' );
|
---|
2073 |
|
---|
2074 | // Write the attributes.
|
---|
2075 | for ( i in attributes )
|
---|
2076 | html.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '" ');
|
---|
2077 |
|
---|
2078 | // Write the content HTML.
|
---|
2079 | html.push( '>', innerHTML, '</', nodeName, '>' );
|
---|
2080 |
|
---|
2081 | // Add contents to the parent HTML array.
|
---|
2082 | htmlList.push( html.join( '' ) );
|
---|
2083 |
|
---|
2084 | ( this._ || ( this._ = {} ) ).dialog = dialog;
|
---|
2085 |
|
---|
2086 | // Override isChanged if it is defined in element definition.
|
---|
2087 | if ( typeof( elementDefinition.isChanged ) == 'boolean' )
|
---|
2088 | this.isChanged = function(){ return elementDefinition.isChanged; };
|
---|
2089 | if ( typeof( elementDefinition.isChanged ) == 'function' )
|
---|
2090 | this.isChanged = elementDefinition.isChanged;
|
---|
2091 |
|
---|
2092 | // Add events.
|
---|
2093 | CKEDITOR.event.implementOn( this );
|
---|
2094 |
|
---|
2095 | this.registerEvents( elementDefinition );
|
---|
2096 | if ( this.accessKeyUp && this.accessKeyDown && elementDefinition.accessKey )
|
---|
2097 | registerAccessKey( this, dialog, 'CTRL+' + elementDefinition.accessKey );
|
---|
2098 |
|
---|
2099 | var me = this;
|
---|
2100 | dialog.on( 'load', function()
|
---|
2101 | {
|
---|
2102 | if ( me.getInputElement() )
|
---|
2103 | {
|
---|
2104 | me.getInputElement().on( 'focus', function()
|
---|
2105 | {
|
---|
2106 | dialog._.tabBarMode = false;
|
---|
2107 | dialog._.hasFocus = true;
|
---|
2108 | me.fire( 'focus' );
|
---|
2109 | }, me );
|
---|
2110 | }
|
---|
2111 | } );
|
---|
2112 |
|
---|
2113 | // Register the object as a tab focus if it can be included.
|
---|
2114 | if ( this.keyboardFocusable )
|
---|
2115 | {
|
---|
2116 | this.tabIndex = elementDefinition.tabIndex || 0;
|
---|
2117 |
|
---|
2118 | this.focusIndex = dialog._.focusList.push( this ) - 1;
|
---|
2119 | this.on( 'focus', function()
|
---|
2120 | {
|
---|
2121 | dialog._.currentFocusIndex = me.focusIndex;
|
---|
2122 | } );
|
---|
2123 | }
|
---|
2124 |
|
---|
2125 | // Completes this object with everything we have in the
|
---|
2126 | // definition.
|
---|
2127 | CKEDITOR.tools.extend( this, elementDefinition );
|
---|
2128 | },
|
---|
2129 |
|
---|
2130 | /**
|
---|
2131 | * Horizontal layout box for dialog UI elements, auto-expends to available width of container.
|
---|
2132 | * @constructor
|
---|
2133 | * @extends CKEDITOR.ui.dialog.uiElement
|
---|
2134 | * @param {CKEDITOR.dialog} dialog
|
---|
2135 | * Parent dialog object.
|
---|
2136 | * @param {Array} childObjList
|
---|
2137 | * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
|
---|
2138 | * container.
|
---|
2139 | * @param {Array} childHtmlList
|
---|
2140 | * Array of HTML code that correspond to the HTML output of all the
|
---|
2141 | * objects in childObjList.
|
---|
2142 | * @param {Array} htmlList
|
---|
2143 | * Array of HTML code that this element will output to.
|
---|
2144 | * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
|
---|
2145 | * The element definition. Accepted fields:
|
---|
2146 | * <ul>
|
---|
2147 | * <li><strong>widths</strong> (Optional) The widths of child cells.</li>
|
---|
2148 | * <li><strong>height</strong> (Optional) The height of the layout.</li>
|
---|
2149 | * <li><strong>padding</strong> (Optional) The padding width inside child
|
---|
2150 | * cells.</li>
|
---|
2151 | * <li><strong>align</strong> (Optional) The alignment of the whole layout
|
---|
2152 | * </li>
|
---|
2153 | * </ul>
|
---|
2154 | * @example
|
---|
2155 | */
|
---|
2156 | hbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
|
---|
2157 | {
|
---|
2158 | if ( arguments.length < 4 )
|
---|
2159 | return;
|
---|
2160 |
|
---|
2161 | this._ || ( this._ = {} );
|
---|
2162 |
|
---|
2163 | var children = this._.children = childObjList,
|
---|
2164 | widths = elementDefinition && elementDefinition.widths || null,
|
---|
2165 | height = elementDefinition && elementDefinition.height || null,
|
---|
2166 | styles = {},
|
---|
2167 | i;
|
---|
2168 | /** @ignore */
|
---|
2169 | var innerHTML = function()
|
---|
2170 | {
|
---|
2171 | var html = [ '<tbody><tr class="cke_dialog_ui_hbox">' ];
|
---|
2172 | for ( i = 0 ; i < childHtmlList.length ; i++ )
|
---|
2173 | {
|
---|
2174 | var className = 'cke_dialog_ui_hbox_child',
|
---|
2175 | styles = [];
|
---|
2176 | if ( i === 0 )
|
---|
2177 | className = 'cke_dialog_ui_hbox_first';
|
---|
2178 | if ( i == childHtmlList.length - 1 )
|
---|
2179 | className = 'cke_dialog_ui_hbox_last';
|
---|
2180 | html.push( '<td class="', className, '" role="presentation" ' );
|
---|
2181 | if ( widths )
|
---|
2182 | {
|
---|
2183 | if ( widths[i] )
|
---|
2184 | styles.push( 'width:' + CKEDITOR.tools.cssLength( widths[i] ) );
|
---|
2185 | }
|
---|
2186 | else
|
---|
2187 | styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
|
---|
2188 | if ( height )
|
---|
2189 | styles.push( 'height:' + CKEDITOR.tools.cssLength( height ) );
|
---|
2190 | if ( elementDefinition && elementDefinition.padding != undefined )
|
---|
2191 | styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
|
---|
2192 | if ( styles.length > 0 )
|
---|
2193 | html.push( 'style="' + styles.join('; ') + '" ' );
|
---|
2194 | html.push( '>', childHtmlList[i], '</td>' );
|
---|
2195 | }
|
---|
2196 | html.push( '</tr></tbody>' );
|
---|
2197 | return html.join( '' );
|
---|
2198 | };
|
---|
2199 |
|
---|
2200 | var attribs = { role : 'presentation' };
|
---|
2201 | elementDefinition && elementDefinition.align && ( attribs.align = elementDefinition.align );
|
---|
2202 |
|
---|
2203 | CKEDITOR.ui.dialog.uiElement.call(
|
---|
2204 | this,
|
---|
2205 | dialog,
|
---|
2206 | elementDefinition || { type : 'hbox' },
|
---|
2207 | htmlList,
|
---|
2208 | 'table',
|
---|
2209 | styles,
|
---|
2210 | attribs,
|
---|
2211 | innerHTML );
|
---|
2212 | },
|
---|
2213 |
|
---|
2214 | /**
|
---|
2215 | * Vertical layout box for dialog UI elements.
|
---|
2216 | * @constructor
|
---|
2217 | * @extends CKEDITOR.ui.dialog.hbox
|
---|
2218 | * @param {CKEDITOR.dialog} dialog
|
---|
2219 | * Parent dialog object.
|
---|
2220 | * @param {Array} childObjList
|
---|
2221 | * Array of {@link CKEDITOR.ui.dialog.uiElement} objects inside this
|
---|
2222 | * container.
|
---|
2223 | * @param {Array} childHtmlList
|
---|
2224 | * Array of HTML code that correspond to the HTML output of all the
|
---|
2225 | * objects in childObjList.
|
---|
2226 | * @param {Array} htmlList
|
---|
2227 | * Array of HTML code that this element will output to.
|
---|
2228 | * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
|
---|
2229 | * The element definition. Accepted fields:
|
---|
2230 | * <ul>
|
---|
2231 | * <li><strong>width</strong> (Optional) The width of the layout.</li>
|
---|
2232 | * <li><strong>heights</strong> (Optional) The heights of individual cells.
|
---|
2233 | * </li>
|
---|
2234 | * <li><strong>align</strong> (Optional) The alignment of the layout.</li>
|
---|
2235 | * <li><strong>padding</strong> (Optional) The padding width inside child
|
---|
2236 | * cells.</li>
|
---|
2237 | * <li><strong>expand</strong> (Optional) Whether the layout should expand
|
---|
2238 | * vertically to fill its container.</li>
|
---|
2239 | * </ul>
|
---|
2240 | * @example
|
---|
2241 | */
|
---|
2242 | vbox : function( dialog, childObjList, childHtmlList, htmlList, elementDefinition )
|
---|
2243 | {
|
---|
2244 | if (arguments.length < 3 )
|
---|
2245 | return;
|
---|
2246 |
|
---|
2247 | this._ || ( this._ = {} );
|
---|
2248 |
|
---|
2249 | var children = this._.children = childObjList,
|
---|
2250 | width = elementDefinition && elementDefinition.width || null,
|
---|
2251 | heights = elementDefinition && elementDefinition.heights || null;
|
---|
2252 | /** @ignore */
|
---|
2253 | var innerHTML = function()
|
---|
2254 | {
|
---|
2255 | var html = [ '<table role="presentation" cellspacing="0" border="0" ' ];
|
---|
2256 | html.push( 'style="' );
|
---|
2257 | if ( elementDefinition && elementDefinition.expand )
|
---|
2258 | html.push( 'height:100%;' );
|
---|
2259 | html.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ), ';' );
|
---|
2260 | html.push( '"' );
|
---|
2261 | html.push( 'align="', CKEDITOR.tools.htmlEncode(
|
---|
2262 | ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
|
---|
2263 |
|
---|
2264 | html.push( '><tbody>' );
|
---|
2265 | for ( var i = 0 ; i < childHtmlList.length ; i++ )
|
---|
2266 | {
|
---|
2267 | var styles = [];
|
---|
2268 | html.push( '<tr><td role="presentation" ' );
|
---|
2269 | if ( width )
|
---|
2270 | styles.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ) );
|
---|
2271 | if ( heights )
|
---|
2272 | styles.push( 'height:' + CKEDITOR.tools.cssLength( heights[i] ) );
|
---|
2273 | else if ( elementDefinition && elementDefinition.expand )
|
---|
2274 | styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
|
---|
2275 | if ( elementDefinition && elementDefinition.padding != undefined )
|
---|
2276 | styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
|
---|
2277 | if ( styles.length > 0 )
|
---|
2278 | html.push( 'style="', styles.join( '; ' ), '" ' );
|
---|
2279 | html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
|
---|
2280 | }
|
---|
2281 | html.push( '</tbody></table>' );
|
---|
2282 | return html.join( '' );
|
---|
2283 | };
|
---|
2284 | CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition || { type : 'vbox' }, htmlList, 'div', null, { role : 'presentation' }, innerHTML );
|
---|
2285 | }
|
---|
2286 | };
|
---|
2287 | })();
|
---|
2288 |
|
---|
2289 | CKEDITOR.ui.dialog.uiElement.prototype =
|
---|
2290 | {
|
---|
2291 | /**
|
---|
2292 | * Gets the root DOM element of this dialog UI object.
|
---|
2293 | * @returns {CKEDITOR.dom.element} Root DOM element of UI object.
|
---|
2294 | * @example
|
---|
2295 | * uiElement.getElement().hide();
|
---|
2296 | */
|
---|
2297 | getElement : function()
|
---|
2298 | {
|
---|
2299 | return CKEDITOR.document.getById( this.domId );
|
---|
2300 | },
|
---|
2301 |
|
---|
2302 | /**
|
---|
2303 | * Gets the DOM element that the user inputs values.
|
---|
2304 | * This function is used by setValue(), getValue() and focus(). It should
|
---|
2305 | * be overrided in child classes where the input element isn't the root
|
---|
2306 | * element.
|
---|
2307 | * @returns {CKEDITOR.dom.element} The element where the user input values.
|
---|
2308 | * @example
|
---|
2309 | * var rawValue = textInput.getInputElement().$.value;
|
---|
2310 | */
|
---|
2311 | getInputElement : function()
|
---|
2312 | {
|
---|
2313 | return this.getElement();
|
---|
2314 | },
|
---|
2315 |
|
---|
2316 | /**
|
---|
2317 | * Gets the parent dialog object containing this UI element.
|
---|
2318 | * @returns {CKEDITOR.dialog} Parent dialog object.
|
---|
2319 | * @example
|
---|
2320 | * var dialog = uiElement.getDialog();
|
---|
2321 | */
|
---|
2322 | getDialog : function()
|
---|
2323 | {
|
---|
2324 | return this._.dialog;
|
---|
2325 | },
|
---|
2326 |
|
---|
2327 | /**
|
---|
2328 | * Sets the value of this dialog UI object.
|
---|
2329 | * @param {Object} value The new value.
|
---|
2330 | * @returns {CKEDITOR.dialog.uiElement} The current UI element.
|
---|
2331 | * @example
|
---|
2332 | * uiElement.setValue( 'Dingo' );
|
---|
2333 | */
|
---|
2334 | setValue : function( value )
|
---|
2335 | {
|
---|
2336 | this.getInputElement().setValue( value );
|
---|
2337 | this.fire( 'change', { value : value } );
|
---|
2338 | return this;
|
---|
2339 | },
|
---|
2340 |
|
---|
2341 | /**
|
---|
2342 | * Gets the current value of this dialog UI object.
|
---|
2343 | * @returns {Object} The current value.
|
---|
2344 | * @example
|
---|
2345 | * var myValue = uiElement.getValue();
|
---|
2346 | */
|
---|
2347 | getValue : function()
|
---|
2348 | {
|
---|
2349 | return this.getInputElement().getValue();
|
---|
2350 | },
|
---|
2351 |
|
---|
2352 | /**
|
---|
2353 | * Tells whether the UI object's value has changed.
|
---|
2354 | * @returns {Boolean} true if changed, false if not changed.
|
---|
2355 | * @example
|
---|
2356 | * if ( uiElement.isChanged() )
|
---|
2357 | * confirm( 'Value changed! Continue?' );
|
---|
2358 | */
|
---|
2359 | isChanged : function()
|
---|
2360 | {
|
---|
2361 | // Override in input classes.
|
---|
2362 | return false;
|
---|
2363 | },
|
---|
2364 |
|
---|
2365 | /**
|
---|
2366 | * Selects the parent tab of this element. Usually called by focus() or overridden focus() methods.
|
---|
2367 | * @returns {CKEDITOR.dialog.uiElement} The current UI element.
|
---|
2368 | * @example
|
---|
2369 | * focus : function()
|
---|
2370 | * {
|
---|
2371 | * this.selectParentTab();
|
---|
2372 | * // do something else.
|
---|
2373 | * }
|
---|
2374 | */
|
---|
2375 | selectParentTab : function()
|
---|
2376 | {
|
---|
2377 | var element = this.getInputElement(),
|
---|
2378 | cursor = element,
|
---|
2379 | tabId;
|
---|
2380 | while ( ( cursor = cursor.getParent() ) && cursor.$.className.search( 'cke_dialog_page_contents' ) == -1 )
|
---|
2381 | { /*jsl:pass*/ }
|
---|
2382 |
|
---|
2383 | // Some widgets don't have parent tabs (e.g. OK and Cancel buttons).
|
---|
2384 | if ( !cursor )
|
---|
2385 | return this;
|
---|
2386 |
|
---|
2387 | tabId = cursor.getAttribute( 'name' );
|
---|
2388 | // Avoid duplicate select.
|
---|
2389 | if ( this._.dialog._.currentTabId != tabId )
|
---|
2390 | this._.dialog.selectPage( tabId );
|
---|
2391 | return this;
|
---|
2392 | },
|
---|
2393 |
|
---|
2394 | /**
|
---|
2395 | * Puts the focus to the UI object. Switches tabs if the UI object isn't in the active tab page.
|
---|
2396 | * @returns {CKEDITOR.dialog.uiElement} The current UI element.
|
---|
2397 | * @example
|
---|
2398 | * uiElement.focus();
|
---|
2399 | */
|
---|
2400 | focus : function()
|
---|
2401 | {
|
---|
2402 | this.selectParentTab().getInputElement().focus();
|
---|
2403 | return this;
|
---|
2404 | },
|
---|
2405 |
|
---|
2406 | /**
|
---|
2407 | * Registers the on* event handlers defined in the element definition.
|
---|
2408 | * The default behavior of this function is:
|
---|
2409 | * <ol>
|
---|
2410 | * <li>
|
---|
2411 | * If the on* event is defined in the class's eventProcesors list,
|
---|
2412 | * then the registration is delegated to the corresponding function
|
---|
2413 | * in the eventProcessors list.
|
---|
2414 | * </li>
|
---|
2415 | * <li>
|
---|
2416 | * If the on* event is not defined in the eventProcessors list, then
|
---|
2417 | * register the event handler under the corresponding DOM event of
|
---|
2418 | * the UI element's input DOM element (as defined by the return value
|
---|
2419 | * of {@link CKEDITOR.ui.dialog.uiElement#getInputElement}).
|
---|
2420 | * </li>
|
---|
2421 | * </ol>
|
---|
2422 | * This function is only called at UI element instantiation, but can
|
---|
2423 | * be overridded in child classes if they require more flexibility.
|
---|
2424 | * @param {CKEDITOR.dialog.uiElementDefinition} definition The UI element
|
---|
2425 | * definition.
|
---|
2426 | * @returns {CKEDITOR.dialog.uiElement} The current UI element.
|
---|
2427 | * @example
|
---|
2428 | */
|
---|
2429 | registerEvents : function( definition )
|
---|
2430 | {
|
---|
2431 | var regex = /^on([A-Z]\w+)/,
|
---|
2432 | match;
|
---|
2433 |
|
---|
2434 | var registerDomEvent = function( uiElement, dialog, eventName, func )
|
---|
2435 | {
|
---|
2436 | dialog.on( 'load', function()
|
---|
2437 | {
|
---|
2438 | uiElement.getInputElement().on( eventName, func, uiElement );
|
---|
2439 | });
|
---|
2440 | };
|
---|
2441 |
|
---|
2442 | for ( var i in definition )
|
---|
2443 | if ( ! ( i in Object.prototype ) )
|
---|
2444 | {
|
---|
2445 | if ( !( match = i.match( regex ) ) )
|
---|
2446 | continue;
|
---|
2447 | if ( this.eventProcessors[i] )
|
---|
2448 | this.eventProcessors[i].call( this, this._.dialog, definition[i] );
|
---|
2449 | else
|
---|
2450 | registerDomEvent( this, this._.dialog, match[1].toLowerCase(), definition[i] );
|
---|
2451 | }
|
---|
2452 |
|
---|
2453 | return this;
|
---|
2454 | },
|
---|
2455 |
|
---|
2456 | /**
|
---|
2457 | * The event processor list used by
|
---|
2458 | * {@link CKEDITOR.ui.dialog.uiElement#getInputElement} at UI element
|
---|
2459 | * instantiation. The default list defines three on* events:
|
---|
2460 | * <ol>
|
---|
2461 | * <li>onLoad - Called when the element's parent dialog opens for the
|
---|
2462 | * first time</li>
|
---|
2463 | * <li>onShow - Called whenever the element's parent dialog opens.</li>
|
---|
2464 | * <li>onHide - Called whenever the element's parent dialog closes.</li>
|
---|
2465 | * </ol>
|
---|
2466 | * @field
|
---|
2467 | * @type Object
|
---|
2468 | * @example
|
---|
2469 | * // This connects the 'click' event in CKEDITOR.ui.dialog.button to onClick
|
---|
2470 | * // handlers in the UI element's definitions.
|
---|
2471 | * CKEDITOR.ui.dialog.button.eventProcessors = CKEDITOR.tools.extend( {},
|
---|
2472 | * CKEDITOR.ui.dialog.uiElement.prototype.eventProcessors,
|
---|
2473 | * { onClick : function( dialog, func ) { this.on( 'click', func ); } },
|
---|
2474 | * true );
|
---|
2475 | */
|
---|
2476 | eventProcessors :
|
---|
2477 | {
|
---|
2478 | onLoad : function( dialog, func )
|
---|
2479 | {
|
---|
2480 | dialog.on( 'load', func, this );
|
---|
2481 | },
|
---|
2482 |
|
---|
2483 | onShow : function( dialog, func )
|
---|
2484 | {
|
---|
2485 | dialog.on( 'show', func, this );
|
---|
2486 | },
|
---|
2487 |
|
---|
2488 | onHide : function( dialog, func )
|
---|
2489 | {
|
---|
2490 | dialog.on( 'hide', func, this );
|
---|
2491 | }
|
---|
2492 | },
|
---|
2493 |
|
---|
2494 | /**
|
---|
2495 | * The default handler for a UI element's access key down event, which
|
---|
2496 | * tries to put focus to the UI element.<br />
|
---|
2497 | * Can be overridded in child classes for more sophisticaed behavior.
|
---|
2498 | * @param {CKEDITOR.dialog} dialog The parent dialog object.
|
---|
2499 | * @param {String} key The key combination pressed. Since access keys
|
---|
2500 | * are defined to always include the CTRL key, its value should always
|
---|
2501 | * include a 'CTRL+' prefix.
|
---|
2502 | * @example
|
---|
2503 | */
|
---|
2504 | accessKeyDown : function( dialog, key )
|
---|
2505 | {
|
---|
2506 | this.focus();
|
---|
2507 | },
|
---|
2508 |
|
---|
2509 | /**
|
---|
2510 | * The default handler for a UI element's access key up event, which
|
---|
2511 | * does nothing.<br />
|
---|
2512 | * Can be overridded in child classes for more sophisticated behavior.
|
---|
2513 | * @param {CKEDITOR.dialog} dialog The parent dialog object.
|
---|
2514 | * @param {String} key The key combination pressed. Since access keys
|
---|
2515 | * are defined to always include the CTRL key, its value should always
|
---|
2516 | * include a 'CTRL+' prefix.
|
---|
2517 | * @example
|
---|
2518 | */
|
---|
2519 | accessKeyUp : function( dialog, key )
|
---|
2520 | {
|
---|
2521 | },
|
---|
2522 |
|
---|
2523 | /**
|
---|
2524 | * Disables a UI element.
|
---|
2525 | * @example
|
---|
2526 | */
|
---|
2527 | disable : function()
|
---|
2528 | {
|
---|
2529 | var element = this.getInputElement();
|
---|
2530 | element.setAttribute( 'disabled', 'true' );
|
---|
2531 | element.addClass( 'cke_disabled' );
|
---|
2532 | },
|
---|
2533 |
|
---|
2534 | /**
|
---|
2535 | * Enables a UI element.
|
---|
2536 | * @example
|
---|
2537 | */
|
---|
2538 | enable : function()
|
---|
2539 | {
|
---|
2540 | var element = this.getInputElement();
|
---|
2541 | element.removeAttribute( 'disabled' );
|
---|
2542 | element.removeClass( 'cke_disabled' );
|
---|
2543 | },
|
---|
2544 |
|
---|
2545 | /**
|
---|
2546 | * Determines whether an UI element is enabled or not.
|
---|
2547 | * @returns {Boolean} Whether the UI element is enabled.
|
---|
2548 | * @example
|
---|
2549 | */
|
---|
2550 | isEnabled : function()
|
---|
2551 | {
|
---|
2552 | return !this.getInputElement().getAttribute( 'disabled' );
|
---|
2553 | },
|
---|
2554 |
|
---|
2555 | /**
|
---|
2556 | * Determines whether an UI element is visible or not.
|
---|
2557 | * @returns {Boolean} Whether the UI element is visible.
|
---|
2558 | * @example
|
---|
2559 | */
|
---|
2560 | isVisible : function()
|
---|
2561 | {
|
---|
2562 | return this.getInputElement().isVisible();
|
---|
2563 | },
|
---|
2564 |
|
---|
2565 | /**
|
---|
2566 | * Determines whether an UI element is focus-able or not.
|
---|
2567 | * Focus-able is defined as being both visible and enabled.
|
---|
2568 | * @returns {Boolean} Whether the UI element can be focused.
|
---|
2569 | * @example
|
---|
2570 | */
|
---|
2571 | isFocusable : function()
|
---|
2572 | {
|
---|
2573 | if ( !this.isEnabled() || !this.isVisible() )
|
---|
2574 | return false;
|
---|
2575 | return true;
|
---|
2576 | }
|
---|
2577 | };
|
---|
2578 |
|
---|
2579 | CKEDITOR.ui.dialog.hbox.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
|
---|
2580 | /**
|
---|
2581 | * @lends CKEDITOR.ui.dialog.hbox.prototype
|
---|
2582 | */
|
---|
2583 | {
|
---|
2584 | /**
|
---|
2585 | * Gets a child UI element inside this container.
|
---|
2586 | * @param {Array|Number} indices An array or a single number to indicate the child's
|
---|
2587 | * position in the container's descendant tree. Omit to get all the children in an array.
|
---|
2588 | * @returns {Array|CKEDITOR.ui.dialog.uiElement} Array of all UI elements in the container
|
---|
2589 | * if no argument given, or the specified UI element if indices is given.
|
---|
2590 | * @example
|
---|
2591 | * var checkbox = hbox.getChild( [0,1] );
|
---|
2592 | * checkbox.setValue( true );
|
---|
2593 | */
|
---|
2594 | getChild : function( indices )
|
---|
2595 | {
|
---|
2596 | // If no arguments, return a clone of the children array.
|
---|
2597 | if ( arguments.length < 1 )
|
---|
2598 | return this._.children.concat();
|
---|
2599 |
|
---|
2600 | // If indices isn't array, make it one.
|
---|
2601 | if ( !indices.splice )
|
---|
2602 | indices = [ indices ];
|
---|
2603 |
|
---|
2604 | // Retrieve the child element according to tree position.
|
---|
2605 | if ( indices.length < 2 )
|
---|
2606 | return this._.children[ indices[0] ];
|
---|
2607 | else
|
---|
2608 | return ( this._.children[ indices[0] ] && this._.children[ indices[0] ].getChild ) ?
|
---|
2609 | this._.children[ indices[0] ].getChild( indices.slice( 1, indices.length ) ) :
|
---|
2610 | null;
|
---|
2611 | }
|
---|
2612 | }, true );
|
---|
2613 |
|
---|
2614 | CKEDITOR.ui.dialog.vbox.prototype = new CKEDITOR.ui.dialog.hbox();
|
---|
2615 |
|
---|
2616 |
|
---|
2617 |
|
---|
2618 | (function()
|
---|
2619 | {
|
---|
2620 | var commonBuilder = {
|
---|
2621 | build : function( dialog, elementDefinition, output )
|
---|
2622 | {
|
---|
2623 | var children = elementDefinition.children,
|
---|
2624 | child,
|
---|
2625 | childHtmlList = [],
|
---|
2626 | childObjList = [];
|
---|
2627 | for ( var i = 0 ; ( i < children.length && ( child = children[i] ) ) ; i++ )
|
---|
2628 | {
|
---|
2629 | var childHtml = [];
|
---|
2630 | childHtmlList.push( childHtml );
|
---|
2631 | childObjList.push( CKEDITOR.dialog._.uiElementBuilders[ child.type ].build( dialog, child, childHtml ) );
|
---|
2632 | }
|
---|
2633 | return new CKEDITOR.ui.dialog[elementDefinition.type]( dialog, childObjList, childHtmlList, output, elementDefinition );
|
---|
2634 | }
|
---|
2635 | };
|
---|
2636 |
|
---|
2637 | CKEDITOR.dialog.addUIElement( 'hbox', commonBuilder );
|
---|
2638 | CKEDITOR.dialog.addUIElement( 'vbox', commonBuilder );
|
---|
2639 | })();
|
---|
2640 |
|
---|
2641 | /**
|
---|
2642 | * Generic dialog command. It opens a specific dialog when executed.
|
---|
2643 | * @constructor
|
---|
2644 | * @augments CKEDITOR.commandDefinition
|
---|
2645 | * @param {string} dialogName The name of the dialog to open when executing
|
---|
2646 | * this command.
|
---|
2647 | * @example
|
---|
2648 | * // Register the "link" command, which opens the "link" dialog.
|
---|
2649 | * editor.addCommand( 'link', <b>new CKEDITOR.dialogCommand( 'link' )</b> );
|
---|
2650 | */
|
---|
2651 | CKEDITOR.dialogCommand = function( dialogName )
|
---|
2652 | {
|
---|
2653 | this.dialogName = dialogName;
|
---|
2654 | };
|
---|
2655 |
|
---|
2656 | CKEDITOR.dialogCommand.prototype =
|
---|
2657 | {
|
---|
2658 | /** @ignore */
|
---|
2659 | exec : function( editor )
|
---|
2660 | {
|
---|
2661 | editor.openDialog( this.dialogName );
|
---|
2662 | },
|
---|
2663 |
|
---|
2664 | // Dialog commands just open a dialog ui, thus require no undo logic,
|
---|
2665 | // undo support should dedicate to specific dialog implementation.
|
---|
2666 | canUndo: false,
|
---|
2667 |
|
---|
2668 | editorFocus : CKEDITOR.env.ie
|
---|
2669 | };
|
---|
2670 |
|
---|
2671 | (function()
|
---|
2672 | {
|
---|
2673 | var notEmptyRegex = /^([a]|[^a])+$/,
|
---|
2674 | integerRegex = /^\d*$/,
|
---|
2675 | numberRegex = /^\d*(?:\.\d+)?$/;
|
---|
2676 |
|
---|
2677 | CKEDITOR.VALIDATE_OR = 1;
|
---|
2678 | CKEDITOR.VALIDATE_AND = 2;
|
---|
2679 |
|
---|
2680 | CKEDITOR.dialog.validate =
|
---|
2681 | {
|
---|
2682 | functions : function()
|
---|
2683 | {
|
---|
2684 | return function()
|
---|
2685 | {
|
---|
2686 | /**
|
---|
2687 | * It's important for validate functions to be able to accept the value
|
---|
2688 | * as argument in addition to this.getValue(), so that it is possible to
|
---|
2689 | * combine validate functions together to make more sophisticated
|
---|
2690 | * validators.
|
---|
2691 | */
|
---|
2692 | var value = this && this.getValue ? this.getValue() : arguments[0];
|
---|
2693 |
|
---|
2694 | var msg = undefined,
|
---|
2695 | relation = CKEDITOR.VALIDATE_AND,
|
---|
2696 | functions = [], i;
|
---|
2697 |
|
---|
2698 | for ( i = 0 ; i < arguments.length ; i++ )
|
---|
2699 | {
|
---|
2700 | if ( typeof( arguments[i] ) == 'function' )
|
---|
2701 | functions.push( arguments[i] );
|
---|
2702 | else
|
---|
2703 | break;
|
---|
2704 | }
|
---|
2705 |
|
---|
2706 | if ( i < arguments.length && typeof( arguments[i] ) == 'string' )
|
---|
2707 | {
|
---|
2708 | msg = arguments[i];
|
---|
2709 | i++;
|
---|
2710 | }
|
---|
2711 |
|
---|
2712 | if ( i < arguments.length && typeof( arguments[i]) == 'number' )
|
---|
2713 | relation = arguments[i];
|
---|
2714 |
|
---|
2715 | var passed = ( relation == CKEDITOR.VALIDATE_AND ? true : false );
|
---|
2716 | for ( i = 0 ; i < functions.length ; i++ )
|
---|
2717 | {
|
---|
2718 | if ( relation == CKEDITOR.VALIDATE_AND )
|
---|
2719 | passed = passed && functions[i]( value );
|
---|
2720 | else
|
---|
2721 | passed = passed || functions[i]( value );
|
---|
2722 | }
|
---|
2723 |
|
---|
2724 | if ( !passed )
|
---|
2725 | {
|
---|
2726 | if ( msg !== undefined )
|
---|
2727 | alert( msg );
|
---|
2728 | if ( this && ( this.select || this.focus ) )
|
---|
2729 | ( this.select || this.focus )();
|
---|
2730 | return false;
|
---|
2731 | }
|
---|
2732 |
|
---|
2733 | return true;
|
---|
2734 | };
|
---|
2735 | },
|
---|
2736 |
|
---|
2737 | regex : function( regex, msg )
|
---|
2738 | {
|
---|
2739 | /*
|
---|
2740 | * Can be greatly shortened by deriving from functions validator if code size
|
---|
2741 | * turns out to be more important than performance.
|
---|
2742 | */
|
---|
2743 | return function()
|
---|
2744 | {
|
---|
2745 | var value = this && this.getValue ? this.getValue() : arguments[0];
|
---|
2746 | if ( !regex.test( value ) )
|
---|
2747 | {
|
---|
2748 | if ( msg !== undefined )
|
---|
2749 | alert( msg );
|
---|
2750 | if ( this && ( this.select || this.focus ) )
|
---|
2751 | {
|
---|
2752 | if ( this.select )
|
---|
2753 | this.select();
|
---|
2754 | else
|
---|
2755 | this.focus();
|
---|
2756 | }
|
---|
2757 | return false;
|
---|
2758 | }
|
---|
2759 | return true;
|
---|
2760 | };
|
---|
2761 | },
|
---|
2762 |
|
---|
2763 | notEmpty : function( msg )
|
---|
2764 | {
|
---|
2765 | return this.regex( notEmptyRegex, msg );
|
---|
2766 | },
|
---|
2767 |
|
---|
2768 | integer : function( msg )
|
---|
2769 | {
|
---|
2770 | return this.regex( integerRegex, msg );
|
---|
2771 | },
|
---|
2772 |
|
---|
2773 | 'number' : function( msg )
|
---|
2774 | {
|
---|
2775 | return this.regex( numberRegex, msg );
|
---|
2776 | },
|
---|
2777 |
|
---|
2778 | equals : function( value, msg )
|
---|
2779 | {
|
---|
2780 | return this.functions( function( val ){ return val == value; }, msg );
|
---|
2781 | },
|
---|
2782 |
|
---|
2783 | notEqual : function( value, msg )
|
---|
2784 | {
|
---|
2785 | return this.functions( function( val ){ return val != value; }, msg );
|
---|
2786 | }
|
---|
2787 | };
|
---|
2788 | })();
|
---|
2789 | })();
|
---|
2790 |
|
---|
2791 | // Extend the CKEDITOR.editor class with dialog specific functions.
|
---|
2792 | CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
|
---|
2793 | /** @lends CKEDITOR.editor.prototype */
|
---|
2794 | {
|
---|
2795 | /**
|
---|
2796 | * Loads and opens a registered dialog.
|
---|
2797 | * @param {String} dialogName The registered name of the dialog.
|
---|
2798 | * @param {Function} callback The function to be invoked after dialog instance created.
|
---|
2799 | * @see CKEDITOR.dialog.add
|
---|
2800 | * @example
|
---|
2801 | * CKEDITOR.instances.editor1.openDialog( 'smiley' );
|
---|
2802 | * @returns {CKEDITOR.dialog} The dialog object corresponding to the dialog displayed. null if the dialog name is not registered.
|
---|
2803 | */
|
---|
2804 | openDialog : function( dialogName, callback )
|
---|
2805 | {
|
---|
2806 | var dialogDefinitions = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
|
---|
2807 | dialogSkin = this.skin.dialog;
|
---|
2808 |
|
---|
2809 | // If the dialogDefinition is already loaded, open it immediately.
|
---|
2810 | if ( typeof dialogDefinitions == 'function' && dialogSkin._isLoaded )
|
---|
2811 | {
|
---|
2812 | var storedDialogs = this._.storedDialogs ||
|
---|
2813 | ( this._.storedDialogs = {} );
|
---|
2814 |
|
---|
2815 | var dialog = storedDialogs[ dialogName ] ||
|
---|
2816 | ( storedDialogs[ dialogName ] = new CKEDITOR.dialog( this, dialogName ) );
|
---|
2817 |
|
---|
2818 | callback && callback.call( dialog, dialog );
|
---|
2819 | dialog.show();
|
---|
2820 |
|
---|
2821 | return dialog;
|
---|
2822 | }
|
---|
2823 | else if ( dialogDefinitions == 'failed' )
|
---|
2824 | throw new Error( '[CKEDITOR.dialog.openDialog] Dialog "' + dialogName + '" failed when loading definition.' );
|
---|
2825 |
|
---|
2826 | // Not loaded? Load the .js file first.
|
---|
2827 | var body = CKEDITOR.document.getBody(),
|
---|
2828 | cursor = body.$.style.cursor,
|
---|
2829 | me = this;
|
---|
2830 |
|
---|
2831 | body.setStyle( 'cursor', 'wait' );
|
---|
2832 |
|
---|
2833 | function onDialogFileLoaded( success )
|
---|
2834 | {
|
---|
2835 | var dialogDefinition = CKEDITOR.dialog._.dialogDefinitions[ dialogName ],
|
---|
2836 | skin = me.skin.dialog;
|
---|
2837 |
|
---|
2838 | // Check if both skin part and definition is loaded.
|
---|
2839 | if ( !skin._isLoaded || loadDefinition && typeof success == 'undefined' )
|
---|
2840 | return;
|
---|
2841 |
|
---|
2842 | // In case of plugin error, mark it as loading failed.
|
---|
2843 | if ( typeof dialogDefinition != 'function' )
|
---|
2844 | CKEDITOR.dialog._.dialogDefinitions[ dialogName ] = 'failed';
|
---|
2845 |
|
---|
2846 | me.openDialog( dialogName, callback );
|
---|
2847 | body.setStyle( 'cursor', cursor );
|
---|
2848 | }
|
---|
2849 |
|
---|
2850 | if ( typeof dialogDefinitions == 'string' )
|
---|
2851 | {
|
---|
2852 | var loadDefinition = 1;
|
---|
2853 | CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( dialogDefinitions ), onDialogFileLoaded );
|
---|
2854 | }
|
---|
2855 |
|
---|
2856 | CKEDITOR.skins.load( this, 'dialog', onDialogFileLoaded );
|
---|
2857 |
|
---|
2858 | return null;
|
---|
2859 | }
|
---|
2860 | });
|
---|
2861 |
|
---|
2862 | CKEDITOR.plugins.add( 'dialog',
|
---|
2863 | {
|
---|
2864 | requires : [ 'dialogui' ]
|
---|
2865 | });
|
---|
2866 |
|
---|
2867 | // Dialog related configurations.
|
---|
2868 |
|
---|
2869 | /**
|
---|
2870 | * The color of the dialog background cover. It should be a valid CSS color
|
---|
2871 | * string.
|
---|
2872 | * @name CKEDITOR.config.dialog_backgroundCoverColor
|
---|
2873 | * @type String
|
---|
2874 | * @default 'white'
|
---|
2875 | * @example
|
---|
2876 | * config.dialog_backgroundCoverColor = 'rgb(255, 254, 253)';
|
---|
2877 | */
|
---|
2878 |
|
---|
2879 | /**
|
---|
2880 | * The opacity of the dialog background cover. It should be a number within the
|
---|
2881 | * range [0.0, 1.0].
|
---|
2882 | * @name CKEDITOR.config.dialog_backgroundCoverOpacity
|
---|
2883 | * @type Number
|
---|
2884 | * @default 0.5
|
---|
2885 | * @example
|
---|
2886 | * config.dialog_backgroundCoverOpacity = 0.7;
|
---|
2887 | */
|
---|
2888 |
|
---|
2889 | /**
|
---|
2890 | * If the dialog has more than one tab, put focus into the first tab as soon as dialog is opened.
|
---|
2891 | * @name CKEDITOR.config.dialog_startupFocusTab
|
---|
2892 | * @type Boolean
|
---|
2893 | * @default false
|
---|
2894 | * @example
|
---|
2895 | * config.dialog_startupFocusTab = true;
|
---|
2896 | */
|
---|
2897 |
|
---|
2898 | /**
|
---|
2899 | * The distance of magnetic borders used in moving and resizing dialogs,
|
---|
2900 | * measured in pixels.
|
---|
2901 | * @name CKEDITOR.config.dialog_magnetDistance
|
---|
2902 | * @type Number
|
---|
2903 | * @default 20
|
---|
2904 | * @example
|
---|
2905 | * config.dialog_magnetDistance = 30;
|
---|
2906 | */
|
---|
2907 |
|
---|
2908 | /**
|
---|
2909 | * Fired when a dialog definition is about to be used to create a dialog into
|
---|
2910 | * an editor instance. This event makes it possible to customize the definition
|
---|
2911 | * before creating it.
|
---|
2912 | * <p>Note that this event is called only the first time a specific dialog is
|
---|
2913 | * opened. Successive openings will use the cached dialog, and this event will
|
---|
2914 | * not get fired.</p>
|
---|
2915 | * @name CKEDITOR#dialogDefinition
|
---|
2916 | * @event
|
---|
2917 | * @param {CKEDITOR.dialog.dialogDefinition} data The dialog defination that
|
---|
2918 | * is being loaded.
|
---|
2919 | * @param {CKEDITOR.editor} editor The editor instance that will use the
|
---|
2920 | * dialog.
|
---|
2921 | */
|
---|