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 ' role="application"' +
\r
122 ' aria-labelledby="cke_', name, '_arialbl"' +
\r
123 ( style ? ' style="' + style + '"' : '' ) +
\r
125 '<span id="cke_', name, '_arialbl" class="cke_voice_label">' + editor.lang.editor + '</span>' +
\r
126 '<span class="' , CKEDITOR.env.cssClass, '" role="presentation">' +
\r
127 '<span class="cke_wrapper cke_', editor.lang.dir, '" role="presentation">' +
\r
128 '<table class="cke_editor" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody>' +
\r
129 '<tr', topHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_top_' , name, '" class="cke_top" role="presentation">' , topHtml , '</td></tr>' +
\r
130 '<tr', contentsHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_contents_', name, '" class="cke_contents" style="height:', height, '" role="presentation">', contentsHtml, '</td></tr>' +
\r
131 '<tr', bottomHtml ? '' : ' style="display:none"', ' role="presentation"><td id="cke_bottom_' , name, '" class="cke_bottom" role="presentation">' , bottomHtml , '</td></tr>' +
\r
132 '</tbody></table>' +
\r
133 //Hide the container when loading skins, later restored by skin css.
\r
134 '<style>.', editor.skinClass, '{visibility:hidden;}</style>' +
\r
137 '</span>' ].join( '' ) );
\r
139 container.getChild( [1, 0, 0, 0, 0] ).unselectable();
\r
140 container.getChild( [1, 0, 0, 0, 2] ).unselectable();
\r
142 if ( elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
143 container.insertAfter( element );
\r
145 element.append( container );
\r
148 * The DOM element that holds the main editor interface.
\r
149 * @name CKEDITOR.editor.prototype.container
\r
150 * @type CKEDITOR.dom.element
\r
152 * var editor = CKEDITOR.instances.editor1;
\r
153 * alert( <b>editor.container</b>.getName() ); "span"
\r
155 editor.container = container;
\r
157 // Disable browser context menu for editor's chrome.
\r
158 container.disableContextMenu();
\r
160 editor.fireOnce( 'themeLoaded' );
\r
161 editor.fireOnce( 'uiReady' );
\r
164 buildDialog : function( editor )
\r
166 var baseIdNumber = CKEDITOR.tools.getNextNumber();
\r
168 var element = CKEDITOR.dom.element.createFromHtml( [
\r
169 '<div class="cke_editor_' + editor.name.replace('.', '\\.') + '_dialog cke_skin_', editor.skinName,
\r
170 '" dir="', editor.lang.dir, '"' +
\r
171 ' lang="', editor.langCode, '"' +
\r
173 ' aria-labelledby="%title#"' +
\r
175 '<table class="cke_dialog', ' ' + CKEDITOR.env.cssClass,
\r
176 ' cke_', editor.lang.dir, '" style="position:absolute" role="presentation">' +
\r
177 '<tr><td role="presentation">' +
\r
178 '<div class="%body" role="presentation">' +
\r
179 '<div id="%title#" class="%title" role="presentation"></div>' +
\r
180 '<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
181 '<div id="%tabs#" class="%tabs" role="tablist"></div>' +
\r
182 '<table class="%contents" role="presentation"><tr>' +
\r
183 '<td id="%contents#" class="%contents" role="presentation"></td>' +
\r
185 '<div id="%footer#" class="%footer" role="presentation"></div>' +
\r
187 '<div id="%tl#" class="%tl"></div>' +
\r
188 '<div id="%tc#" class="%tc"></div>' +
\r
189 '<div id="%tr#" class="%tr"></div>' +
\r
190 '<div id="%ml#" class="%ml"></div>' +
\r
191 '<div id="%mr#" class="%mr"></div>' +
\r
192 '<div id="%bl#" class="%bl"></div>' +
\r
193 '<div id="%bc#" class="%bc"></div>' +
\r
194 '<div id="%br#" class="%br"></div>' +
\r
198 //Hide the container when loading skins, later restored by skin css.
\r
199 ( CKEDITOR.env.ie ? '' : '<style>.cke_dialog{visibility:hidden;}</style>' ),
\r
203 .replace( /#/g, '_' + baseIdNumber )
\r
204 .replace( /%/g, 'cke_dialog_' ) );
\r
206 var body = element.getChild( [ 0, 0, 0, 0, 0 ] ),
\r
207 title = body.getChild( 0 ),
\r
208 close = body.getChild( 1 );
\r
210 // Make the Title and Close Button unselectable.
\r
211 title.unselectable();
\r
212 close.unselectable();
\r
219 dialog : element.getChild( 0 ),
\r
222 tabs : body.getChild( 2 ),
\r
223 contents : body.getChild( [ 3, 0, 0, 0 ] ),
\r
224 footer : body.getChild( 4 )
\r
229 destroy : function( editor )
\r
231 var container = editor.container;
\r
232 container.clearCustomData();
\r
233 editor.element.clearCustomData();
\r
236 * IE BUG: Removing the editor DOM elements while the selection is inside
\r
237 * the editing area would break IE7/8's selection system. So we need to put
\r
238 * the selection back to the parent document without scrolling the window.
\r
241 if ( CKEDITOR.env.ie )
\r
243 container.setStyle( 'display', 'none' );
\r
245 var $range = document.body.createTextRange();
\r
246 $range.moveToElementText( container.$ );
\r
249 // Putting the selection to a display:none element - this will certainly
\r
250 // fail. But! We've just put the selection document back to the parent
\r
251 // document without scrolling the window!
\r
258 container.remove();
\r
260 if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
\r
261 editor.element.show();
\r
263 delete editor.element;
\r
268 CKEDITOR.editor.prototype.getThemeSpace = function( spaceName )
\r
270 var spacePrefix = 'cke_' + spaceName;
\r
271 var space = this._[ spacePrefix ] ||
\r
272 ( this._[ spacePrefix ] = CKEDITOR.document.getById( spacePrefix + '_' + this.name ) );
\r
276 CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, resizeInner )
\r
278 var numberRegex = /^\d+$/;
\r
279 if ( numberRegex.test( width ) )
\r
282 var container = this.container,
\r
283 contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),
\r
284 outer = resizeInner ? container.getChild( 1 ) : container;
\r
286 // Resize the width first.
\r
287 // WEBKIT BUG: Webkit requires that we put the editor off from display when we
\r
288 // resize it. If we don't, the browser crashes!
\r
289 CKEDITOR.env.webkit && outer.setStyle( 'display', 'none' );
\r
290 outer.setStyle( 'width', width );
\r
291 if ( CKEDITOR.env.webkit )
\r
293 outer.$.offsetWidth;
\r
294 outer.setStyle( 'display', '' );
\r
297 // Get the height delta between the outer table and the content area.
\r
298 // If we're setting the content area's height, then we don't need the delta.
\r
299 var delta = isContentHeight ? 0 : ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 );
\r
300 contents.setStyle( 'height', Math.max( height - delta, 0 ) + 'px' );
\r
302 // Emit a resize event.
\r
303 this.fire( 'resize' );
\r
306 CKEDITOR.editor.prototype.getResizable = function()
\r
308 return this.container.getChild( 1 );
\r
312 * Makes it possible to place some of the editor UI blocks, like the toolbar
\r
313 * and the elements path, into any element in the page.
\r
314 * The elements used to hold the UI blocks can be shared among several editor
\r
315 * instances. In that case, only the blocks of the active editor instance will
\r
317 * @name CKEDITOR.config.sharedSpaces
\r
319 * @default undefined
\r
321 * // Place the toolbar inside the element with ID "someElementId" and the
\r
322 * // elements path into the element with ID "anotherId".
\r
323 * config.sharedSpaces =
\r
325 * top : 'someElementId',
\r
326 * bottom : 'anotherId'
\r
329 * // Place the toolbar inside the element with ID "someElementId". The
\r
330 * // elements path will remain attached to the editor UI.
\r
331 * config.sharedSpaces =
\r
333 * top : 'someElementId'
\r