JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / themes / default / theme.js
index 00219ff..f7ff8e4 100644 (file)
@@ -1,10 +1,17 @@
 /*\r
-Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
+/**\r
+ * @name CKEDITOR.theme\r
+ * @class\r
+ */\r
+\r
 CKEDITOR.themes.add( 'default', (function()\r
 {\r
+       var hiddenSkins = {};\r
+\r
        function checkSharedSpace( editor, spaceName )\r
        {\r
                var container,\r
@@ -21,8 +28,10 @@ CKEDITOR.themes.add( 'default', (function()
                {\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="cke_shared "' +\r
+                               ' dir="'+ editor.lang.dir + '"' +\r
+                               '>' +\r
+                               '<span class="' + editor.skinClass + ' ' + editor.id + ' 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
@@ -40,6 +49,10 @@ CKEDITOR.themes.add( 'default', (function()
                        // Get the deeper inner <div>.\r
                        container = mainContainer.getChild( [0,0,0,0] );\r
 \r
+                       // Save a reference to the shared space container.\r
+                       !editor.sharedSpaces && ( editor.sharedSpaces = {} );\r
+                       editor.sharedSpaces[ spaceName ] = container;\r
+\r
                        // When the editor gets focus, we show the space container, hiding others.\r
                        editor.on( 'focus', function()\r
                                {\r
@@ -65,7 +78,7 @@ CKEDITOR.themes.add( 'default', (function()
                return container;\r
        }\r
 \r
-       return {\r
+       return /** @lends CKEDITOR.theme */ {\r
                build : function( editor, themePath )\r
                {\r
                        var name = editor.name,\r
@@ -110,15 +123,20 @@ CKEDITOR.themes.add( 'default', (function()
                        sharedTop               && ( sharedTop.setHtml( topHtml )               , topHtml = '' );\r
                        sharedBottoms   && ( sharedBottoms.setHtml( bottomHtml ), bottomHtml = '' );\r
 \r
+                       var hideSkin = '<style>.' + editor.skinClass + '{visibility:hidden;}</style>';\r
+                       if ( hiddenSkins[ editor.skinClass ] )\r
+                               hideSkin = '';\r
+                       else\r
+                               hiddenSkins[ editor.skinClass ] = 1;\r
+\r
                        var container = CKEDITOR.dom.element.createFromHtml( [\r
                                '<span' +\r
                                        ' id="cke_', name, '"' +\r
-                                       ' onmousedown="return false;"' +\r
-                                       ' class="', editor.skinClass, ' cke_editor_', name, '"' +\r
+                                       ' class="', editor.skinClass, ' ', editor.id, ' cke_editor_', name, '"' +\r
                                        ' dir="', editor.lang.dir, '"' +\r
                                        ' title="', ( CKEDITOR.env.gecko ? ' ' : '' ), '"' +\r
                                        ' lang="', editor.langCode, '"' +\r
-                                       ( CKEDITOR.env.webkit? ' tabindex="' + tabIndex + '"' : '' ) +\r
+                                               ( CKEDITOR.env.webkit? ' tabindex="' + tabIndex + '"' : '' ) +\r
                                        ' role="application"' +\r
                                        ' aria-labelledby="cke_', name, '_arialbl"' +\r
                                        ( style ? ' style="' + style + '"' : '' ) +\r
@@ -132,7 +150,7 @@ CKEDITOR.themes.add( 'default', (function()
                                                                '<tr', bottomHtml       ? '' : ' style="display:none"', ' role="presentation"><td id="cke_bottom_'      , name, '" class="cke_bottom" role="presentation">'     , bottomHtml    , '</td></tr>' +\r
                                                        '</tbody></table>' +\r
                                                        //Hide the container when loading skins, later restored by skin css.\r
-                                                       '<style>.', editor.skinClass, '{visibility:hidden;}</style>' +\r
+                                                       hideSkin +\r
                                                '</span>' +\r
                                        '</span>' +\r
                                '</span>' ].join( '' ) );\r
@@ -158,6 +176,18 @@ CKEDITOR.themes.add( 'default', (function()
                        // Disable browser context menu for editor's chrome.\r
                        container.disableContextMenu();\r
 \r
+                       // Use a class to indicate that the current selection is in different direction than the UI.\r
+                       editor.on( 'contentDirChanged', function( evt )\r
+                       {\r
+                               var func = ( editor.lang.dir != evt.data ? 'add' : 'remove' ) + 'Class';\r
+\r
+                               container.getChild( 1 )[ func ]( 'cke_mixed_dir_content' );\r
+\r
+                               // Put the mixed direction class on the respective element also for shared spaces.\r
+                               var toolbarSpace = this.sharedSpaces && this.sharedSpaces[ this.config.toolbarLocation ];\r
+                               toolbarSpace && toolbarSpace.getParent().getParent()[ func ]( 'cke_mixed_dir_content' );\r
+                       });\r
+\r
                        editor.fireOnce( 'themeLoaded' );\r
                        editor.fireOnce( 'uiReady' );\r
                },\r
@@ -167,7 +197,7 @@ CKEDITOR.themes.add( 'default', (function()
                        var baseIdNumber = CKEDITOR.tools.getNextNumber();\r
 \r
                        var element = CKEDITOR.dom.element.createFromHtml( [\r
-                                       '<div class="cke_editor_' + editor.name.replace('.', '\\.') + '_dialog cke_skin_', editor.skinName,\r
+                                       '<div class="', editor.id, '_dialog cke_editor_', editor.name.replace('.', '\\.'), '_dialog cke_skin_', editor.skinName,\r
                                                '" dir="', editor.lang.dir, '"' +\r
                                                ' lang="', editor.langCode, '"' +\r
                                                ' role="dialog"' +\r
@@ -180,10 +210,14 @@ CKEDITOR.themes.add( 'default', (function()
                                                                '<div id="%title#" class="%title" role="presentation"></div>' +\r
                                                                '<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
                                                                '<div id="%tabs#" class="%tabs" role="tablist"></div>' +\r
-                                                               '<table class="%contents" role="presentation"><tr>' +\r
+                                                               '<table class="%contents" role="presentation">' +\r
+                                                               '<tr>' +\r
                                                                  '<td id="%contents#" class="%contents" role="presentation"></td>' +\r
-                                                               '</tr></table>' +\r
-                                                               '<div id="%footer#" class="%footer" role="presentation"></div>' +\r
+                                                               '</tr>' +\r
+                                                               '<tr>' +\r
+                                                                 '<td id="%footer#" class="%footer" role="presentation"></td>' +\r
+                                                               '</tr>' +\r
+                                                               '</table>' +\r
                                                        '</div>' +\r
                                                        '<div id="%tl#" class="%tl"></div>' +\r
                                                        '<div id="%tc#" class="%tc"></div>' +\r
@@ -222,24 +256,28 @@ CKEDITOR.themes.add( 'default', (function()
                                        close           : close,\r
                                        tabs            : body.getChild( 2 ),\r
                                        contents        : body.getChild( [ 3, 0, 0, 0 ] ),\r
-                                       footer          : body.getChild( 4 )\r
+                                       footer          : body.getChild( [ 3, 0, 1, 0 ] )\r
                                }\r
                        };\r
                },\r
 \r
                destroy : function( editor )\r
                {\r
-                       var container = editor.container;\r
-                       container.clearCustomData();\r
-                       editor.element.clearCustomData();\r
+                       var container = editor.container,\r
+                               element = editor.element;\r
 \r
                        if ( container )\r
+                       {\r
+                               container.clearCustomData();\r
                                container.remove();\r
+                       }\r
 \r
-                       if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )\r
-                               editor.element.show();\r
-\r
-                       delete editor.element;\r
+                       if ( element )\r
+                       {\r
+                               element.clearCustomData();\r
+                               editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE && element.show();\r
+                               delete editor.element;\r
+                       }\r
                }\r
        };\r
 })() );\r
@@ -314,12 +352,13 @@ CKEDITOR.editor.prototype.resize = function( width, height, isContentHeight, res
  * Gets the element that can be freely used to check the editor size. This method\r
  * is mainly used by the resize plugin, which adds a UI handle that can be used\r
  * to resize the editor.\r
+ * @param {Boolean} forContents Whether to return the "contents" part of the theme instead of the container.\r
  * @returns {CKEDITOR.dom.element} The resizable element.\r
  * @example\r
  */\r
-CKEDITOR.editor.prototype.getResizable = function()\r
+CKEDITOR.editor.prototype.getResizable = function( forContents )\r
 {\r
-       return this.container.getChild( 1 );\r
+       return forContents ? CKEDITOR.document.getById( 'cke_contents_' + this.name ) : this.container;\r
 };\r
 \r
 /**\r
@@ -351,6 +390,6 @@ CKEDITOR.editor.prototype.getResizable = function()
 /**\r
  * Fired after the editor instance is resized through\r
  * the {@link CKEDITOR.editor.prototype.resize} method.\r
- * @name CKEDITOR#resize\r
+ * @name CKEDITOR.editor#resize\r
  * @event\r
  */\r