Back to Bootstrap class

Method collapse

public static void
collapse
(mixed $selector = '', mixed $params = [])
Add javascript support for Bootstrap collapse
Parameters
  • string $selector Common class for the collapse
  • string[] $params Additional parameters - see below
Returns
  • void
Since
  • 4.0.0
-
  • \Exception
Class: Bootstrap
Project: Joomla

Method collapse - Source code

/**
 * Add javascript support for Bootstrap collapse
 *
 * @param   string    $selector  Common class for the collapse
 * @param   string[]  $params    Additional parameters - see below
 *
 * @return  void
 *
 * @throws \Exception
 *
 * @since   4.0.0
 *
 * Options for the collapse can be:
 * - parent    string   false  If parent is provided, then all collapsible elements under the specified parent will
 *                             be closed when this collapsible item is shown.
 * - toggle    boolean  true   Toggles the collapsible element on invocation
 */
public static function collapse($selector = '', $params = []) : void
{
    // Only load once
    if (!empty(static::$loaded[__METHOD__][$selector])) {
        return;
    }
    if ($selector !== '') {
        // Setup options object
        $opt = [];
        $opt['parent'] = isset($params['parent']) ? $params['parent'] : false;
        $opt['toggle'] = isset($params['toggle']) ? (bool) $params['toggle'] : true;
        Factory::getDocument()->addScriptOptions('bootstrap.collapse', [$selector => (object) array_filter((array) $opt)]);
    }
    // Include the Bootstrap component
    Factory::getApplication()->getDocument()->getWebAssetManager()->useScript('bootstrap.collapse');
    static::$loaded[__METHOD__][$selector] = true;
}