JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / themes / default / theme.js
index 97dd0ef..96ff928 100644 (file)
@@ -1,10 +1,70 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
 CKEDITOR.themes.add( 'default', (function()\r
 {\r
+       function checkSharedSpace( editor, spaceName )\r
+       {\r
+               var container,\r
+                       element;\r
+\r
+               // Try to retrieve the target element from the sharedSpaces settings.\r
+               element = editor.config.sharedSpaces;\r
+               element = element && element[ spaceName ];\r
+               element = element && CKEDITOR.document.getById( element );\r
+\r
+               // If the element is available, we'll then create the container for\r
+               // the space.\r
+               if ( element )\r
+               {\r
+                       // Creates an HTML structure that reproduces the editor class hierarchy.\r
+                       var html =\r
+                               '<span class="cke_shared">' +\r
+                               '<span class="' + editor.skinClass + ' cke_editor_' + editor.name + '">' +\r
+                               '<span class="' + CKEDITOR.env.cssClass + '">' +\r
+                               '<span class="cke_wrapper cke_' + editor.lang.dir + '">' +\r
+                               '<span class="cke_editor">' +\r
+                               '<div class="cke_' + spaceName + '">' +\r
+                               '</div></span></span></span></span></span>';\r
+\r
+                       var mainContainer = element.append( CKEDITOR.dom.element.createFromHtml( html, element.getDocument() ) );\r
+\r
+                       // Only the first container starts visible. Others get hidden.\r
+                       if ( element.getCustomData( 'cke_hasshared' ) )\r
+                               mainContainer.hide();\r
+                       else\r
+                               element.setCustomData( 'cke_hasshared', 1 );\r
+\r
+                       // Get the deeper inner <div>.\r
+                       container = mainContainer.getChild( [0,0,0,0] );\r
+\r
+                       // When the editor gets focus, we show the space container, hiding others.\r
+                       editor.on( 'focus', function()\r
+                               {\r
+                                       for ( var i = 0, sibling, children = element.getChildren() ; ( sibling = children.getItem( i ) ) ; i++ )\r
+                                       {\r
+                                               if ( sibling.type == CKEDITOR.NODE_ELEMENT\r
+                                                       && !sibling.equals( mainContainer )\r
+                                                       && sibling.hasClass( 'cke_shared' ) )\r
+                                               {\r
+                                                       sibling.hide();\r
+                                               }\r
+                                       }\r
+\r
+                                       mainContainer.show();\r
+                               });\r
+\r
+                       editor.on( 'destroy', function()\r
+                               {\r
+                                       mainContainer.remove();\r
+                               });\r
+               }\r
+\r
+               return container;\r
+       }\r
+\r
        return {\r
                build : function( editor, themePath )\r
                {\r
@@ -44,11 +104,17 @@ CKEDITOR.themes.add( 'default', (function()
                                style += "width: " + width + ";";\r
                        }\r
 \r
+                       var sharedTop           = topHtml && checkSharedSpace( editor, 'top' ),\r
+                               sharedBottoms   = checkSharedSpace( editor, 'bottom' );\r
+\r
+                       sharedTop               && ( sharedTop.setHtml( topHtml )               , topHtml = '' );\r
+                       sharedBottoms   && ( sharedBottoms.setHtml( bottomHtml ), bottomHtml = '' );\r
+\r
                        var container = CKEDITOR.dom.element.createFromHtml( [\r
                                '<span' +\r
                                        ' id="cke_', name, '"' +\r
                                        ' onmousedown="return false;"' +\r
-                                       ' class="', editor.skinClass, '"' +\r
+                                       ' class="', editor.skinClass, ' cke_editor_', name, '"' +\r
                                        ' dir="', editor.lang.dir, '"' +\r
                                        ' title="', ( CKEDITOR.env.gecko ? ' ' : '' ), '"' +\r
                                        ' lang="', editor.langCode, '"' +\r
@@ -98,7 +164,7 @@ CKEDITOR.themes.add( 'default', (function()
                        var baseIdNumber = CKEDITOR.tools.getNextNumber();\r
 \r
                        var element = CKEDITOR.dom.element.createFromHtml( [\r
-                                       '<div id="cke_' + editor.name.replace('.', '\\.') + '_dialog" class="cke_skin_', editor.skinName,\r
+                                       '<div class="cke_editor_' + editor.name.replace('.', '\\.') + '_dialog cke_skin_', editor.skinName,\r
                                                '" dir="', editor.lang.dir, '"' +\r
                                                ' lang="', editor.langCode, '"' +\r
                                                '>' +\r
@@ -210,9 +276,9 @@ CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, res
        if ( numberRegex.test( width ) )\r
                width += 'px';\r
 \r
-       var contents = CKEDITOR.document.getById( 'cke_contents_' + this.name );\r
-       var outer = resizeInner ? contents.getAscendant( 'table' ).getParent()\r
-               : contents.getAscendant( 'table' ).getParent().getParent().getParent();\r
+       var container = this.container,\r
+               contents = CKEDITOR.document.getById( 'cke_contents_' + this.name ),\r
+               outer = resizeInner ? container.getChild( 0 ) : container;\r
 \r
        // Resize the width first.\r
        // WEBKIT BUG: Webkit requires that we put the editor off from display when we\r
@@ -236,5 +302,31 @@ CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, res
 \r
 CKEDITOR.editor.prototype.getResizable = function()\r
 {\r
-       return this.container.getChild( [ 0, 0 ] );\r
+       return this.container.getChild( 0 );\r
 };\r
+\r
+/**\r
+ * Makes it possible to place some of the editor UI blocks, like the toolbar\r
+ * and the elements path, into any element in the page.\r
+ * The elements used to hold the UI blocks can be shared among several editor\r
+ * instances. In that case, only the blocks of the active editor instance will\r
+ * display.\r
+ * @name CKEDITOR.config.sharedSpaces\r
+ * @type Object\r
+ * @default undefined\r
+ * @example\r
+ * // Place the toolbar inside the element with ID "someElementId" and the\r
+ * // elements path into the element with ID "anotherId".\r
+ * config.sharedSpaces =\r
+ * {\r
+ *     top : 'someElementId',\r
+ *     bottom : 'anotherId'\r
+ * };\r
+ * @example\r
+ * // Place the toolbar inside the element with ID "someElementId". The\r
+ * // elements path will remain attached to the editor UI.\r
+ * config.sharedSpaces =\r
+ * {\r
+ *     top : 'someElementId'\r
+ * };\r
+ */\r