Example #1
0
 /**
  * Add javascript support for Bootstrap accordians and insert the accordian
  *
  * @param   string  $selector  The ID selector for the tooltip.
  * @param   array   $params    An array of options for the tooltip.
  *                             Options for the tooltip can be:
  *                             - parent  selector  If selector then all collapsible elements under the specified parent will be closed when this
  *                                                 collapsible item is shown. (similar to traditional accordion behavior)
  *                             - toggle  boolean   Toggles the collapsible element on invocation
  *                             - active  string    Sets the active slide during load
  *
  * @return  string  HTML for the accordian
  *
  * @since   3.0
  */
 public static function startAccordion($selector = 'myAccordian', $params = array())
 {
     $sig = md5(serialize(array($selector, $params)));
     if (!isset(static::$loaded[__METHOD__][$sig])) {
         // Include Bootstrap framework
         static::framework();
         // Setup options object
         $opt['parent'] = isset($params['parent']) ? (bool) $params['parent'] : false;
         $opt['toggle'] = isset($params['toggle']) ? (bool) $params['toggle'] : true;
         $opt['active'] = isset($params['active']) ? (string) $params['active'] : '';
         $options = JHtmlBootstrap::getJSObject($opt);
         // Attach accordion to document
         JFactory::getDocument()->addScriptDeclaration("(function(\$){\n                    \$('#{$selector}').collapse({$options});\n                })(jQuery);");
         // Set static array
         static::$loaded[__METHOD__][$sig] = true;
         static::$loaded[__METHOD__]['active'] = $opt['active'];
     }
     return '<div id="' . $selector . '" class="accordion">';
 }