Ticket #4454: resizewithwindow.plugin.js

File resizewithwindow.plugin.js, 2.8 KB (added by Paul Veldema, 11 years ago)
Line 
1/*
2 * This ckeditor resize plugin is an alternative to the 'resize' plugin.
3 * The plugin 'resize' must be disabled for this plugin to work.
4 *
5 * Also you need to add the following css to your css files:
6 * .cke_chrome {
7 *      padding: 0 !important;
8 *      }
9 *
10 * Currently only tested with the Kama skin and ckeditor 4.1.1.
11 *
12 */
13
14CKEDITOR.plugins.add( 'resizewithwindow', 
15{ 
16        init : function( editor )
17        {
18                var baseEditorInnerGrey;
19               
20                editor.on( "instanceReady",     function()
21                {
22                        jQuery( function()
23                        {
24                                // ckeditor 4
25                                jQuery( window ).resize( function()
26                                                {
27                                                        resizeTriggered() ;
28                                                }
29                                ) ;
30                                resizeTriggered();
31
32                        } )
33                } ) ;
34               
35                editor.on('afterCommandExec',function(e)
36                {
37                        if (e.data.name == 'toolbarCollapse' || e.data.name == 'maximize' || e.data.name == 'source') 
38                        {
39                                resizeTriggered();
40                        }
41                });
42               
43                editor.on('dataReady', function(e) {
44                        resizeTriggered();
45                });
46               
47                editor.on('triggerResize', function(e) {
48                        resizeTriggered();
49                });
50               
51                function resizeTriggered()
52                {
53                        var maximizestate = editor.getCommand( 'maximize' ).state;
54                        var referencedheight = 50;
55                       
56                        if ( maximizestate == CKEDITOR.TRISTATE_ON ) {
57                                referencedheight = jQuery(window).height();
58                        } else {
59                                var textarea = editor.element.$;
60                                var editorFrame = jQuery(textarea).parents( "div:first" ) ; 
61                                baseEditorInnerGrey = jQuery(".cke_inner", editorFrame);
62                                referencedheight = editorFrame.height();
63                        }
64                       
65                        var content = jQuery(".cke_contents", baseEditorInnerGrey);
66                        var toolbar = jQuery(".cke_top", baseEditorInnerGrey);
67                       
68                        // Browser quirks: this correction prevents a vertical scroll bar in the window.
69                        var extraheightCorrection = 8;
70                        if (jQuery.browser.mozilla) {
71                                extraheightCorrection = 11;
72                        }
73                        if (jQuery.browser.webkit) {
74                                extraheightCorrection = 12;
75                        }
76                        if (jQuery.browser.msie) {
77                                extraheightCorrection = 10;
78                        }
79                        baseEditorInnerGrey.height(referencedheight - extraheightCorrection);
80                       
81                        var toolbarHeight = toolbar.outerHeight( true ) ;
82                        // The text area height depends on the enabling of the charcount plugin.
83                        // Correct the height of the text area in java script because css does not work.
84                        var heightCorrection = 13;
85                        if (editor.config.extraPlugins.indexOf('wordcount') > -1) {
86                                var wordcount = jQuery(".cke_bottom", baseEditorInnerGrey);
87                                heightCorrection = wordcount.outerHeight( true ) ;
88                                // Extra height correction is needed on the content component.
89                                // Otherwise the characters of the wordcount component will not
90                                // stay within the grey (in case of the kama skin) background
91                                // component.
92                                heightCorrection += 7;
93                        }
94                        var newHeight = referencedheight - (toolbarHeight + heightCorrection) ;
95                        content.height( newHeight + "px");
96                }
97        }
98} ) ;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy