You are here

function beautytips_admin in BeautyTips 7.2

Same name and namespace in other branches
  1. 6.2 beautytips.admin.inc \beautytips_admin()
  2. 6 beautytips.module \beautytips_admin()

Menu callback - beautytips admin settings form

1 string reference to 'beautytips_admin'
beautytips_menu in ./beautytips.module
Implements hook_menu().

File

./beautytips.admin.inc, line 11
Beautytips settings form and submit action

Code

function beautytips_admin() {
  $form['beautytips_always_add'] = [
    '#title' => t('Add beautytips js to every page'),
    '#description' => t('This allows you to give the class \'beautytips\' to any element on a page and the title attribute will popup as a beautytip.<br /> i.e. <i> &lt;p class="beautytips" title="type the text you want beautytips to display here"&gt .....&lt/p&gt</i>'),
    '#type' => 'checkbox',
    '#default_value' => variable_get('beautytips_always_add', 0),
    '#weight' => -1,
  ];
  $selectors = variable_get('beautytips_added_selectors_array', '');
  $form['beautytips_added_selectors_string'] = [
    '#title' => t('Add beautytips to the following selectors'),
    '#description' => t("Separate selectors with a comma.  Beautytips will be added to each of these on every page.  The element's title attribute will be the text used. (OPTIONAL)"),
    '#type' => 'textfield',
    '#default_value' => is_array($selectors) ? implode(", ", $selectors) : '',
    '#weight' => -1,
  ];
  $form['beautytips_ltr'] = [
    '#title' => t('Support Left to Right display'),
    '#description' => t('Only check this if this is an ltr site.  This adds css to support it.'),
    '#type' => 'checkbox',
    '#default_value' => variable_get('beautytips_ltr', 0),
  ];
  $form['beautytips_default_styles'] = [
    '#type' => 'fieldset',
    '#title' => 'Styling Options',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];
  $styles = beautytips_get_styles(TRUE);
  if (count($styles)) {
    unset($styles['default']);
    foreach ($styles as $name => $style) {
      $bt_style_options[$name]['cssSelect'] = '#edit-beautytips-default-style-' . str_replace('_', '-', $name);
      $bt_style_options[$name]['text'] = 'Aenean risus purus, pharetra in, blandit quis, gravida a, turpis.  Aenean risus purus, pharetra in, blandit quis, gravida a, turpis.  Aenean risus purus, pharetra in, blandit quis, gravida a, turpis.';
      $bt_style_options[$name]['width'] = isset($style['width']) ? $style['width'] : '300px';
      $bt_style_options[$name]['style'] = $name;
      $style_options[$name] = $name;
    }
  }
  $bt_style_options['default_hover'] = [
    'cssSelect' => '#beautytips-site-wide-popup',
    'text' => 'Sed justo nibh, ultrices ut gravida et, laoreet et elit. Nullam consequat lacus et dui dignissim venenatis. Curabitur quis urna eget mi interdum viverra quis eu enim. Ut sit amet nunc augue. Morbi fermentum ultricies velit sed aliquam. Etiam dui tortor, auctor sed tempus ac, auctor sed sapien.',
    'positions' => [
      'right',
    ],
  ];

  // TODO: Determine what to do if default style has been removed.
  $form['beautytips_default_styles']['beautytips_default_style'] = [
    '#type' => 'radios',
    '#title' => t('Choose a default style'),
    '#description' => t('Mouse over the radio buttons to see a preview.'),
    '#prefix' => '<div id="beauty-default-styles">',
    '#suffix' => '</div>',
    '#options' => $style_options,
    '#default_value' => variable_get('beautytips_default_style', 'plain'),
  ];
  $style_options = [
    'fill' => t('background color (string - html color)'),
    'strokeWidth' => t('width of border (integer)'),
    'strokeStyle' => t('color of border (string - html color)'),
    'width' => t('width of popup (number in px)'),
    'padding' => t('space between content and border (number in px)'),
    'cornerRadius' => t('Controls roundness of corners (integer)'),
    'spikeGirth' => t('thickness of spike (integer)'),
    'spikeLength' => t('length of spike (integer)'),
    'shadowBlur' => t('Size of popup shadow (integer)'),
    'shadowColor' => t('Color of popup shadow (string - html color)'),
  ];
  $form['beautytips_default_styles']['custom_styles'] = [
    '#type' => 'fieldset',
    '#title' => t('Custom Style Options'),
    '#description' => t('<b>Set a custom style.</b><br /> Note: These will use the default style that is selected as a base <br /> but will overide elements such as background color, border color etc.   <br /><i>Leave these empty unless you know what you are doing.</i><div id="beautytips-popup-changes"><div id="beauty-click-text"><p>Double Click here to view popup with custom changes</p></div></div>'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#attributes' => [
      'class' => [
        'bt-custom-styles',
      ],
    ],
    '#prefix' => '<div id="beautytips-site-wide-popup"><div id="beauty-text"><p>Hover here to see the current site-wide beautytips</p></div></div>',
  ];
  $custom_style = variable_get('beautytips_custom_style', NULL);
  foreach ($style_options as $option => $description) {
    $form['beautytips_default_styles']['custom_styles']['bt-options-box-' . $option] = [
      '#title' => $option,
      '#description' => $description,
      '#type' => 'textfield',
      '#default_value' => isset($custom_style[$option]) ? $custom_style[$option] : '',
    ];
  }
  $form['beautytips_default_styles']['custom_styles']['bt-options-box-shadow'] = [
    '#title' => 'shadow',
    '#description' => t('Whether or not the popup has a shadow'),
    '#type' => 'radios',
    '#options' => [
      'default' => t('Default'),
      'shadow' => t('Shadow On'),
      'no_shadow' => t('Shadow Off'),
    ],
    '#attributes' => [
      'class' => [
        'beautytips-options-shadow',
      ],
    ],
    '#default_value' => isset($custom_style['shadow']) ? $custom_style['shadow'] : 'default',
  ];
  $form['beautytips_default_styles']['custom_styles']['bt-options-cssClass'] = [
    '#title' => 'cssClass',
    '#description' => t('The class that will be applied to the box wrapper div (of the TIP)'),
    '#type' => 'textfield',
    '#default_value' => isset($custom_style['cssClass']) ? $custom_style['cssClass'] : '',
  ];
  $css_style_options = [
    'color',
    'fontFamily',
    'fontWeight',
    'fontSize',
  ];
  $form['beautytips_default_styles']['custom_styles']['css-styles'] = [
    '#type' => 'fieldset',
    '#title' => t('Font Styling'),
    '#description' => t('Enter css options for changing the font style'),
    '#attributes' => [
      'class' => [
        'beautytips-css-styling',
      ],
    ],
    '#collapsible' => FALSE,
  ];
  foreach ($css_style_options as $option) {
    $form['beautytips_default_styles']['custom_styles']['css-styles']['bt-options-css-' . $option] = [
      '#title' => $option,
      '#type' => 'textfield',
      '#default_value' => isset($custom_style['cssStyles'][$option]) ? $custom_style['cssStyles'][$option] : '',
    ];
  }
  $form['#submit'][] = 'beautytips_admin_submit';
  $path = drupal_get_path('module', 'beautytips');
  drupal_add_js($path . '/other_libs/colorpicker/js/colorpicker.js');
  drupal_add_css($path . '/other_libs/colorpicker/css/colorpicker.css');
  drupal_add_css($path . '/css/beautytips.css');
  beautytips_add_beautytips($bt_style_options);
  drupal_add_js($path . '/js/bt_admin_page.js');
  if (module_exists('beautytips_ui')) {
    beautytips_ui_admin_settings($form);
  }
  return system_settings_form($form);
}