Short snipped removing default resizable “grippie” from textarea in favor of using the “resize” CSS3 property. No more resizable textareas, no more textarea expanders 🙂
Why I don’t like Grippie?
Why I don’t like Grippie, resizable textarea feature in Drupal? I think, it’s relict from the IE6 era + it’s another server request (grippie.png) + and therefore another useless bunch of JavaScript code.
How to disable resizable textarea in Drupal
This code is from Drupal textarea API page function theme_textarea:
function theme_textarea($variables) {
$element = $variables ['element'];
element_set_attributes($element, array('id', 'name', 'cols', 'rows'));
_form_set_class($element, array('form-textarea'));
$wrapper_attributes = array(
'class' => array('form-textarea-wrapper'),
);
// Add resizable behavior.
if (!empty($element ['#resizable'])) {
drupal_add_library('system', 'drupal.textarea');
$wrapper_attributes ['class'][] = 'resizable';
}
$output = '<div' . drupal_attributes($wrapper_attributes) . '>';
$output .= '<textarea' . drupal_attributes($element ['#attributes']) . '>' . check_plain($element ['#value']) . '</textarea>';
$output .= '</div>';
return $output;
}
Core of the trick – simple remove this part:
// Add resizable behavior.
if (!empty($element ['#resizable'])) {
drupal_add_library('system', 'drupal.textarea');
$wrapper_attributes ['class'][] = 'resizable';
}
And copy it to the template.php in your theme folder. Don’t forget to adjust the first line with your theme name. For example, my theme name id “crypto” so first line will be:
function crypto_textarea($variables) {
All code together in template.php will looks like:
/**
* Override of theme('textarea').
* Deprecate misc/textarea.js in favor of using the 'resize' CSS3 property.
*/
function crypto_textarea($variables) {
$element = $variables ['element'];
element_set_attributes($element, array('id', 'name', 'cols', 'rows'));
_form_set_class($element, array('form-textarea'));
$wrapper_attributes = array(
'class' => array('form-textarea-wrapper'),
);
$output = '<div' . drupal_attributes($wrapper_attributes) . '>';
$output .= '<textarea' . drupal_attributes($element ['#attributes']) . '>' . check_plain($element ['#value']) . '</textarea>';
$output .= '</div>';
return $output;
}
Flush all caches and that’s it! You have successfully removed resizable textarea from your Drupal installation.
Update:
If you are extra lazy drupaler, check out the module Disable resizable textarea.
Leave a Reply