Skip to content

Commit

Permalink
Update Grid Widget and Image Group Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Sep 5, 2024
1 parent aa8fdb8 commit 44fb38c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 24 deletions.
61 changes: 38 additions & 23 deletions framework/elements/grid/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
defined('_JEXEC') or die;

use Astroid\Helper\Style;
use Astroid\Helper;
use Astroid\Helper\Media;
use Joomla\CMS\Uri\Uri;

extract($displayData);
$grids = $params->get('grids', '');
Expand Down Expand Up @@ -158,24 +161,25 @@
$button_margin_top = $params->get('button_margin_top', '');
echo '<div class="row'.$row_column_cls.'">';
foreach ($grids as $key => $grid) {
$grid_params = Style::getSubFormParams($grid->params);
$link_target = !empty($grid_params['link_target']) ? ' target="'.$grid_params['link_target'].'"' : '';
$grid_params = Helper::loadParams($grid->params);
$link_target = !empty($grid_params->get('link_target', '')) ? ' target="'.$grid_params->get('link_target', '').'"' : '';

$media = '';
if ($grid_params['type'] == 'image' && $grid_params['image']) {
if ($grid_params->get('type', '') == 'image' && $grid_params->get('image', '')) {
$media = '<div class="as-image-cover position-relative overflow-hidden' . ($layout == 'overlay' ? ' astroid-image-overlay-cover' : '') . $image_border_radius . $hover_effect . $transition . ($media_position == 'bottom' ? ' order-2 ' : '') . '">';
$media .= '<img class="' . ($image_fullwidth ? 'w-100' : '') . ($enable_image_cover || $media_position == 'left' || $media_position == 'right' ? ' object-fit-cover h-100' : '') . ($params->get('card_style', '') == 'none' ? '' : ' card-img-'. $media_position) .'" src="'. Astroid\Helper\Media::getPath() . '/' . $grid_params['image'].'" alt="'.$grid_params['title'].'">';
$media .= '<img class="' . ($image_fullwidth ? 'w-100' : '') . ($enable_image_cover || $media_position == 'left' || $media_position == 'right' ? ' object-fit-cover h-100' : '') . ($params->get('card_style', '') == 'none' ? '' : ' card-img-'. $media_position) .'" src="'. Astroid\Helper\Media::getPath() . '/' . $grid_params->get('image', '').'" alt="'.$grid_params->get('title', '').'">';
$media .= '</div>';
if ( !empty($grid_params['link']) ) {
$media = '<a href="'. $grid_params['link'] . '"'.$link_target.' class="'.($media_position == 'bottom' ? 'order-2 ' : '').'">'. $media .'</a>';
if ( !empty($grid_params->get('link', '')) ) {
$media = '<a href="'. $grid_params->get('link', '') . '"'.$link_target.' class="'.($media_position == 'bottom' ? 'order-2 ' : '').'">'. $media .'</a>';
}
} elseif ($grid_params['type'] == 'icon') {
if ($grid_params['icon_type'] == 'fontawesome') {
$media = '<i class="astroid-icon '. ($media_position == 'bottom' ? 'order-2 ' : '') .$grid_params['fa_icon'].'"></i>';
} elseif ($grid_params->get('type', '') == 'icon') {
if ($grid_params->get('icon_type', '') == 'fontawesome') {
$media = '<i class="astroid-icon '. ($media_position == 'bottom' ? 'order-2 ' : '') .$grid_params->get('fa_icon', '').'"></i>';
} else {
$media = '<i class="astroid-icon '. ($media_position == 'bottom' ? 'order-2 ' : '') .$grid_params['custom_icon'].'"></i>';
$media = '<i class="astroid-icon '. ($media_position == 'bottom' ? 'order-2 ' : '') .$grid_params->get('custom_icon', '').'"></i>';
}
if ( !empty($grid_params['link']) && !empty($params->get('enable_icon_link', 0)) ) {
$media = '<a href="'. $grid_params['link'] . '"'.$link_target.' class="'.($media_position == 'bottom' ? 'order-2 ' : '').'">'. $media .'</a>';
if ( !empty($grid_params->get('link', '')) && !empty($params->get('enable_icon_link', 0)) ) {
$media = '<a href="'. $grid_params->get('link', '') . '"'.$link_target.' class="'.($media_position == 'bottom' ? 'order-2 ' : '').'">'. $media .'</a>';
}
}

Expand All @@ -197,22 +201,22 @@
if ($media_position == 'inside') {
echo $media;
}
if (!empty($grid_params['meta']) && $meta_position == 'before') {
echo '<div class="astroid-meta">' . $grid_params['meta'] . '</div>';
if (!empty($grid_params->get('meta', '')) && $meta_position == 'before') {
echo '<div class="astroid-meta">' . $grid_params->get('meta', '') . '</div>';
}
if (!empty($grid_params['title'])) {
echo '<'.$title_html_element.' class="astroid-heading">'. $grid_params['title'] . '</'.$title_html_element.'>';
if (!empty($grid_params->get('title', ''))) {
echo '<'.$title_html_element.' class="astroid-heading">'. $grid_params->get('title', '') . '</'.$title_html_element.'>';
}
if (!empty($grid_params['meta']) && $meta_position == 'after') {
echo '<div class="astroid-meta">' . $grid_params['meta'] . '</div>';
if (!empty($grid_params->get('meta', '')) && $meta_position == 'after') {
echo '<div class="astroid-meta">' . $grid_params->get('meta', '') . '</div>';
}
if (!empty($grid_params['description'])) {
echo '<div class="astroid-text">' . $grid_params['description'] . '</div>';
if (!empty($grid_params->get('description', ''))) {
echo '<div class="astroid-text">' . $grid_params->get('description', '') . '</div>';
}
if (!empty($grid_params['link']) && !empty($grid_params['link_title'])) {
if (!empty($grid_params->get('link', '')) && !empty($grid_params->get('link_title', ''))) {
$button_class = $button_style !== 'text' ? 'btn btn-' . (intval($button_outline) ? 'outline-' : '') . $button_style . $button_size. $button_bd_radius : 'as-btn-text text-uppercase text-reset';
$btn_title = $button_style == 'text' ? '<small>'. $grid_params['link_title'] . '</small>' : $grid_params['link_title'];
echo '<a class="'. $button_class . (!empty($button_margin_top) ? ' mt-' . $button_margin_top : '') .'" href="'.$grid_params['link'].'" role="button"'.$link_target.'>' . $btn_title . '</a>';
$btn_title = $button_style == 'text' ? '<small>'. $grid_params->get('link_title', '') . '</small>' : $grid_params->get('link_title', '');
echo '<a class="'. $button_class . (!empty($button_margin_top) ? ' mt-' . $button_margin_top : '') .'" href="'.$grid_params->get('link', '').'" role="button"'.$link_target.'>' . $btn_title . '</a>';
}

echo '</div>'; // End Card-Body
Expand All @@ -223,6 +227,17 @@
}

echo '</div></div>';

if ($grid_params->get('enable_background_image', 0)) {
$image = $grid_params->get('background_image', '');
if (!empty($image)) {
$element->style->child('#grid-' . $grid->id)->child('.card')->addCss('background-image', 'url(' . Uri::base(true) . '/' . Media::getPath() . '/' . $image . ')');
$element->style->child('#grid-' . $grid->id)->child('.card')->addCss('background-repeat', $grid_params->get('background_repeat', ''));
$element->style->child('#grid-' . $grid->id)->child('.card')->addCss('background-size', $grid_params->get('background_size', ''));
$element->style->child('#grid-' . $grid->id)->child('.card')->addCss('background-attachment', $grid_params->get('background_attchment', ''));
$element->style->child('#grid-' . $grid->id)->child('.card')->addCss('background-position', $grid_params->get('background_position', ''));
}
}
}
echo '</div>';

Expand Down
31 changes: 31 additions & 0 deletions framework/elements/grid/grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,37 @@
<option value="_parent">Parent Frame</option>
<option value="_top">Full body of the window</option>
</field>

<field name="enable_background_image" type="astroidradio" astroid-switch="true" default="0" label="ASTROID_WIDGET_ENABLE_BACKGROUND_IMAGE"/>
<field ngShow="[enable_background_image]==1" name="background_image" type="astroidmedia" label="TPL_ASTROID_BACKGROUND_IMAGE_LABEL"/>
<field ngShow="[enable_background_image]==1" name="background_repeat" type="astroidlist" label="TPL_ASTROID_BACKGROUND_REPEAT_LABEL">
<option value="">JGLOBAL_INHERIT</option>
<option value="no-repeat">TPL_ASTROID_BACKGROUND_NO_REPEAT_LABEL</option>
<option value="repeat-x">TPL_ASTROID_BACKGROUND_REPEAT_HORIZONTALLY_LABEL</option>
<option value="repeat-y">TPL_ASTROID_BACKGROUND_REPEAT_VERTICAL_LABEL</option>
</field>
<field ngShow="[enable_background_image]==1" name="background_size" type="astroidlist" label="ASTROID_BACKGROUND_SIZE">
<option value="">JGLOBAL_INHERIT</option>
<option value="cover">ASTROID_BACKGROUND_SIZE_COVER</option>
<option value="contain">ASTROID_BACKGROUND_SIZE_CONTAIN</option>
</field>
<field ngShow="[enable_background_image]==1" name="background_attchment" type="astroidlist" label="ASTROID_BACKGROUND_ATTCHMENT">
<option value="">JGLOBAL_INHERIT</option>
<option value="scroll">ASTROID_BACKGROUND_ATTCHMENT_SCROLL</option>
<option value="fixed">ASTROID_BACKGROUND_ATTCHMENT_FIXED</option>
</field>
<field ngShow="[enable_background_image]==1" name="background_position" type="astroidlist" label="ASTROID_BACKGROUND_POSITION_LABEL">
<option value="">JGLOBAL_INHERIT</option>
<option value="left top">ASTROID_BACKGROUND_POSITION_LEFT_TOP</option>
<option value="left center">ASTROID_BACKGROUND_POSITION_LEFT_CENTER</option>
<option value="left bottom">ASTROID_BACKGROUND_POSITION_LEFT_BOTTOM</option>
<option value="right top">ASTROID_BACKGROUND_POSITION_RIGHT_TOP</option>
<option value="right center">ASTROID_BACKGROUND_POSITION_RIGHT_CENTER</option>
<option value="right bottom">ASTROID_BACKGROUND_POSITION_RIGHT_BOTTOM</option>
<option value="center top">ASTROID_BACKGROUND_POSITION_CENTER_TOP</option>
<option value="center center">ASTROID_BACKGROUND_POSITION_CENTER_CENTER</option>
<option value="center bottom">ASTROID_BACKGROUND_POSITION_CENTER_BOTTOM</option>
</field>
</fieldset>
</fields>
</form>
Expand Down
8 changes: 7 additions & 1 deletion framework/elements/imagegroup/imagegroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Astroid\Framework;
use Astroid\Helper\Style;
use Joomla\CMS\Uri\Uri;

extract($displayData);
$images = $params->get('images', '');
Expand All @@ -37,13 +38,18 @@

$enable_column_alignment = $params->get('enable_column_alignment', 0);
$column_alignment = $params->get('column_alignment', '');
$text_alignment = $params->get('text_alignment', '');

$row_column_cls = 'row';

if ($enable_column_alignment) {
$row_column_cls .= ' ' . $column_alignment;
}

if ($text_alignment) {
$row_column_cls .= ' justify-content-' . $text_alignment;
}

if ($use_masonry && !$enable_slider) {
$row_column_cls .= ' as-masonry';
}
Expand Down Expand Up @@ -165,7 +171,7 @@
echo '<a href="'.$image_params['link'].'" title="'.$image_params['title'].'">';
}
echo '<div class="position-relative overflow-hidden' . $border_radius . $box_shadow . $hover_effect . $transition . '">';
echo '<img src="'. Astroid\Helper\Media::getPath() . '/' . $image_params['image'].'" alt="'.$image_params['title'].'" class="d-inline-block">';
echo '<img src="'. Astroid\Helper\Media::getMediaPath($image_params['image']).'" alt="'.$image_params['title'].'" class="d-inline-block">';
echo '</div>';
if ($image_params['use_link']) {
echo '</a>';
Expand Down
9 changes: 9 additions & 0 deletions framework/library/astroid/Helper/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public static function getPath()
}
}

public static function getMediaPath($link): string
{
if(strpos($link, "http://") !== false || strpos($link, "https://") !== false){
return $link;
} else {
return self::getPath() . '/' . $link;
}
}

public static function library()
{
$input = Factory::getApplication()->input;
Expand Down

0 comments on commit 44fb38c

Please sign in to comment.