source: trunk/admin/inc/ckeditor/_source/plugins/autogrow/plugin.js@ 407

Last change on this file since 407 was 239, checked in by luc, 9 years ago

Admin: correzione visulaizzazione immissione dati spoglio per Chrome e Safari - Aggiornamento dell'editor da FCKeditor a CKeditor , accessibili anche a Chrome e Safari.

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1/*
2Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3For licensing, see LICENSE.html or http://ckeditor.com/license
4*/
5
6/**
7 * @file AutoGrow plugin
8 */
9(function(){
10
11 // Actual content height, figured out by appending check the last element's document position.
12 function contentHeight( scrollable )
13 {
14 var overflowY = scrollable.getStyle( 'overflow-y' );
15
16 var doc = scrollable.getDocument();
17 // Create a temporary marker element.
18 var marker = CKEDITOR.dom.element.createFromHtml( '<span style="margin:0;padding:0;border:0;clear:both;width:1px;height:1px;display:block;">' + ( CKEDITOR.env.webkit ? '&nbsp;' : '' ) + '</span>', doc );
19 doc[ CKEDITOR.env.ie? 'getBody' : 'getDocumentElement']().append( marker );
20
21 var height = marker.getDocumentPosition( doc ).y + marker.$.offsetHeight;
22 marker.remove();
23 scrollable.setStyle( 'overflow-y', overflowY );
24 return height;
25 }
26
27 var resizeEditor = function( editor )
28 {
29 if ( !editor.window )
30 return;
31
32 var doc = editor.document,
33 iframe = new CKEDITOR.dom.element( doc.getWindow().$.frameElement ),
34 body = doc.getBody(),
35 htmlElement = doc.getDocumentElement(),
36 currentHeight = editor.window.getViewPaneSize().height,
37 // Quirks mode overflows body, standards overflows document element
38 scrollable = doc.$.compatMode == 'BackCompat' ? body : htmlElement,
39 newHeight = contentHeight( scrollable );
40
41 // Additional space specified by user.
42 newHeight += ( editor.config.autoGrow_bottomSpace || 0 );
43
44 var min = editor.config.autoGrow_minHeight != undefined ? editor.config.autoGrow_minHeight : 200,
45 max = editor.config.autoGrow_maxHeight || Infinity;
46
47 newHeight = Math.max( newHeight, min );
48 newHeight = Math.min( newHeight, max );
49
50 if ( newHeight != currentHeight )
51 {
52 newHeight = editor.fire( 'autoGrow', { currentHeight : currentHeight, newHeight : newHeight } ).newHeight;
53 editor.resize( editor.container.getStyle( 'width' ), newHeight, true );
54 }
55
56 if ( scrollable.$.scrollHeight > scrollable.$.clientHeight && newHeight < max )
57 scrollable.setStyle( 'overflow-y', 'hidden' );
58 else
59 scrollable.removeStyle( 'overflow-y' );
60
61
62 };
63
64 CKEDITOR.plugins.add( 'autogrow',
65 {
66 init : function( editor )
67 {
68 editor.addCommand( 'autogrow', { exec : resizeEditor, modes : { wysiwyg:1 }, readOnly: 1, canUndo: false, editorFocus: false } );
69
70 var eventsList = { contentDom:1, key:1, selectionChange:1, insertElement:1 };
71 editor.config.autoGrow_onStartup && ( eventsList[ 'instanceReady' ] = 1 );
72 for ( var eventName in eventsList )
73 {
74 editor.on( eventName, function( evt )
75 {
76 var maximize = editor.getCommand( 'maximize' );
77 // Some time is required for insertHtml, and it gives other events better performance as well.
78 if ( evt.editor.mode == 'wysiwyg' &&
79 // Disable autogrow when the editor is maximized .(#6339)
80 ( !maximize || maximize.state != CKEDITOR.TRISTATE_ON ) )
81 {
82 setTimeout( function()
83 {
84 resizeEditor( evt.editor );
85 // Second pass to make correction upon
86 // the first resize, e.g. scrollbar.
87 resizeEditor( evt.editor );
88 }, 100 );
89 }
90 });
91 }
92 }
93 });
94})();
95/**
96 * The minimum height that the editor can reach using the AutoGrow feature.
97 * @name CKEDITOR.config.autoGrow_minHeight
98 * @type Number
99 * @default <code>200</code>
100 * @since 3.4
101 * @example
102 * config.autoGrow_minHeight = 300;
103 */
104
105/**
106 * The maximum height that the editor can reach using the AutoGrow feature. Zero means unlimited.
107 * @name CKEDITOR.config.autoGrow_maxHeight
108 * @type Number
109 * @default <code>0</code>
110 * @since 3.4
111 * @example
112 * config.autoGrow_maxHeight = 400;
113 */
114
115 /**
116 * Whether to have the auto grow happen on editor creation.
117 * @name CKEDITOR.config.autoGrow_onStartup
118 * @type Boolean
119 * @default false
120 * @since 3.6.2
121 * @example
122 * config.autoGrow_onStartup = true;
123 */
124
125/**
126 * Fired when the AutoGrow plugin is about to change the size of the editor.
127 * @name CKEDITOR.editor#autogrow
128 * @event
129 * @param {Number} data.currentHeight The current height of the editor (before resizing).
130 * @param {Number} data.newHeight The new height of the editor (after resizing). It can be changed
131 * to determine a different height value to be used instead.
132 */
133
134
135/**
136 * Extra height in pixel to leave between the bottom boundary of content with document size when auto resizing.
137 * @name CKEDITOR.config.autoGrow_bottomSpace
138 * @type Number
139 * @default 0
140 * @since 3.6.2
141 */
Note: See TracBrowser for help on using the repository browser.