/**
* Add javascript support for Bootstrap tooltips
*
* Add a title attribute to any element in the form
* title="title::text"
*
* @param string $selector The ID selector for the tooltip.
* @param array $options An array of options for the tooltip.
*
* @return void
*
* @since 3.0
*
* Options for the tooltip can be:
* - animation boolean apply a css fade transition to the popover
* - container string|boolean Appends the popover to a specific element: { container: 'body' }
* - delay number|object delay showing and hiding the popover (ms) - does not apply to manual trigger type
* If a number is supplied, delay is applied to both hide/show
* Object structure is: delay: { show: 500, hide: 100 }
* - html boolean Insert HTML into the popover. If false, jQuery's text method will be used to
* insert content into the dom.
* - placement string|function how to position the popover - top | bottom | left | right
* - selector string If a selector is provided, popover objects will be
* delegated to the specified targets.
* - template string Base HTML to use when creating the popover.
* - title string|function default title value if `title` tag isn't present
* - trigger string how popover is triggered - hover | focus | manual
* - constraints array An array of constraints - passed through to Popper.
* - offset string Offset of the popover relative to its target.
*/
public static function tooltip($selector = '', $options = []) : void
{
// Only load once
if (isset(static::$loaded[__METHOD__][$selector])) {
return;
}
if ($selector !== '') {
// Setup options object
$opt['animation'] = isset($options['animation']) ? (bool) $options['animation'] : true;
$opt['container'] = isset($options['container']) ? $options['container'] : 'body';
$opt['delay'] = isset($options['delay']) ? (int) $options['delay'] : 0;
$opt['html'] = isset($options['html']) ? (bool) $options['html'] : true;
$opt['placement'] = isset($options['placement']) ? $options['placement'] : null;
$opt['selector'] = isset($options['selector']) ? $options['selector'] : false;
$opt['template'] = isset($options['template']) ? $options['template'] : null;
$opt['title'] = isset($options['title']) ? $options['title'] : null;
$opt['trigger'] = isset($options['trigger']) ? $options['trigger'] : 'hover focus';
$opt['fallbackPlacement'] = isset($options['fallbackPlacement']) ? $options['fallbackPlacement'] : null;
$opt['boundary'] = isset($options['boundary']) ? $options['boundary'] : 'clippingParents';
$opt['customClass'] = isset($options['customClass']) ? $options['customClass'] : null;
$opt['sanitize'] = isset($options['sanitize']) ? (bool) $options['sanitize'] : true;
$opt['allowList'] = isset($options['allowList']) ? $options['allowList'] : null;
Factory::getDocument()->addScriptOptions('bootstrap.tooltip', [$selector => (object) array_filter((array) $opt)]);
}
// Include the Bootstrap component
Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.popover');
// Set static array
static::$loaded[__METHOD__][$selector] = true;
}