You are here

function tinybrowser_textarea in TinyBrowser 7

Inline image/link insertion to textareas.

3 string references to 'tinybrowser_textarea'
tinybrowser_admin_submit in ./tinybrowser.module
Submit admin form
tinybrowser_element_info in ./tinybrowser.module
Implements hook_element_info().
tinybrowser_settings_form in ./tinybrowser.module

File

./tinybrowser.module, line 1096

Code

function tinybrowser_textarea($element, $form_state, $complete_form) {
  static $ids;
  if (!isset($ids)) {
    $ids = FALSE;
    if (tinybrowser_access() && ($setting = str_replace(' ', '', variable_get('tinybrowser_textarea', '')))) {
      $ids = array();
      foreach (explode(',', $setting) as $id) {
        $ids[$id] = 1;
      }
    }
  }

  // $ids is something like below when user entered
  //  'edit-body-und-0-summary, edit-body-und-0-value' in the config page
  // Array(
  //   [edit-body-und-0-summary] => 1,
  //   [edit-body-und-0-value] => 1,
  // );
  //
  // $element['#id'] is the ID of the current form element
  //
  // This function is called for every 'textfield' and 'textarea' form element.
  //
  if ($ids) {
    if (isset($ids[$element['#id']]) || tinybrowser_id_match($ids, $element['#id'])) {
      tinybrowser_set_js_variables();
      drupal_add_js(drupal_get_path('module', 'tinybrowser') . '/tinybrowser/tb_standalone.js');
      if (!isset($element['#description'])) {
        $element['#description'] = '';
      }

      // avoid warning
      $element['#description'] .= '<div class="tinybrowser-inline-wrapper">' . t('Insert !image or !link.', array(
        '!image' => '<a href="" onclick="tinyBrowserPopUp(\'image\',\'' . $element['#id'] . '\'); return false;">' . t('image') . '</a>',
        '!link' => '<a href="" onclick="tinyBrowserPopUp(\'file\',\'' . $element['#id'] . '\'); return false;">' . t('link') . '</a>',
      )) . '</div>';
    }
  }
  return $element;
}