Source for file dropdown.php

Documentation is available at dropdown.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.  * HTML utility class for building a dropdown menu
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       3.0
  18.  */
  19. abstract class JHtmlDropdown
  20. {
  21.     /**
  22.      * @var    array  Array containing information for loaded files
  23.      * @since  3.0
  24.      */
  25.     protected static $loaded array();
  26.  
  27.     /**
  28.      * @var    string  HTML markup for the dropdown list
  29.      * @since  3.0
  30.      */
  31.     protected static $dropDownList null;
  32.  
  33.     /**
  34.      * Method to inject needed script
  35.      *
  36.      * @return  void 
  37.      *
  38.      * @since   3.0
  39.      */
  40.     public static function init()
  41.     {
  42.         // Only load once
  43.         if (isset(static::$loaded[__METHOD__]))
  44.         {
  45.             return;
  46.         }
  47.  
  48.         // Depends on Bootstrap
  49.         JHtml::_('bootstrap.framework');
  50.  
  51.         JFactory::getDocument()->addScriptDeclaration("
  52.             (function($){
  53.                 $(document).ready(function (){
  54.                     $('.has-context')
  55.                     .mouseenter(function (){
  56.                         $('.btn-group',$(this)).show();
  57.                     })
  58.                     .mouseleave(function (){
  59.                         $('.btn-group',$(this)).hide();
  60.                         $('.btn-group',$(this)).removeClass('open');
  61.                     });
  62.  
  63.                     contextAction =function (cbId, task)
  64.                     {
  65.                         $('input[name=\"cid[]\"]').removeAttr('checked');
  66.                         $('#' + cbId).attr('checked','checked');
  67.                         Joomla.submitbutton(task);
  68.                     }
  69.                 });
  70.             })(jQuery);
  71.             "
  72.         );
  73.  
  74.         // Set static array
  75.         static::$loaded[__METHOD__true;
  76.         return;
  77.     }
  78.  
  79.     /**
  80.      * Method to start a new dropdown menu
  81.      *
  82.      * @return  void 
  83.      *
  84.      * @since   3.0
  85.      */
  86.     public static function start()
  87.     {
  88.         // Only start once
  89.         if (isset(static::$loaded[__METHOD__]&& static::$loaded[__METHOD__== true)
  90.         {
  91.             return;
  92.         }
  93.  
  94.         $dropDownList '<div class="btn-group" style="margin-left:6px;display:none">
  95.                             <a href="#" data-toggle="dropdown" class="dropdown-toggle btn btn-mini">
  96.                                 <span class="caret"></span>
  97.                             </a>
  98.                             <ul class="dropdown-menu">';
  99.         static::$dropDownList $dropDownList;
  100.         static::$loaded[__METHOD__true;
  101.         return;
  102.     }
  103.  
  104.     /**
  105.      * Method to render current dropdown menu
  106.      *
  107.      * @return  string  HTML markup for the dropdown list
  108.      *
  109.      * @since   3.0
  110.      */
  111.     public static function render()
  112.     {
  113.         $dropDownList static::$dropDownList;
  114.         $dropDownList .= '</ul></div>';
  115.         static::$dropDownList    null;
  116.         static::$loaded['JHtmlDropdown::start'false;
  117.  
  118.         return $dropDownList;
  119.  
  120.     }
  121.  
  122.     /**
  123.      * Append an edit item to the current dropdown menu
  124.      *
  125.      * @param   integer  $id          Record ID
  126.      * @param   string   $prefix      Task prefix
  127.      * @param   string   $customLink  The custom link if dont use default Joomla action format
  128.      *
  129.      * @return  void 
  130.      *
  131.      * @since   3.0
  132.      */
  133.     public static function edit($id$prefix ''$customLink '')
  134.     {
  135.         static::start();
  136.  
  137.         if (!$customLink)
  138.         {
  139.             $option JFactory::getApplication()->input->getCmd('option');
  140.             $link 'index.php?option=' $option;
  141.         }
  142.         else
  143.         {
  144.             $link $customLink;
  145.         }
  146.  
  147.         $link .= '&task=' $prefix 'edit&id=' $id;
  148.         $link JRoute::_($link);
  149.  
  150.         static::addCustomItem(JText::_('JACTION_EDIT')$link);
  151.         return;
  152.     }
  153.  
  154.     /**
  155.      * Append a publish item to the current dropdown menu
  156.      *
  157.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  158.      * @param   string  $prefix      The task prefix
  159.      *
  160.      * @return  void 
  161.      *
  162.      * @since   3.0
  163.      */
  164.     public static function publish($checkboxId$prefix '')
  165.     {
  166.         $task $prefix 'publish';
  167.         static::addCustomItem(JText::_('JTOOLBAR_PUBLISH')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  168.         return;
  169.     }
  170.  
  171.     /**
  172.      * Append an unpublish item to the current dropdown menu
  173.      *
  174.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  175.      * @param   string  $prefix      The task prefix
  176.      *
  177.      * @return  void 
  178.      *
  179.      * @since   3.0
  180.      */
  181.     public static function unpublish($checkboxId$prefix '')
  182.     {
  183.         $task $prefix 'unpublish';
  184.         static::addCustomItem(JText::_('JTOOLBAR_UNPUBLISH')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  185.         return;
  186.     }
  187.  
  188.     /**
  189.      * Append a featured item to the current dropdown menu
  190.      *
  191.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  192.      * @param   string  $prefix      The task prefix
  193.      *
  194.      * @return  void 
  195.      *
  196.      * @since   3.0
  197.      */
  198.     public static function featured($checkboxId$prefix '')
  199.     {
  200.         $task $prefix 'featured';
  201.         static::addCustomItem(JText::_('JFEATURED')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  202.         return;
  203.     }
  204.  
  205.     /**
  206.      * Append an unfeatured item to the current dropdown menu
  207.      *
  208.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  209.      * @param   string  $prefix      The task prefix
  210.      *
  211.      * @return  void 
  212.      *
  213.      * @since   3.0
  214.      */
  215.     public static function unfeatured($checkboxId$prefix '')
  216.     {
  217.         $task $prefix 'unfeatured';
  218.         static::addCustomItem(JText::_('JUNFEATURED')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  219.         return;
  220.     }
  221.  
  222.     /**
  223.      * Append an archive item to the current dropdown menu
  224.      *
  225.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  226.      * @param   string  $prefix      The task prefix
  227.      *
  228.      * @return  void 
  229.      *
  230.      * @since   3.0
  231.      */
  232.     public static function archive($checkboxId$prefix '')
  233.     {
  234.         $task $prefix 'archive';
  235.         static::addCustomItem(JText::_('JTOOLBAR_ARCHIVE')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  236.         return;
  237.     }
  238.  
  239.     /**
  240.      * Append an unarchive item to the current dropdown menu
  241.      *
  242.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  243.      * @param   string  $prefix      The task prefix
  244.      *
  245.      * @return  void 
  246.      *
  247.      * @since   3.0
  248.      */
  249.     public static function unarchive($checkboxId$prefix '')
  250.     {
  251.         $task $prefix 'unpublish';
  252.         static::addCustomItem(JText::_('JTOOLBAR_UNARCHIVE')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  253.         return;
  254.     }
  255.  
  256.     /**
  257.      * Append a trash item to the current dropdown menu
  258.      *
  259.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  260.      * @param   string  $prefix      The task prefix
  261.      *
  262.      * @return  void 
  263.      *
  264.      * @since   3.0
  265.      */
  266.     public static function trash($checkboxId$prefix '')
  267.     {
  268.         $task $prefix 'trash';
  269.         static::addCustomItem(JText::_('JTOOLBAR_TRASH')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  270.         return;
  271.     }
  272.  
  273.     /**
  274.      * Append an untrash item to the current dropdown menu
  275.      *
  276.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  277.      * @param   string  $prefix      The task prefix
  278.      *
  279.      * @return  void 
  280.      *
  281.      * @since   3.0
  282.      */
  283.     public static function untrash($checkboxId$prefix '')
  284.     {
  285.         $task $prefix 'publish';
  286.         static::addCustomItem(JText::_('JTOOLBAR_UNTRASH')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  287.         return;
  288.     }
  289.  
  290.     /**
  291.      * Append a checkin item to the current dropdown menu
  292.      *
  293.      * @param   string  $checkboxId  ID of corresponding checkbox of the record
  294.      * @param   string  $prefix      The task prefix
  295.      *
  296.      * @return  void 
  297.      *
  298.      * @since   3.0
  299.      */
  300.     public static function checkin($checkboxId$prefix '')
  301.     {
  302.         $task $prefix 'checkin';
  303.         static::addCustomItem(JText::_('JTOOLBAR_CHECKIN')'javascript:void(0)''onclick="contextAction(\'' $checkboxId '\', \'' $task '\')"');
  304.         return;
  305.     }
  306.  
  307.     /**
  308.      * Writes a divider between dropdown items
  309.      *
  310.      * @return  void 
  311.      *
  312.      * @since   3.0
  313.      */
  314.     public static function divider()
  315.     {
  316.         static::$dropDownList .= '<li class="divider"></li>';
  317.         return;
  318.     }
  319.  
  320.     /**
  321.      * Append a custom item to current dropdown menu
  322.      *
  323.      * @param   string   $label           The label of item
  324.      * @param   string   $link            The link of item
  325.      * @param   string   $linkAttributes  Custom link attributes
  326.      * @param   string   $className       Class name of item
  327.      * @param   boolean  $ajaxLoad        True if using ajax load when item clicked
  328.      * @param   string   $jsCallBackFunc  Javascript function name, called when ajax load successfully
  329.      *
  330.      * @return  void 
  331.      *
  332.      * @since   3.0
  333.      */
  334.     public static function addCustomItem($label$link 'javascript:void(0)'$linkAttributes ''$className ''$ajaxLoad false,
  335.         $jsCallBackFunc null)
  336.     {
  337.         static::start();
  338.  
  339.         if ($ajaxLoad)
  340.         {
  341.             $href ' href = "javascript:void(0)" onclick="loadAjax(\'' $link '\', \'' $jsCallBackFunc '\')"';
  342.         }
  343.         else
  344.         {
  345.             $href ' href = "' $link '" ';
  346.         }
  347.  
  348.         $dropDownList static::$dropDownList;
  349.         $dropDownList .= '<li class="' $className '"><a ' $linkAttributes $href ' >';
  350.         $dropDownList .= $label;
  351.         $dropDownList .= '</a></li>';
  352.         static::$dropDownList $dropDownList;
  353.         return;
  354.     }
  355. }

Documentation generated on Tue, 19 Nov 2013 15:01:45 +0100 by phpDocumentor 1.4.3