Back to Bootstrap class

Method modal

public static void
(mixed $selector = '', mixed $options = [])
Add javascript support for Bootstrap modal
Parameters
  • string $selector The ID selector for the modal.
  • array $options An array of options for the modal.
Returns
  • void
Since
  • 4.0.0
Class: Bootstrap
Project: Joomla

Method modal - Source code

/**
 * Add javascript support for Bootstrap modal
 *
 * @param   string  $selector  The ID selector for the modal.
 * @param   array   $options   An array of options for the modal.
 *
 * @return  void
 *
 * @since   4.0.0
 *
 * Options for the modal can be:
 * - backdrop     string|  true  Includes a modal-backdrop element. Alternatively, specify static
 *                boolean         for a backdrop which doesn't close the modal on click.
 * - keyboard     boolean  true  Closes the modal when escape key is pressed
 * - focus        boolean  true  Closes the modal when escape key is pressed
 */
public static function modal($selector = '', $options = []) : void
{
    // Only load once
    if (!empty(static::$loaded[__METHOD__][$selector])) {
        return;
    }
    if ($selector !== '') {
        // Setup options object
        $opt['backdrop'] = isset($options['backdrop']) ? $options['backdrop'] : false;
        $opt['keyboard'] = isset($options['keyboard']) ? (bool) $options['keyboard'] : true;
        $opt['focus'] = isset($options['focus']) ? (bool) $options['focus'] : true;
        Factory::getDocument()->addScriptOptions('bootstrap.modal', [$selector => (object) array_filter((array) $opt)]);
    }
    // Include the Bootstrap component
    Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.modal');
    static::$loaded[__METHOD__][$selector] = true;
}