Back to Bootstrap class

Method dropdown

public static void
(mixed $selector = '', mixed $params = [])
Add javascript support for Bootstrap dropdowns
Parameters
  • string $selector Common class for the dropdowns
  • array $params The options for the dropdowns
Returns
  • void
Since
  • 4.0.0
Class: Bootstrap
Project: Joomla

Method dropdown - Source code

/**
 * Add javascript support for Bootstrap dropdowns
 *
 * @param   string  $selector  Common class for the dropdowns
 * @param   array   $params    The options for the dropdowns
 *
 * @return  void
 *
 * @since   4.0.0
 *
 * Options for the collapse can be:
 * - flip       boolean  true          Allow Dropdown to flip in case of an overlapping on the reference element
 * - boundary   string   scrollParent  Overflow constraint boundary of the dropdown menu
 * - reference  string   toggle        Reference element of the dropdown menu. Accepts 'toggle' or 'parent'
 * - display    string   dynamic       By default, we use Popper for dynamic positioning. Disable this with static
 */
public static function dropdown($selector = '', $params = []) : void
{
    // Only load once
    if (!empty(static::$loaded[__METHOD__][$selector])) {
        return;
    }
    if ($selector !== '') {
        // Setup options object
        $opt = [];
        $opt['flip'] = isset($params['flip']) ? $params['flip'] : true;
        $opt['boundary'] = isset($params['boundary']) ? $params['boundary'] : 'scrollParent';
        $opt['reference'] = isset($params['reference']) ? $params['reference'] : 'toggle';
        $opt['display'] = isset($params['display']) ? $params['display'] : 'dynamic';
        $opt['popperConfig'] = isset($params['popperConfig']) ? (bool) $params['popperConfig'] : true;
        Factory::getDocument()->addScriptOptions('bootstrap.dropdown', [$selector => (object) array_filter((array) $opt)]);
    }
    // Include the Bootstrap component
    Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.dropdown');
    static::$loaded[__METHOD__][$selector] = true;
}