Ticket #4606: plugin.js

File plugin.js, 1.8 KB (added by Wesley Walser, 14 years ago)

autogrow plugin

Line 
1(function() 
2{
3        function check( editor, wrapper ) 
4        {
5                var desiredHeight = getDesiredHeight(editor),
6                        currentHeight = editor.window.getViewPaneSize().height,
7                        newHeight = getEffectiveHeight( editor, desiredHeight );
8
9                if ( newHeight != currentHeight )
10                {
11                        newHeight = editor.fire( 'beforeAutogrow' , {currentHeight : currentHeight, newHeight : newHeight} ).newHeight;
12                       
13                        wrapper.setStyle('height', newHeight + 'px');
14                        editor.fire( 'afterAutogrow' );
15                }
16        }
17
18        function getEffectiveHeight( editor, height ) 
19        {
20                var min = editor.config.autogrowMinHeight,
21                        max = editor.config.autogrowMaxHeight;
22                if ( min && min > height ) 
23                        height = min;
24                else if ( max && max < height ) 
25                        height = max;
26                return height;
27        }
28
29        function getDesiredHeight( editor ) 
30        {
31                var doc = editor.document.$,
32                        size;
33
34                if ( CKEDITOR.env.ie )
35                        size = doc.documentElement.scrollHeight;
36                else 
37                        size = doc.documentElement.offsetHeight;
38                return size;
39        }
40
41        CKEDITOR.plugins.add( 'autogrow', {
42               
43                init : function( editor ) 
44                {
45                        editor.on( 'mode', function( event )
46                        {
47                                event.removeListener();
48                                var wrapper = CKEDITOR.document.getById('cke_contents_' + editor.name);
49                                function listener () 
50                                {
51                                        check(editor, wrapper);
52                                }
53
54                                editor.on('contentDom', listener);
55                                editor.on('key', listener);
56                                editor.on('selectionChange', listener);
57                                editor.on('insertElement', function() 
58                                {
59                                        setTimeout(listener, 1000);
60                                });
61                        });
62                }
63        });
64
65        /**
66         * Minimum height of an editor instance that uses the autogrow plugin
67         * @type Number
68         * @default 200
69         * @example
70         * config.autogrowMinHeight = 200;
71         */
72        CKEDITOR.config.autogrowMinHeight = 200;
73
74        /**
75         * Maximum height of an editor instance that uses the autogrow plugin
76         * @type Number
77         * @default 500
78         * @example
79         * config.autogrowMaxHeight = 500;
80         */
81        CKEDITOR.config.autogrowMaxHeight = 500;
82})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy