This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,130 @@
<?php
namespace Nextend\SmartSlider3\Widget\Arrow\ArrowImage;
use Nextend\Framework\Form\Element\Grouping;
use Nextend\Framework\Form\Element\OnOff;
use Nextend\Framework\Form\Element\Radio\ImageListFromFolder;
use Nextend\Framework\Form\Element\Select;
use Nextend\Framework\Form\Element\Style;
use Nextend\Framework\Form\Element\Text;
use Nextend\Framework\Form\Element\Text\Color;
use Nextend\Framework\Form\Element\Text\FieldImage;
use Nextend\Framework\Form\Fieldset\FieldsetRow;
use Nextend\SmartSlider3\Form\Element\Group\WidgetPosition;
use Nextend\SmartSlider3\Widget\Arrow\AbstractWidgetArrow;
class ArrowImage extends AbstractWidgetArrow {
protected $defaults = array(
'widget-arrow-desktop-image-width' => 32,
'widget-arrow-tablet-image-width' => 32,
'widget-arrow-mobile-image-width' => 16,
'widget-arrow-previous-image' => '',
'widget-arrow-previous' => '$ss$/plugins/widgetarrow/image/image/previous/normal.svg',
'widget-arrow-previous-color' => 'ffffffcc',
'widget-arrow-previous-hover' => 0,
'widget-arrow-previous-hover-color' => 'ffffffcc',
'widget-arrow-style' => '{"data":[{"backgroundcolor":"000000ab","padding":"20|*|10|*|20|*|10|*|px","boxshadow":"0|*|0|*|0|*|0|*|000000ff","border":"0|*|solid|*|000000ff","borderradius":"5","extra":""},{"backgroundcolor":"000000cf"}]}',
'widget-arrow-previous-position-mode' => 'simple',
'widget-arrow-previous-position-area' => 6,
'widget-arrow-previous-position-offset' => 15,
'widget-arrow-next-position-mode' => 'simple',
'widget-arrow-next-position-area' => 7,
'widget-arrow-next-position-offset' => 15,
'widget-arrow-animation' => 'fade',
'widget-arrow-mirror' => 1,
'widget-arrow-next-image' => '',
'widget-arrow-next' => '$ss$/plugins/widgetarrow/image/image/next/normal.svg',
'widget-arrow-next-color' => 'ffffffcc',
'widget-arrow-next-hover' => 0,
'widget-arrow-next-hover-color' => 'ffffffcc',
'widget-arrow-previous-alt' => 'previous arrow',
'widget-arrow-next-alt' => 'next arrow',
'widget-arrow-base64' => 1
);
public function renderFields($container) {
$rowPrevious = new FieldsetRow($container, 'widget-arrow-image-row-previous');
$fieldPrevious = new ImageListFromFolder($rowPrevious, 'widget-arrow-previous', n2_x('Previous', 'Arrow direction'), '', array(
'folder' => self::getAssetsPath() . '/previous/'
));
$fieldPrevious->setHasDisabled(false);
$groupingPreviousColorContainer = new Grouping($rowPrevious, 'widget-arrow-image-row-icon-grouping-previous-color-container');
$groupingPreviousColor = new Grouping($groupingPreviousColorContainer, 'widget-arrow-image-row-icon-grouping-previous-color');
new Color($groupingPreviousColor, 'widget-arrow-previous-color', n2_('Color'), '', array(
'alpha' => true
));
new OnOff($groupingPreviousColor, 'widget-arrow-previous-hover', n2_('Hover'), 0, array(
'relatedFieldsOn' => array(
'sliderwidget-arrow-previous-hover-color'
)
));
new Color($groupingPreviousColor, 'widget-arrow-previous-hover-color', n2_('Hover color'), '', array(
'alpha' => true
));
$row2 = new FieldsetRow($container, 'widget-arrow-image-row-2');
new Style($row2, 'widget-arrow-style', n2_('Arrow'), '', array(
'mode' => 'button',
'preview' => 'SmartSliderAdminWidgetArrowImage',
));
new WidgetPosition($row2, 'widget-arrow-previous-position', n2_('Previous position'));
new WidgetPosition($row2, 'widget-arrow-next-position', n2_('Next position'));
$row3 = new FieldsetRow($container, 'widget-arrow-image-row-3');
new Text($row3, 'widget-arrow-previous-alt', n2_('Previous alt tag'), 'previous arrow');
new Text($row3, 'widget-arrow-next-alt', n2_('Next alt tag'), 'next arrow');
new OnOff($row3, 'widget-arrow-base64', n2_('Base64'), 1, array(
'tipLabel' => n2_('Base64'),
'tipDescription' => n2_('Base64 encoded arrow images are loading faster and they are colorable. But optimization plugins often have errors in their codes related to them, so if your arrow won\'t load, turn this option off.'),
'tipLink' => 'https://smartslider.helpscoutdocs.com/article/1782-arrow#base64',
'relatedFieldsOn' => array(
'sliderwidget-arrow-image-row-icon-grouping-previous-color',
'sliderwidget-arrow-image-row-icon-grouping-next-color'
)
));
$row4 = new FieldsetRow($container, 'widget-arrow-image-row-4');
new Text\Number($row4, 'widget-arrow-desktop-image-width', n2_('Image width - Desktop'), '', array(
'wide' => 4,
'unit' => 'px'
));
new Text\Number($row4, 'widget-arrow-tablet-image-width', n2_('Image width - Tablet'), '', array(
'wide' => 4,
'unit' => 'px'
));
new Text\Number($row4, 'widget-arrow-mobile-image-width', n2_('Image width - Mobile'), '', array(
'wide' => 4,
'unit' => 'px'
));
}
public function prepareExport($export, $params) {
$export->addImage($params->get($this->key . 'previous-image', ''));
$export->addImage($params->get($this->key . 'next-image', ''));
$export->addVisual($params->get($this->key . 'style'));
}
public function prepareImport($import, $params) {
$params->set($this->key . 'previous-image', $import->fixImage($params->get($this->key . 'previous-image', '')));
$params->set($this->key . 'next-image', $import->fixImage($params->get($this->key . 'next-image', '')));
$params->set($this->key . 'style', $import->fixSection($params->get($this->key . 'style', '')));
}
}

View File

@ -0,0 +1,302 @@
<?php
namespace Nextend\SmartSlider3\Widget\Arrow\ArrowImage;
use Nextend\Framework\Asset\Js\Js;
use Nextend\Framework\FastImageSize\FastImageSize;
use Nextend\Framework\Filesystem\Filesystem;
use Nextend\Framework\Misc\Base64;
use Nextend\Framework\Parser\Color;
use Nextend\Framework\ResourceTranslator\ResourceTranslator;
use Nextend\Framework\View\Html;
use Nextend\SmartSlider3\Widget\AbstractWidgetFrontend;
class ArrowImageFrontend extends AbstractWidgetFrontend {
protected $rendered = false;
protected $previousArguments;
protected $nextArguments;
public function __construct($sliderWidget, $widget, $params) {
parent::__construct($sliderWidget, $widget, $params);
if ($this->isRenderable('previous')) {
$this->addToPlacement($this->key . 'previous-position-', array(
$this,
'renderPrevious'
));
}
if ($this->isRenderable('next')) {
$this->addToPlacement($this->key . 'next-position-', array(
$this,
'renderNext'
));
}
}
private function isRenderable($side) {
$arrow = $this->params->get($this->key . $side . '-image');
if (empty($arrow)) {
$arrow = $this->params->get($this->key . $side);
if ($arrow == -1) {
$arrow = null;
}
}
return !!$arrow;
}
public function renderPrevious($attributes = array()) {
$this->render();
if ($this->previousArguments) {
array_unshift($this->previousArguments, $attributes);
return call_user_func_array(array(
$this,
'getHTML'
), $this->previousArguments);
}
return '';
}
public function renderNext($attributes = array()) {
$this->render();
if ($this->nextArguments) {
array_unshift($this->nextArguments, $attributes);
return call_user_func_array(array(
$this,
'getHTML'
), $this->nextArguments);
}
return '';
}
private function render() {
if ($this->rendered) return;
$this->rendered = true;
$slider = $this->slider;
$id = $this->slider->elementId;
$params = $this->params;
if ($slider->getSlidesCount() <= 1) {
return '';
}
$previousImage = $params->get($this->key . 'previous-image');
$previousValue = $params->get($this->key . 'previous');
$previousColor = $params->get($this->key . 'previous-color');
$previousHover = $params->get($this->key . 'previous-hover');
$previousHoverColor = $params->get($this->key . 'previous-hover-color');
if (empty($previousImage)) {
if ($previousValue == -1) {
$previous = false;
} else {
$previous = ResourceTranslator::pathToResource(self::getAssetsPath() . '/previous/' . basename($previousValue));
}
} else {
$previous = $previousImage;
}
if ($params->get($this->key . 'mirror')) {
$nextColor = $previousColor;
$nextHover = $previousHover;
$nextHoverColor = $previousHoverColor;
if (empty($previousImage)) {
if ($previousValue == -1) {
$next = false;
} else {
$next = ResourceTranslator::pathToResource(self::getAssetsPath() . '/next/' . basename($previousValue));
}
} else {
$next = $previousImage;
$slider->addCSS('#' . $id . '-arrow-next' . '{transform: rotate(180deg);}');
}
} else {
$next = $params->get($this->key . 'next-image');
$nextColor = $params->get($this->key . 'next-color');
$nextHover = $params->get($this->key . 'next-hover');
$nextHoverColor = $params->get($this->key . 'next-hover-color');
if (empty($next)) {
$nextValue = $params->get($this->key . 'next');
if ($nextValue == -1) {
$next = false;
} else {
$next = ResourceTranslator::pathToResource(self::getAssetsPath() . '/next/' . basename($nextValue));
}
}
}
if ($previous || $next) {
$slider->addLess(self::getAssetsPath() . '/style.n2less', array(
"sliderid" => $slider->elementId
));
Js::addStaticGroup(self::getAssetsPath() . '/dist/w-arrow-image.min.js', 'w-arrow-image');
$displayAttributes = $this->getDisplayAttributes($params, $this->key);
$animation = $params->get($this->key . 'animation');
if ($animation == 'none' || $animation == 'fade') {
$styleClass = $slider->addStyle($params->get($this->key . 'style'), 'heading');
} else {
$styleClass = $slider->addStyle($params->get($this->key . 'style'), 'heading-active');
}
if ($previous) {
$this->previousArguments = array(
$id,
$animation,
'previous',
$previous,
$displayAttributes,
$styleClass,
$previousColor,
$previousHover,
$previousHoverColor
);
}
if ($next) {
$this->nextArguments = array(
$id,
$animation,
'next',
$next,
$displayAttributes,
$styleClass,
$nextColor,
$nextHover,
$nextHoverColor
);
}
$desktopWidth = $params->get('widget-arrow-desktop-image-width');
$tabletWidth = $params->get('widget-arrow-tablet-image-width');
$mobileWidth = $params->get('widget-arrow-mobile-image-width');
$slider->addDeviceCSS('all', 'div#' . $id . ' .nextend-arrow img{width: ' . $desktopWidth . 'px}');
if ($tabletWidth != $desktopWidth) {
$slider->addDeviceCSS('tabletportrait', 'div#' . $id . ' .nextend-arrow img{width: ' . $tabletWidth . 'px}');
$slider->addDeviceCSS('tabletlandscape', 'div#' . $id . ' .nextend-arrow img{width: ' . $tabletWidth . 'px}');
}
if ($mobileWidth != $desktopWidth) {
$slider->addDeviceCSS('mobileportrait', 'div#' . $id . ' .nextend-arrow img{width: ' . $mobileWidth . 'px}');
$slider->addDeviceCSS('mobilelandscape', 'div#' . $id . ' .nextend-arrow img{width: ' . $mobileWidth . 'px}');
}
$slider->features->addInitCallback('new _N2.SmartSliderWidgetArrowImage(this);');
$slider->sliderType->addJSDependency('SmartSliderWidgetArrowImage');
}
}
/**
* @param array $attributes
* @param string $id
* @param string $animation
* @param string $side
* @param string $imageRaw
* @param string $displayAttributes
* @param string $styleClass
* @param string $color
* @param int $hover
* @param string $hoverColor
*
* @return string
*/
private function getHTML($attributes, $id, $animation, $side, $imageRaw, $displayAttributes, $styleClass, $color = 'ffffffcc', $hover = 0, $hoverColor = 'ffffffcc') {
$imageHover = null;
$ext = pathinfo($imageRaw, PATHINFO_EXTENSION);
/**
* We can not colorize SVGs when base64 disabled.
*/
if ($ext == 'svg' && ResourceTranslator::isResource($imageRaw) && $this->params->get($this->key . 'base64', 1)) {
list($color, $opacity) = Color::colorToSVG($color);
$content = Filesystem::readFile(ResourceTranslator::toPath($imageRaw));
$image = 'data:image/svg+xml;base64,' . Base64::encode(str_replace(array(
'fill="#FFF"',
'opacity="1"'
), array(
'fill="#' . $color . '"',
'opacity="' . $opacity . '"'
), $content));
if ($hover) {
list($color, $opacity) = Color::colorToSVG($hoverColor);
$imageHover = 'data:image/svg+xml;base64,' . Base64::encode(str_replace(array(
'fill="#FFF"',
'opacity="1"'
), array(
'fill="#' . $color . '"',
'opacity="' . $opacity . '"'
), $content));
}
} else {
$image = ResourceTranslator::toUrl($imageRaw);
}
$alt = $this->params->get($this->key . $side . '-alt', $side . ' arrow');
$sizeAttributes = array();
FastImageSize::initAttributes($imageRaw, $sizeAttributes);
if ($imageHover === null) {
$image = Html::image($image, $alt, $sizeAttributes + Html::addExcludeLazyLoadAttributes());
} else {
$image = Html::image($image, $alt, $sizeAttributes + Html::addExcludeLazyLoadAttributes(array(
'class' => 'n2-arrow-normal-img'
))) . Html::image($imageHover, $alt, $sizeAttributes + Html::addExcludeLazyLoadAttributes(array(
'class' => 'n2-arrow-hover-img'
)));
}
if ($animation == 'none' || $animation == 'fade') {
return Html::tag('div', Html::mergeAttributes($attributes, $displayAttributes, array(
'id' => $id . '-arrow-' . $side,
'class' => $styleClass . 'nextend-arrow n2-ow-all nextend-arrow-' . $side . ' nextend-arrow-animated-' . $animation,
'role' => 'button',
'aria-label' => $alt,
'tabindex' => '0'
)), $image);
}
return Html::tag('div', Html::mergeAttributes($attributes, $displayAttributes, array(
'id' => $id . '-arrow-' . $side,
'class' => 'nextend-arrow nextend-arrow-animated n2-ow-all nextend-arrow-animated-' . $animation . ' nextend-arrow-' . $side,
'role' => 'button',
'aria-label' => $alt,
'tabindex' => '0'
)), Html::tag('div', array(
'class' => $styleClass
), $image) . Html::tag('div', array(
'class' => $styleClass . ' n2-active'
), $image));
}
}