You are here

function img_assist_textarea in Image Assist 5.3

Same name and namespace in other branches
  1. 5 img_assist.module \img_assist_textarea()
  2. 5.2 img_assist.module \img_assist_textarea()
  3. 6.2 img_assist.module \img_assist_textarea()
  4. 6 img_assist.module \img_assist_textarea()

Add JavaScript settings for generating the image link underneath textareas.

File

./img_assist.module, line 143
Image Assist module

Code

function img_assist_textarea($element) {
  static $initialized = FALSE;
  if (!user_access('access img_assist')) {
    return $element;
  }
  $link = variable_get('img_assist_link', 'icon');
  if ($link == 'icon' || $link == 'text') {
    if (_img_assist_textarea_match($element['#id']) && _img_assist_page_match() && !strstr($_GET['q'], 'img_assist')) {
      if (!$initialized) {

        // Add settings.
        $settings['link'] = $link;
        $settings['link_text'] = t('Add image');

        // D5 only.
        if ($link == 'icon') {
          $settings['icon'] = drupal_get_path('module', 'img_assist') . '/add-image.jpg';
        }
        drupal_add_js(array(
          'img_assist' => $settings,
        ), 'setting');
        $initialized = TRUE;
      }

      // Attach behavior.
      // @todo Some browsers do not support underscores in CSS classes.
      if (!isset($element['#attributes']['class'])) {
        $element['#attributes']['class'] = 'img_assist';
      }
      else {
        $element['#attributes']['class'] .= ' img_assist';
      }
    }
  }
  return $element;
}