You are here

function img_assist_textarea in Image Assist 6.2

Same name and namespace in other branches
  1. 5.3 img_assist.module \img_assist_textarea()
  2. 5 img_assist.module \img_assist_textarea()
  3. 5.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.

1 string reference to 'img_assist_textarea'
img_assist_elements in ./img_assist.module
Implementation of hook_elements().

File

./img_assist.module, line 151
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;
        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;
}