]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/plugins/maximize/plugin.js
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 function protectFormStyles( formElement
) {
8 if ( !formElement
|| formElement
.type
!= CKEDITOR
.NODE_ELEMENT
|| formElement
.getName() != 'form' )
11 var hijackRecord
= [],
12 hijackNames
= [ 'style', 'className' ];
13 for ( var i
= 0; i
< hijackNames
.length
; i
++ ) {
14 var name
= hijackNames
[ i
];
15 var $node
= formElement
.$.elements
.namedItem( name
);
17 var hijackNode
= new CKEDITOR
.dom
.element( $node
);
18 hijackRecord
.push( [ hijackNode
, hijackNode
.nextSibling
] );
26 function restoreFormStyles( formElement
, hijackRecord
) {
27 if ( !formElement
|| formElement
.type
!= CKEDITOR
.NODE_ELEMENT
|| formElement
.getName() != 'form' )
30 if ( hijackRecord
.length
> 0 ) {
31 for ( var i
= hijackRecord
.length
- 1; i
>= 0; i
-- ) {
32 var node
= hijackRecord
[ i
][ 0 ];
33 var sibling
= hijackRecord
[ i
][ 1 ];
35 node
.insertBefore( sibling
);
37 node
.appendTo( formElement
);
42 function saveStyles( element
, isInsideEditor
) {
43 var data
= protectFormStyles( element
);
46 var $element
= element
.$;
48 if ( !isInsideEditor
) {
49 retval
[ 'class' ] = $element
.className
|| '';
50 $element
.className
= '';
53 retval
.inline
= $element
.style
.cssText
|| '';
54 if ( !isInsideEditor
) // Reset any external styles that might interfere. (http://dev.ckeditor.com/ticket/2474)
55 $element
.style
.cssText
= 'position: static; overflow: visible';
57 restoreFormStyles( data
);
61 function restoreStyles( element
, savedStyles
) {
62 var data
= protectFormStyles( element
);
63 var $element
= element
.$;
64 if ( 'class' in savedStyles
)
65 $element
.className
= savedStyles
[ 'class' ];
66 if ( 'inline' in savedStyles
)
67 $element
.style
.cssText
= savedStyles
.inline
;
68 restoreFormStyles( data
);
71 function refreshCursor( editor
) {
72 if ( editor
.editable().isInline() )
75 // Refresh all editor instances on the page (http://dev.ckeditor.com/ticket/5724).
76 var all
= CKEDITOR
.instances
;
77 for ( var i
in all
) {
79 if ( one
.mode
== 'wysiwyg' && !one
.readOnly
) {
80 var body
= one
.document
.getBody();
81 // Refresh 'contentEditable' otherwise
82 // DOM lifting breaks design mode. (http://dev.ckeditor.com/ticket/5560)
83 body
.setAttribute( 'contentEditable', false );
84 body
.setAttribute( 'contentEditable', true );
88 if ( editor
.editable().hasFocus
) {
89 editor
.toolbox
.focus();
94 CKEDITOR
.plugins
.add( 'maximize', {
95 // jscs:disable maximumLineLength
96 lang: 'af,ar,az,bg,bn,bs,ca,cs,cy,da,de,de-ch,el,en,en-au,en-ca,en-gb,eo,es,es-mx,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,oc,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn', // %REMOVE_LINE_CORE%
97 // jscs:enable maximumLineLength
98 icons: 'maximize', // %REMOVE_LINE_CORE%
99 hidpi: true, // %REMOVE_LINE_CORE%
100 init: function( editor
) {
101 // Maximize plugin isn't available in inline mode yet.
102 if ( editor
.elementMode
== CKEDITOR
.ELEMENT_MODE_INLINE
)
105 var lang
= editor
.lang
;
106 var mainDocument
= CKEDITOR
.document
,
107 mainWindow
= mainDocument
.getWindow();
109 // Saved selection and scroll position for the editing area.
110 var savedSelection
, savedScroll
;
112 // Saved scroll position for the outer window.
115 // Saved resize handler function.
116 function resizeHandler() {
117 var viewPaneSize
= mainWindow
.getViewPaneSize();
118 editor
.resize( viewPaneSize
.width
, viewPaneSize
.height
, null, true );
121 // Retain state after mode switches.
122 var savedState
= CKEDITOR
.TRISTATE_OFF
;
124 editor
.addCommand( 'maximize', {
125 // Disabled on iOS (http://dev.ckeditor.com/ticket/8307).
126 modes: { wysiwyg: !CKEDITOR
.env
.iOS
, source: !CKEDITOR
.env
.iOS
},
130 var container
= editor
.container
.getFirst( function( node
) {
131 return node
.type
== CKEDITOR
.NODE_ELEMENT
&& node
.hasClass( 'cke_inner' );
133 var contents
= editor
.ui
.space( 'contents' );
135 // Save current selection and scroll position in editing area.
136 if ( editor
.mode
== 'wysiwyg' ) {
137 var selection
= editor
.getSelection();
138 savedSelection
= selection
&& selection
.getRanges();
139 savedScroll
= mainWindow
.getScrollPosition();
141 var $textarea
= editor
.editable().$;
142 savedSelection
= !CKEDITOR
.env
.ie
&& [ $textarea
.selectionStart
, $textarea
.selectionEnd
];
143 savedScroll
= [ $textarea
.scrollLeft
, $textarea
.scrollTop
];
146 // Go fullscreen if the state is off.
147 if ( this.state
== CKEDITOR
.TRISTATE_OFF
) {
148 // Add event handler for resizing.
149 mainWindow
.on( 'resize', resizeHandler
);
151 // Save the scroll bar position.
152 outerScroll
= mainWindow
.getScrollPosition();
154 // Save and reset the styles for the entire node tree.
155 var currentNode
= editor
.container
;
156 while ( ( currentNode
= currentNode
.getParent() ) ) {
157 currentNode
.setCustomData( 'maximize_saved_styles', saveStyles( currentNode
) );
158 // Show under floatpanels (-1) and context menu (-2).
159 currentNode
.setStyle( 'z-index', editor
.config
.baseFloatZIndex
- 5 );
161 contents
.setCustomData( 'maximize_saved_styles', saveStyles( contents
, true ) );
162 container
.setCustomData( 'maximize_saved_styles', saveStyles( container
, true ) );
166 overflow: CKEDITOR
.env
.webkit
? '' : 'hidden', // http://dev.ckeditor.com/ticket/6896
171 mainDocument
.getDocumentElement().setStyles( styles
);
172 !CKEDITOR
.env
.gecko
&& mainDocument
.getDocumentElement().setStyle( 'position', 'fixed' );
173 !( CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.quirks
) && mainDocument
.getBody().setStyles( styles
);
175 // Scroll to the top left (IE needs some time for it - http://dev.ckeditor.com/ticket/4923).
176 CKEDITOR
.env
.ie
? setTimeout( function() {
177 mainWindow
.$.scrollTo( 0, 0 );
178 }, 0 ) : mainWindow
.$.scrollTo( 0, 0 );
180 // Resize and move to top left.
181 // Special treatment for FF Quirks (http://dev.ckeditor.com/ticket/7284)
182 container
.setStyle( 'position', CKEDITOR
.env
.gecko
&& CKEDITOR
.env
.quirks
? 'fixed' : 'absolute' );
183 container
.$.offsetLeft
; // SAFARI BUG: See http://dev.ckeditor.com/ticket/2066.
184 container
.setStyles( {
185 // Show under floatpanels (-1) and context menu (-2).
186 'z-index': editor
.config
.baseFloatZIndex
- 5,
191 // Add cke_maximized class before resize handle since that will change things sizes (http://dev.ckeditor.com/ticket/5580)
192 container
.addClass( 'cke_maximized' );
196 // Still not top left? Fix it. (Bug http://dev.ckeditor.com/ticket/174)
197 var offset
= container
.getDocumentPosition();
198 container
.setStyles( {
199 left: ( -1 * offset
.x
) + 'px',
200 top: ( -1 * offset
.y
) + 'px'
203 // Fixing positioning editor chrome in Firefox break design mode. (http://dev.ckeditor.com/ticket/5149)
204 CKEDITOR
.env
.gecko
&& refreshCursor( editor
);
206 // Restore from fullscreen if the state is on.
207 else if ( this.state
== CKEDITOR
.TRISTATE_ON
) {
208 // Remove event handler for resizing.
209 mainWindow
.removeListener( 'resize', resizeHandler
);
211 // Restore CSS styles for the entire node tree.
212 var editorElements
= [ contents
, container
];
213 for ( var i
= 0; i
< editorElements
.length
; i
++ ) {
214 restoreStyles( editorElements
[ i
], editorElements
[ i
].getCustomData( 'maximize_saved_styles' ) );
215 editorElements
[ i
].removeCustomData( 'maximize_saved_styles' );
218 currentNode
= editor
.container
;
219 while ( ( currentNode
= currentNode
.getParent() ) ) {
220 restoreStyles( currentNode
, currentNode
.getCustomData( 'maximize_saved_styles' ) );
221 currentNode
.removeCustomData( 'maximize_saved_styles' );
224 // Restore the window scroll position.
225 CKEDITOR
.env
.ie
? setTimeout( function() {
226 mainWindow
.$.scrollTo( outerScroll
.x
, outerScroll
.y
);
227 }, 0 ) : mainWindow
.$.scrollTo( outerScroll
.x
, outerScroll
.y
);
229 // Remove cke_maximized class.
230 container
.removeClass( 'cke_maximized' );
232 // Webkit requires a re-layout on editor chrome. (http://dev.ckeditor.com/ticket/6695)
233 if ( CKEDITOR
.env
.webkit
) {
234 container
.setStyle( 'display', 'inline' );
235 setTimeout( function() {
236 container
.setStyle( 'display', 'block' );
240 // Emit a resize event, because this time the size is modified in
242 editor
.fire( 'resize', {
243 outerHeight: editor
.container
.$.offsetHeight
,
244 contentsHeight: contents
.$.offsetHeight
,
245 outerWidth: editor
.container
.$.offsetWidth
251 // Toggle button label.
252 var button
= this.uiItems
[ 0 ];
253 // Only try to change the button if it exists (http://dev.ckeditor.com/ticket/6166)
255 var label
= ( this.state
== CKEDITOR
.TRISTATE_OFF
) ? lang
.maximize
.maximize : lang
.maximize
.minimize
;
256 var buttonNode
= CKEDITOR
.document
.getById( button
._
.id
);
257 buttonNode
.getChild( 1 ).setHtml( label
);
258 buttonNode
.setAttribute( 'title', label
);
259 buttonNode
.setAttribute( 'href', 'javascript:void("' + label
+ '");' ); // jshint ignore:line
262 // Restore selection and scroll position in editing area.
263 if ( editor
.mode
== 'wysiwyg' ) {
264 if ( savedSelection
) {
265 // Fixing positioning editor chrome in Firefox break design mode. (http://dev.ckeditor.com/ticket/5149)
266 CKEDITOR
.env
.gecko
&& refreshCursor( editor
);
268 editor
.getSelection().selectRanges( savedSelection
);
269 var element
= editor
.getSelection().getStartElement();
270 element
&& element
.scrollIntoView( true );
272 mainWindow
.$.scrollTo( savedScroll
.x
, savedScroll
.y
);
275 if ( savedSelection
) {
276 $textarea
.selectionStart
= savedSelection
[ 0 ];
277 $textarea
.selectionEnd
= savedSelection
[ 1 ];
279 $textarea
.scrollLeft
= savedScroll
[ 0 ];
280 $textarea
.scrollTop
= savedScroll
[ 1 ];
283 savedSelection
= savedScroll
= null;
284 savedState
= this.state
;
286 editor
.fire( 'maximize', this.state
);
291 editor
.ui
.addButton
&& editor
.ui
.addButton( 'Maximize', {
292 label: lang
.maximize
.maximize
,
297 // Restore the command state after mode change, unless it has been changed to disabled (http://dev.ckeditor.com/ticket/6467)
298 editor
.on( 'mode', function() {
299 var command
= editor
.getCommand( 'maximize' );
300 command
.setState( command
.state
== CKEDITOR
.TRISTATE_DISABLED
? CKEDITOR
.TRISTATE_DISABLED : savedState
);
301 }, null, null, 100 );
307 * Event fired when the maximize command is called.
308 * It also indicates whether an editor is maximized or not.
311 * @member CKEDITOR.editor
312 * @param {CKEDITOR.editor} editor This editor instance.
313 * @param {Number} data Current state of the command. See {@link CKEDITOR#TRISTATE_ON} and {@link CKEDITOR#TRISTATE_OFF}.