JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / floatpanel / plugin.js
index 178459e..5569e5e 100644 (file)
@@ -1,5 +1,5 @@
 /*\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
@@ -16,14 +16,8 @@ CKEDITOR.plugins.add( 'floatpanel',
        function getPanel( editor, doc, parentElement, definition, level )\r
        {\r
                // Generates the panel key: docId-eleId-skinName-langDir[-uiColor][-CSSs][-level]\r
-               var key =\r
-                       doc.getUniqueId() +\r
-                       '-' + parentElement.getUniqueId() +\r
-                       '-' + editor.skinName +\r
-                       '-' + editor.lang.dir +\r
-                       ( ( editor.uiColor && ( '-' + editor.uiColor ) ) || '' ) +\r
-                       ( ( definition.css && ( '-' + definition.css ) ) || '' ) +\r
-                       ( ( level && ( '-' + level ) ) || '' );\r
+               var key = CKEDITOR.tools.genKey( doc.getUniqueId(), parentElement.getUniqueId(), editor.skinName, editor.lang.dir,\r
+                       editor.uiColor || '', definition.css || '', level || '' );\r
 \r
                var panel = panels[ key ];\r
 \r
@@ -46,7 +40,7 @@ CKEDITOR.plugins.add( 'floatpanel',
        {\r
                $ : function( editor, parentElement, definition, level )\r
                {\r
-                       definition.forceIFrame = true;\r
+                       definition.forceIFrame = 1;\r
 \r
                        var doc = parentElement.getDocument(),\r
                                panel = getPanel( editor, doc, parentElement, definition, level || 0 ),\r
@@ -57,6 +51,7 @@ CKEDITOR.plugins.add( 'floatpanel',
 \r
                        this._ =\r
                        {\r
+                               editor : editor,\r
                                // The panel that will be floating.\r
                                panel : panel,\r
                                parentElement : parentElement,\r
@@ -66,6 +61,8 @@ CKEDITOR.plugins.add( 'floatpanel',
                                children : [],\r
                                dir : editor.lang.dir\r
                        };\r
+\r
+                       editor.on( 'mode', function(){ this.hide(); }, this );\r
                },\r
 \r
                proto :\r
@@ -104,7 +101,11 @@ CKEDITOR.plugins.add( 'floatpanel',
                                        block = panel.showBlock( name );\r
 \r
                                this.allowBlur( false );\r
-                               isShowing = true;\r
+                               isShowing = 1;\r
+\r
+                               // Record from where the focus is when open panel.\r
+                               this._.returnFocus = this._.editor.focusManager.hasFocus ? this._.editor : new CKEDITOR.dom.element( CKEDITOR.document.$.activeElement );\r
+\r
 \r
                                var element = this.element,\r
                                        iframe = this._.iframe,\r
@@ -129,9 +130,11 @@ CKEDITOR.plugins.add( 'floatpanel',
 \r
                                element.setStyles(\r
                                        {\r
-                                               top : '-30000px',\r
+                                               top : top + 'px',\r
+                                               left: 0,\r
                                                display : ''\r
                                        });\r
+\r
                                // Don't use display or visibility style because we need to\r
                                // calculate the rendering layout later and focus the element.\r
                                element.setOpacity( 0 );\r
@@ -159,14 +162,17 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                        // the blur event may get fired even when focusing\r
                                                        // inside the window itself, so we must ensure the\r
                                                        // target is out of it.\r
-                                                       var target;\r
-                                                       if ( CKEDITOR.env.ie && !this.allowBlur()\r
-                                                                || ( target = ev.data.getTarget() )\r
-                                                                     && target.getName && target.getName() != 'iframe' )\r
+                                                       var target = ev.data.getTarget() ;\r
+                                                       if ( target.getName && target.getName() != 'iframe' )\r
                                                                return;\r
 \r
                                                        if ( this.visible && !this._.activeChild && !isShowing )\r
+                                                       {\r
+                                                               // Panel close is caused by user's navigating away the focus, e.g. click outside the panel.\r
+                                                               // DO NOT restore focus in this case.\r
+                                                               delete this._.returnFocus;\r
                                                                this.hide();\r
+                                                       }\r
                                                },\r
                                                this );\r
 \r
@@ -215,7 +221,7 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                                // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug\r
                                                                // (#3426)\r
                                                                if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && width > 0 )\r
-                                                                       width += ( target.$.offsetWidth || 0 ) - ( target.$.clientWidth || 0 );\r
+                                                                       width += ( target.$.offsetWidth || 0 ) - ( target.$.clientWidth || 0 ) + 3;\r
                                                                // A little extra at the end.\r
                                                                // If not present, IE6 might break into the next line, but also it looks better this way\r
                                                                width += 4 ;\r
@@ -231,7 +237,7 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                                // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug\r
                                                                // (#3426)\r
                                                                if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0 )\r
-                                                                       height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 );\r
+                                                                       height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 ) + 3;\r
 \r
                                                                target.setStyle( 'height', height + 'px' );\r
 \r
@@ -282,6 +288,14 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                                }\r
                                                        }\r
 \r
+                                                       // Trigger the onHide event of the previously active panel to prevent\r
+                                                       // incorrect styles from being applied (#6170)\r
+                                                       var innerElement = element.getFirst(),\r
+                                                               activePanel;\r
+                                                       if ( ( activePanel = innerElement.getCustomData( 'activePanel' ) ) )\r
+                                                               activePanel.onHide && activePanel.onHide.call( this, 1 );\r
+                                                       innerElement.setCustomData( 'activePanel', this );\r
+\r
                                                        element.setStyles(\r
                                                                {\r
                                                                        top : top + 'px',\r
@@ -299,22 +313,36 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                        // We need this get fired manually because of unfired focus() function.\r
                                                        this.allowBlur( true );\r
                                                }, 0, this);\r
-                                       }, 0, this);\r
+                                       },  CKEDITOR.env.air ? 200 : 0, this);\r
                                this.visible = 1;\r
 \r
                                if ( this.onShow )\r
                                        this.onShow.call( this );\r
 \r
-                               isShowing = false;\r
+                               isShowing = 0;\r
                        },\r
 \r
-                       hide : function()\r
+                       hide : function( returnFocus )\r
                        {\r
                                if ( this.visible && ( !this.onHide || this.onHide.call( this ) !== true ) )\r
                                {\r
                                        this.hideChild();\r
+                                       // Blur previously focused element. (#6671)\r
+                                       CKEDITOR.env.gecko && this._.iframe.getFrameDocument().$.activeElement.blur();\r
                                        this.element.setStyle( 'display', 'none' );\r
                                        this.visible = 0;\r
+                                       this.element.getFirst().removeCustomData( 'activePanel' );\r
+\r
+                                       // Return focus properly. (#6247)\r
+                                       var focusReturn = returnFocus !== false && this._.returnFocus;\r
+                                       if ( focusReturn )\r
+                                       {\r
+                                               // Webkit requires focus moved out panel iframe first.\r
+                                               if ( CKEDITOR.env.webkit && focusReturn.type )\r
+                                                       focusReturn.getWindow().$.focus();\r
+\r
+                                               focusReturn.focus();\r
+                                       }\r
                                }\r
                        },\r
 \r
@@ -370,6 +398,8 @@ CKEDITOR.plugins.add( 'floatpanel',
                                if ( activeChild )\r
                                {\r
                                        delete activeChild.onHide;\r
+                                       // Sub panels don't manage focus. (#7881)\r
+                                       delete activeChild._.returnFocus;\r
                                        delete this._.activeChild;\r
                                        activeChild.hide();\r
                                }\r