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