You are here

function beautytips_manager_build_beautytip in BeautyTips 7.2

Same name and namespace in other branches
  1. 8 beautytips_manager/beautytips_manager.module \beautytips_manager_build_beautytip()
  2. 6.2 beautytips_manager.module \beautytips_manager_build_beautytip()

Given a custom tip, build an array of options that can be passed to beautytips_add_beautytips().

1 call to beautytips_manager_build_beautytip()
beautytips_manager_init in ./beautytips_manager.module
Implements hook_init().

File

./beautytips_manager.module, line 218
Code related to defining and displaying custom beautytips and styles.

Code

function beautytips_manager_build_beautytip($tip) {
  $single_triggers = [
    'hover',
    'hoverIntent',
  ];
  $trigger = in_array($tip->trigger_on, $single_triggers) ? $tip->trigger_on : [
    $tip->trigger_on,
    $tip->trigger_off,
  ];
  $options = [
    'cssSelect' => check_plain($tip->element),
    'style' => $tip->style,
    'trigger' => $trigger,
    'shrinkToFit' => (bool) $tip->shrink,
    'ajaxDisableLink' => (bool) $tip->disable_link,
  ];
  if ($tip->animation_on) {
    $options['animate']['on'] = $tip->animation_on;
  }
  if ($tip->animation_off) {
    $options['animate']['off'] = $tip->animation_off;
  }
  if ($tip->positions) {
    $options['positions'] = explode(',', $tip->positions);
  }
  switch ($tip->content_type) {
    case 'attribute':
      if ($tip->content) {
        $options['contentSelector'] = "\$(this).attr('" . check_plain($tip->content) . "')";
      }
      break;
    case 'text':
      $options['text'] = check_markup($tip->content);
      break;
    case 'ajax':
      $options['ajaxPath'] = !$tip->content ? "\$(this).attr('href')" : [
        "\$(this).attr('href')",
        filter_xss($tip->content),
      ];
      break;
    case 'js':
      $options['contentSelector'] = filter_xss($tip->content);
      break;
  }
  return $options;
}