CoreFiles by mySites.guru
jquery.php135 lines, 3,129 bytes, from Joomla_4.0.0-alpha8-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha7
md5
2c41bba0af336b971e56d28b6f023678
sha1
f51cb98798924e12d7caa7dc1cf5141da79ed5a4
sha256
940c67a54a99aa4460d670031868844e288f81a1319cf8ac4fed85600b69efb8
<?php
/**
 * @package     Joomla.Libraries
 * @subpackage  HTML
 *
 * @copyright   Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;

/**
 * Utility class for jQuery JavaScript behaviors
 *
 * @since  3.0
 */
abstract class JHtmlJquery
{
	/**
	 * Array containing information for loaded files
	 *
	 * @var    array
	 * @since  3.0
	 */
	protected static $loaded = array();

	/**
	 * Method to load the jQuery JavaScript framework into the document head
	 *
	 * If debugging mode is on an uncompressed version of jQuery is included for easier debugging.
	 *
	 * @param   boolean  $noConflict  True to load jQuery in noConflict mode [optional]
	 * @param   mixed    $debug       Is debugging mode on? [optional]
	 * @param   boolean  $migrate     True to enable the jQuery Migrate plugin
	 *
	 * @return  void
	 *
	 * @since   3.0
	 *
	 * @deprecated 5.0  Use Joomla\CMS\WebAsset\WebAssetRegistry::enableAsset();
	 */
	public static function framework($noConflict = true, $debug = null, $migrate = false)
	{
		$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
		$wa->enableAsset('jquery');

		// Check if we are loading in noConflict
		if ($noConflict)
		{
			$wa->enableAsset('jquery-noconflict');
		}

		// Check if we are loading Migrate
		if ($migrate)
		{
			$wa->enableAsset('jquery-migrate');
		}

		return;
	}

	/**
	 * Method to load the jQuery UI JavaScript framework into the document head
	 *
	 * If debugging mode is on an uncompressed version of jQuery UI is included for easier debugging.
	 *
	 * @param   array  $components  The jQuery UI components to load [optional]
	 * @param   mixed  $debug       Is debugging mode on? [optional]
	 *
	 * @return  void
	 *
	 * @since   3.0
	 *
	 * @deprecated 5.0  Use Joomla\CMS\WebAsset\WebAssetRegistry::enableAsset();
	 */
	public static function ui(array $components = array('core'), $debug = null)
	{
		// Set an array containing the supported jQuery UI components handled by this method
		$supported = array('core', 'sortable');

		$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

		foreach ($components as $component)
		{
			if (in_array($component, $supported))
			{
				$wa->enableAsset('jquery.ui.' . $component);
			}
		}

		return;
	}

	/**
	 * Auto set CSRF token to ajaxSetup so all jQuery ajax call will contains CSRF token.
	 *
	 * @param   string  $name  The CSRF meta tag name.
	 *
	 * @return  void
	 *
	 * @throws  \InvalidArgumentException
	 *
	 * @since   3.8.0
	 */
	public static function token($name = 'csrf.token')
	{
		// Only load once
		if (!empty(static::$loaded[__METHOD__][$name]))
		{
			return;
		}

		static::framework();
		HTMLHelper::_('form.csrf', $name);

		$doc = Factory::getDocument();

		$doc->addScriptDeclaration(
<<<JS
;(function ($) {
	$.ajaxSetup({
		headers: {
			'X-CSRF-Token': Joomla.getOptions('$name')
		}
	});
})(jQuery);
JS
		);

		static::$loaded[__METHOD__][$name] = true;
	}
}

The same content is in 2 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha8. See them all, or every version of this file.