2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
7 * @name CKEDITOR.theme
\r
11 CKEDITOR.themes.add( 'default', (function()
\r
13 function checkSharedSpace( editor, spaceName )
\r
18 // Try to retrieve the target element from the sharedSpaces settings.
\r
19 element = editor.config.sharedSpaces;
\r
20 element = element && element[ spaceName ];
\r
21 element = element && CKEDITOR.document.getById( element );
\r
23 // If the element is available, we'll then create the container for
\r
27 // Creates an HTML structure that reproduces the editor class hierarchy.
\r
29 '<span class="cke_shared "' +
\r
30 ' dir="'+ editor.lang.dir + '"' +
\r
32 '<span class="' + editor.skinClass + ' ' + editor.id + ' cke_editor_' + editor.name + '">' +
\r
33 '<span class="' + CKEDITOR.env.cssClass + '">' +
\r
34 '<span class="cke_wrapper cke_' + editor.lang.dir + '">' +
\r
35 '<span class="cke_editor">' +
\r
36 '<div class="cke_' + spaceName + '">' +
\r
37 '</div></span></span></span></span></span>';
\r
39 var mainContainer = element.append( CKEDITOR.dom.element.createFromHtml( html, element.getDocument() ) );
\r
41 // Only the first container starts visible. Others get hidden.
\r
42 if ( element.getCustomData( 'cke_hasshared' ) )
\r
43 mainContainer.hide();
\r
45 element.setCustomData( 'cke_hasshared', 1 );
\r
47 // Get the deeper inner <div>.
\r
48 container = mainContainer.getChild( [0,0,0,0] );
\r
50 // Save a reference to the shared space container.
\r
51 !editor.sharedSpaces && ( editor.sharedSpaces = {} );
\r
52 editor.sharedSpaces[ spaceName ] = container;
\r
54 // When the editor gets focus, we show the space container, hiding others.
\r
55 editor.on( 'focus', function()
\r
57 for ( var i = 0, sibling, children = element.getChildren() ; ( sibling = children.getItem( i ) ) ; i++ )
\r
59 if ( sibling.type == CKEDITOR.NODE_ELEMENT
\r
60 && !sibling.equals( mainContainer )
\r
61 && sibling.hasClass( 'cke_shared' ) )
\r
67 mainContainer.show();
\r
70 editor.on( 'destroy', function()
\r
72 mainContainer.remove();
\r
79 return /** @lends CKEDITOR.theme */ {
\r
80 build : function( editor, themePath )
\r
82 var name = editor.name,
\r
83 element = editor.element,
\r
84 elementMode = editor.elementMode;
\r
86 if ( !element || elementMode == CKEDITOR.ELEMENT_MODE_NONE )
\r
89 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
92 // Get the HTML for the predefined spaces.
\r
93 var topHtml = editor.fire( 'themeSpace', { space : 'top', html : '' } ).html;
\r
94 var contentsHtml = editor.fire( 'themeSpace', { space : 'contents', html : '' } ).html;
\r
95 var bottomHtml = editor.fireOnce( 'themeSpace', { space : 'bottom', html : '' } ).html;
\r
97 var height = contentsHtml && editor.config.height;
\r
99 var tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
\r
101 // The editor height is considered only if the contents space got filled.
\r
102 if ( !contentsHtml )
\r
104 else if ( !isNaN( height ) )
\r
108 var width = editor.config.width;
\r
112 if ( !isNaN( width ) )
\r
115 style += "width: " + width + ";";
\r
118 var sharedTop = topHtml && checkSharedSpace( editor, 'top' ),
\r
119 sharedBottoms = checkSharedSpace( editor, 'bottom' );
\r
121 sharedTop && ( sharedTop.setHtml( topHtml ) , topHtml = '' );
\r
122 sharedBottoms && ( sharedBottoms.setHtml( bottomHtml ), bottomHtml = '' );
\r
124 var container = CKEDITOR.dom.element.createFromHtml( [
\r
126 ' id="cke_', name, '"' +
\r
127 ' class="', editor.skinClass, ' ', editor.id, ' cke_editor_', name, '"' +
\r
128 ' dir="', editor.lang.dir, '"' +
\r
129 ' title="', ( CKEDITOR.env.gecko ? ' ' : '' ), '"' +
\r
130 ' lang="', editor.langCode, '"' +
\r
131 ( CKEDITOR.env.webkit? ' tabindex="' + tabIndex + '"' : '' ) +
\r
132 ' role="application"' +
\r
133 ' aria-labelledby="cke_', name, '_arialbl"' +
\r
134 ( style ? ' style="' + style + '"' : '' ) +
\r
136 '<span id="cke_', name, '_arialbl" class="cke_voice_label">' + editor.lang.editor + '</span>' +
\r
137 '<span class="' , CKEDITOR.env.cssClass, '" role="presentation">' +
\r
138 '<span class="cke_wrapper cke_', editor.lang.dir, '" role="presentation">' +
\r
139 '<table class="cke_editor" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody>' +
\r
140 '<tr', topHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_top_' , name, '" class="cke_top" role="presentation">' , topHtml , '</td></tr>' +
\r
141 '<tr', contentsHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_contents_', name, '" class="cke_contents" style="height:', height, '" role="presentation">', contentsHtml, '</td></tr>' +
\r
142 '<tr', bottomHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_bottom_' , name, '" class="cke_bottom" role="presentation">' , bottomHtml , '</td></tr>' +
\r
143 '</tbody></table>' +
\r
144 //Hide the container when loading skins, later restored by skin css.
\r
145 '<style>.', editor.skinClass, '{visibility:hidden;}</style>' +
\r
148 '</span>' ].join( '' ) );
\r
150 container.getChild( [1, 0, 0, 0, 0] ).unselectable();
\r
151 container.getChild( [1, 0, 0, 0, 2] ).unselectable();
\r
153 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
154 container.insertAfter( element );
\r
156 element.append( container );
\r
159 * The DOM element that holds the main editor interface.
\r
160 * @name CKEDITOR.editor.prototype.container
\r
161 * @type CKEDITOR.dom.element
\r
163 * var editor = CKEDITOR.instances.editor1;
\r
164 * alert( <b>editor.container</b>.getName() ); "span"
\r
166 editor.container = container;
\r
168 // Disable browser context menu for editor's chrome.
\r
169 container.disableContextMenu();
\r
171 // Use a class to indicate that the current selection is in different direction than the UI.
\r
172 editor.on( 'contentDirChanged', function( evt )
\r
174 var func = ( editor.lang.dir != evt.data ? 'add' : 'remove' ) + 'Class';
\r
176 container.getChild( 1 )[ func ]( 'cke_mixed_dir_content' );
\r
178 // Put the mixed direction class on the respective element also for shared spaces.
\r
179 var toolbarSpace = this.sharedSpaces && this.sharedSpaces[ this.config.toolbarLocation ];
\r
180 toolbarSpace && toolbarSpace.getParent().getParent()[ func ]( 'cke_mixed_dir_content' );
\r
183 editor.fireOnce( 'themeLoaded' );
\r
184 editor.fireOnce( 'uiReady' );
\r
187 buildDialog : function( editor )
\r
189 var baseIdNumber = CKEDITOR.tools.getNextNumber();
\r
191 var element = CKEDITOR.dom.element.createFromHtml( [
\r
192 '<div class="', editor.id, '_dialog cke_editor_', editor.name.replace('.', '\\.'), '_dialog cke_skin_', editor.skinName,
\r
193 '" dir="', editor.lang.dir, '"' +
\r
194 ' lang="', editor.langCode, '"' +
\r
196 ' aria-labelledby="%title#"' +
\r
198 '<table class="cke_dialog', ' ' + CKEDITOR.env.cssClass,
\r
199 ' cke_', editor.lang.dir, '" style="position:absolute" role="presentation">' +
\r
200 '<tr><td role="presentation">' +
\r
201 '<div class="%body" role="presentation">' +
\r
202 '<div id="%title#" class="%title" role="presentation"></div>' +
\r
203 '<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
204 '<div id="%tabs#" class="%tabs" role="tablist"></div>' +
\r
205 '<table class="%contents" role="presentation">' +
\r
207 '<td id="%contents#" class="%contents" role="presentation"></td>' +
\r
210 '<td id="%footer#" class="%footer" role="presentation"></td>' +
\r
214 '<div id="%tl#" class="%tl"></div>' +
\r
215 '<div id="%tc#" class="%tc"></div>' +
\r
216 '<div id="%tr#" class="%tr"></div>' +
\r
217 '<div id="%ml#" class="%ml"></div>' +
\r
218 '<div id="%mr#" class="%mr"></div>' +
\r
219 '<div id="%bl#" class="%bl"></div>' +
\r
220 '<div id="%bc#" class="%bc"></div>' +
\r
221 '<div id="%br#" class="%br"></div>' +
\r
225 //Hide the container when loading skins, later restored by skin css.
\r
226 ( CKEDITOR.env.ie ? '' : '<style>.cke_dialog{visibility:hidden;}</style>' ),
\r
230 .replace( /#/g, '_' + baseIdNumber )
\r
231 .replace( /%/g, 'cke_dialog_' ) );
\r
233 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
\r
234 title = body.getChild( 0 ),
\r
235 close = body.getChild( 1 );
\r
237 // Make the Title and Close Button unselectable.
\r
238 title.unselectable();
\r
239 close.unselectable();
\r
246 dialog : element.getChild( 0 ),
\r
249 tabs : body.getChild( 2 ),
\r
250 contents : body.getChild( [ 3, 0, 0, 0 ] ),
\r
251 footer : body.getChild( [ 3, 0, 1, 0 ] )
\r
256 destroy : function( editor )
\r
258 var container = editor.container,
\r
259 element = editor.element;
\r
263 container.clearCustomData();
\r
264 container.remove();
\r
269 element.clearCustomData();
\r
270 editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.show();
\r
271 delete editor.element;
\r
278 * Returns the DOM element that represents a theme space. The default theme defines
\r
279 * three spaces, namely "top", "contents" and "bottom", representing the main
\r
280 * blocks that compose the editor interface.
\r
281 * @param {String} spaceName The space name.
\r
282 * @returns {CKEDITOR.dom.element} The element that represents the space.
\r
284 * // Hide the bottom space in the UI.
\r
285 * var bottom = editor.getThemeSpace( 'bottom' );
\r
286 * bottom.setStyle( 'display', 'none' );
\r
288 CKEDITOR.editor.prototype.getThemeSpace = function( spaceName )
\r
290 var spacePrefix = 'cke_' + spaceName;
\r
291 var space = this._[ spacePrefix ] ||
\r
292 ( this._[ spacePrefix ] = CKEDITOR.document.getById( spacePrefix + '_' + this.name ) );
\r
297 * Resizes the editor interface.
\r
298 * @param {Number|String} width The new width. It can be an pixels integer or a
\r
300 * @param {Number|String} height The new height. It can be an pixels integer or
\r
301 * a CSS size value.
\r
302 * @param {Boolean} [isContentHeight] Indicates that the provided height is to
\r
303 * be applied to the editor contents space, not to the entire editor
\r
304 * interface. Defaults to false.
\r
305 * @param {Boolean} [resizeInner] Indicates that the first inner interface
\r
306 * element must receive the size, not the outer element. The default theme
\r
307 * defines the interface inside a pair of span elements
\r
308 * (<span><span>...</span></span>). By default the
\r
309 * first span element receives the sizes. If this parameter is set to
\r
310 * true, the second span is sized instead.
\r
312 * editor.resize( 900, 300 );
\r
314 * editor.resize( '100%', 450, true );
\r
316 CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, resizeInner )
\r
318 var container = this.container,
\r
319 contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),
\r
320 outer = resizeInner ? container.getChild( 1 ) : container;
\r
322 // Resize the width first.
\r
323 // WEBKIT BUG: Webkit requires that we put the editor off from display when we
\r
324 // resize it. If we don't, the browser crashes!
\r
325 CKEDITOR.env.webkit && outer.setStyle( 'display', 'none' );
\r
326 // Set as border box width. (#5353)
\r
327 outer.setSize( 'width', width, true );
\r
328 if ( CKEDITOR.env.webkit )
\r
330 outer.$.offsetWidth;
\r
331 outer.setStyle( 'display', '' );
\r
334 // Get the height delta between the outer table and the content area.
\r
335 // If we're setting the content area's height, then we don't need the delta.
\r
336 var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
\r
337 contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
\r
339 // Emit a resize event.
\r
340 this.fire( 'resize' );
\r
344 * Gets the element that can be freely used to check the editor size. This method
\r
345 * is mainly used by the resize plugin, which adds a UI handle that can be used
\r
346 * to resize the editor.
\r
347 * @returns {CKEDITOR.dom.element} The resizable element.
\r
350 CKEDITOR.editor.prototype.getResizable = function()
\r
352 return this.container;
\r
356 * Makes it possible to place some of the editor UI blocks, like the toolbar
\r
357 * and the elements path, into any element in the page.
\r
358 * The elements used to hold the UI blocks can be shared among several editor
\r
359 * instances. In that case, only the blocks of the active editor instance will
\r
361 * @name CKEDITOR.config.sharedSpaces
\r
363 * @default undefined
\r
365 * // Place the toolbar inside the element with ID "someElementId" and the
\r
366 * // elements path into the element with ID "anotherId".
\r
367 * config.sharedSpaces =
\r
369 * top : 'someElementId',
\r
370 * bottom : 'anotherId'
\r
373 * // Place the toolbar inside the element with ID "someElementId". The
\r
374 * // elements path will remain attached to the editor UI.
\r
375 * config.sharedSpaces =
\r
377 * top : 'someElementId'
\r
382 * Fired after the editor instance is resized through
\r
383 * the {@link CKEDITOR.editor.prototype.resize} method.
\r
384 * @name CKEDITOR.editor#resize
\r