Respect the number of rows set in the field configuration to adjust the height of the text edit box. Patch created from code by K3vin in #5.

Files: 

Comments

mkesicki’s picture

Status:Active» Needs review

@Diogenes,
thank you for patch. We try check this as soon as possible.

BBC’s picture

Thanks for this. The patch works nicely. Any pointers for making this work on content types where a field has unlimited values?

I'm hoping that there's an easy way to put a regular expression in the case such that any of the following would match, but haven't been having any luck so far.

edit-fieldname-und-0-view
edit-fieldname-und-1-view
edit-fieldname-und-2-view
etc.

Thanks!

Diogenes’s picture

Good question. It wasn't clear to me how these index numbers were generated. Now it is.

You can add multiple case statements for the same block of code or you could add a default case statement block that would render each case of the unlimited set to be the same size. See if that works.

-Dio

K3vin’s picture

StatusFileSize
new478 bytes

I had the same issue and took a different approach to fix it by adding a bit of custom javascript via a module.

<?php
function mymodule_global_preprocess_page(&$variables){
 
// Add script to node edit page, to resize the CKEditor.
 
if (arg(2) == 'edit' || arg(3) == 'edit'){
   
drupal_add_js(drupal_get_path('module', 'mymodule_global') . '/ckeditor-tweak.js');
  }
}
?>
(function ($) {
  // Tweak the CKEditors height depending upon the numbers of rows set in the
  // select area.
  Drupal.behaviors.CKEditorTweak = {
    attach: function (context) {
      if (typeof(CKEDITOR) != 'undefined'){
        CKEDITOR.on('instanceReady', function(e) {
          var name = e.editor.name;
          var rows = $("#" + name).eq(0).attr('rows');
          if (rows){
            var height = 150 + rows * 40;
            e.editor.resize('100%', height);
          }
        } );
      }
    }
  };
})(jQuery)

The script checks the number of rows the original textarea was set to and scales the editor accordingly, if it is of use to anyone, I have attached it here.

Willynux’s picture

Diogenes method works although I had to change the id from edit-body-und-0-summary to edit-body-en-0-summary.
This would be a nice patch to be included on the module (wysiwyg and/or ckeditor). It's a very useful feature.

Diogenes’s picture

@Willnux - good catch there!

I have never really understood how the language thingy works and after spending a morning trying to figure it out, I'm totally confounded.

I enabled the Locale and Content Translation modules, added another language, enabled multi lingual support on the content type, and added some new content in the new language. After I save this and look at the entry in the field_data_body table, it is ALWAYS 'und' in the language column. AFAIK, the ckeditor module uses this field to create the element id - so no matter how I have things configured, the textarea_id is always edit-body-und-0-value.

What am I missing?

Update: after reading this and this and this, I get the impression this used to work in D6 but does not work in D7. Arrrgh!!!

At any rate here is a slightly modified version of the Drupal.textareaSize() that will hopefully handle these situations. NOTE: no point using this for D7

   Drupal.textareaSize = function(textarea_id, textarea_settings) {
     // Clone the textarea_settings
     // @see http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object/122704#122704
     // @TODO - try out other methods listed in link

     // Deep copy here - not necessary.
     // var clone_set = jQuery.extend(true, {}, textarea_settings);
     // Shallow copy -- still uses jQuery.
     var clone_set = jQuery.extend({}, textarea_settings);
     // @todo - simple dom copy.

     // In the event that the textarea_id has a different language setting.
     var prefix = '-body-';
     var suffix = '-0-';
     var lang = 'und';
    
     var idx1 = textarea_id.indexOf(prefix);
     if(idx1 > 1) {
       // Determine the language setting if it is not 'undefined'.
       // 012345678901234567890
       //'edit-body-und-0-value'
       var idx2 = textarea_id.indexOf(suffix);
       lang = textarea_id.substring(idx1 + 6, idx2);
     }

     switch(textarea_id) {
       // For the summary edit box, if one exists
       case 'edit-body-und-0-summary':
       case 'edit-body-' + lang + '-0-summary':
         clone_set.height = 100;
         break;

       // This value is the visible height in pixels on an iPad I, landscape mode.
       // @see http://www.websitedimensions.com/
       // These are the id's for the plain text and rich text views.  With the
       // styling, a scroll bar will appear if the value is exceeded.
       case 'edit-body-und-0-value':
       case 'edit-body-' + lang + '-0-value':
         clone_set.height = 660;
         break;

       case 'edit-comment-body-und-0-value':
       case 'edit-comment-body-' + lang + '-0-value':
         clone_set.height = 100;
         break;

       default:
         break;
       }
       return clone_set;
   };

I really doubt this is the best way to do things, but it's a start.

Diogenes’s picture

@K3vin - Kudos to ya kid. I like your idea better than mine. Can you reroll it as a patch for this module?

K3vin’s picture

@Diogenes, sure no problem. Kinda busy now, so might take some time!

Renee S’s picture

K3vin: this is lovely, thanks, I just added it to my theme's js and it works perfectly.

ShaunDychko’s picture

#4 works great.

ShaunDychko’s picture

Issue summary:View changes
StatusFileSize
new798 bytes
mengi’s picture

Is this issue a duplicate of #1154730?

K3vin’s picture

I think so. And it looks like the solution in #1154730 is much nicer!

mengi’s picture

Test patch in number #11 and it works.

The patch in #1154730 (looks to be a duplicate issue) works as well. The patches take different approaches to adjustable the height of the widget. The patch in #1154730 gives a more accurate height in my opinion. Patch in #11 seems to add additional rows to the fields row number. The shortest I could get it was 5 rows.

DamienMcKenna’s picture

Status:Needs review» Closed (duplicate)
Issue tags:-ckeditor