X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Fmaximize%2Fplugin.js;h=97ac0b0f3e12ed3e3b964afc2d04aa0130ee4d1c;hb=e73319a12b56100b29ef456fd74114fe5519e01c;hp=2258c5a9f5eba6f6a14dc3970469ba8e58a943e9;hpb=e7789c1ad838194d45eeee6ac2eb6e55f5cf35a1;p=ckeditor.git diff --git a/_source/plugins/maximize/plugin.js b/_source/plugins/maximize/plugin.js index 2258c5a..97ac0b0 100644 --- a/_source/plugins/maximize/plugin.js +++ b/_source/plugins/maximize/plugin.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -10,8 +10,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license if ( !formElement || formElement.type != CKEDITOR.NODE_ELEMENT || formElement.getName() != 'form' ) return []; - var hijackRecord = []; - var hijackNames = [ 'style', 'className' ]; + var hijackRecord = [], + hijackNames = [ 'style', 'className' ]; for ( var i = 0 ; i < hijackNames.length ; i++ ) { var name = hijackNames[i]; @@ -78,55 +78,85 @@ For licensing, see LICENSE.html or http://ckeditor.com/license restoreFormStyles( data ); } - function getResizeHandler( mainWindow, editor ) + function refreshCursor( editor ) { - return function() + // Refresh all editor instances on the page (#5724). + var all = CKEDITOR.instances; + for ( var i in all ) { - var viewPaneSize = mainWindow.getViewPaneSize(); - editor.resize( viewPaneSize.width, viewPaneSize.height, null, true ); - }; - } + var one = all[ i ]; + if ( one.mode == 'wysiwyg' && !one.readOnly ) + { + var body = one.document.getBody(); + // Refresh 'contentEditable' otherwise + // DOM lifting breaks design mode. (#5560) + body.setAttribute( 'contentEditable', false ); + body.setAttribute( 'contentEditable', true ); + } + } - function refreshCursor( editor ) - { if ( editor.focusManager.hasFocus ) { - var focusGrabber = editor.container.append( CKEDITOR.dom.element.createFromHtml( - '' ) ); - - focusGrabber.on( 'focus', function() - { - editor.focus(); - } ); - focusGrabber.focus(); - focusGrabber.remove(); + editor.toolbox.focus(); + editor.focus(); } } + /** + * Adding an iframe shim to this element, OR removing the existing one if already applied. + * Note: This will only affect IE version below 7. + */ + function createIframeShim( element ) + { + if ( !CKEDITOR.env.ie || CKEDITOR.env.version > 6 ) + return null; + + var shim = CKEDITOR.dom.element.createFromHtml( '' ); + return element.append( shim, true ); + } + CKEDITOR.plugins.add( 'maximize', { init : function( editor ) { var lang = editor.lang; - var mainDocument = CKEDITOR.document; - var mainWindow = mainDocument.getWindow(); + var mainDocument = CKEDITOR.document, + mainWindow = mainDocument.getWindow(); // Saved selection and scroll position for the editing area. - var savedSelection; - var savedScroll; + var savedSelection, + savedScroll; // Saved scroll position for the outer window. var outerScroll; + var shim; + // Saved resize handler function. - var resizeHandler = getResizeHandler( mainWindow, editor ); + function resizeHandler() + { + var viewPaneSize = mainWindow.getViewPaneSize(); + shim && shim.setStyles( { width : viewPaneSize.width + 'px', height : viewPaneSize.height + 'px' } ); + editor.resize( viewPaneSize.width, viewPaneSize.height, null, true ); + } // Retain state after mode switches. var savedState = CKEDITOR.TRISTATE_OFF; editor.addCommand( 'maximize', { - modes : { wysiwyg : 1, source : 1 }, + // Disabled on iOS (#8307). + modes : { wysiwyg : !CKEDITOR.env.iOS, source : !CKEDITOR.env.iOS }, + readOnly : 1, editorFocus : false, exec : function() { @@ -166,20 +196,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license container.setCustomData( 'maximize_saved_styles', saveStyles( container, true ) ); // Hide scroll bars. - if ( CKEDITOR.env.ie ) - { - mainDocument.$.documentElement.style.overflow = - mainDocument.getBody().$.style.overflow = 'hidden'; - } - else - { - mainDocument.getBody().setStyles( - { - overflow : 'hidden', - width : '0px', - height : '0px' - } ); - } + var styles = + { + overflow : CKEDITOR.env.webkit ? '' : 'hidden', // #6896 + width : 0, + height : 0 + }; + + mainDocument.getDocumentElement().setStyles( styles ); + !CKEDITOR.env.gecko && mainDocument.getDocumentElement().setStyle( 'position', 'fixed' ); + !( CKEDITOR.env.gecko && CKEDITOR.env.quirks ) && mainDocument.getBody().setStyles( styles ); // Scroll to the top left (IE needs some time for it - #4923). CKEDITOR.env.ie ? @@ -187,8 +213,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license mainWindow.$.scrollTo( 0, 0 ); // Resize and move to top left. - var viewPaneSize = mainWindow.getViewPaneSize(); - container.setStyle( 'position', 'absolute' ); + // Special treatment for FF Quirks (#7284) + container.setStyle( 'position', CKEDITOR.env.gecko && CKEDITOR.env.quirks ? 'fixed' : 'absolute' ); container.$.offsetLeft; // SAFARI BUG: See #2066. container.setStyles( { @@ -196,7 +222,13 @@ For licensing, see LICENSE.html or http://ckeditor.com/license left : '0px', top : '0px' } ); - editor.resize( viewPaneSize.width, viewPaneSize.height, null, true ); + + shim = createIframeShim( container ); // IE6 select element penetration when maximized. (#4459) + + // Add cke_maximized class before resize handle since that will change things sizes (#5580) + container.addClass( 'cke_maximized' ); + + resizeHandler(); // Still not top left? Fix it. (Bug #174) var offset = container.getDocumentPosition(); @@ -209,8 +241,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Fixing positioning editor chrome in Firefox break design mode. (#5149) CKEDITOR.env.gecko && refreshCursor( editor ); - // Add cke_maximized class. - container.addClass( 'cke_maximized' ); } else if ( this.state == CKEDITOR.TRISTATE_ON ) // Restore from fullscreen if the state is on. { @@ -240,6 +270,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Remove cke_maximized class. container.removeClass( 'cke_maximized' ); + // Webkit requires a re-layout on editor chrome. (#6695) + if ( CKEDITOR.env.webkit ) + { + container.setStyle( 'display', 'inline' ); + setTimeout( function(){ container.setStyle( 'display', 'block' ); }, 0 ); + } + + if ( shim ) + { + shim.remove(); + shim = null; + } + // Emit a resize event, because this time the size is modified in // restoreStyles. editor.fire( 'resize' ); @@ -249,12 +292,16 @@ For licensing, see LICENSE.html or http://ckeditor.com/license // Toggle button label. var button = this.uiItems[ 0 ]; - var label = ( this.state == CKEDITOR.TRISTATE_OFF ) - ? lang.maximize : lang.minimize; - var buttonNode = editor.element.getDocument().getById( button._.id ); - buttonNode.getChild( 1 ).setHtml( label ); - buttonNode.setAttribute( 'title', label ); - buttonNode.setAttribute( 'href', 'javascript:void("' + label + '");' ); + // Only try to change the button if it exists (#6166) + if( button ) + { + var label = ( this.state == CKEDITOR.TRISTATE_OFF ) + ? lang.maximize : lang.minimize; + var buttonNode = editor.element.getDocument().getById( button._.id ); + buttonNode.getChild( 1 ).setHtml( label ); + buttonNode.setAttribute( 'title', label ); + buttonNode.setAttribute( 'href', 'javascript:void("' + label + '");' ); + } // Restore selection and scroll position in editing area. if ( editor.mode == 'wysiwyg' ) @@ -295,10 +342,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license command : 'maximize' } ); - // Restore the command state after mode change. + // Restore the command state after mode change, unless it has been changed to disabled (#6467) editor.on( 'mode', function() { - editor.getCommand( 'maximize' ).setState( savedState ); + var command = editor.getCommand( 'maximize' ); + command.setState( command.state == CKEDITOR.TRISTATE_DISABLED ? CKEDITOR.TRISTATE_DISABLED : savedState ); }, null, null, 100 ); } } );