JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0.2
[ckeditor.git] / _source / plugins / floatpanel / plugin.js
index 0a93528..0e158cd 100644 (file)
@@ -55,10 +55,6 @@ CKEDITOR.plugins.add( 'floatpanel',
 \r
                        this.element = element;\r
 \r
-                       // Register panels to editor for easy destroying ( #4241 ).\r
-                       editor.panels ? editor.panels.push( element ) : editor.panels = [ element ];\r
-\r
-\r
                        this._ =\r
                        {\r
                                // The panel that will be floating.\r
@@ -135,7 +131,6 @@ CKEDITOR.plugins.add( 'floatpanel',
                                        {\r
                                                top : top + 'px',\r
                                                left : '-3000px',\r
-                                               visibility : 'hidden',\r
                                                opacity : '0',  // FF3 is ignoring "visibility"\r
                                                display : ''\r
                                        });\r
@@ -153,7 +148,7 @@ CKEDITOR.plugins.add( 'floatpanel',
 \r
                                        focused.on( 'blur', function( ev )\r
                                                {\r
-                                                       if ( CKEDITOR.env.ie && !this.allowBlur() )\r
+                                                       if ( !this.allowBlur() )\r
                                                                return;\r
 \r
                                                        // As we are using capture to register the listener,\r
@@ -195,16 +190,9 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                if ( rtl )\r
                                                        left -= element.$.offsetWidth;\r
 \r
-                                               element.setStyles(\r
-                                                       {\r
-                                                               left : left + 'px',\r
-                                                               visibility      : '',\r
-                                                               opacity : '1'   // FF3 is ignoring "visibility"\r
-                                                       });\r
-\r
-                                               if ( block.autoSize )\r
+                                               var panelLoad = CKEDITOR.tools.bind( function ()\r
                                                {\r
-                                                       function setHeight()\r
+                                                       if ( block.autoSize )\r
                                                        {\r
                                                                var target = element.getFirst();\r
                                                                var height = block.element.$.scrollHeight;\r
@@ -220,16 +208,40 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                                // Fix IE < 8 visibility.\r
                                                                panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' );\r
                                                        }\r
-\r
-                                                       if ( panel.isLoaded )\r
-                                                               setHeight();\r
                                                        else\r
-                                                               panel.onLoad = setHeight;\r
-                                               }\r
-                                               else\r
-                                                       element.getFirst().removeStyle( 'height' );\r
+                                                               element.getFirst().removeStyle( 'height' );\r
+\r
+                                                       var panelElement = panel.element,\r
+                                                               panelWindow = panelElement.getWindow(),\r
+                                                               windowScroll = panelWindow.getScrollPosition(),\r
+                                                               viewportSize = panelWindow.getViewPaneSize(),\r
+                                                               panelSize =\r
+                                                               {\r
+                                                                       'height' : panelElement.$.offsetHeight,\r
+                                                                       'width' : panelElement.$.offsetWidth\r
+                                                               };\r
+\r
+                                                       // If the menu is horizontal off, shift it toward\r
+                                                       // the opposite language direction.\r
+                                                       if ( rtl ? left < 0 : left + panelSize.width > viewportSize.width + windowScroll.x )\r
+                                                               left += ( panelSize.width * ( rtl ? 1 : -1 ) );\r
+\r
+                                                       // Vertical off screen is simpler.\r
+                                                       if( top + panelSize.height > viewportSize.height + windowScroll.y )\r
+                                                               top -= panelSize.height;\r
+\r
+                                                       element.setStyles(\r
+                                                               {\r
+                                                                       top : top + 'px',\r
+                                                                       left : left + 'px',\r
+                                                                       opacity : '1'\r
+                                                               } );\r
+\r
+                                               } , this );\r
+\r
+                                               panel.isLoaded ? panelLoad() : panel.onLoad = panelLoad;\r
 \r
-                                               // Set the IFrame focus, so the blur event gets fired.\r
+                                               // Set the panel frame focus, so the blur event gets fired.\r
                                                CKEDITOR.tools.setTimeout( function()\r
                                                        {\r
                                                                if ( definition.voiceLabel )\r
@@ -243,14 +255,11 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                                                iframe.setAttribute( 'title', ' ' );\r
                                                                        }\r
                                                                }\r
-                                                               if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )\r
-                                                                       iframe.focus();\r
-                                                               else\r
-                                                                       iframe.$.contentWindow.focus();\r
 \r
+                                                               iframe.$.contentWindow.focus();\r
                                                                // We need this get fired manually because of unfired focus() function.\r
-                                                               if ( CKEDITOR.env.ie && !CKEDITOR.env.quirks )\r
-                                                                       this.allowBlur( true );\r
+                                                               this.allowBlur( true );\r
+\r
                                                        }, 0, this);\r
                                        }, 0, this);\r
                                this.visible = 1;\r
@@ -329,4 +338,23 @@ CKEDITOR.plugins.add( 'floatpanel',
                        }\r
                }\r
        });\r
+\r
+       CKEDITOR.on( 'instanceDestroyed', function()\r
+       {\r
+               var isLastInstance = CKEDITOR.tools.isEmpty( CKEDITOR.instances );\r
+\r
+               for( var i in panels )\r
+               {\r
+                       var panel = panels[ i ];\r
+                       // Safe to destroy it since there're no more instances.(#4241)\r
+                       if( isLastInstance )\r
+                               panel.destroy();\r
+                       // Panel might be used by other instances, just hide them.(#4552)\r
+                       else\r
+                               panel.element.hide();\r
+               }\r
+               // Remove the registration.\r
+               isLastInstance && ( panels = {} );\r
+\r
+       } );\r
 })();\r