+++ /dev/null
-/*\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
-CKEDITOR.plugins.add( 'floatpanel',\r
-{\r
- requires : [ 'panel' ]\r
-});\r
-\r
-(function()\r
-{\r
- var panels = {};\r
- var isShowing = false;\r
-\r
- function getPanel( editor, doc, parentElement, definition, level )\r
- {\r
- // Generates the panel key: docId-eleId-skinName-langDir[-uiColor][-CSSs][-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
- if ( !panel )\r
- {\r
- panel = panels[ key ] = new CKEDITOR.ui.panel( doc, definition );\r
- panel.element = parentElement.append( CKEDITOR.dom.element.createFromHtml( panel.renderHtml( editor ), doc ) );\r
-\r
- panel.element.setStyles(\r
- {\r
- display : 'none',\r
- position : 'absolute'\r
- });\r
- }\r
-\r
- return panel;\r
- }\r
-\r
- CKEDITOR.ui.floatPanel = CKEDITOR.tools.createClass(\r
- {\r
- $ : function( editor, parentElement, definition, level )\r
- {\r
- definition.forceIFrame = 1;\r
-\r
- var doc = parentElement.getDocument(),\r
- panel = getPanel( editor, doc, parentElement, definition, level || 0 ),\r
- element = panel.element,\r
- iframe = element.getFirst().getFirst();\r
-\r
- this.element = element;\r
-\r
- this._ =\r
- {\r
- editor : editor,\r
- // The panel that will be floating.\r
- panel : panel,\r
- parentElement : parentElement,\r
- definition : definition,\r
- document : doc,\r
- iframe : iframe,\r
- children : [],\r
- dir : editor.lang.dir\r
- };\r
-\r
- editor.on( 'mode', function(){ this.hide(); }, this );\r
- },\r
-\r
- proto :\r
- {\r
- addBlock : function( name, block )\r
- {\r
- return this._.panel.addBlock( name, block );\r
- },\r
-\r
- addListBlock : function( name, multiSelect )\r
- {\r
- return this._.panel.addListBlock( name, multiSelect );\r
- },\r
-\r
- getBlock : function( name )\r
- {\r
- return this._.panel.getBlock( name );\r
- },\r
-\r
- /*\r
- corner (LTR):\r
- 1 = top-left\r
- 2 = top-right\r
- 3 = bottom-right\r
- 4 = bottom-left\r
-\r
- corner (RTL):\r
- 1 = top-right\r
- 2 = top-left\r
- 3 = bottom-left\r
- 4 = bottom-right\r
- */\r
- showBlock : function( name, offsetParent, corner, offsetX, offsetY )\r
- {\r
- var panel = this._.panel,\r
- block = panel.showBlock( name );\r
-\r
- 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
- position = offsetParent.getDocumentPosition( element.getDocument() ),\r
- rtl = this._.dir == 'rtl';\r
-\r
- var left = position.x + ( offsetX || 0 ),\r
- top = position.y + ( offsetY || 0 );\r
-\r
- // Floating panels are off by (-1px, 0px) in RTL mode. (#3438)\r
- if ( rtl && ( corner == 1 || corner == 4 ) )\r
- left += offsetParent.$.offsetWidth;\r
- else if ( !rtl && ( corner == 2 || corner == 3 ) )\r
- left += offsetParent.$.offsetWidth - 1;\r
-\r
- if ( corner == 3 || corner == 4 )\r
- top += offsetParent.$.offsetHeight - 1;\r
-\r
- // Memorize offsetParent by it's ID.\r
- this._.panel._.offsetParentId = offsetParent.getId();\r
-\r
- element.setStyles(\r
- {\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
-\r
- // To allow the context menu to decrease back their width\r
- element.getFirst().removeStyle( 'width' );\r
-\r
- // Configure the IFrame blur event. Do that only once.\r
- if ( !this._.blurSet )\r
- {\r
- // Non IE prefer the event into a window object.\r
- var focused = CKEDITOR.env.ie ? iframe : new CKEDITOR.dom.window( iframe.$.contentWindow );\r
-\r
- // With addEventListener compatible browsers, we must\r
- // useCapture when registering the focus/blur events to\r
- // guarantee they will be firing in all situations. (#3068, #3222 )\r
- CKEDITOR.event.useCapture = true;\r
-\r
- focused.on( 'blur', function( ev )\r
- {\r
- if ( !this.allowBlur() )\r
- return;\r
-\r
- // As we are using capture to register the listener,\r
- // 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
- 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
- focused.on( 'focus', function()\r
- {\r
- this._.focused = true;\r
- this.hideChild();\r
- this.allowBlur( true );\r
- },\r
- this );\r
-\r
- CKEDITOR.event.useCapture = false;\r
-\r
- this._.blurSet = 1;\r
- }\r
-\r
- panel.onEscape = CKEDITOR.tools.bind( function( keystroke )\r
- {\r
- if ( this.onEscape && this.onEscape( keystroke ) === false )\r
- return false;\r
- },\r
- this );\r
-\r
- CKEDITOR.tools.setTimeout( function()\r
- {\r
- if ( rtl )\r
- left -= element.$.offsetWidth;\r
-\r
- var panelLoad = CKEDITOR.tools.bind( function ()\r
- {\r
- var target = element.getFirst();\r
-\r
- if ( block.autoSize )\r
- {\r
- // 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
- widthNode = widthNode.parentNode;\r
-\r
- if ( CKEDITOR.env.ie )\r
- widthNode = widthNode.document.body;\r
-\r
- var width = widthNode.scrollWidth;\r
- // Account for extra height needed due to IE quirks box model bug:\r
- // 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 ) + 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
-\r
- target.setStyle( 'width', width + 'px' );\r
-\r
- // IE doesn't compute the scrollWidth if a filter is applied previously\r
- block.element.addClass( 'cke_frameLoaded' );\r
-\r
- var height = block.element.$.scrollHeight;\r
-\r
- // Account for extra height needed due to IE quirks box model bug:\r
- // 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 ) + 3;\r
-\r
- target.setStyle( 'height', height + 'px' );\r
-\r
- // Fix IE < 8 visibility.\r
- panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' );\r
- }\r
- else\r
- target.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
- // 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
- } );\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
- 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 = 0;\r
- },\r
-\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
- allowBlur : function( allow ) // Prevent editor from hiding the panel. #3222.\r
- {\r
- var panel = this._.panel;\r
- if ( allow != undefined )\r
- panel.allowBlur = allow;\r
-\r
- return panel.allowBlur;\r
- },\r
-\r
- showAsChild : function( panel, blockName, offsetParent, corner, offsetX, offsetY )\r
- {\r
- // Skip reshowing of child which is already visible.\r
- if ( this._.activeChild == panel && panel._.panel._.offsetParentId == offsetParent.getId() )\r
- return;\r
-\r
- this.hideChild();\r
-\r
- panel.onHide = CKEDITOR.tools.bind( function()\r
- {\r
- // Use a timeout, so we give time for this menu to get\r
- // potentially focused.\r
- CKEDITOR.tools.setTimeout( function()\r
- {\r
- if ( !this._.focused )\r
- this.hide();\r
- },\r
- 0, this );\r
- },\r
- this );\r
-\r
- this._.activeChild = panel;\r
- this._.focused = false;\r
-\r
- panel.showBlock( blockName, offsetParent, corner, offsetX, offsetY );\r
-\r
- /* #3767 IE: Second level menu may not have borders */\r
- if ( CKEDITOR.env.ie7Compat || ( CKEDITOR.env.ie8 && CKEDITOR.env.ie6Compat ) )\r
- {\r
- setTimeout(function()\r
- {\r
- panel.element.getChild( 0 ).$.style.cssText += '';\r
- }, 100);\r
- }\r
- },\r
-\r
- hideChild : function()\r
- {\r
- var activeChild = this._.activeChild;\r
-\r
- 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
- }\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