4c04d14885f35fe27f3e65b2fefb6414479768dd
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
8 function protectFormStyles( formElement
)
10 if ( !formElement
|| formElement
.type
!= CKEDITOR
.NODE_ELEMENT
|| formElement
.getName() != 'form' )
13 var hijackRecord
= [],
14 hijackNames
= [ 'style', 'className' ];
15 for ( var i
= 0 ; i
< hijackNames
.length
; i
++ )
17 var name
= hijackNames
[i
];
18 var $node
= formElement
.$.elements
.namedItem( name
);
21 var hijackNode
= new CKEDITOR
.dom
.element( $node
);
22 hijackRecord
.push( [ hijackNode
, hijackNode
.nextSibling
] );
30 function restoreFormStyles( formElement
, hijackRecord
)
32 if ( !formElement
|| formElement
.type
!= CKEDITOR
.NODE_ELEMENT
|| formElement
.getName() != 'form' )
35 if ( hijackRecord
.length
> 0 )
37 for ( var i
= hijackRecord
.length
- 1 ; i
>= 0 ; i
-- )
39 var node
= hijackRecord
[i
][0];
40 var sibling
= hijackRecord
[i
][1];
42 node
.insertBefore( sibling
);
44 node
.appendTo( formElement
);
49 function saveStyles( element
, isInsideEditor
)
51 var data
= protectFormStyles( element
);
54 var $element
= element
.$;
56 if ( !isInsideEditor
)
58 retval
[ 'class' ] = $element
.className
|| '';
59 $element
.className
= '';
62 retval
.inline
= $element
.style
.cssText
|| '';
63 if ( !isInsideEditor
) // Reset any external styles that might interfere. (#2474)
64 $element
.style
.cssText
= 'position: static; overflow: visible';
66 restoreFormStyles( data
);
70 function restoreStyles( element
, savedStyles
)
72 var data
= protectFormStyles( element
);
73 var $element
= element
.$;
74 if ( 'class' in savedStyles
)
75 $element
.className
= savedStyles
[ 'class' ];
76 if ( 'inline' in savedStyles
)
77 $element
.style
.cssText
= savedStyles
.inline
;
78 restoreFormStyles( data
);
81 function refreshCursor( editor
)
83 // Refresh all editor instances on the page (#5724).
84 var all
= CKEDITOR
.instances
;
88 if ( one
.mode
== 'wysiwyg' && !one
.readOnly
)
90 var body
= one
.document
.getBody();
91 // Refresh 'contentEditable' otherwise
92 // DOM lifting breaks design mode. (#5560)
93 body
.setAttribute( 'contentEditable', false );
94 body
.setAttribute( 'contentEditable', true );
98 if ( editor
.focusManager
.hasFocus
)
100 editor
.toolbox
.focus();
106 * Adding an iframe shim to this element, OR removing the existing one if already applied.
107 * Note: This will only affect IE version below 7.
109 function createIframeShim( element
)
111 if ( !CKEDITOR
.env
.ie
|| CKEDITOR
.env
.version
> 6 )
114 var shim
= CKEDITOR
.dom
.element
.createFromHtml( '<iframe frameborder="0" tabindex="-1"' +
115 ' src="javascript:' +
116 'void((function(){' +
118 ( CKEDITOR
.env
.isCustomDomain() ? 'document.domain=\'' + this.getDocument().$.domain
+ '\';' : '' ) +
119 'document.close();' +
121 ' style="display:block;position:absolute;z-index:-1;' +
122 'progid:DXImageTransform.Microsoft.Alpha(opacity=0);' +
124 return element
.append( shim
, true );
127 CKEDITOR
.plugins
.add( 'maximize',
129 init : function( editor
)
131 var lang
= editor
.lang
;
132 var mainDocument
= CKEDITOR
.document
,
133 mainWindow
= mainDocument
.getWindow();
135 // Saved selection and scroll position for the editing area.
139 // Saved scroll position for the outer window.
144 // Saved resize handler function.
145 function resizeHandler()
147 var viewPaneSize
= mainWindow
.getViewPaneSize();
148 shim
&& shim
.setStyles( { width
: viewPaneSize
.width
+ 'px', height
: viewPaneSize
.height
+ 'px' } );
149 editor
.resize( viewPaneSize
.width
, viewPaneSize
.height
, null, true );
152 // Retain state after mode switches.
153 var savedState
= CKEDITOR
.TRISTATE_OFF
;
155 editor
.addCommand( 'maximize',
157 modes
: { wysiwyg
: 1, source
: 1 },
162 var container
= editor
.container
.getChild( 1 );
163 var contents
= editor
.getThemeSpace( 'contents' );
165 // Save current selection and scroll position in editing area.
166 if ( editor
.mode
== 'wysiwyg' )
168 var selection
= editor
.getSelection();
169 savedSelection
= selection
&& selection
.getRanges();
170 savedScroll
= mainWindow
.getScrollPosition();
174 var $textarea
= editor
.textarea
.$;
175 savedSelection
= !CKEDITOR
.env
.ie
&& [ $textarea
.selectionStart
, $textarea
.selectionEnd
];
176 savedScroll
= [ $textarea
.scrollLeft
, $textarea
.scrollTop
];
179 if ( this.state
== CKEDITOR
.TRISTATE_OFF
) // Go fullscreen if the state is off.
181 // Add event handler for resizing.
182 mainWindow
.on( 'resize', resizeHandler
);
184 // Save the scroll bar position.
185 outerScroll
= mainWindow
.getScrollPosition();
187 // Save and reset the styles for the entire node tree.
188 var currentNode
= editor
.container
;
189 while ( ( currentNode
= currentNode
.getParent() ) )
191 currentNode
.setCustomData( 'maximize_saved_styles', saveStyles( currentNode
) );
192 currentNode
.setStyle( 'z-index', editor
.config
.baseFloatZIndex
- 1 );
194 contents
.setCustomData( 'maximize_saved_styles', saveStyles( contents
, true ) );
195 container
.setCustomData( 'maximize_saved_styles', saveStyles( container
, true ) );
200 overflow
: CKEDITOR
.env
.webkit
? '' : 'hidden', // #6896
205 mainDocument
.getDocumentElement().setStyles( styles
);
206 !CKEDITOR
.env
.gecko
&& mainDocument
.getDocumentElement().setStyle( 'position', 'fixed' );
207 !( CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.quirks
) && mainDocument
.getBody().setStyles( styles
);
209 // Scroll to the top left (IE needs some time for it - #4923).
211 setTimeout( function() { mainWindow
.$.scrollTo( 0, 0 ); }, 0 ) :
212 mainWindow
.$.scrollTo( 0, 0 );
214 // Resize and move to top left.
215 // Special treatment for FF Quirks (#7284)
216 container
.setStyle( 'position', CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.quirks
? 'fixed' : 'absolute' );
217 container
.$.offsetLeft
; // SAFARI BUG: See #2066.
220 'z-index' : editor
.config
.baseFloatZIndex
- 1,
225 shim
= createIframeShim( container
); // IE6 select element penetration when maximized. (#4459)
227 // Add cke_maximized class before resize handle since that will change things sizes (#5580)
228 container
.addClass( 'cke_maximized' );
232 // Still not top left? Fix it. (Bug #174)
233 var offset
= container
.getDocumentPosition();
236 left
: ( -1 * offset
.x
) + 'px',
237 top
: ( -1 * offset
.y
) + 'px'
240 // Fixing positioning editor chrome in Firefox break design mode. (#5149)
241 CKEDITOR
.env
.gecko
&& refreshCursor( editor
);
244 else if ( this.state
== CKEDITOR
.TRISTATE_ON
) // Restore from fullscreen if the state is on.
246 // Remove event handler for resizing.
247 mainWindow
.removeListener( 'resize', resizeHandler
);
249 // Restore CSS styles for the entire node tree.
250 var editorElements
= [ contents
, container
];
251 for ( var i
= 0 ; i
< editorElements
.length
; i
++ )
253 restoreStyles( editorElements
[i
], editorElements
[i
].getCustomData( 'maximize_saved_styles' ) );
254 editorElements
[i
].removeCustomData( 'maximize_saved_styles' );
257 currentNode
= editor
.container
;
258 while ( ( currentNode
= currentNode
.getParent() ) )
260 restoreStyles( currentNode
, currentNode
.getCustomData( 'maximize_saved_styles' ) );
261 currentNode
.removeCustomData( 'maximize_saved_styles' );
264 // Restore the window scroll position.
266 setTimeout( function() { mainWindow
.$.scrollTo( outerScroll
.x
, outerScroll
.y
); }, 0 ) :
267 mainWindow
.$.scrollTo( outerScroll
.x
, outerScroll
.y
);
269 // Remove cke_maximized class.
270 container
.removeClass( 'cke_maximized' );
272 // Webkit requires a re-layout on editor chrome. (#6695)
273 if ( CKEDITOR
.env
.webkit
)
275 container
.setStyle( 'display', 'inline' );
276 setTimeout( function(){ container
.setStyle( 'display', 'block' ); }, 0 );
285 // Emit a resize event, because this time the size is modified in
287 editor
.fire( 'resize' );
292 // Toggle button label.
293 var button
= this.uiItems
[ 0 ];
294 // Only try to change the button if it exists (#6166)
297 var label
= ( this.state
== CKEDITOR
.TRISTATE_OFF
)
298 ? lang
.maximize
: lang
.minimize
;
299 var buttonNode
= editor
.element
.getDocument().getById( button
._
.id
);
300 buttonNode
.getChild( 1 ).setHtml( label
);
301 buttonNode
.setAttribute( 'title', label
);
302 buttonNode
.setAttribute( 'href', 'javascript:void("' + label
+ '");' );
305 // Restore selection and scroll position in editing area.
306 if ( editor
.mode
== 'wysiwyg' )
308 if ( savedSelection
)
310 // Fixing positioning editor chrome in Firefox break design mode. (#5149)
311 CKEDITOR
.env
.gecko
&& refreshCursor( editor
);
313 editor
.getSelection().selectRanges(savedSelection
);
314 var element
= editor
.getSelection().getStartElement();
315 element
&& element
.scrollIntoView( true );
319 mainWindow
.$.scrollTo( savedScroll
.x
, savedScroll
.y
);
323 if ( savedSelection
)
325 $textarea
.selectionStart
= savedSelection
[0];
326 $textarea
.selectionEnd
= savedSelection
[1];
328 $textarea
.scrollLeft
= savedScroll
[0];
329 $textarea
.scrollTop
= savedScroll
[1];
332 savedSelection
= savedScroll
= null;
333 savedState
= this.state
;
338 editor
.ui
.addButton( 'Maximize',
340 label
: lang
.maximize
,
344 // Restore the command state after mode change, unless it has been changed to disabled (#6467)
345 editor
.on( 'mode', function()
347 var command
= editor
.getCommand( 'maximize' );
348 command
.setState( command
.state
== CKEDITOR
.TRISTATE_DISABLED
? CKEDITOR
.TRISTATE_DISABLED
: savedState
);
349 }, null, null, 100 );