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 ' tabindex="' + tabIndex + '"' +
\r
122 ( style ? ' style="' + style + '"' : '' ) +
\r
124 '<span class="' , CKEDITOR.env.cssClass, '">' +
\r
125 '<span class="cke_wrapper cke_', editor.lang.dir, '">' +
\r
126 '<table class="cke_editor" border="0" cellspacing="0" cellpadding="0"><tbody>' +
\r
127 '<tr', topHtml ? '' : ' style="display:none"', '><td id="cke_top_' , name, '" class="cke_top">' , topHtml , '</td></tr>' +
\r
128 '<tr', contentsHtml ? '' : ' style="display:none"', '><td id="cke_contents_', name, '" class="cke_contents" style="height:', height, '">', contentsHtml, '</td></tr>' +
\r
129 '<tr', bottomHtml ? '' : ' style="display:none"', '><td id="cke_bottom_' , name, '" class="cke_bottom">' , bottomHtml , '</td></tr>' +
\r
130 '</tbody></table>' +
\r
131 //Hide the container when loading skins, later restored by skin css.
\r
132 '<style>.', editor.skinClass, '{visibility:hidden;}</style>' +
\r
135 '</span>' ].join( '' ) );
\r
137 container.getChild( [0, 0, 0, 0, 0] ).unselectable();
\r
138 container.getChild( [0, 0, 0, 0, 2] ).unselectable();
\r
140 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
141 container.insertAfter( element );
\r
143 element.append( container );
\r
146 * The DOM element that holds the main editor interface.
\r
147 * @name CKEDITOR.editor.prototype.container
\r
148 * @type CKEDITOR.dom.element
\r
150 * var editor = CKEDITOR.instances.editor1;
\r
151 * alert( <b>editor.container</b>.getName() ); "span"
\r
153 editor.container = container;
\r
155 // Disable browser context menu for editor's chrome.
\r
156 container.disableContextMenu();
\r
158 editor.fireOnce( 'themeLoaded' );
\r
159 editor.fireOnce( 'uiReady' );
\r
162 buildDialog : function( editor )
\r
164 var baseIdNumber = CKEDITOR.tools.getNextNumber();
\r
166 var element = CKEDITOR.dom.element.createFromHtml( [
\r
167 '<div class="cke_editor_' + editor.name.replace('.', '\\.') + '_dialog cke_skin_', editor.skinName,
\r
168 '" dir="', editor.lang.dir, '"' +
\r
169 ' lang="', editor.langCode, '"' +
\r
171 '<table class="cke_dialog', ' ' + CKEDITOR.env.cssClass,
\r
172 ' cke_', editor.lang.dir, '" style="position:absolute">' +
\r
174 '<div class="%body">' +
\r
175 '<div id="%title#" class="%title"></div>' +
\r
176 '<div id="%close_button#" class="%close_button">' +
\r
179 '<div id="%tabs#" class="%tabs"></div>' +
\r
180 '<table class="%contents"><tr>' +
\r
181 '<td id="%contents#" class="%contents"></td>' +
\r
183 '<div id="%footer#" class="%footer"></div>' +
\r
185 '<div id="%tl#" class="%tl"></div>' +
\r
186 '<div id="%tc#" class="%tc"></div>' +
\r
187 '<div id="%tr#" class="%tr"></div>' +
\r
188 '<div id="%ml#" class="%ml"></div>' +
\r
189 '<div id="%mr#" class="%mr"></div>' +
\r
190 '<div id="%bl#" class="%bl"></div>' +
\r
191 '<div id="%bc#" class="%bc"></div>' +
\r
192 '<div id="%br#" class="%br"></div>' +
\r
196 //Hide the container when loading skins, later restored by skin css.
\r
197 ( CKEDITOR.env.ie ? '' : '<style>.cke_dialog{visibility:hidden;}</style>' ),
\r
201 .replace( /#/g, '_' + baseIdNumber )
\r
202 .replace( /%/g, 'cke_dialog_' ) );
\r
204 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
\r
205 title = body.getChild( 0 ),
\r
206 close = body.getChild( 1 );
\r
208 // Make the Title and Close Button unselectable.
\r
209 title.unselectable();
\r
210 close.unselectable();
\r
217 dialog : element.getChild( 0 ),
\r
220 tabs : body.getChild( 2 ),
\r
221 contents : body.getChild( [ 3, 0, 0, 0 ] ),
\r
222 footer : body.getChild( 4 )
\r
227 destroy : function( editor )
\r
229 var container = editor.container;
\r
232 * IE BUG: Removing the editor DOM elements while the selection is inside
\r
233 * the editing area would break IE7/8's selection system. So we need to put
\r
234 * the selection back to the parent document without scrolling the window.
\r
237 if ( CKEDITOR.env.ie )
\r
239 container.setStyle( 'display', 'none' );
\r
241 var $range = document.body.createTextRange();
\r
242 $range.moveToElementText( container.$ );
\r
245 // Putting the selection to a display:none element - this will certainly
\r
246 // fail. But! We've just put the selection document back to the parent
\r
247 // document without scrolling the window!
\r
254 container.remove();
\r
256 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
258 editor.element.show();
\r
259 delete editor.element;
\r
265 CKEDITOR.editor.prototype.getThemeSpace = function( spaceName )
\r
267 var spacePrefix = 'cke_' + spaceName;
\r
268 var space = this._[ spacePrefix ] ||
\r
269 ( this._[ spacePrefix ] = CKEDITOR.document.getById( spacePrefix + '_' + this.name ) );
\r
273 CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, resizeInner )
\r
275 var numberRegex = /^\d+$/;
\r
276 if ( numberRegex.test( width ) )
\r
279 var container = this.container,
\r
280 contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),
\r
281 outer = resizeInner ? container.getChild( 0 ) : container;
\r
283 // Resize the width first.
\r
284 // WEBKIT BUG: Webkit requires that we put the editor off from display when we
\r
285 // resize it. If we don't, the browser crashes!
\r
286 CKEDITOR.env.webkit && outer.setStyle( 'display', 'none' );
\r
287 outer.setStyle( 'width', width );
\r
288 if ( CKEDITOR.env.webkit )
\r
290 outer.$.offsetWidth;
\r
291 outer.setStyle( 'display', '' );
\r
294 // Get the height delta between the outer table and the content area.
\r
295 // If we're setting the content area's height, then we don't need the delta.
\r
296 var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
\r
297 contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
\r
299 // Emit a resize event.
\r
300 this.fire( 'resize' );
\r
303 CKEDITOR.editor.prototype.getResizable = function()
\r
305 return this.container.getChild( 0 );
\r
309 * Makes it possible to place some of the editor UI blocks, like the toolbar
\r
310 * and the elements path, into any element in the page.
\r
311 * The elements used to hold the UI blocks can be shared among several editor
\r
312 * instances. In that case, only the blocks of the active editor instance will
\r
314 * @name CKEDITOR.config.sharedSpaces
\r
316 * @default undefined
\r
318 * // Place the toolbar inside the element with ID "someElementId" and the
\r
319 * // elements path into the element with ID "anotherId".
\r
320 * config.sharedSpaces =
\r
322 * top : 'someElementId',
\r
323 * bottom : 'anotherId'
\r
326 * // Place the toolbar inside the element with ID "someElementId". The
\r
327 * // elements path will remain attached to the editor UI.
\r
328 * config.sharedSpaces =
\r
330 * top : 'someElementId'
\r