[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\HTML\Helpers; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\HTML\HTMLHelper; 14 15 // phpcs:disable PSR1.Files.SideEffects 16 \defined('JPATH_PLATFORM') or die; 17 // phpcs:enable PSR1.Files.SideEffects 18 19 /** 20 * Utility class for jQuery JavaScript behaviors 21 * 22 * @since 3.0 23 */ 24 abstract class Jquery 25 { 26 /** 27 * Array containing information for loaded files 28 * 29 * @var array 30 * @since 3.0 31 */ 32 protected static $loaded = array(); 33 34 /** 35 * Method to load the jQuery JavaScript framework into the document head 36 * 37 * If debugging mode is on an uncompressed version of jQuery is included for easier debugging. 38 * 39 * @param boolean $noConflict True to load jQuery in noConflict mode [optional] 40 * @param mixed $debug Is debugging mode on? [optional] 41 * @param boolean $migrate True to enable the jQuery Migrate plugin 42 * 43 * @return void 44 * 45 * @since 3.0 46 * 47 * @deprecated 5.0 Use Joomla\CMS\WebAsset\WebAssetManager::useAsset(); 48 */ 49 public static function framework($noConflict = true, $debug = null, $migrate = false) 50 { 51 $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); 52 $wa->useScript('jquery'); 53 54 // Check if we are loading in noConflict 55 if ($noConflict) { 56 $wa->useScript('jquery-noconflict'); 57 } 58 59 // Check if we are loading Migrate 60 if ($migrate) { 61 $wa->useScript('jquery-migrate'); 62 } 63 } 64 65 /** 66 * Auto set CSRF token to ajaxSetup so all jQuery ajax call will contains CSRF token. 67 * 68 * @param string $name The CSRF meta tag name. 69 * 70 * @return void 71 * 72 * @throws \InvalidArgumentException 73 * 74 * @since 3.8.0 75 */ 76 public static function token($name = 'csrf.token') 77 { 78 // Only load once 79 if (!empty(static::$loaded[__METHOD__][$name])) { 80 return; 81 } 82 83 static::framework(); 84 HTMLHelper::_('form.csrf', $name); 85 86 $doc = Factory::getDocument(); 87 88 $doc->addScriptDeclaration( 89 <<<JS 90 ;(function ($) { 91 $.ajaxSetup({ 92 headers: { 93 'X-CSRF-Token': Joomla.getOptions('$name') 94 } 95 }); 96 })(jQuery); 97 JS 98 ); 99 100 static::$loaded[__METHOD__][$name] = true; 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |