2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 function protectFormStyles( formElement )
\r
10 if ( !formElement || formElement.type != CKEDITOR.NODE_ELEMENT || formElement.getName() != 'form' )
\r
13 var hijackRecord = [],
\r
14 hijackNames = [ 'style', 'className' ];
\r
15 for ( var i = 0 ; i < hijackNames.length ; i++ )
\r
17 var name = hijackNames[i];
\r
18 var $node = formElement.$.elements.namedItem( name );
\r
21 var hijackNode = new CKEDITOR.dom.element( $node );
\r
22 hijackRecord.push( [ hijackNode, hijackNode.nextSibling ] );
\r
23 hijackNode.remove();
\r
27 return hijackRecord;
\r
30 function restoreFormStyles( formElement, hijackRecord )
\r
32 if ( !formElement || formElement.type != CKEDITOR.NODE_ELEMENT || formElement.getName() != 'form' )
\r
35 if ( hijackRecord.length > 0 )
\r
37 for ( var i = hijackRecord.length - 1 ; i >= 0 ; i-- )
\r
39 var node = hijackRecord[i][0];
\r
40 var sibling = hijackRecord[i][1];
\r
42 node.insertBefore( sibling );
\r
44 node.appendTo( formElement );
\r
49 function saveStyles( element, isInsideEditor )
\r
51 var data = protectFormStyles( element );
\r
54 var $element = element.$;
\r
56 if ( !isInsideEditor )
\r
58 retval[ 'class' ] = $element.className || '';
\r
59 $element.className = '';
\r
62 retval.inline = $element.style.cssText || '';
\r
63 if ( !isInsideEditor ) // Reset any external styles that might interfere. (#2474)
\r
64 $element.style.cssText = 'position: static; overflow: visible';
\r
66 restoreFormStyles( data );
\r
70 function restoreStyles( element, savedStyles )
\r
72 var data = protectFormStyles( element );
\r
73 var $element = element.$;
\r
74 if ( 'class' in savedStyles )
\r
75 $element.className = savedStyles[ 'class' ];
\r
76 if ( 'inline' in savedStyles )
\r
77 $element.style.cssText = savedStyles.inline;
\r
78 restoreFormStyles( data );
\r
81 function refreshCursor( editor )
\r
83 // Refresh all editor instances on the page (#5724).
\r
84 var all = CKEDITOR.instances;
\r
85 for ( var i in all )
\r
88 if ( one.mode == 'wysiwyg' && !one.readOnly )
\r
90 var body = one.document.getBody();
\r
91 // Refresh 'contentEditable' otherwise
\r
92 // DOM lifting breaks design mode. (#5560)
\r
93 body.setAttribute( 'contentEditable', false );
\r
94 body.setAttribute( 'contentEditable', true );
\r
98 if ( editor.focusManager.hasFocus )
\r
100 editor.toolbox.focus();
\r
106 * Adding an iframe shim to this element, OR removing the existing one if already applied.
\r
107 * Note: This will only affect IE version below 7.
\r
109 function createIframeShim( element )
\r
111 if ( !CKEDITOR.env.ie || CKEDITOR.env.version > 6 )
\r
114 var shim = CKEDITOR.dom.element.createFromHtml( '<iframe frameborder="0" tabindex="-1"' +
\r
115 ' src="javascript:' +
\r
116 'void((function(){' +
\r
117 'document.open();' +
\r
118 ( CKEDITOR.env.isCustomDomain() ? 'document.domain=\'' + this.getDocument().$.domain + '\';' : '' ) +
\r
119 'document.close();' +
\r
121 ' style="display:block;position:absolute;z-index:-1;' +
\r
122 'progid:DXImageTransform.Microsoft.Alpha(opacity=0);' +
\r
124 return element.append( shim, true );
\r
127 CKEDITOR.plugins.add( 'maximize',
\r
129 init : function( editor )
\r
131 var lang = editor.lang;
\r
132 var mainDocument = CKEDITOR.document,
\r
133 mainWindow = mainDocument.getWindow();
\r
135 // Saved selection and scroll position for the editing area.
\r
136 var savedSelection,
\r
139 // Saved scroll position for the outer window.
\r
144 // Saved resize handler function.
\r
145 function resizeHandler()
\r
147 var viewPaneSize = mainWindow.getViewPaneSize();
\r
148 shim && shim.setStyles( { width : viewPaneSize.width + 'px', height : viewPaneSize.height + 'px' } );
\r
149 editor.resize( viewPaneSize.width, viewPaneSize.height, null, true );
\r
152 // Retain state after mode switches.
\r
153 var savedState = CKEDITOR.TRISTATE_OFF;
\r
155 editor.addCommand( 'maximize',
\r
157 // Disabled on iOS (#8307).
\r
158 modes : { wysiwyg : !CKEDITOR.env.iOS, source : !CKEDITOR.env.iOS },
\r
160 editorFocus : false,
\r
163 var container = editor.container.getChild( 1 );
\r
164 var contents = editor.getThemeSpace( 'contents' );
\r
166 // Save current selection and scroll position in editing area.
\r
167 if ( editor.mode == 'wysiwyg' )
\r
169 var selection = editor.getSelection();
\r
170 savedSelection = selection && selection.getRanges();
\r
171 savedScroll = mainWindow.getScrollPosition();
\r
175 var $textarea = editor.textarea.$;
\r
176 savedSelection = !CKEDITOR.env.ie && [ $textarea.selectionStart, $textarea.selectionEnd ];
\r
177 savedScroll = [ $textarea.scrollLeft, $textarea.scrollTop ];
\r
180 if ( this.state == CKEDITOR.TRISTATE_OFF ) // Go fullscreen if the state is off.
\r
182 // Add event handler for resizing.
\r
183 mainWindow.on( 'resize', resizeHandler );
\r
185 // Save the scroll bar position.
\r
186 outerScroll = mainWindow.getScrollPosition();
\r
188 // Save and reset the styles for the entire node tree.
\r
189 var currentNode = editor.container;
\r
190 while ( ( currentNode = currentNode.getParent() ) )
\r
192 currentNode.setCustomData( 'maximize_saved_styles', saveStyles( currentNode ) );
\r
193 currentNode.setStyle( 'z-index', editor.config.baseFloatZIndex - 1 );
\r
195 contents.setCustomData( 'maximize_saved_styles', saveStyles( contents, true ) );
\r
196 container.setCustomData( 'maximize_saved_styles', saveStyles( container, true ) );
\r
198 // Hide scroll bars.
\r
201 overflow : CKEDITOR.env.webkit ? '' : 'hidden', // #6896
\r
206 mainDocument.getDocumentElement().setStyles( styles );
\r
207 !CKEDITOR.env.gecko && mainDocument.getDocumentElement().setStyle( 'position', 'fixed' );
\r
208 !( CKEDITOR.env.gecko && CKEDITOR.env.quirks ) && mainDocument.getBody().setStyles( styles );
\r
210 // Scroll to the top left (IE needs some time for it - #4923).
\r
212 setTimeout( function() { mainWindow.$.scrollTo( 0, 0 ); }, 0 ) :
\r
213 mainWindow.$.scrollTo( 0, 0 );
\r
215 // Resize and move to top left.
\r
216 // Special treatment for FF Quirks (#7284)
\r
217 container.setStyle( 'position', CKEDITOR.env.gecko && CKEDITOR.env.quirks ? 'fixed' : 'absolute' );
\r
218 container.$.offsetLeft; // SAFARI BUG: See #2066.
\r
219 container.setStyles(
\r
221 'z-index' : editor.config.baseFloatZIndex - 1,
\r
226 shim = createIframeShim( container ); // IE6 select element penetration when maximized. (#4459)
\r
228 // Add cke_maximized class before resize handle since that will change things sizes (#5580)
\r
229 container.addClass( 'cke_maximized' );
\r
233 // Still not top left? Fix it. (Bug #174)
\r
234 var offset = container.getDocumentPosition();
\r
235 container.setStyles(
\r
237 left : ( -1 * offset.x ) + 'px',
\r
238 top : ( -1 * offset.y ) + 'px'
\r
241 // Fixing positioning editor chrome in Firefox break design mode. (#5149)
\r
242 CKEDITOR.env.gecko && refreshCursor( editor );
\r
245 else if ( this.state == CKEDITOR.TRISTATE_ON ) // Restore from fullscreen if the state is on.
\r
247 // Remove event handler for resizing.
\r
248 mainWindow.removeListener( 'resize', resizeHandler );
\r
250 // Restore CSS styles for the entire node tree.
\r
251 var editorElements = [ contents, container ];
\r
252 for ( var i = 0 ; i < editorElements.length ; i++ )
\r
254 restoreStyles( editorElements[i], editorElements[i].getCustomData( 'maximize_saved_styles' ) );
\r
255 editorElements[i].removeCustomData( 'maximize_saved_styles' );
\r
258 currentNode = editor.container;
\r
259 while ( ( currentNode = currentNode.getParent() ) )
\r
261 restoreStyles( currentNode, currentNode.getCustomData( 'maximize_saved_styles' ) );
\r
262 currentNode.removeCustomData( 'maximize_saved_styles' );
\r
265 // Restore the window scroll position.
\r
267 setTimeout( function() { mainWindow.$.scrollTo( outerScroll.x, outerScroll.y ); }, 0 ) :
\r
268 mainWindow.$.scrollTo( outerScroll.x, outerScroll.y );
\r
270 // Remove cke_maximized class.
\r
271 container.removeClass( 'cke_maximized' );
\r
273 // Webkit requires a re-layout on editor chrome. (#6695)
\r
274 if ( CKEDITOR.env.webkit )
\r
276 container.setStyle( 'display', 'inline' );
\r
277 setTimeout( function(){ container.setStyle( 'display', 'block' ); }, 0 );
\r
286 // Emit a resize event, because this time the size is modified in
\r
288 editor.fire( 'resize' );
\r
291 this.toggleState();
\r
293 // Toggle button label.
\r
294 var button = this.uiItems[ 0 ];
\r
295 // Only try to change the button if it exists (#6166)
\r
298 var label = ( this.state == CKEDITOR.TRISTATE_OFF )
\r
299 ? lang.maximize : lang.minimize;
\r
300 var buttonNode = editor.element.getDocument().getById( button._.id );
\r
301 buttonNode.getChild( 1 ).setHtml( label );
\r
302 buttonNode.setAttribute( 'title', label );
\r
303 buttonNode.setAttribute( 'href', 'javascript:void("' + label + '");' );
\r
306 // Restore selection and scroll position in editing area.
\r
307 if ( editor.mode == 'wysiwyg' )
\r
309 if ( savedSelection )
\r
311 // Fixing positioning editor chrome in Firefox break design mode. (#5149)
\r
312 CKEDITOR.env.gecko && refreshCursor( editor );
\r
314 editor.getSelection().selectRanges(savedSelection);
\r
315 var element = editor.getSelection().getStartElement();
\r
316 element && element.scrollIntoView( true );
\r
320 mainWindow.$.scrollTo( savedScroll.x, savedScroll.y );
\r
324 if ( savedSelection )
\r
326 $textarea.selectionStart = savedSelection[0];
\r
327 $textarea.selectionEnd = savedSelection[1];
\r
329 $textarea.scrollLeft = savedScroll[0];
\r
330 $textarea.scrollTop = savedScroll[1];
\r
333 savedSelection = savedScroll = null;
\r
334 savedState = this.state;
\r
339 editor.ui.addButton( 'Maximize',
\r
341 label : lang.maximize,
\r
342 command : 'maximize'
\r
345 // Restore the command state after mode change, unless it has been changed to disabled (#6467)
\r
346 editor.on( 'mode', function()
\r
348 var command = editor.getCommand( 'maximize' );
\r
349 command.setState( command.state == CKEDITOR.TRISTATE_DISABLED ? CKEDITOR.TRISTATE_DISABLED : savedState );
\r
350 }, null, null, 100 );
\r