2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.themes.add( 'default', (function()
\r
8 function checkSharedSpace( editor, spaceName )
\r
13 // Try to retrieve the target element from the sharedSpaces settings.
\r
14 element = editor.config.sharedSpaces;
\r
15 element = element && element[ spaceName ];
\r
16 element = element && CKEDITOR.document.getById( element );
\r
18 // If the element is available, we'll then create the container for
\r
22 // Creates an HTML structure that reproduces the editor class hierarchy.
\r
24 '<span class="cke_shared">' +
\r
25 '<span class="' + editor.skinClass + ' cke_editor_' + editor.name + '">' +
\r
26 '<span class="' + CKEDITOR.env.cssClass + '">' +
\r
27 '<span class="cke_wrapper cke_' + editor.lang.dir + '">' +
\r
28 '<span class="cke_editor">' +
\r
29 '<div class="cke_' + spaceName + '">' +
\r
30 '</div></span></span></span></span></span>';
\r
32 var mainContainer = element.append( CKEDITOR.dom.element.createFromHtml( html, element.getDocument() ) );
\r
34 // Only the first container starts visible. Others get hidden.
\r
35 if ( element.getCustomData( 'cke_hasshared' ) )
\r
36 mainContainer.hide();
\r
38 element.setCustomData( 'cke_hasshared', 1 );
\r
40 // Get the deeper inner <div>.
\r
41 container = mainContainer.getChild( [0,0,0,0] );
\r
43 // When the editor gets focus, we show the space container, hiding others.
\r
44 editor.on( 'focus', function()
\r
46 for ( var i = 0, sibling, children = element.getChildren() ; ( sibling = children.getItem( i ) ) ; i++ )
\r
48 if ( sibling.type == CKEDITOR.NODE_ELEMENT
\r
49 && !sibling.equals( mainContainer )
\r
50 && sibling.hasClass( 'cke_shared' ) )
\r
56 mainContainer.show();
\r
59 editor.on( 'destroy', function()
\r
61 mainContainer.remove();
\r
69 build : function( editor, themePath )
\r
71 var name = editor.name,
\r
72 element = editor.element,
\r
73 elementMode = editor.elementMode;
\r
75 if ( !element || elementMode == CKEDITOR.ELEMENT_MODE_NONE )
\r
78 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
81 // Get the HTML for the predefined spaces.
\r
82 var topHtml = editor.fire( 'themeSpace', { space : 'top', html : '' } ).html;
\r
83 var contentsHtml = editor.fire( 'themeSpace', { space : 'contents', html : '' } ).html;
\r
84 var bottomHtml = editor.fireOnce( 'themeSpace', { space : 'bottom', html : '' } ).html;
\r
86 var height = contentsHtml && editor.config.height;
\r
88 var tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
\r
90 // The editor height is considered only if the contents space got filled.
\r
91 if ( !contentsHtml )
\r
93 else if ( !isNaN( height ) )
\r
97 var width = editor.config.width;
\r
101 if ( !isNaN( width ) )
\r
104 style += "width: " + width + ";";
\r
107 var sharedTop = topHtml && checkSharedSpace( editor, 'top' ),
\r
108 sharedBottoms = checkSharedSpace( editor, 'bottom' );
\r
110 sharedTop && ( sharedTop.setHtml( topHtml ) , topHtml = '' );
\r
111 sharedBottoms && ( sharedBottoms.setHtml( bottomHtml ), bottomHtml = '' );
\r
113 var container = CKEDITOR.dom.element.createFromHtml( [
\r
115 ' id="cke_', name, '"' +
\r
116 ' onmousedown="return false;"' +
\r
117 ' class="', editor.skinClass, ' cke_editor_', name, '"' +
\r
118 ' dir="', editor.lang.dir, '"' +
\r
119 ' title="', ( CKEDITOR.env.gecko ? ' ' : '' ), '"' +
\r
120 ' lang="', editor.langCode, '"' +
\r
121 ( CKEDITOR.env.webkit? ' tabindex="' + tabIndex + '"' : '' ) +
\r
122 ' role="application"' +
\r
123 ' aria-labelledby="cke_', name, '_arialbl"' +
\r
124 ( style ? ' style="' + style + '"' : '' ) +
\r
126 '<span id="cke_', name, '_arialbl" class="cke_voice_label">' + editor.lang.editor + '</span>' +
\r
127 '<span class="' , CKEDITOR.env.cssClass, '" role="presentation">' +
\r
128 '<span class="cke_wrapper cke_', editor.lang.dir, '" role="presentation">' +
\r
129 '<table class="cke_editor" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody>' +
\r
130 '<tr', topHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_top_' , name, '" class="cke_top" role="presentation">' , topHtml , '</td></tr>' +
\r
131 '<tr', contentsHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_contents_', name, '" class="cke_contents" style="height:', height, '" role="presentation">', contentsHtml, '</td></tr>' +
\r
132 '<tr', bottomHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_bottom_' , name, '" class="cke_bottom" role="presentation">' , bottomHtml , '</td></tr>' +
\r
133 '</tbody></table>' +
\r
134 //Hide the container when loading skins, later restored by skin css.
\r
135 '<style>.', editor.skinClass, '{visibility:hidden;}</style>' +
\r
138 '</span>' ].join( '' ) );
\r
140 container.getChild( [1, 0, 0, 0, 0] ).unselectable();
\r
141 container.getChild( [1, 0, 0, 0, 2] ).unselectable();
\r
143 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
144 container.insertAfter( element );
\r
146 element.append( container );
\r
149 * The DOM element that holds the main editor interface.
\r
150 * @name CKEDITOR.editor.prototype.container
\r
151 * @type CKEDITOR.dom.element
\r
153 * var editor = CKEDITOR.instances.editor1;
\r
154 * alert( <b>editor.container</b>.getName() ); "span"
\r
156 editor.container = container;
\r
158 // Disable browser context menu for editor's chrome.
\r
159 container.disableContextMenu();
\r
161 editor.fireOnce( 'themeLoaded' );
\r
162 editor.fireOnce( 'uiReady' );
\r
165 buildDialog : function( editor )
\r
167 var baseIdNumber = CKEDITOR.tools.getNextNumber();
\r
169 var element = CKEDITOR.dom.element.createFromHtml( [
\r
170 '<div class="cke_editor_' + editor.name.replace('.', '\\.') + '_dialog cke_skin_', editor.skinName,
\r
171 '" dir="', editor.lang.dir, '"' +
\r
172 ' lang="', editor.langCode, '"' +
\r
174 ' aria-labelledby="%title#"' +
\r
176 '<table class="cke_dialog', ' ' + CKEDITOR.env.cssClass,
\r
177 ' cke_', editor.lang.dir, '" style="position:absolute" role="presentation">' +
\r
178 '<tr><td role="presentation">' +
\r
179 '<div class="%body" role="presentation">' +
\r
180 '<div id="%title#" class="%title" role="presentation"></div>' +
\r
181 '<a id="%close_button#" class="%close_button" href="javascript:void(0)" title="' + editor.lang.common.close+'" role="button"><span class="cke_label">X</span></a>' +
\r
182 '<div id="%tabs#" class="%tabs" role="tablist"></div>' +
\r
183 '<table class="%contents" role="presentation"><tr>' +
\r
184 '<td id="%contents#" class="%contents" role="presentation"></td>' +
\r
186 '<div id="%footer#" class="%footer" role="presentation"></div>' +
\r
188 '<div id="%tl#" class="%tl"></div>' +
\r
189 '<div id="%tc#" class="%tc"></div>' +
\r
190 '<div id="%tr#" class="%tr"></div>' +
\r
191 '<div id="%ml#" class="%ml"></div>' +
\r
192 '<div id="%mr#" class="%mr"></div>' +
\r
193 '<div id="%bl#" class="%bl"></div>' +
\r
194 '<div id="%bc#" class="%bc"></div>' +
\r
195 '<div id="%br#" class="%br"></div>' +
\r
199 //Hide the container when loading skins, later restored by skin css.
\r
200 ( CKEDITOR.env.ie ? '' : '<style>.cke_dialog{visibility:hidden;}</style>' ),
\r
204 .replace( /#/g, '_' + baseIdNumber )
\r
205 .replace( /%/g, 'cke_dialog_' ) );
\r
207 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
\r
208 title = body.getChild( 0 ),
\r
209 close = body.getChild( 1 );
\r
211 // Make the Title and Close Button unselectable.
\r
212 title.unselectable();
\r
213 close.unselectable();
\r
220 dialog : element.getChild( 0 ),
\r
223 tabs : body.getChild( 2 ),
\r
224 contents : body.getChild( [ 3, 0, 0, 0 ] ),
\r
225 footer : body.getChild( 4 )
\r
230 destroy : function( editor )
\r
232 var container = editor.container;
\r
233 container.clearCustomData();
\r
234 editor.element.clearCustomData();
\r
237 container.remove();
\r
239 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
240 editor.element.show();
\r
242 delete editor.element;
\r
248 * Returns the DOM element that represents a theme space. The default theme defines
\r
249 * three spaces, namely "top", "contents" and "bottom", representing the main
\r
250 * blocks that compose the editor interface.
\r
251 * @param {String} spaceName The space name.
\r
252 * @returns {CKEDITOR.dom.element} The element that represents the space.
\r
254 * // Hide the bottom space in the UI.
\r
255 * var bottom = editor.getThemeSpace( 'bottom' );
\r
256 * bottom.setStyle( 'display', 'none' );
\r
258 CKEDITOR.editor.prototype.getThemeSpace = function( spaceName )
\r
260 var spacePrefix = 'cke_' + spaceName;
\r
261 var space = this._[ spacePrefix ] ||
\r
262 ( this._[ spacePrefix ] = CKEDITOR.document.getById( spacePrefix + '_' + this.name ) );
\r
267 * Resizes the editor interface.
\r
268 * @param {Number|String} width The new width. It can be an pixels integer or a
\r
270 * @param {Number|String} height The new height. It can be an pixels integer or
\r
271 * a CSS size value.
\r
272 * @param {Boolean} [isContentHeight] Indicates that the provided height is to
\r
273 * be applied to the editor contents space, not to the entire editor
\r
274 * interface. Defaults to false.
\r
275 * @param {Boolean} [resizeInner] Indicates that the first inner interface
\r
276 * element must receive the size, not the outer element. The default theme
\r
277 * defines the interface inside a pair of span elements
\r
278 * (<span><span>...</span></span>). By default the
\r
279 * first span element receives the sizes. If this parameter is set to
\r
280 * true, the second span is sized instead.
\r
282 * editor.resize( 900, 300 );
\r
284 * editor.resize( '100%', 450, true );
\r
286 CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, resizeInner )
\r
288 var container = this.container,
\r
289 contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),
\r
290 outer = resizeInner ? container.getChild( 1 ) : container;
\r
292 // Resize the width first.
\r
293 // WEBKIT BUG: Webkit requires that we put the editor off from display when we
\r
294 // resize it. If we don't, the browser crashes!
\r
295 CKEDITOR.env.webkit && outer.setStyle( 'display', 'none' );
\r
296 // Set as border box width. (#5353)
\r
297 outer.setSize( 'width', width, true );
\r
298 if ( CKEDITOR.env.webkit )
\r
300 outer.$.offsetWidth;
\r
301 outer.setStyle( 'display', '' );
\r
304 // Get the height delta between the outer table and the content area.
\r
305 // If we're setting the content area's height, then we don't need the delta.
\r
306 var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
\r
307 contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
\r
309 // Emit a resize event.
\r
310 this.fire( 'resize' );
\r
314 * Gets the element that can be freely used to check the editor size. This method
\r
315 * is mainly used by the resize plugin, which adds a UI handle that can be used
\r
316 * to resize the editor.
\r
317 * @returns {CKEDITOR.dom.element} The resizable element.
\r
320 CKEDITOR.editor.prototype.getResizable = function()
\r
322 return this.container.getChild( 1 );
\r
326 * Makes it possible to place some of the editor UI blocks, like the toolbar
\r
327 * and the elements path, into any element in the page.
\r
328 * The elements used to hold the UI blocks can be shared among several editor
\r
329 * instances. In that case, only the blocks of the active editor instance will
\r
331 * @name CKEDITOR.config.sharedSpaces
\r
333 * @default undefined
\r
335 * // Place the toolbar inside the element with ID "someElementId" and the
\r
336 * // elements path into the element with ID "anotherId".
\r
337 * config.sharedSpaces =
\r
339 * top : 'someElementId',
\r
340 * bottom : 'anotherId'
\r
343 * // Place the toolbar inside the element with ID "someElementId". The
\r
344 * // elements path will remain attached to the editor UI.
\r
345 * config.sharedSpaces =
\r
347 * top : 'someElementId'
\r
352 * Fired after the editor instance is resized through
\r
353 * the {@link CKEDITOR.editor.prototype.resize} method.
\r
354 * @name CKEDITOR#resize
\r