From 8681e758463e85b2142a3eed72c18bf83e29c1c8 Mon Sep 17 00:00:00 2001 From: Fedik Date: Sun, 30 Sep 2018 11:11:06 +0300 Subject: [PATCH] WebAsset HtmlBehavior use assets --- build/media_src/system/joomla.asset.json | 10 ++++++++ libraries/cms/html/behavior.php | 29 ++++-------------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/build/media_src/system/joomla.asset.json b/build/media_src/system/joomla.asset.json index 596b197ddd9f6..017321869e31d 100644 --- a/build/media_src/system/joomla.asset.json +++ b/build/media_src/system/joomla.asset.json @@ -45,6 +45,16 @@ "js": [ "media/system/js/showon.min.js" ] + }, + "fields.validate": { + "name": "fields.validate", + "dependencies": [ + "core", + "punycode" + ], + "js": [ + "media/system/js/fields/validate.min.js" + ] } } } diff --git a/libraries/cms/html/behavior.php b/libraries/cms/html/behavior.php index daf3815f568c5..7b57fbbfe90db 100644 --- a/libraries/cms/html/behavior.php +++ b/libraries/cms/html/behavior.php @@ -68,7 +68,7 @@ public static function core() } HTMLHelper::_('form.csrf'); - HTMLHelper::_('script', 'system/core.min.js', array('version' => 'auto', 'relative' => true)); + Factory::getContainer()->get('webasset')->enableAsset('core'); // Add core and base uri paths so javascript scripts can use them. Factory::getDocument()->addScriptOptions( @@ -140,8 +140,7 @@ public static function formvalidator() Text::script('JLIB_FORM_FIELD_REQUIRED_CHECK'); Text::script('JLIB_FORM_FIELD_INVALID_VALUE'); - HTMLHelper::_('script', 'vendor/punycode/punycode.js', array('version' => 'auto', 'relative' => true)); - HTMLHelper::_('script', 'system/fields/validate.min.js', array('version' => 'auto', 'relative' => true)); + Factory::getContainer()->get('webasset')->enableAsset('fields.validate'); static::$loaded[__METHOD__] = true; } @@ -170,18 +169,7 @@ public static function switcher() */ public static function combobox() { - if (isset(static::$loaded[__METHOD__])) - { - return; - } - - // Include core - static::core(); - - HTMLHelper::_('stylesheet', 'vendor/awesomplete/awesomplete.css', array('version' => 'auto', 'relative' => true)); - HTMLHelper::_('script', 'vendor/awesomplete/awesomplete.js', array('version' => 'auto', 'relative' => true)); - - static::$loaded[__METHOD__] = true; + Factory::getContainer()->get('webasset')->enableAsset('awesomplete'); } /** @@ -259,10 +247,7 @@ public static function multiselect($id = 'adminForm') return; } - // Include core - static::core(); - - HTMLHelper::_('script', 'system/multiselect.min.js', array('version' => 'auto', 'relative' => true)); + Factory::getContainer()->get('webasset')->enableAsset('multiselect'); // Pass the required options to the javascript Factory::getDocument()->addScriptOptions('js-multiselect', ['formName' => $id]); @@ -438,14 +423,10 @@ public static function keepalive() // If we are in the frontend or logged in as a user, we can use the ajax component to reduce the load $uri = 'index.php' . ($app->isClient('site') || !Factory::getUser()->guest ? '?option=com_ajax&format=json' : ''); - // Include core - static::core(); - // Add keepalive script options. Factory::getDocument()->addScriptOptions('system.keepalive', array('interval' => $refreshTime * 1000, 'uri' => Route::_($uri))); - // Add script. - HTMLHelper::_('script', 'system/keepalive.js', array('version' => 'auto', 'relative' => true)); + Factory::getContainer()->get('webasset')->enableAsset('keepalive'); static::$loaded[__METHOD__] = true;