You are here

function beautytips_manager_build_beautytip in BeautyTips 8

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

Given a custom tip.

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_page_attachments in beautytips_manager/beautytips_manager.module
Implements hook_page_attachments().

File

beautytips_manager/beautytips_manager.module, line 184
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' => Html::escape($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('" . Html::escape($tip->content) . "')";
      }
      break;
    case 'text':
      $options['text'] = new FormattableMarkup($tip->content);
      break;
    case 'ajax':
      $options['ajaxPath'] = !$tip->content ? "\$(this).attr('href')" : [
        "\$(this).attr('href')",
        Xss::filter($tip->content),
      ];
      break;
    case 'js':
      $options['contentSelector'] = Xss::filter($tip->content);
      break;
  }
  return $options;
}