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 var hiddenSkins = {};
\r
15 function checkSharedSpace( editor, spaceName )
\r
20 // Try to retrieve the target element from the sharedSpaces settings.
\r
21 element = editor.config.sharedSpaces;
\r
22 element = element && element[ spaceName ];
\r
23 element = element && CKEDITOR.document.getById( element );
\r
25 // If the element is available, we'll then create the container for
\r
29 // Creates an HTML structure that reproduces the editor class hierarchy.
\r
31 '<span class="cke_shared "' +
\r
32 ' dir="'+ editor.lang.dir + '"' +
\r
34 '<span class="' + editor.skinClass + ' ' + editor.id + ' cke_editor_' + editor.name + '">' +
\r
35 '<span class="' + CKEDITOR.env.cssClass + '">' +
\r
36 '<span class="cke_wrapper cke_' + editor.lang.dir + '">' +
\r
37 '<span class="cke_editor">' +
\r
38 '<div class="cke_' + spaceName + '">' +
\r
39 '</div></span></span></span></span></span>';
\r
41 var mainContainer = element.append( CKEDITOR.dom.element.createFromHtml( html, element.getDocument() ) );
\r
43 // Only the first container starts visible. Others get hidden.
\r
44 if ( element.getCustomData( 'cke_hasshared' ) )
\r
45 mainContainer.hide();
\r
47 element.setCustomData( 'cke_hasshared', 1 );
\r
49 // Get the deeper inner <div>.
\r
50 container = mainContainer.getChild( [0,0,0,0] );
\r
52 // Save a reference to the shared space container.
\r
53 !editor.sharedSpaces && ( editor.sharedSpaces = {} );
\r
54 editor.sharedSpaces[ spaceName ] = container;
\r
56 // When the editor gets focus, we show the space container, hiding others.
\r
57 editor.on( 'focus', function()
\r
59 for ( var i = 0, sibling, children = element.getChildren() ; ( sibling = children.getItem( i ) ) ; i++ )
\r
61 if ( sibling.type == CKEDITOR.NODE_ELEMENT
\r
62 && !sibling.equals( mainContainer )
\r
63 && sibling.hasClass( 'cke_shared' ) )
\r
69 mainContainer.show();
\r
72 editor.on( 'destroy', function()
\r
74 mainContainer.remove();
\r
81 return /** @lends CKEDITOR.theme */ {
\r
82 build : function( editor, themePath )
\r
84 var name = editor.name,
\r
85 element = editor.element,
\r
86 elementMode = editor.elementMode;
\r
88 if ( !element || elementMode == CKEDITOR.ELEMENT_MODE_NONE )
\r
91 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
94 // Get the HTML for the predefined spaces.
\r
95 var topHtml = editor.fire( 'themeSpace', { space : 'top', html : '' } ).html;
\r
96 var contentsHtml = editor.fire( 'themeSpace', { space : 'contents', html : '' } ).html;
\r
97 var bottomHtml = editor.fireOnce( 'themeSpace', { space : 'bottom', html : '' } ).html;
\r
99 var height = contentsHtml && editor.config.height;
\r
101 var tabIndex = editor.config.tabIndex || editor.element.getAttribute( 'tabindex' ) || 0;
\r
103 // The editor height is considered only if the contents space got filled.
\r
104 if ( !contentsHtml )
\r
106 else if ( !isNaN( height ) )
\r
110 var width = editor.config.width;
\r
114 if ( !isNaN( width ) )
\r
117 style += "width: " + width + ";";
\r
120 var sharedTop = topHtml && checkSharedSpace( editor, 'top' ),
\r
121 sharedBottoms = checkSharedSpace( editor, 'bottom' );
\r
123 sharedTop && ( sharedTop.setHtml( topHtml ) , topHtml = '' );
\r
124 sharedBottoms && ( sharedBottoms.setHtml( bottomHtml ), bottomHtml = '' );
\r
126 var hideSkin = '<style>.' + editor.skinClass + '{visibility:hidden;}</style>';
\r
127 if ( hiddenSkins[ editor.skinClass ] )
\r
130 hiddenSkins[ editor.skinClass ] = 1;
\r
132 var container = CKEDITOR.dom.element.createFromHtml( [
\r
134 ' id="cke_', name, '"' +
\r
135 ' class="', editor.skinClass, ' ', editor.id, ' cke_editor_', name, '"' +
\r
136 ' dir="', editor.lang.dir, '"' +
\r
137 ' title="', ( CKEDITOR.env.gecko ? ' ' : '' ), '"' +
\r
138 ' lang="', editor.langCode, '"' +
\r
139 ( CKEDITOR.env.webkit? ' tabindex="' + tabIndex + '"' : '' ) +
\r
140 ' role="application"' +
\r
141 ' aria-labelledby="cke_', name, '_arialbl"' +
\r
142 ( style ? ' style="' + style + '"' : '' ) +
\r
144 '<span id="cke_', name, '_arialbl" class="cke_voice_label">' + editor.lang.editor + '</span>' +
\r
145 '<span class="' , CKEDITOR.env.cssClass, '" role="presentation">' +
\r
146 '<span class="cke_wrapper cke_', editor.lang.dir, '" role="presentation">' +
\r
147 '<table class="cke_editor" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody>' +
\r
148 '<tr', topHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_top_' , name, '" class="cke_top" role="presentation">' , topHtml , '</td></tr>' +
\r
149 '<tr', contentsHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_contents_', name, '" class="cke_contents" style="height:', height, '" role="presentation">', contentsHtml, '</td></tr>' +
\r
150 '<tr', bottomHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_bottom_' , name, '" class="cke_bottom" role="presentation">' , bottomHtml , '</td></tr>' +
\r
151 '</tbody></table>' +
\r
152 //Hide the container when loading skins, later restored by skin css.
\r
156 '</span>' ].join( '' ) );
\r
158 container.getChild( [1, 0, 0, 0, 0] ).unselectable();
\r
159 container.getChild( [1, 0, 0, 0, 2] ).unselectable();
\r
161 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
162 container.insertAfter( element );
\r
164 element.append( container );
\r
167 * The DOM element that holds the main editor interface.
\r
168 * @name CKEDITOR.editor.prototype.container
\r
169 * @type CKEDITOR.dom.element
\r
171 * var editor = CKEDITOR.instances.editor1;
\r
172 * alert( <b>editor.container</b>.getName() ); "span"
\r
174 editor.container = container;
\r
176 // Disable browser context menu for editor's chrome.
\r
177 container.disableContextMenu();
\r
179 // Use a class to indicate that the current selection is in different direction than the UI.
\r
180 editor.on( 'contentDirChanged', function( evt )
\r
182 var func = ( editor.lang.dir != evt.data ? 'add' : 'remove' ) + 'Class';
\r
184 container.getChild( 1 )[ func ]( 'cke_mixed_dir_content' );
\r
186 // Put the mixed direction class on the respective element also for shared spaces.
\r
187 var toolbarSpace = this.sharedSpaces && this.sharedSpaces[ this.config.toolbarLocation ];
\r
188 toolbarSpace && toolbarSpace.getParent().getParent()[ func ]( 'cke_mixed_dir_content' );
\r
191 editor.fireOnce( 'themeLoaded' );
\r
192 editor.fireOnce( 'uiReady' );
\r
195 buildDialog : function( editor )
\r
197 var baseIdNumber = CKEDITOR.tools.getNextNumber();
\r
199 var element = CKEDITOR.dom.element.createFromHtml( [
\r
200 '<div class="', editor.id, '_dialog cke_editor_', editor.name.replace('.', '\\.'), '_dialog cke_skin_', editor.skinName,
\r
201 '" dir="', editor.lang.dir, '"' +
\r
202 ' lang="', editor.langCode, '"' +
\r
204 ' aria-labelledby="%title#"' +
\r
206 '<table class="cke_dialog', ' ' + CKEDITOR.env.cssClass,
\r
207 ' cke_', editor.lang.dir, '" style="position:absolute" role="presentation">' +
\r
208 '<tr><td role="presentation">' +
\r
209 '<div class="%body" role="presentation">' +
\r
210 '<div id="%title#" class="%title" role="presentation"></div>' +
\r
211 '<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
212 '<div id="%tabs#" class="%tabs" role="tablist"></div>' +
\r
213 '<table class="%contents" role="presentation">' +
\r
215 '<td id="%contents#" class="%contents" role="presentation"></td>' +
\r
218 '<td id="%footer#" class="%footer" role="presentation"></td>' +
\r
222 '<div id="%tl#" class="%tl"></div>' +
\r
223 '<div id="%tc#" class="%tc"></div>' +
\r
224 '<div id="%tr#" class="%tr"></div>' +
\r
225 '<div id="%ml#" class="%ml"></div>' +
\r
226 '<div id="%mr#" class="%mr"></div>' +
\r
227 '<div id="%bl#" class="%bl"></div>' +
\r
228 '<div id="%bc#" class="%bc"></div>' +
\r
229 '<div id="%br#" class="%br"></div>' +
\r
233 //Hide the container when loading skins, later restored by skin css.
\r
234 ( CKEDITOR.env.ie ? '' : '<style>.cke_dialog{visibility:hidden;}</style>' ),
\r
238 .replace( /#/g, '_' + baseIdNumber )
\r
239 .replace( /%/g, 'cke_dialog_' ) );
\r
241 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
\r
242 title = body.getChild( 0 ),
\r
243 close = body.getChild( 1 );
\r
245 // IFrame shim for dialog that masks activeX in IE. (#7619)
\r
246 if ( CKEDITOR.env.ie && !CKEDITOR.env.ie6Compat )
\r
248 var isCustomDomain = CKEDITOR.env.isCustomDomain(),
\r
249 src = 'javascript:void(function(){' + encodeURIComponent( 'document.open();' + ( isCustomDomain ? ( 'document.domain="' + document.domain + '";' ) : '' ) + 'document.close();' ) + '}())',
\r
250 iframe = CKEDITOR.dom.element.createFromHtml( '<iframe' +
\r
251 ' frameBorder="0"' +
\r
252 ' class="cke_iframe_shim"' +
\r
253 ' src="' + src + '"' +
\r
256 iframe.appendTo( body.getParent() );
\r
259 // Make the Title and Close Button unselectable.
\r
260 title.unselectable();
\r
261 close.unselectable();
\r
268 dialog : element.getChild( 0 ),
\r
271 tabs : body.getChild( 2 ),
\r
272 contents : body.getChild( [ 3, 0, 0, 0 ] ),
\r
273 footer : body.getChild( [ 3, 0, 1, 0 ] )
\r
278 destroy : function( editor )
\r
280 var container = editor.container,
\r
281 element = editor.element;
\r
285 container.clearCustomData();
\r
286 container.remove();
\r
291 element.clearCustomData();
\r
292 editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.show();
\r
293 delete editor.element;
\r
300 * Returns the DOM element that represents a theme space. The default theme defines
\r
301 * three spaces, namely "top", "contents" and "bottom", representing the main
\r
302 * blocks that compose the editor interface.
\r
303 * @param {String} spaceName The space name.
\r
304 * @returns {CKEDITOR.dom.element} The element that represents the space.
\r
306 * // Hide the bottom space in the UI.
\r
307 * var bottom = editor.getThemeSpace( 'bottom' );
\r
308 * bottom.setStyle( 'display', 'none' );
\r
310 CKEDITOR.editor.prototype.getThemeSpace = function( spaceName )
\r
312 var spacePrefix = 'cke_' + spaceName;
\r
313 var space = this._[ spacePrefix ] ||
\r
314 ( this._[ spacePrefix ] = CKEDITOR.document.getById( spacePrefix + '_' + this.name ) );
\r
319 * Resizes the editor interface.
\r
320 * @param {Number|String} width The new width. It can be an pixels integer or a
\r
322 * @param {Number|String} height The new height. It can be an pixels integer or
\r
323 * a CSS size value.
\r
324 * @param {Boolean} [isContentHeight] Indicates that the provided height is to
\r
325 * be applied to the editor contents space, not to the entire editor
\r
326 * interface. Defaults to false.
\r
327 * @param {Boolean} [resizeInner] Indicates that the first inner interface
\r
328 * element must receive the size, not the outer element. The default theme
\r
329 * defines the interface inside a pair of span elements
\r
330 * (<span><span>...</span></span>). By default the
\r
331 * first span element receives the sizes. If this parameter is set to
\r
332 * true, the second span is sized instead.
\r
334 * editor.resize( 900, 300 );
\r
336 * editor.resize( '100%', 450, true );
\r
338 CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, resizeInner )
\r
340 var container = this.container,
\r
341 contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),
\r
342 contentsFrame = CKEDITOR.env.webkit && this.document && this.document.getWindow().$.frameElement,
\r
343 outer = resizeInner ? container.getChild( 1 ) : container;
\r
345 // Set as border box width. (#5353)
\r
346 outer.setSize( 'width', width, true );
\r
348 // WebKit needs to refresh the iframe size to avoid rendering issues. (1/2) (#8348)
\r
349 contentsFrame && ( contentsFrame.style.width = '1%' );
\r
351 // Get the height delta between the outer table and the content area.
\r
352 // If we're setting the content area's height, then we don't need the delta.
\r
353 var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
\r
354 contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
\r
356 // WebKit needs to refresh the iframe size to avoid rendering issues. (2/2) (#8348)
\r
357 contentsFrame && ( contentsFrame.style.width = '100%' );
\r
359 // Emit a resize event.
\r
360 this.fire( 'resize' );
\r
364 * Gets the element that can be freely used to check the editor size. This method
\r
365 * is mainly used by the resize plugin, which adds a UI handle that can be used
\r
366 * to resize the editor.
\r
367 * @param {Boolean} forContents Whether to return the "contents" part of the theme instead of the container.
\r
368 * @returns {CKEDITOR.dom.element} The resizable element.
\r
371 CKEDITOR.editor.prototype.getResizable = function( forContents )
\r
373 return forContents ? CKEDITOR.document.getById( 'cke_contents_' + this.name ) : this.container;
\r
377 * Makes it possible to place some of the editor UI blocks, like the toolbar
\r
378 * and the elements path, into any element in the page.
\r
379 * The elements used to hold the UI blocks can be shared among several editor
\r
380 * instances. In that case, only the blocks of the active editor instance will
\r
382 * @name CKEDITOR.config.sharedSpaces
\r
384 * @default undefined
\r
386 * // Place the toolbar inside the element with ID "someElementId" and the
\r
387 * // elements path into the element with ID "anotherId".
\r
388 * config.sharedSpaces =
\r
390 * top : 'someElementId',
\r
391 * bottom : 'anotherId'
\r
394 * // Place the toolbar inside the element with ID "someElementId". The
\r
395 * // elements path will remain attached to the editor UI.
\r
396 * config.sharedSpaces =
\r
398 * top : 'someElementId'
\r
403 * Fired after the editor instance is resized through
\r
404 * the {@link CKEDITOR.editor.prototype.resize} method.
\r
405 * @name CKEDITOR.editor#resize
\r