[3019] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | CKEDITOR.plugins.add( 'floatpanel',
|
---|
| 7 | {
|
---|
| 8 | requires : [ 'panel' ]
|
---|
| 9 | });
|
---|
| 10 |
|
---|
| 11 | (function()
|
---|
| 12 | {
|
---|
| 13 | var panels = {};
|
---|
| 14 | var isShowing = false;
|
---|
| 15 |
|
---|
| 16 | function getPanel( editor, doc, parentElement, definition, level )
|
---|
| 17 | {
|
---|
| 18 | // Generates the panel key: docId-eleId-skinName-langDir[-uiColor][-CSSs][-level]
|
---|
| 19 | var key =
|
---|
| 20 | doc.getUniqueId() +
|
---|
| 21 | '-' + parentElement.getUniqueId() +
|
---|
| 22 | '-' + editor.skinName +
|
---|
| 23 | '-' + editor.lang.dir +
|
---|
| 24 | ( ( editor.uiColor && ( '-' + editor.uiColor ) ) || '' ) +
|
---|
| 25 | ( ( definition.css && ( '-' + definition.css ) ) || '' ) +
|
---|
| 26 | ( ( level && ( '-' + level ) ) || '' );
|
---|
| 27 |
|
---|
| 28 | var panel = panels[ key ];
|
---|
| 29 |
|
---|
| 30 | if ( !panel )
|
---|
| 31 | {
|
---|
| 32 | panel = panels[ key ] = new CKEDITOR.ui.panel( doc, definition );
|
---|
| 33 | panel.element = parentElement.append( CKEDITOR.dom.element.createFromHtml( panel.renderHtml( editor ), doc ) );
|
---|
| 34 |
|
---|
| 35 | panel.element.setStyles(
|
---|
| 36 | {
|
---|
| 37 | display : 'none',
|
---|
| 38 | position : 'absolute'
|
---|
| 39 | });
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | return panel;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | CKEDITOR.ui.floatPanel = CKEDITOR.tools.createClass(
|
---|
| 46 | {
|
---|
| 47 | $ : function( editor, parentElement, definition, level )
|
---|
| 48 | {
|
---|
| 49 | definition.forceIFrame = true;
|
---|
| 50 |
|
---|
| 51 | var doc = parentElement.getDocument(),
|
---|
| 52 | panel = getPanel( editor, doc, parentElement, definition, level || 0 ),
|
---|
| 53 | element = panel.element,
|
---|
| 54 | iframe = element.getFirst().getFirst();
|
---|
| 55 |
|
---|
| 56 | this.element = element;
|
---|
| 57 |
|
---|
| 58 | // Register panels to editor for easy destroying ( #4241 ).
|
---|
| 59 | editor.panels ? editor.panels.push( element ) : editor.panels = [ element ];
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | this._ =
|
---|
| 63 | {
|
---|
| 64 | // The panel that will be floating.
|
---|
| 65 | panel : panel,
|
---|
| 66 | parentElement : parentElement,
|
---|
| 67 | definition : definition,
|
---|
| 68 | document : doc,
|
---|
| 69 | iframe : iframe,
|
---|
| 70 | children : [],
|
---|
| 71 | dir : editor.lang.dir
|
---|
| 72 | };
|
---|
| 73 | },
|
---|
| 74 |
|
---|
| 75 | proto :
|
---|
| 76 | {
|
---|
| 77 | addBlock : function( name, block )
|
---|
| 78 | {
|
---|
| 79 | return this._.panel.addBlock( name, block );
|
---|
| 80 | },
|
---|
| 81 |
|
---|
| 82 | addListBlock : function( name, multiSelect )
|
---|
| 83 | {
|
---|
| 84 | return this._.panel.addListBlock( name, multiSelect );
|
---|
| 85 | },
|
---|
| 86 |
|
---|
| 87 | getBlock : function( name )
|
---|
| 88 | {
|
---|
| 89 | return this._.panel.getBlock( name );
|
---|
| 90 | },
|
---|
| 91 |
|
---|
| 92 | /*
|
---|
| 93 | corner (LTR):
|
---|
| 94 | 1 = top-left
|
---|
| 95 | 2 = top-right
|
---|
| 96 | 3 = bottom-right
|
---|
| 97 | 4 = bottom-left
|
---|
| 98 |
|
---|
| 99 | corner (RTL):
|
---|
| 100 | 1 = top-right
|
---|
| 101 | 2 = top-left
|
---|
| 102 | 3 = bottom-left
|
---|
| 103 | 4 = bottom-right
|
---|
| 104 | */
|
---|
| 105 | showBlock : function( name, offsetParent, corner, offsetX, offsetY )
|
---|
| 106 | {
|
---|
| 107 | var panel = this._.panel,
|
---|
| 108 | block = panel.showBlock( name );
|
---|
| 109 |
|
---|
| 110 | this.allowBlur( false );
|
---|
| 111 | isShowing = true;
|
---|
| 112 |
|
---|
| 113 | var element = this.element,
|
---|
| 114 | iframe = this._.iframe,
|
---|
| 115 | definition = this._.definition,
|
---|
| 116 | position = offsetParent.getDocumentPosition( element.getDocument() ),
|
---|
| 117 | rtl = this._.dir == 'rtl';
|
---|
| 118 |
|
---|
| 119 | var left = position.x + ( offsetX || 0 ),
|
---|
| 120 | top = position.y + ( offsetY || 0 );
|
---|
| 121 |
|
---|
| 122 | // Floating panels are off by (-1px, 0px) in RTL mode. (#3438)
|
---|
| 123 | if ( rtl && ( corner == 1 || corner == 4 ) )
|
---|
| 124 | left += offsetParent.$.offsetWidth;
|
---|
| 125 | else if ( !rtl && ( corner == 2 || corner == 3 ) )
|
---|
| 126 | left += offsetParent.$.offsetWidth - 1;
|
---|
| 127 |
|
---|
| 128 | if ( corner == 3 || corner == 4 )
|
---|
| 129 | top += offsetParent.$.offsetHeight - 1;
|
---|
| 130 |
|
---|
| 131 | // Memorize offsetParent by it's ID.
|
---|
| 132 | this._.panel._.offsetParentId = offsetParent.getId();
|
---|
| 133 |
|
---|
| 134 | element.setStyles(
|
---|
| 135 | {
|
---|
| 136 | top : top + 'px',
|
---|
| 137 | left : '-3000px',
|
---|
| 138 | visibility : 'hidden',
|
---|
| 139 | opacity : '0', // FF3 is ignoring "visibility"
|
---|
| 140 | display : ''
|
---|
| 141 | });
|
---|
| 142 |
|
---|
| 143 | // Configure the IFrame blur event. Do that only once.
|
---|
| 144 | if ( !this._.blurSet )
|
---|
| 145 | {
|
---|
| 146 | // Non IE prefer the event into a window object.
|
---|
| 147 | var focused = CKEDITOR.env.ie ? iframe : new CKEDITOR.dom.window( iframe.$.contentWindow );
|
---|
| 148 |
|
---|
| 149 | // With addEventListener compatible browsers, we must
|
---|
| 150 | // useCapture when registering the focus/blur events to
|
---|
| 151 | // guarantee they will be firing in all situations. (#3068, #3222 )
|
---|
| 152 | CKEDITOR.event.useCapture = true;
|
---|
| 153 |
|
---|
| 154 | focused.on( 'blur', function( ev )
|
---|
| 155 | {
|
---|
| 156 | if ( CKEDITOR.env.ie && !this.allowBlur() )
|
---|
| 157 | return;
|
---|
| 158 |
|
---|
| 159 | // As we are using capture to register the listener,
|
---|
| 160 | // the blur event may get fired even when focusing
|
---|
| 161 | // inside the window itself, so we must ensure the
|
---|
| 162 | // target is out of it.
|
---|
| 163 | var target = ev.data.getTarget(),
|
---|
| 164 | targetWindow = target.getWindow && target.getWindow();
|
---|
| 165 |
|
---|
| 166 | if ( targetWindow && targetWindow.equals( focused ) )
|
---|
| 167 | return;
|
---|
| 168 |
|
---|
| 169 | if ( this.visible && !this._.activeChild && !isShowing )
|
---|
| 170 | this.hide();
|
---|
| 171 | },
|
---|
| 172 | this );
|
---|
| 173 |
|
---|
| 174 | focused.on( 'focus', function()
|
---|
| 175 | {
|
---|
| 176 | this._.focused = true;
|
---|
| 177 | this.hideChild();
|
---|
| 178 | this.allowBlur( true );
|
---|
| 179 | },
|
---|
| 180 | this );
|
---|
| 181 |
|
---|
| 182 | CKEDITOR.event.useCapture = false;
|
---|
| 183 |
|
---|
| 184 | this._.blurSet = 1;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | panel.onEscape = CKEDITOR.tools.bind( function()
|
---|
| 188 | {
|
---|
| 189 | this.onEscape && this.onEscape();
|
---|
| 190 | },
|
---|
| 191 | this );
|
---|
| 192 |
|
---|
| 193 | CKEDITOR.tools.setTimeout( function()
|
---|
| 194 | {
|
---|
| 195 | if ( rtl )
|
---|
| 196 | left -= element.$.offsetWidth;
|
---|
| 197 |
|
---|
| 198 | element.setStyles(
|
---|
| 199 | {
|
---|
| 200 | left : left + 'px',
|
---|
| 201 | visibility : '',
|
---|
| 202 | opacity : '1' // FF3 is ignoring "visibility"
|
---|
| 203 | });
|
---|
| 204 |
|
---|
| 205 | if ( block.autoSize )
|
---|
| 206 | {
|
---|
| 207 | function setHeight()
|
---|
| 208 | {
|
---|
| 209 | var target = element.getFirst();
|
---|
| 210 | var height = block.element.$.scrollHeight;
|
---|
| 211 |
|
---|
| 212 | // Account for extra height needed due to IE quirks box model bug:
|
---|
| 213 | // http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug
|
---|
| 214 | // (#3426)
|
---|
| 215 | if ( CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0 )
|
---|
| 216 | height += ( target.$.offsetHeight || 0 ) - ( target.$.clientHeight || 0 );
|
---|
| 217 |
|
---|
| 218 | target.setStyle( 'height', height + 'px' );
|
---|
| 219 |
|
---|
| 220 | // Fix IE < 8 visibility.
|
---|
| 221 | panel._.currentBlock.element.setStyle( 'display', 'none' ).removeStyle( 'display' );
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | if ( panel.isLoaded )
|
---|
| 225 | setHeight();
|
---|
| 226 | else
|
---|
| 227 | panel.onLoad = setHeight;
|
---|
| 228 | }
|
---|
| 229 | else
|
---|
| 230 | element.getFirst().removeStyle( 'height' );
|
---|
| 231 |
|
---|
| 232 | // Set the IFrame focus, so the blur event gets fired.
|
---|
| 233 | CKEDITOR.tools.setTimeout( function()
|
---|
| 234 | {
|
---|
| 235 | if ( definition.voiceLabel )
|
---|
| 236 | {
|
---|
| 237 | if ( CKEDITOR.env.gecko )
|
---|
| 238 | {
|
---|
| 239 | var container = iframe.getParent();
|
---|
| 240 | container.setAttribute( 'role', 'region' );
|
---|
| 241 | container.setAttribute( 'title', definition.voiceLabel );
|
---|
| 242 | iframe.setAttribute( 'role', 'region' );
|
---|
| 243 | iframe.setAttribute( 'title', ' ' );
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | if ( CKEDITOR.env.ie && CKEDITOR.env.quirks )
|
---|
| 247 | iframe.focus();
|
---|
| 248 | else
|
---|
| 249 | iframe.$.contentWindow.focus();
|
---|
| 250 |
|
---|
| 251 | // We need this get fired manually because of unfired focus() function.
|
---|
| 252 | if ( CKEDITOR.env.ie && !CKEDITOR.env.quirks )
|
---|
| 253 | this.allowBlur( true );
|
---|
| 254 | }, 0, this);
|
---|
| 255 | }, 0, this);
|
---|
| 256 | this.visible = 1;
|
---|
| 257 |
|
---|
| 258 | if ( this.onShow )
|
---|
| 259 | this.onShow.call( this );
|
---|
| 260 |
|
---|
| 261 | isShowing = false;
|
---|
| 262 | },
|
---|
| 263 |
|
---|
| 264 | hide : function()
|
---|
| 265 | {
|
---|
| 266 | if ( this.visible && ( !this.onHide || this.onHide.call( this ) !== true ) )
|
---|
| 267 | {
|
---|
| 268 | this.hideChild();
|
---|
| 269 | this.element.setStyle( 'display', 'none' );
|
---|
| 270 | this.visible = 0;
|
---|
| 271 | }
|
---|
| 272 | },
|
---|
| 273 |
|
---|
| 274 | allowBlur : function( allow ) // Prevent editor from hiding the panel. #3222.
|
---|
| 275 | {
|
---|
| 276 | var panel = this._.panel;
|
---|
| 277 | if ( allow != undefined )
|
---|
| 278 | panel.allowBlur = allow;
|
---|
| 279 |
|
---|
| 280 | return panel.allowBlur;
|
---|
| 281 | },
|
---|
| 282 |
|
---|
| 283 | showAsChild : function( panel, blockName, offsetParent, corner, offsetX, offsetY )
|
---|
| 284 | {
|
---|
| 285 | // Skip reshowing of child which is already visible.
|
---|
| 286 | if ( this._.activeChild == panel && panel._.panel._.offsetParentId == offsetParent.getId() )
|
---|
| 287 | return;
|
---|
| 288 |
|
---|
| 289 | this.hideChild();
|
---|
| 290 |
|
---|
| 291 | panel.onHide = CKEDITOR.tools.bind( function()
|
---|
| 292 | {
|
---|
| 293 | // Use a timeout, so we give time for this menu to get
|
---|
| 294 | // potentially focused.
|
---|
| 295 | CKEDITOR.tools.setTimeout( function()
|
---|
| 296 | {
|
---|
| 297 | if ( !this._.focused )
|
---|
| 298 | this.hide();
|
---|
| 299 | },
|
---|
| 300 | 0, this );
|
---|
| 301 | },
|
---|
| 302 | this );
|
---|
| 303 |
|
---|
| 304 | this._.activeChild = panel;
|
---|
| 305 | this._.focused = false;
|
---|
| 306 |
|
---|
| 307 | panel.showBlock( blockName, offsetParent, corner, offsetX, offsetY );
|
---|
| 308 |
|
---|
| 309 | /* #3767 IE: Second level menu may not have borders */
|
---|
| 310 | if ( CKEDITOR.env.ie7Compat || ( CKEDITOR.env.ie8 && CKEDITOR.env.ie6Compat ) )
|
---|
| 311 | {
|
---|
| 312 | setTimeout(function()
|
---|
| 313 | {
|
---|
| 314 | panel.element.getChild( 0 ).$.style.cssText += '';
|
---|
| 315 | }, 100);
|
---|
| 316 | }
|
---|
| 317 | },
|
---|
| 318 |
|
---|
| 319 | hideChild : function()
|
---|
| 320 | {
|
---|
| 321 | var activeChild = this._.activeChild;
|
---|
| 322 |
|
---|
| 323 | if ( activeChild )
|
---|
| 324 | {
|
---|
| 325 | delete activeChild.onHide;
|
---|
| 326 | delete this._.activeChild;
|
---|
| 327 | activeChild.hide();
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | });
|
---|
| 332 | })();
|
---|