Skip to content

Commit

Permalink
Optimized load asset files
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Oct 30, 2023
1 parent 410f198 commit 63dcc74
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 181 deletions.
21 changes: 6 additions & 15 deletions framework/fields/jdrating.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,12 @@ public function getInput()
. '}'
. ($clear ? ', clearable: true' : '')
. '});';
if (ASTROID_JOOMLA_VERSION == 4) {
$script .= '$(document).on("subform-row-add", function(event){'
. '$(event.detail.row).find(".ui.rating").rating({'
. 'onRate:function(value){'
. '$(this).siblings("input[type=hidden]").val(value);'
. '}'
. '});';
} else {
$script .= '$(document).on("subform-row-add", function(event, row){'
. '$(row).find(".ui.rating").rating({'
. 'onRate:function(value){'
. '$(this).siblings("input[type=hidden]").val(value);'
. '}'
. '});';
}
$script .= '$(document).on("subform-row-add", function(event){'
. '$(event.detail.row).find(".ui.rating").rating({'
. 'onRate:function(value){'
. '$(this).siblings("input[type=hidden]").val(value);'
. '}'
. '});';
$script .= '});'
. '$(".btn-rating-clear").click(function(){'
. '$(this).siblings(".ui.rating").rating("clear rating");'
Expand Down
2 changes: 1 addition & 1 deletion framework/forms/article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<field type="jdrating" name="astroid_article_review_rating" label="ASTROID_OVERALL_RATING" description="ASTROID_OVERALL_RATING_DESC" default="5" max="10" rating-type="star" showon="astroid_article_type:review" clear="true" />
<field type="text" name="astroid_article_button_action" label="ASTROID_CALL_ACTION_BUTTON" description="ASTROID_CALL_ACTION_BUTTON_DESC" showon="astroid_article_type:review" />
<field type="text" name="astroid_article_button_link" label="ASTROID_BUTTON_LINK" description="ASTROID_BUTTON_LINK_DESC" showon="astroid_article_type:review" />
<field showon="astroid_article_type:review" name="astroid_article_review_criterias" type="subform" formsource="libraries/astroid/framework/forms/reviewcriteria.xml" multiple="true" label="ASTROID_REVIEW_CRITERIAS" description="ASTROID_REVIEW_CRITERIAS_DESC" />
<field showon="astroid_article_type:review" name="astroid_article_review_criterias" type="subform" formsource="libraries/astroid/framework/forms/reviewcriteria.xml" multiple="true" label="ASTROID_REVIEW_CRITERIAS" description="ASTROID_REVIEW_CRITERIAS_DESC"/>
<!-- Quote Options -->
<field type="spacer" showon="astroid_article_type:quote" name="astroidarticlequote" label="ASTROID_ARTICLE_OPTIONS_QUOTE_LABEL" />
<field type="text" name="astroid_article_quote_text" label="ASTROID_ARTICLE_QUOTE_TEXT" description="ASTROID_ARTICLE_QUOTE_TEXT_DESC" showon="astroid_article_type:quote" />
Expand Down
2 changes: 1 addition & 1 deletion framework/forms/reviewcriteria.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fieldset name="astroid_article_review_criteria" label="ASTROID_GALLERY_ITEMS">
<fieldset name="astroid_article_review_criteria" label="ASTROID_GALLERY_ITEMS" addfieldpath="/libraries/astroid/framework/fields">
<field name="title" label="ASTROID_REVIEW_CRITERIAS_TEXT" description="ASTROID_REVIEW_CRITERIAS_TEXT_DESC" type="text" />
<field name="score" label="ASTROID_REVIEW_CRITERIAS_SCORE" description="ASTROID_REVIEW_CRITERIAS_SCORE_DESC" type="jdrating" default="5" rating-type="star" max="10" />
</fieldset>
Expand Down
6 changes: 5 additions & 1 deletion framework/frontend/document/body.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
*/

// No direct access.
use Joomla\CMS\Factory;

defined('_JEXEC') or die;
extract($displayData);
Astroid\Framework::getDebugger()->log('Render Body');

$document = Astroid\Framework::getDocument();
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

Astroid\Helper\Head::meta(); // site meta
Astroid\Helper\Head::styles(); // site Styles
Astroid\Helper\Head::scripts(); // site scripts
Astroid\Helper\Head::favicon(); // site favicon

