Source for file bootstrap.php

Documentation is available at bootstrap.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Utility class for Bootstrap elements.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       3.0
  18.  */
  19. abstract class JHtmlBootstrap
  20. {
  21.     /**
  22.      * @var    array  Array containing information for loaded files
  23.      * @since  3.0
  24.      */
  25.     protected static $loaded array();
  26.  
  27.     /**
  28.      * Add javascript support for the Bootstrap affix plugin
  29.      *
  30.      * @param   string  $selector  Unique selector for the element to be affixed.
  31.      * @param   array   $params    An array of options.
  32.      *                              Options for the affix plugin can be:
  33.      *                              - offset  number|function|object  Pixels to offset from screen when calculating position of scroll.
  34.      *                                                                If a single number is provided, the offset will be applied in both top
  35.      *                                                                and left directions. To listen for a single direction, or multiple
  36.      *                                                                unique offsets, just provide an object offset: { x: 10 }.
  37.      *                                                                Use a function when you need to dynamically provide an offset
  38.      *                                                                (useful for some responsive designs).
  39.      *
  40.      * @return  void 
  41.      *
  42.      * @since   3.1
  43.      */
  44.     public static function affix($selector 'affix'$params array())
  45.     {
  46.         $sig md5(serialize(array($selector$params)));
  47.  
  48.         if (!isset(static::$loaded[__METHOD__][$sig]))
  49.         {
  50.             // Include Bootstrap framework
  51.             static::framework();
  52.  
  53.             // Setup options object
  54.             $opt['offset'= isset($params['offset']$params['offset'10;
  55.  
  56.             $options JHtml::getJSObject($opt);
  57.  
  58.             // Attach the carousel to document
  59.             JFactory::getDocument()->addScriptDeclaration(
  60.                 "(function($){
  61.                     $('#$selector').affix($options);
  62.                     })(jQuery);"
  63.             );
  64.  
  65.             // Set static array
  66.             static::$loaded[__METHOD__][$sigtrue;
  67.         }
  68.  
  69.         return;
  70.     }
  71.  
  72.     /**
  73.      * Add javascript support for Bootstrap alerts
  74.      *
  75.      * @param   string  $selector  Common class for the alerts
  76.      *
  77.      * @return  void 
  78.      *
  79.      * @since   3.0
  80.      */
  81.     public static function alert($selector 'alert')
  82.     {
  83.         // Only load once
  84.         if (isset(static::$loaded[__METHOD__][$selector]))
  85.         {
  86.             return;
  87.         }
  88.  
  89.         // Include Bootstrap framework
  90.         static::framework();
  91.  
  92.         // Attach the alerts to the document
  93.         JFactory::getDocument()->addScriptDeclaration(
  94.             "(function($){
  95.                 $('.$selector').alert();
  96.                 })(jQuery);"
  97.         );
  98.  
  99.         static::$loaded[__METHOD__][$selectortrue;
  100.  
  101.         return;
  102.     }
  103.  
  104.     /**
  105.      * Add javascript support for Bootstrap buttons
  106.      *
  107.      * @param   string  $selector  Common class for the buttons
  108.      *
  109.      * @return  void 
  110.      *
  111.      * @since   3.1
  112.      */
  113.     public static function button($selector 'button')
  114.     {
  115.         // Only load once
  116.         if (isset(static::$loaded[__METHOD__][$selector]))
  117.         {
  118.             return;
  119.         }
  120.  
  121.         // Include Bootstrap framework
  122.         static::framework();
  123.  
  124.         // Attach the alerts to the document
  125.         JFactory::getDocument()->addScriptDeclaration(
  126.             "(function($){
  127.                 $('.$selector').button();
  128.                 })(jQuery);"
  129.         );
  130.  
  131.         static::$loaded[__METHOD__][$selectortrue;
  132.  
  133.         return;
  134.     }
  135.  
  136.     /**
  137.      * Add javascript support for Bootstrap carousels
  138.      *
  139.      * @param   string  $selector  Common class for the carousels.
  140.      * @param   array   $params    An array of options for the modal.
  141.      *                              Options for the modal can be:
  142.      *                              - interval  number  The amount of time to delay between automatically cycling an item.
  143.      *                                                  If false, carousel will not automatically cycle.
  144.      *                              - pause     string  Pauses the cycling of the carousel on mouseenter and resumes the cycling
  145.      *                                                  of the carousel on mouseleave.
  146.      *
  147.      * @return  void 
  148.      *
  149.      * @since   3.0
  150.      */
  151.     public static function carousel($selector 'carousel'$params array())
  152.     {
  153.         $sig md5(serialize(array($selector$params)));
  154.  
  155.         if (!isset(static::$loaded[__METHOD__][$sig]))
  156.         {
  157.             // Include Bootstrap framework
  158.             static::framework();
  159.  
  160.             // Setup options object
  161.             $opt['interval'= isset($params['interval']? (int) $params['interval'5000;
  162.             $opt['pause']    = isset($params['pause']$params['pause''hover';
  163.  
  164.             $options JHtml::getJSObject($opt);
  165.  
  166.             // Attach the carousel to document
  167.             JFactory::getDocument()->addScriptDeclaration(
  168.                 "(function($){
  169.                     $('.$selector').carousel($options);
  170.                     })(jQuery);"
  171.             );
  172.  
  173.             // Set static array
  174.             static::$loaded[__METHOD__][$sigtrue;
  175.         }
  176.  
  177.         return;
  178.     }
  179.  
  180.     /**
  181.      * Add javascript support for Bootstrap dropdowns
  182.      *
  183.      * @param   string  $selector  Common class for the dropdowns
  184.      *
  185.      * @return  void 
  186.      *
  187.      * @since   3.0
  188.      */
  189.     public static function dropdown($selector 'dropdown-toggle')
  190.     {
  191.         // Only load once
  192.         if (isset(static::$loaded[__METHOD__][$selector]))
  193.         {
  194.             return;
  195.         }
  196.  
  197.         // Include Bootstrap framework
  198.         static::framework();
  199.  
  200.         // Attach the dropdown to the document
  201.         JFactory::getDocument()->addScriptDeclaration(
  202.             "(function($){
  203.                 $('.$selector').dropdown();
  204.                 })(jQuery);"
  205.         );
  206.  
  207.         static::$loaded[__METHOD__][$selectortrue;
  208.  
  209.         return;
  210.     }
  211.  
  212.     /**
  213.      * Method to load the Bootstrap JavaScript framework into the document head
  214.      *
  215.      * If debugging mode is on an uncompressed version of Bootstrap is included for easier debugging.
  216.      *
  217.      * @param   mixed  $debug  Is debugging mode on? [optional]
  218.      *
  219.      * @return  void 
  220.      *
  221.      * @since   3.0
  222.      */
  223.     public static function framework($debug null)
  224.     {
  225.         // Only load once
  226.         if (!empty(static::$loaded[__METHOD__]))
  227.         {
  228.             return;
  229.         }
  230.  
  231.         // Load jQuery
  232.         JHtml::_('jquery.framework');
  233.  
  234.         // If no debugging value is set, use the configuration setting
  235.         if ($debug === null)
  236.         {
  237.             $config JFactory::getConfig();
  238.             $debug = (boolean) $config->get('debug');
  239.         }
  240.  
  241.         JHtml::_('script''jui/bootstrap.min.js'falsetruefalsefalse$debug);
  242.         static::$loaded[__METHOD__true;
  243.  
  244.         return;
  245.     }
  246.  
  247.     /**
  248.      * Add javascript support for Bootstrap modals
  249.      *
  250.      * @param   string  $selector  The ID selector for the modal.
  251.      * @param   array   $params    An array of options for the modal.
  252.      *                              Options for the modal can be:
  253.      *                              - backdrop  boolean  Includes a modal-backdrop element.
  254.      *                              - keyboard  boolean  Closes the modal when escape key is pressed.
  255.      *                              - show      boolean  Shows the modal when initialized.
  256.      *                              - remote    string   An optional remote URL to load
  257.      *
  258.      * @return  void 
  259.      *
  260.      * @since   3.0
  261.      */
  262.     public static function modal($selector 'modal'$params array())
  263.     {
  264.         $sig md5(serialize(array($selector$params)));
  265.  
  266.         if (!isset(static::$loaded[__METHOD__][$sig]))
  267.         {
  268.             // Include Bootstrap framework
  269.             static::framework();
  270.  
  271.             // Setup options object
  272.             $opt['backdrop'= isset($params['backdrop']? (boolean) $params['backdrop'true;
  273.             $opt['keyboard'= isset($params['keyboard']? (boolean) $params['keyboard'true;
  274.             $opt['show']     = isset($params['show']? (boolean) $params['show'true;
  275.             $opt['remote']   = isset($params['remote']?  $params['remote''';
  276.  
  277.             $options JHtml::getJSObject($opt);
  278.  
  279.             // Attach the modal to document
  280.             JFactory::getDocument()->addScriptDeclaration(
  281.                 "(function($){
  282.                     $('#$selector').modal($options);
  283.                     })(jQuery);"
  284.             );
  285.  
  286.             // Set static array
  287.             static::$loaded[__METHOD__][$sigtrue;
  288.         }
  289.  
  290.         return;
  291.     }
  292.  
  293.     /**
  294.      * Method to render a Bootstrap modal
  295.      *
  296.      * @param   string  $selector  The ID selector for the modal.
  297.      * @param   array   $params    An array of options for the modal.
  298.      * @param   string  $footer    Optional markup for the modal footer
  299.      *
  300.      * @return  string  HTML markup for a modal
  301.      *
  302.      * @since   3.0
  303.      */
  304.     public static function renderModal($selector 'modal'$params array()$footer '')
  305.     {
  306.         // Ensure the behavior is loaded
  307.         static::modal($selector$params);
  308.  
  309.         $html "<div class=\"modal hide fade\" id=\"" $selector "\">\n";
  310.         $html .= "<div class=\"modal-header\">\n";
  311.         $html .= "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">×</button>\n";
  312.         $html .= "<h3>" $params['title'"</h3>\n";
  313.         $html .= "</div>\n";
  314.         $html .= "<div id=\"" $selector "-container\">\n";
  315.         $html .= "</div>\n";
  316.         $html .= "</div>\n";
  317.  
  318.         $html .= "<script>";
  319.         $html .= "jQuery('#" $selector "').on('show', function () {\n";
  320.         $html .= "document.getElementById('" $selector "-container').innerHTML = '<div class=\"modal-body\"><iframe class=\"iframe\" src=\""
  321.             . $params['url'"\" height=\"" $params['height'"\" width=\"" $params['width'"\"></iframe></div>" $footer "';\n";
  322.         $html .= "});\n";
  323.         $html .= "</script>";
  324.  
  325.         return $html;
  326.     }
  327.  
  328.     /**
  329.      * Add javascript support for Bootstrap popovers
  330.      *
  331.      * Use element's Title as popover content
  332.      *
  333.      * @param   string  $selector  Selector for the tooltip
  334.      * @param   array   $params    An array of options for the tooltip.
  335.      *                   Options for the tooltip can be:
  336.      *                       animation  boolean          apply a css fade transition to the tooltip
  337.      *                       html       boolean          Insert HTML into the tooltip. If false, jQuery's text method will be used to insert
  338.      *                                                   content into the dom.
  339.      *                       placement  string|function  how to position the tooltip - top | bottom | left | right
  340.      *                       selector   string           If a selector is provided, tooltip objects will be delegated to the specified targets.
  341.      *                       trigger    string           how tooltip is triggered - hover | focus | manual
  342.      *                       title      string|function  default title value if `title` tag isn't present
  343.      *                       content    string|function  default content value if `data-content` attribute isn't present
  344.      *                       delay      number|object    delay showing and hiding the tooltip (ms) - does not apply to manual trigger type
  345.      *                                                   If a number is supplied, delay is applied to both hide/show
  346.      *                                                   Object structure is: delay: { show: 500, hide: 100 }
  347.      *                       container  string|boolean   Appends the popover to a specific element: { container: 'body' }
  348.      *
  349.      * @return  void 
  350.      *
  351.      * @since   3.0
  352.      */
  353.     public static function popover($selector '.hasPopover'$params array())
  354.     {
  355.         // Only load once
  356.         if (isset(static::$loaded[__METHOD__][$selector]))
  357.         {
  358.             return;
  359.         }
  360.  
  361.         // Include Bootstrap framework
  362.         static::framework();
  363.  
  364.         $opt['animation'= isset($params['animation']$params['animation'null;
  365.         $opt['html'= isset($params['html']$params['html'true;
  366.         $opt['placement'= isset($params['placement']$params['placement'null;
  367.         $opt['selector'= isset($params['selector']$params['selector'null;
  368.         $opt['title'= isset($params['title']$params['title'null;
  369.         $opt['trigger'= isset($params['trigger']$params['trigger''hover focus';
  370.         $opt['content'= isset($params['content']$params['content'null;
  371.         $opt['delay'= isset($params['delay']$params['delay'null;
  372.         $opt['container'= isset($params['container']$params['container'"body";
  373.  
  374.         $options JHtml::getJSObject($opt);
  375.  
  376.         // Attach the popover to the document
  377.         JFactory::getDocument()->addScriptDeclaration(
  378.             "jQuery(document).ready(function()
  379.             {
  380.                 jQuery('" $selector "').popover(" $options ");
  381.             });"
  382.         );
  383.  
  384.         static::$loaded[__METHOD__][$selectortrue;
  385.  
  386.         return;
  387.     }
  388.  
  389.     /**
  390.      * Add javascript support for Bootstrap ScrollSpy
  391.      *
  392.      * @param   string  $selector  The ID selector for the ScrollSpy element.
  393.      * @param   array   $params    An array of options for the ScrollSpy.
  394.      *                              Options for the modal can be:
  395.      *                              - offset  number  Pixels to offset from top when calculating position of scroll.
  396.      *
  397.      * @return  void 
  398.      *
  399.      * @since   3.0
  400.      */
  401.     public static function scrollspy($selector 'navbar'$params array())
  402.     {
  403.         $sig md5(serialize(array($selector$params)));
  404.  
  405.         if (!isset(static::$loaded[__METHOD__][$sig]))
  406.         {
  407.             // Include Bootstrap framework
  408.             static::framework();
  409.  
  410.             // Setup options object
  411.             $opt['offset'= isset($params['offset']? (int) $params['offset'10;
  412.  
  413.             $options JHtml::getJSObject($opt);
  414.  
  415.             // Attach ScrollSpy to document
  416.             JFactory::getDocument()->addScriptDeclaration(
  417.                 "(function($){
  418.                     $('#$selector').scrollspy($options);
  419.                     })(jQuery);"
  420.             );
  421.  
  422.             // Set static array
  423.             static::$loaded[__METHOD__][$sigtrue;
  424.         }
  425.  
  426.         return;
  427.     }
  428.  
  429.     /**
  430.      * Add javascript support for Bootstrap tooltips
  431.      *
  432.      * Add a title attribute to any element in the form
  433.      * title="title::text"
  434.      *
  435.      * @param   string  $selector  The ID selector for the tooltip.
  436.      * @param   array   $params    An array of options for the tooltip.
  437.      *                              Options for the tooltip can be:
  438.      *                              - animation  boolean          Apply a CSS fade transition to the tooltip
  439.      *                              - html       boolean          Insert HTML into the tooltip. If false, jQuery's text method will be used to insert
  440.      *                                                            content into the dom.
  441.      *                              - placement  string|function  How to position the tooltip - top | bottom | left | right
  442.      *                              - selector   string           If a selector is provided, tooltip objects will be delegated to the specified targets.
  443.      *                              - title      string|function  Default title value if `title` tag isn't present
  444.      *                              - trigger    string           How tooltip is triggered - hover | focus | manual
  445.      *                              - delay      integer          Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type
  446.      *                                                            If a number is supplied, delay is applied to both hide/show
  447.      *                                                            Object structure is: delay: { show: 500, hide: 100 }
  448.      *                              - container  string|boolean   Appends the popover to a specific element: { container: 'body' }
  449.      *
  450.      * @return  void 
  451.      *
  452.      * @since   3.0
  453.      */
  454.     public static function tooltip($selector '.hasTooltip'$params array())
  455.     {
  456.         if (!isset(static::$loaded[__METHOD__][$selector]))
  457.         {
  458.             // Include Bootstrap framework
  459.             static::framework();
  460.  
  461.             // Setup options object
  462.             $opt['animation'= isset($params['animation']? (boolean) $params['animation'null;
  463.             $opt['html']      = isset($params['html']? (boolean) $params['html'true;
  464.             $opt['placement'= isset($params['placement']? (string) $params['placement'null;
  465.             $opt['selector']  = isset($params['selector']? (string) $params['selector'null;
  466.             $opt['title']     = isset($params['title']? (string) $params['title'null;
  467.             $opt['trigger']   = isset($params['trigger']? (string) $params['trigger'null;
  468.             $opt['delay']     = isset($params['delay']? (int) $params['delay'null;
  469.             $opt['container'= isset($params['container']? (int) $params['container'"body";
  470.             $opt['template']  = isset($params['template']? (string) $params['template'null;
  471.  
  472.             $options JHtml::getJSObject($opt);
  473.  
  474.             // Attach tooltips to document
  475.             JFactory::getDocument()->addScriptDeclaration(
  476.                 "jQuery(document).ready(function()
  477.                 {
  478.                     jQuery('" $selector "').tooltip(" $options ");
  479.                 });"
  480.             );
  481.  
  482.             // Set static array
  483.             static::$loaded[__METHOD__][$selectortrue;
  484.         }
  485.  
  486.         return;
  487.     }
  488.  
  489.     /**
  490.      * Add javascript support for Bootstrap typeahead
  491.      *
  492.      * @param   string  $selector  The selector for the typeahead element.
  493.      * @param   array   $params    An array of options for the typeahead element.
  494.      *                              Options for the tooltip can be:
  495.      *                              - source       array, function  The data source to query against. May be an array of strings or a function.
  496.      *                                                              The function is passed two arguments, the query value in the input field and the
  497.      *                                                              process callback. The function may be used synchronously by returning the data
  498.      *                                                              source directly or asynchronously via the process callback's single argument.
  499.      *                              - items        number           The max number of items to display in the dropdown.
  500.      *                              - minLength    number           The minimum character length needed before triggering autocomplete suggestions
  501.      *                              - matcher      function         The method used to determine if a query matches an item. Accepts a single argument,
  502.      *                                                              the item against which to test the query. Access the current query with this.query.
  503.      *                                                              Return a boolean true if query is a match.
  504.      *                              - sorter       function         Method used to sort autocomplete results. Accepts a single argument items and has
  505.      *                                                              the scope of the typeahead instance. Reference the current query with this.query.
  506.      *                              - updater      function         The method used to return selected item. Accepts a single argument, the item and
  507.      *                                                              has the scope of the typeahead instance.
  508.      *                              - highlighter  function         Method used to highlight autocomplete results. Accepts a single argument item and
  509.      *                                                              has the scope of the typeahead instance. Should return html.
  510.      *
  511.      * @return  void 
  512.      *
  513.      * @since   3.0
  514.      */
  515.     public static function typeahead($selector '.typeahead'$params array())
  516.     {
  517.         if (!isset(static::$loaded[__METHOD__][$selector]))
  518.         {
  519.             // Include Bootstrap framework
  520.             static::framework();
  521.  
  522.             // Setup options object
  523.             $opt['source']      = isset($params['source']$params['source''[]';
  524.             $opt['items']       = isset($params['items']? (int) $params['items'8;
  525.             $opt['minLength']   = isset($params['minLength']? (int) $params['minLength'1;
  526.             $opt['matcher']     = isset($params['matcher']? (string) $params['matcher'null;
  527.             $opt['sorter']      = isset($params['sorter']? (string) $params['sorter'null;
  528.             $opt['updater']     = isset($params['updater']? (string) $params['updater'null;
  529.             $opt['highlighter'= isset($params['highlighter']? (int) $params['highlighter'null;
  530.  
  531.             $options JHtml::getJSObject($opt);
  532.  
  533.             // Attach tooltips to document
  534.             JFactory::getDocument()->addScriptDeclaration(
  535.                 "jQuery(document).ready(function()
  536.                 {
  537.                     jQuery('" $selector "').typeahead(" $options ");
  538.                 });"
  539.             );
  540.  
  541.             // Set static array
  542.             static::$loaded[__METHOD__][$selectortrue;
  543.         }
  544.  
  545.         return;
  546.     }
  547.  
  548.     /**
  549.      * Add javascript support for Bootstrap accordians and insert the accordian
  550.      *
  551.      * @param   string  $selector  The ID selector for the tooltip.
  552.      * @param   array   $params    An array of options for the tooltip.
  553.      *                              Options for the tooltip can be:
  554.      *                              - parent  selector  If selector then all collapsible elements under the specified parent will be closed when this
  555.      *                                                  collapsible item is shown. (similar to traditional accordion behavior)
  556.      *                              - toggle  boolean   Toggles the collapsible element on invocation
  557.      *                              - active  string    Sets the active slide during load
  558.      *
  559.      * @return  string  HTML for the accordian
  560.      *
  561.      * @since   3.0
  562.      */
  563.     public static function startAccordion($selector 'myAccordian'$params array())
  564.     {
  565.         $sig md5(serialize(array($selector$params)));
  566.  
  567.         if (!isset(static::$loaded[__METHOD__][$sig]))
  568.         {
  569.             // Include Bootstrap framework
  570.             static::framework();
  571.  
  572.             // Setup options object
  573.             $opt['parent'= isset($params['parent']? (boolean) $params['parent'false;
  574.             $opt['toggle'= isset($params['toggle']? (boolean) $params['toggle'true;
  575.             $opt['active'= isset($params['active']? (string) $params['active''';
  576.  
  577.             $options JHtml::getJSObject($opt);
  578.  
  579.             // Attach accordion to document
  580.             JFactory::getDocument()->addScriptDeclaration(
  581.                 "(function($){
  582.                     $('#$selector').collapse($options);
  583.                 })(jQuery);"
  584.             );
  585.  
  586.             // Set static array
  587.             static::$loaded[__METHOD__][$sigtrue;
  588.             static::$loaded[__METHOD__]['active'$opt['active'];
  589.         }
  590.  
  591.         return '<div id="' $selector '" class="accordion">';
  592.     }
  593.  
  594.     /**
  595.      * Close the current accordion
  596.      *
  597.      * @return  string  HTML to close the accordian
  598.      *
  599.      * @since   3.0
  600.      */
  601.     public static function endAccordion()
  602.     {
  603.         return '</div>';
  604.     }
  605.  
  606.     /**
  607.      * Begins the display of a new accordion slide.
  608.      *
  609.      * @param   string  $selector  Identifier of the accordion group.
  610.      * @param   string  $text      Text to display.
  611.      * @param   string  $id        Identifier of the slide.
  612.      * @param   string  $class     Class of the accordion group.
  613.      *
  614.      * @return  string  HTML to add the slide
  615.      *
  616.      * @since   3.0
  617.      */
  618.     public static function addSlide($selector$text$id$class '')
  619.     {
  620.         $in (static::$loaded['JHtmlBootstrap::startAccordion']['active'== $id' in' '';
  621.         $class (!empty($class)) ' ' $class '';
  622.  
  623.         $html '<div class="accordion-group' $class '">'
  624.             . '<div class="accordion-heading">'
  625.             . '<strong><a href="#' $id '" data-parent="#' $selector '" data-toggle="collapse" class="accordion-toggle">'
  626.             . $text
  627.             . '</a></strong>'
  628.             . '</div>'
  629.             . '<div class="accordion-body collapse' $in '" id="' $id '">'
  630.             . '<div class="accordion-inner">';
  631.  
  632.         return $html;
  633.     }
  634.  
  635.     /**
  636.      * Close the current slide
  637.      *
  638.      * @return  string  HTML to close the slide
  639.      *
  640.      * @since   3.0
  641.      */
  642.     public static function endSlide()
  643.     {
  644.         return '</div></div></div>';
  645.     }
  646.  
  647.     /**
  648.      * Creates a tab pane
  649.      *
  650.      * @param   string  $selector  The pane identifier.
  651.      * @param   array   $params    The parameters for the pane
  652.      *
  653.      * @return  string 
  654.      *
  655.      * @since   3.1
  656.      */
  657.     public static function startTabSet($selector 'myTab'$params array())
  658.     {
  659.         $sig md5(serialize(array($selector$params)));
  660.  
  661.         if (!isset(static::$loaded[__METHOD__][$sig]))
  662.         {
  663.             // Include Bootstrap framework
  664.             static::framework();
  665.  
  666.             // Setup options object
  667.             $opt['active'(isset($params['active']&& ($params['active'])) ? (string) $params['active''';
  668.  
  669.             // Attach tabs to document
  670.             JFactory::getDocument()
  671.                 ->addScriptDeclaration(JLayoutHelper::render('libraries.cms.html.bootstrap.starttabsetscript'array('selector' => $selector)));
  672.  
  673.             // Set static array
  674.             static::$loaded[__METHOD__][$sigtrue;
  675.             static::$loaded[__METHOD__][$selector]['active'$opt['active'];
  676.         }
  677.  
  678.         $html JLayoutHelper::render('libraries.cms.html.bootstrap.starttabset'array('selector' => $selector));
  679.  
  680.         return $html;
  681.     }
  682.  
  683.     /**
  684.      * Close the current tab pane
  685.      *
  686.      * @return  string  HTML to close the pane
  687.      *
  688.      * @since   3.1
  689.      */
  690.     public static function endTabSet()
  691.     {
  692.         $html JLayoutHelper::render('libraries.cms.html.bootstrap.endtabset');
  693.  
  694.         return $html;
  695.     }
  696.  
  697.     /**
  698.      * Begins the display of a new tab content panel.
  699.      *
  700.      * @param   string  $selector  Identifier of the panel.
  701.      * @param   string  $id        The ID of the div element
  702.      * @param   string  $title     The title text for the new UL tab
  703.      *
  704.      * @return  string  HTML to start a new panel
  705.      *
  706.      * @since   3.1
  707.      */
  708.     public static function addTab($selector$id$title)
  709.     {
  710.         static $tabScriptLayout null;
  711.         static $tabLayout null;
  712.  
  713.         $tabScriptLayout is_null($tabScriptLayoutnew JLayoutFile('libraries.cms.html.bootstrap.addtabscript'$tabScriptLayout;
  714.         $tabLayout is_null($tabLayoutnew JLayoutFile('libraries.cms.html.bootstrap.addtab'$tabLayout;
  715.  
  716.         $active (static::$loaded['JHtmlBootstrap::startTabSet'][$selector]['active'== $id' active' '';
  717.  
  718.         // Inject tab into UL
  719.         JFactory::getDocument()
  720.         ->addScriptDeclaration($tabScriptLayout->render(array('selector' => $selector,'id' => $id'active' => $active'title' => $title)));
  721.  
  722.         $html $tabLayout->render(array('id' => $id'active' => $active));
  723.  
  724.         return $html;
  725.     }
  726.  
  727.     /**
  728.      * Close the current tab content panel
  729.      *
  730.      * @return  string  HTML to close the pane
  731.      *
  732.      * @since   3.1
  733.      */
  734.     public static function endTab()
  735.     {
  736.         $html JLayoutHelper::render('libraries.cms.html.bootstrap.endtab');
  737.  
  738.         return $html;
  739.     }
  740.  
  741.     /**
  742.      * Creates a tab pane
  743.      *
  744.      * @param   string  $selector  The pane identifier.
  745.      * @param   array   $params    The parameters for the pane
  746.      *
  747.      * @return  string 
  748.      *
  749.      * @since   3.0
  750.      * @deprecated  4.0    Use JHtml::_('bootstrap.startTabSet') instead.
  751.      */
  752.     public static function startPane($selector 'myTab'$params array())
  753.     {
  754.         $sig md5(serialize(array($selector$params)));
  755.         if (!isset(static::$loaded['JHtmlBootstrap::startTabSet'][$sig]))
  756.         {
  757.             // Include Bootstrap framework
  758.             static::framework();
  759.  
  760.             // Setup options object
  761.             $opt['active'= isset($params['active']? (string) $params['active''';
  762.  
  763.             // Attach tooltips to document
  764.             JFactory::getDocument()->addScriptDeclaration(
  765.                 "(function($){
  766.                     $('#$selector a').click(function (e) {
  767.                         e.preventDefault();
  768.                         $(this).tab('show');
  769.                     });
  770.                 })(jQuery);"
  771.             );
  772.  
  773.             // Set static array
  774.             static::$loaded['JHtmlBootstrap::startTabSet'][$sigtrue;
  775.             static::$loaded['JHtmlBootstrap::startTabSet'][$selector]['active'$opt['active'];
  776.         }
  777.  
  778.         return '<div class="tab-content" id="' $selector 'Content">';
  779.     }
  780.  
  781.     /**
  782.      * Close the current tab pane
  783.      *
  784.      * @return  string  HTML to close the pane
  785.      *
  786.      * @since   3.0
  787.      * @deprecated  4.0    Use JHtml::_('bootstrap.endTabSet') instead.
  788.      */
  789.     public static function endPane()
  790.     {
  791.         return '</div>';
  792.     }
  793.  
  794.     /**
  795.      * Begins the display of a new tab content panel.
  796.      *
  797.      * @param   string  $selector  Identifier of the panel.
  798.      * @param   string  $id        The ID of the div element
  799.      *
  800.      * @return  string  HTML to start a new panel
  801.      *
  802.      * @since   3.0
  803.      * @deprecated  4.0 Use JHtml::_('bootstrap.addTab') instead.
  804.      */
  805.     public static function addPanel($selector$id)
  806.     {
  807.         $active (static::$loaded['JHtmlBootstrap::startTabSet'][$selector]['active'== $id' active' '';
  808.  
  809.         return '<div id="' $id '" class="tab-pane' $active '">';
  810.     }
  811.  
  812.     /**
  813.      * Close the current tab content panel
  814.      *
  815.      * @return  string  HTML to close the pane
  816.      *
  817.      * @since   3.0
  818.      * @deprecated  4.0 Use JHtml::_('bootstrap.endTab') instead.
  819.      */
  820.     public static function endPanel()
  821.     {
  822.         return '</div>';
  823.     }
  824.  
  825.     /**
  826.      * Loads CSS files needed by Bootstrap
  827.      *
  828.      * @param   boolean  $includeMainCss  If true, main bootstrap.css files are loaded
  829.      * @param   string   $direction       rtl or ltr direction. If empty, ltr is assumed
  830.      * @param   array    $attribs         Optional array of attributes to be passed to JHtml::_('stylesheet')
  831.      *
  832.      * @return  void 
  833.      *
  834.      * @since   3.0
  835.      */
  836.     public static function loadCss($includeMainCss true$direction 'ltr'$attribs array())
  837.     {
  838.         // Load Bootstrap main CSS
  839.         if ($includeMainCss)
  840.         {
  841.             JHtml::_('stylesheet''jui/bootstrap.min.css'$attribstrue);
  842.             JHtml::_('stylesheet''jui/bootstrap-responsive.min.css'$attribstrue);
  843.             JHtml::_('stylesheet''jui/bootstrap-extended.css'$attribstrue);
  844.         }
  845.  
  846.         // Load Bootstrap RTL CSS
  847.         if ($direction === 'rtl')
  848.         {
  849.             JHtml::_('stylesheet''jui/bootstrap-rtl.css'$attribstrue);
  850.         }
  851.     }
  852. }

Documentation generated on Tue, 19 Nov 2013 14:54:43 +0100 by phpDocumentor 1.4.3