1 <?php
  2 /**
  3  * @package     Joomla.Libraries
  4  * @subpackage  HTML
  5  *
  6  * @copyright   Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
  7  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8  */
  9 
 10 defined('JPATH_PLATFORM') or die;
 11 
 12 /**
 13  * Utility class for jQuery JavaScript behaviors
 14  *
 15  * @since  3.0
 16  */
 17 abstract class JHtmlJquery
 18 {
 19     /**
 20      * @var    array  Array containing information for loaded files
 21      * @since  3.0
 22      */
 23     protected static $loaded = array();
 24 
 25     /**
 26      * Method to load the jQuery JavaScript framework into the document head
 27      *
 28      * If debugging mode is on an uncompressed version of jQuery is included for easier debugging.
 29      *
 30      * @param   boolean  $noConflict  True to load jQuery in noConflict mode [optional]
 31      * @param   mixed    $debug       Is debugging mode on? [optional]
 32      * @param   boolean  $migrate     True to enable the jQuery Migrate plugin
 33      *
 34      * @return  void
 35      *
 36      * @since   3.0
 37      */
 38     public static function framework($noConflict = true, $debug = null, $migrate = true)
 39     {
 40         // Only load once
 41         if (!empty(static::$loaded[__METHOD__]))
 42         {
 43             return;
 44         }
 45 
 46         // If no debugging value is set, use the configuration setting
 47         if ($debug === null)
 48         {
 49             $debug = (boolean) JFactory::getConfig()->get('debug');
 50         }
 51 
 52         JHtml::_('script', 'jui/jquery.min.js', array('version' => 'auto', 'relative' => true, 'detectDebug' => $debug));
 53 
 54         // Check if we are loading in noConflict
 55         if ($noConflict)
 56         {
 57             JHtml::_('script', 'jui/jquery-noconflict.js', array('version' => 'auto', 'relative' => true));
 58         }
 59 
 60         // Check if we are loading Migrate
 61         if ($migrate)
 62         {
 63             JHtml::_('script', 'jui/jquery-migrate.min.js', array('version' => 'auto', 'relative' => true, 'detectDebug' => $debug));
 64         }
 65 
 66         static::$loaded[__METHOD__] = true;
 67 
 68         return;
 69     }
 70 
 71     /**
 72      * Method to load the jQuery UI JavaScript framework into the document head
 73      *
 74      * If debugging mode is on an uncompressed version of jQuery UI is included for easier debugging.
 75      *
 76      * @param   array  $components  The jQuery UI components to load [optional]
 77      * @param   mixed  $debug       Is debugging mode on? [optional]
 78      *
 79      * @return  void
 80      *
 81      * @since   3.0
 82      */
 83     public static function ui(array $components = array('core'), $debug = null)
 84     {
 85         // Set an array containing the supported jQuery UI components handled by this method
 86         $supported = array('core', 'sortable');
 87 
 88         // Include jQuery
 89         static::framework();
 90 
 91         // If no debugging value is set, use the configuration setting
 92         if ($debug === null)
 93         {
 94             $debug = JDEBUG;
 95         }
 96 
 97         // Load each of the requested components
 98         foreach ($components as $component)
 99         {
100             // Only attempt to load the component if it's supported in core and hasn't already been loaded
101             if (in_array($component, $supported) && empty(static::$loaded[__METHOD__][$component]))
102             {
103                 JHtml::_('script', 'jui/jquery.ui.' . $component . '.min.js', array('version' => 'auto', 'relative' => true, 'detectDebug' => $debug));
104                 static::$loaded[__METHOD__][$component] = true;
105             }
106         }
107 
108         return;
109     }
110 }
111