I have repurposed the fckeditor2 autogrow feature for ckeditor 3 and it works fine (IE7 and FF3.5) - tho please feel free to point out anything redundant as I feel I have been staring at this way too long.
I just need the vertical scrollbar to be hidden at all times, cos it looks silly flashing on and off. and wondered if anyone knew which container it is in as my random poking as not been successful (unless caching was ruining my testing)
This is my code for the autogrow functionality: (I only needed vertical growth but I can add horizontal in once I have got it all working if anyone is interested)
plugins/autogrow/plugin.js
(added via config option:= extraPlugins:autogrow' )
I just need the vertical scrollbar to be hidden at all times, cos it looks silly flashing on and off. and wondered if anyone knew which container it is in as my random poking as not been successful (unless caching was ruining my testing)
This is my code for the autogrow functionality: (I only needed vertical growth but I can add horizontal in once I have got it all working if anyone is interested)
plugins/autogrow/plugin.js
(added via config option:= extraPlugins:autogrow' )
(function() { CKEDITOR.plugins.autogrow = { getHeightDelta : function( editor ) { var contents = CKEDITOR.document.getById( 'cke_contents_' + editor.name ); var outer = contents.getAscendant( 'table' ).getParent().getParent().getParent(); // Get the height delta between the outer table and the content area. var delta = ( outer.$.offsetHeight || 0 ) - ( contents.$.clientHeight || 0 ); return delta; }, getEffectiveHeight : function( height ) { if ( height < CKEDITOR.config.autogrow_minheight ) height = CKEDITOR.config.autogrow_minheight; else { var max = CKEDITOR.config.autogrow_maxheight; if ( max && max > 0 && height > max ) height = max; } return height; } }; function checkSize ( evt ) { var editor = evt.editor; var delta = plugin.getHeightDelta(editor) ; var $body = editor.document.$.body; if(delta != 0){ var newHeight = delta + $body.offsetHeight; newHeight = plugin.getEffectiveHeight( newHeight ) ; var contents = CKEDITOR.document.getById( 'cke_contents_' + editor.name ); newHeight = Math.max( newHeight, 0 ) + 'px'; if(contents.getStyle('height') != newHeight) { contents.setStyle( 'height', newHeight ); } } }; var plugin = CKEDITOR.plugins.autogrow; CKEDITOR.plugins.add( 'autogrow', { init : function( editor ) { editor.on( 'insertHtml', checkSize ); editor.on( 'insertElement', checkSize ); editor.on( 'selectionChange', checkSize ); editor.on( 'instanceReady', checkSize ); } } ); })(); CKEDITOR.config.autogrow_maxheight = 0; CKEDITOR.config.autogrow_minheight = 50;
Re: Hide Scrollbar for my autogrow functionality
One question - does
have to be set in the plugin.js file? Can it be set in my CKEDITOR.replace call?
There may be situations where each editor should have different startup heights.
Thanks!
Re: Hide Scrollbar for my autogrow functionality
So the default values are in the plugin but they will be overwritten if you set them in the replace
Thank you so much for the input
Re: Hide Scrollbar for my autogrow functionality
Can you explain this comment?
I wanted to avoid the editor from doing its resizing at startup (the flicker looked odd) so I set height: value equal to the autogrow_minheight: value in my Replace call. In doing so, I found that the editor was still resizing at startup. I determined that my height: value needed to be 10 units higher than that of autogrow_minheight:
I suppose this is coming from the 10units you added as mentioned in the comment.
Re: Hide Scrollbar for my autogrow functionality
However, if you are not removing the resize plugin then you could remove this 10px.
What I really should have done is either
a) done a check to see if the resize plugin was active or not
b) find the magic id that would give me the right height in the first place.
I will have a look at this this evening and see if I can do one of the above...
Re: Hide Scrollbar for my autogrow functionality
anyhow.. I have tweaked autogrow so you can provide your own padding from config if you need it
I have also changed it so it still works if the delta value =0 (which occurs when you hack the style sheet to remove all the padding you don't really want and removePlugins: resize,elementspath)
so it still isn't perfect as I would prefer not to have to hack some padding in.. but I am just not sure how else to do it. But at least you have the option to change the value/set to 0 if you need to
Re: Hide Scrollbar for my autogrow functionality
What padding is affected by the autogrow value?
On another note, is your editor available for public viewing? I would love to check out your settings since it looks like you have alot of experience with CKEditor.
Re: Hide Scrollbar for my autogrow functionality
It all worked fine when I still had the plugins resize and elementspath, but removing them just upset it, so the vertical padding was added (basically it just extends the editable area to a tad longer than it needs for the content in it). but if you don't need it. Don't include it.
Also sometimes a little extra space at the bottom looks nice and it has the added advantage that the vertical scrollbar doesn't flicker in and out as much...
Would you believe it but my editor isn't actually finished yet. Still have some magic to weave. The main bits are there but it kinda looks like crap at the moment so need to make it pretty. Basically I had a WYSIWYG editor based on fckeditor 2.0 and I foolishly decided to upgrade it, which actually turned into a complete rewrite and if I ever finish it.. It will be better than the original (mainly because scope creep crept in)