Expand All @@ -39,7 +43,7 @@
$astroid_content_class[] = 'sidebar-dir-' . $params->get('header_sidebar_menu_mode', 'left');
}
if ($header && !empty($header_mode) && $header_mode != 'sidebar') {
$document->addScript('vendor/jquery/jquery.easing.min.js', 'body');
$wa->registerAndUseScript('astroid.jquery.easing', 'astroid/jquery.easing.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
}
?>
<!-- astroid container -->
Expand Down
6 changes: 4 additions & 2 deletions framework/frontend/document/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* DO NOT MODIFY THIS FILE DIRECTLY AS IT WILL BE OVERWRITTEN IN THE NEXT UPDATE
* Just copy the file to ROOT/templates/YOURTEMPLATE/html/frontend/ folder to create and override
*/

use Joomla\CMS\Factory;
// No direct access.
defined('_JEXEC') or die;
extract($displayData);

$document = Astroid\Framework::getDocument();
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

Astroid\Helper\Head::meta(); // site meta
Astroid\Helper\Head::scripts(); // site scripts
Expand Down Expand Up @@ -41,7 +42,8 @@
$astroid_content_class[] = 'sidebar-dir-' . $params->get('header_sidebar_menu_mode', 'left');
}
if ($header && !empty($header_mode) && $header_mode != 'sidebar') {
$document->addScript('vendor/jquery/jquery.easing.min.js', 'body');
// $document->addScript('vendor/jquery/jquery.easing.min.js', 'body');
$wa->registerAndUseScript('astroid.jquery.easing', 'astroid/jquery.easing.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
}
?>
<!-- astroid container -->
Expand Down
8 changes: 6 additions & 2 deletions framework/frontend/mobilemenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
* You can easily override all files under /frontend/ folder.
* Just copy the file to ROOT/templates/YOURTEMPLATE/html/frontend/ folder to create and override
*/
use Joomla\CMS\Factory;
// No direct access.
defined('_JEXEC') or die;
extract($displayData);

$params = Astroid\Framework::getTemplate()->getParams();
$document = Astroid\Framework::getDocument();
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

$header = $params->get('header', TRUE);
$header_mobile_menu = $params->get('header_mobile_menu', '');
Expand All @@ -31,8 +33,10 @@
$mode = $params->get('header_sidebar_menu_mode', 'left');
$dir = $header ? ($header_mode == 'sidebar' ? $mode : $dir) : $dir;

$document->addScript('vendor/astroid/js/offcanvas.js', 'body');
$document->addScript('vendor/astroid/js/mobilemenu.js', 'body');
$wa->registerAndUseScript('astroid.offcanvas', 'astroid/offcanvas.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
$wa->registerAndUseScript('astroid.mobilemenu', 'astroid/mobilemenu.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
//$document->addScript('vendor/astroid/js/offcanvas.js', 'body');
//$document->addScript('vendor/astroid/js/mobilemenu.js', 'body');
?>
<div class="astroid-mobilemenu d-none d-init dir-<?php echo $dir; ?>" data-class-prefix="astroid-mobilemenu" id="astroid-mobilemenu">
<div class="burger-menu-button active">
Expand Down
8 changes: 6 additions & 2 deletions framework/frontend/offcanvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
* You can easily override all files under /frontend/ folder.
* Just copy the file to ROOT/templates/YOURTEMPLATE/html/frontend/ folder to create and override
*/
use Joomla\CMS\Factory;
// No direct access.
use Joomla\CMS\Language\Text;
defined('_JEXEC') or die;
extract($displayData);
$params = Astroid\Framework::getTemplate()->getParams();
$document = Astroid\Framework::getDocument();
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

$header = $params->get('header', TRUE);
$enable_offcanvas = $params->get('enable_offcanvas', FALSE);
Expand All @@ -23,10 +25,12 @@
}

$module_position = 'offcanvas';
$document->addScript('vendor/astroid/js/offcanvas.js', 'body');
$wa->registerAndUseScript('astroid.offcanvas', 'astroid/offcanvas.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
//$document->addScript('vendor/astroid/js/offcanvas.js', 'body');
$hasMenu = $document->hasModule($module_position, 'mod_menu');
if ($hasMenu) {
$document->addScript('vendor/astroid/js/mobilemenu.js', 'body');
$wa->registerAndUseScript('astroid.mobilemenu', 'astroid/mobilemenu.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
// $document->addScript('vendor/astroid/js/mobilemenu.js', 'body');
}

$togglevisibility = $params->get('offcanvas_togglevisibility', 'd-block');
Expand Down
2 changes: 1 addition & 1 deletion framework/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

\JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_cache/models', 'CacheModel');

class AstroidFrameworkHelper
class AstroidFrameworkHelper extends Astroid\Helper
{

public static function getAstroidElements()
Expand Down
3 changes: 1 addition & 2 deletions framework/layouts/manager/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
$preset_arr[] = $presets[$pidx]['preset'];
}
$color_mode = $plugin_params->get('astroid_color_mode_enable', 0);
$doc = Factory::getDocument();
$color_mode_theme = (isset($_COOKIE['astroid_colormode']) && $_COOKIE['astroid_colormode'] ? $_COOKIE['astroid_colormode'] : 'light');
?>
<!DOCTYPE html>
Expand All @@ -31,7 +30,7 @@
<title><?php echo $template->title; ?></title>
<link href="<?php echo ASTROID_MEDIA_URL . 'images/favicon.png'; ?>" rel="shortcut icon" type="image/vnd.microsoft.icon" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script type="application/json" id="astroid-script-options"><?php echo json_encode($doc->getScriptOptions()) ?></script>
<script type="application/json" id="astroid-script-options"><?php echo json_encode($document->getScriptOptions()) ?></script>
<astroid:include type="head-styles" /> <!-- head styles -->
<astroid:include type="head-scripts" /> <!-- head scripts -->
</head>
Expand Down
10 changes: 4 additions & 6 deletions framework/library/astroid/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ protected function manager()
$pluginParams = Helper::getPluginParams();
$plg_color_mode = $pluginParams->get('astroid_color_mode_enable', 0);

$doc = Factory::getDocument();
$config = [
'site_url' => Uri::root(),
'base_url' => Uri::base(true),
Expand All @@ -144,14 +143,14 @@ protected function manager()
'astroid_admin_token' => Session::getFormToken(),
'astroid_action' => Helper::getAstroidUrl('save', ['template' => $template->template . '-' . $template->id])
];
$doc->addScriptOptions('astroid_lib', $config);
$document->addScriptOptions('astroid_lib', $config);

// Get Language
$lang = array();
foreach (Helper\Constants::$translationStrings as $string) {
$lang[strtoupper($string)] = Factory::getApplication()->getLanguage()->_($string);
}
$doc->addScriptOptions('astroid_lang', $lang);
$document->addScriptOptions('astroid_lang', $lang);

// Prepare content
$form_content = array();
Expand Down Expand Up @@ -242,13 +241,12 @@ protected function manager()
$fieldset->label = Text::_($fieldset->label);
$fieldset->childs = $groups;
$form_content[] = $fieldset;

$presets = Helper::getPresets();
}
$doc->addScriptOptions('astroid_content', $form_content);
$document->addScriptOptions('astroid_content', $form_content);

// styles
$stylesheets = ['vendor/manager/dist/index.css'];
$document->loadFontAwesome();
$document->addStyleSheet($stylesheets);

Helper::triggerEvent('onBeforeAstroidAdminRender', [&$template]);
Expand Down
13 changes: 3 additions & 10 deletions framework/library/astroid/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@

defined('_JEXEC') or die;

if (ASTROID_JOOMLA_VERSION == 3) {
JLoader::register('ModRelatedItemsHelper', JPATH_ROOT . '/modules/mod_related_items/helper.php');
\JLoader::registerAlias('RelatedItemsHelper', 'ModRelatedItemsHelper');
}

class Article
{

Expand Down Expand Up @@ -47,6 +42,8 @@ function __construct($article, $categoryView = false)
$this->template = Framework::getTemplate();

$mainframe = Factory::getApplication();
$wa = $mainframe->getDocument()->getWebAssetManager();
$wa->useScript('bootstrap.carousel');
$this->params = new Registry();
$itemId = $mainframe->input->get('Itemid', 0, 'INT');
if ($itemId) {
Expand Down Expand Up @@ -265,11 +262,7 @@ public function renderRelatedPosts()
$params = new Registry();
$params->loadArray(['maximum' => $count]);

if (ASTROID_JOOMLA_VERSION >= 4) {
$items = Factory::getApplication()->bootModule('mod_related_items', 'site')->getHelper('RelatedItemsHelper')->getRelatedArticles($params, Factory::getApplication());
} else {
$items = RelatedItemsHelper::getList($params);
}
$items = Factory::getApplication()->bootModule('mod_related_items', 'site')->getHelper('RelatedItemsHelper')->getRelatedArticles($params, Factory::getApplication());

Framework::getDocument()->include('blog.modules.related', ['items' => $items, 'display_posttypeicon' => $this->showRelatedPostTypeIcon(), 'display_badge' => $this->showRelatedArticleBadge()]);
}
Expand Down
17 changes: 3 additions & 14 deletions framework/library/astroid/Component/Includer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static function _headMeta()

public static function _headStyles()
{
Helper\Head::styles();
$document = Framework::getDocument();
$document->astroidCustomCSS();
$content = $document->renderLinks();
$content .= $document->getStylesheets();
$content .= $document->astroidInlineCSS();
Expand All @@ -77,27 +77,16 @@ public static function _headStyles()
public static function _headScripts()
{
$document = Framework::getDocument();
$content = '';
$content .= $document->getScripts('head');
$content = $document->getScripts('head');
$content .= $document->getCustomTags('head');
return $content;
}

public static function _bodyScripts()
{
$document = Framework::getDocument();
if (Framework::isSite()) {
$document->addScript('vendor/astroid/js/script.js', 'body');
}
if (Helper::getPluginParams()->get('astroid_debug', 0)) {
$document->addScript('vendor/astroid/js/debug.js', 'body');
}
$content = '';
$content .= $document->getScripts('body');
$content = $document->getScripts('body');
$content .= $document->getCustomTags('body');
if (Framework::isSite()) {
$content .= '<script>jQuery.noConflict(true);</script>';
}
return $content;
}

Expand Down
56 changes: 17 additions & 39 deletions framework/library/astroid/Component/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Language\Multilanguage;

if (ASTROID_JOOMLA_VERSION == 3) {
\JLoader::register('ModMenuHelper', JPATH_SITE . '/modules/mod_menu/helper.php');
}

class Menu
{

Expand All @@ -36,8 +32,11 @@ public static function getMenu($menutype = '', $nav_class = [], $logo = null, $l

$params = Framework::getTemplate()->getParams();
$document = Framework::getDocument();
$document->addScript('vendor/astroid/js/megamenu.js', 'body');
$document->addScript('vendor/hoverIntent/jquery.hoverIntent.min.js', 'body');
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('astroid.megamenu', 'astroid/megamenu.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
$wa->registerAndUseScript('astroid.jquery.hoverIntent', 'astroid/jquery.hoverIntent.min.js', ['relative' => true, 'version' => 'auto'], [], ['jquery']);
// $document->addScript('vendor/astroid/js/megamenu.js', 'body');
// $document->addScript('vendor/hoverIntent/jquery.hoverIntent.min.js', 'body');

$header_endLevel = $params->get('header_endLevel', 0);
if ($endLevel !== null) {
Expand All @@ -49,17 +48,10 @@ public static function getMenu($menutype = '', $nav_class = [], $logo = null, $l
$menu_params = new Registry();
$menu_params->loadString($header_menu_params);

if (ASTROID_JOOMLA_VERSION == 3) {
$list = \ModMenuHelper::getList($menu_params);
$base = \ModMenuHelper::getBase($menu_params);
$active = \ModMenuHelper::getActive($menu_params);
$default = \ModMenuHelper::getDefault();
} else {
$list = MenuHelper::getList($menu_params);
$base = MenuHelper::getBase($menu_params);
$active = MenuHelper::getActive($menu_params);
$default = MenuHelper::getDefault();
}
$list = MenuHelper::getList($menu_params);
$base = MenuHelper::getBase($menu_params);
$active = MenuHelper::getActive($menu_params);
$default = MenuHelper::getDefault();

$active_id = $active->id;
$default_id = $default->id;
Expand Down Expand Up @@ -591,17 +583,10 @@ public static function getMobileMenu($menutype = '', $nav_class = [])
$menu_params = new Registry();
$menu_params->loadString($header_menu_params);

if (ASTROID_JOOMLA_VERSION == 3) {
$list = \ModMenuHelper::getList($menu_params);
$base = \ModMenuHelper::getBase($menu_params);
$active = \ModMenuHelper::getActive($menu_params);
$default = \ModMenuHelper::getDefault();
} else {
$list = MenuHelper::getList($menu_params);
$base = MenuHelper::getBase($menu_params);
$active = MenuHelper::getActive($menu_params);
$default = MenuHelper::getDefault();
}
$list = MenuHelper::getList($menu_params);
$base = MenuHelper::getBase($menu_params);
$active = MenuHelper::getActive($menu_params);
$default = MenuHelper::getDefault();

$active_id = $active->id;
$default_id = $default->id;
Expand Down Expand Up @@ -647,17 +632,10 @@ public static function getSidebarMenu($menutype = '')
$menu_params = new Registry();
$menu_params->loadString($header_menu_params);

if (ASTROID_JOOMLA_VERSION == 3) {
$list = \ModMenuHelper::getList($menu_params);
$base = \ModMenuHelper::getBase($menu_params);
$active = \ModMenuHelper::getActive($menu_params);
$default = \ModMenuHelper::getDefault();
} else {
$list = MenuHelper::getList($menu_params);
$base = MenuHelper::getBase($menu_params);
$active = MenuHelper::getActive($menu_params);
$default = MenuHelper::getDefault();
}
$list = MenuHelper::getList($menu_params);
$base = MenuHelper::getBase($menu_params);
$active = MenuHelper::getActive($menu_params);
$default = MenuHelper::getDefault();

$active_id = $active->id;
$default_id = $default->id;
Expand Down
Loading

0 comments on commit 63dcc74

Please sign in to comment.