JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.6.1
[ckeditor.git] / _source / plugins / floatpanel / plugin.js
index ab8c19f..5569e5e 100644 (file)
@@ -51,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
@@ -102,6 +103,10 @@ CKEDITOR.plugins.add( 'floatpanel',
                                this.allowBlur( false );\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
                                        definition = this._.definition,\r
@@ -157,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
@@ -213,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
@@ -229,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
@@ -314,14 +322,27 @@ CKEDITOR.plugins.add( 'floatpanel',
                                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
@@ -377,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