JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5
[ckeditor.git] / _source / plugins / floatpanel / plugin.js
index 849d5fc..505ecbd 100644 (file)
@@ -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
@@ -66,6 +60,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 +100,7 @@ CKEDITOR.plugins.add( 'floatpanel',
                                        block = panel.showBlock( name );\r
 \r
                                this.allowBlur( false );\r
-                               isShowing = true;\r
+                               isShowing = 1;\r
 \r
                                var element = this.element,\r
                                        iframe = this._.iframe,\r
@@ -130,13 +126,16 @@ CKEDITOR.plugins.add( 'floatpanel',
                                element.setStyles(\r
                                        {\r
                                                top : top + 'px',\r
-                                               left : '-3000px',\r
-                                               opacity : '0',  // FF3 is ignoring "visibility"\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
+\r
                                // To allow the context menu to decrease back their width\r
-                               element.getFirst().removeStyle('width');\r
+                               element.getFirst().removeStyle( 'width' );\r
 \r
                                // Configure the IFrame blur event. Do that only once.\r
                                if ( !this._.blurSet )\r
@@ -158,10 +157,10 @@ 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 = ev.data.getTarget(),\r
-                                                               targetWindow = target.getWindow && target.getWindow();\r
-\r
-                                                       if ( targetWindow && targetWindow.equals( focused ) )\r
+                                                       var target;\r
+                                                       if ( CKEDITOR.env.ie && !this.allowBlur()\r
+                                                                || ( target = ev.data.getTarget() )\r
+                                                                     && target.getName && target.getName() != 'iframe' )\r
                                                                return;\r
 \r
                                                        if ( this.visible && !this._.activeChild && !isShowing )\r
@@ -182,9 +181,10 @@ CKEDITOR.plugins.add( 'floatpanel',
                                        this._.blurSet = 1;\r
                                }\r
 \r
-                               panel.onEscape = CKEDITOR.tools.bind( function()\r
+                               panel.onEscape = CKEDITOR.tools.bind( function( keystroke )\r
                                        {\r
-                                               this.onEscape && this.onEscape();\r
+                                               if ( this.onEscape && this.onEscape( keystroke ) === false )\r
+                                                       return false;\r
                                        },\r
                                        this );\r
 \r
@@ -202,10 +202,10 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                                // We must adjust first the width or IE6 could include extra lines in the height computation\r
                                                                var widthNode = block.element.$;\r
 \r
-                                                               if ( CKEDITOR.env.gecko || CKEDITOR.env.opera)\r
+                                                               if ( CKEDITOR.env.gecko || CKEDITOR.env.opera )\r
                                                                        widthNode = widthNode.parentNode;\r
 \r
-                                                               if ( CKEDITOR.env.ie)\r
+                                                               if ( CKEDITOR.env.ie )\r
                                                                        widthNode = widthNode.document.body;\r
 \r
                                                                var width = widthNode.scrollWidth;\r
@@ -258,44 +258,60 @@ CKEDITOR.plugins.add( 'floatpanel',
                                                        if ( top + panelSize.height > viewportSize.height + windowScroll.y )\r
                                                                top -= panelSize.height;\r
 \r
+                                                       // If IE is in RTL, we have troubles with absolute\r
+                                                       // position and horizontal scrolls. Here we have a\r
+                                                       // series of hacks to workaround it. (#6146)\r
+                                                       if ( CKEDITOR.env.ie )\r
+                                                       {\r
+                                                               var offsetParent = new CKEDITOR.dom.element( element.$.offsetParent ),\r
+                                                                       scrollParent = offsetParent;\r
+\r
+                                                               // Quirks returns <body>, but standards returns <html>.\r
+                                                               if ( scrollParent.getName() == 'html' )\r
+                                                                       scrollParent = scrollParent.getDocument().getBody();\r
+\r
+                                                               if ( scrollParent.getComputedStyle( 'direction' ) == 'rtl' )\r
+                                                               {\r
+                                                                       // For IE8, there is not much logic on this, but it works.\r
+                                                                       if ( CKEDITOR.env.ie8Compat )\r
+                                                                               left -= element.getDocument().getDocumentElement().$.scrollLeft * 2;\r
+                                                                       else\r
+                                                                               left -= ( offsetParent.$.scrollWidth - offsetParent.$.clientWidth );\r
+                                                               }\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
-                                                                       left : left + 'px',\r
-                                                                       opacity : '1'\r
+                                                                       left : left + 'px'\r
                                                                } );\r
-\r
+                                                       element.setOpacity( 1 );\r
                                                } , this );\r
 \r
                                                panel.isLoaded ? panelLoad() : panel.onLoad = panelLoad;\r
 \r
                                                // Set the panel frame focus, so the blur event gets fired.\r
                                                CKEDITOR.tools.setTimeout( function()\r
-                                                       {\r
-                                                               if ( definition.voiceLabel )\r
-                                                               {\r
-                                                                       if ( CKEDITOR.env.gecko )\r
-                                                                       {\r
-                                                                               var container = iframe.getParent();\r
-                                                                               container.setAttribute( 'role', 'region' );\r
-                                                                               container.setAttribute( 'title', definition.voiceLabel );\r
-                                                                               iframe.setAttribute( 'role', 'region' );\r
-                                                                               iframe.setAttribute( 'title', ' ' );\r
-                                                                       }\r
-                                                               }\r
-\r
-                                                               iframe.$.contentWindow.focus();\r
-                                                               // We need this get fired manually because of unfired focus() function.\r
-                                                               this.allowBlur( true );\r
-\r
-                                                       }, 0, this);\r
-                                       }, 0, this);\r
+                                               {\r
+                                                       iframe.$.contentWindow.focus();\r
+                                                       // We need this get fired manually because of unfired focus() function.\r
+                                                       this.allowBlur( true );\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
@@ -305,6 +321,7 @@ CKEDITOR.plugins.add( 'floatpanel',
                                        this.hideChild();\r
                                        this.element.setStyle( 'display', 'none' );\r
                                        this.visible = 0;\r
+                                       this.element.getFirst().removeCustomData( 'activePanel' );\r
                                }\r
                        },\r
 \r