Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/JsHelper.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Created on Tue Oct 27 2020
*
*
* @package yii2-extentions
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2010 - 2020 Sergey Coderius
*
* @author Sergey Coderius <sunrise4fun@gmail.com>
* @link https://github.com/coderius - My github. See more my packages here...
* @link https://coderius.biz.ua/ - My dev. blog
*
*
* Contact email: sunrise4fun@gmail.com - Have suggestions, contact me |:=)
*/

Expand Down Expand Up @@ -59,6 +59,4 @@ public static function newJsObject($instanceName, $params = [])
$params = implode(",", $params);
return new \yii\web\JsExpression("new {$instanceName}({$params})");
}


}
}
73 changes: 36 additions & 37 deletions src/SlideDefault.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Created on Wed Oct 28 2020
*
*
* @package yii2-extentions
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2010 - 2020 Sergey Coderius
*
* @author Sergey Coderius <sunrise4fun@gmail.com>
* @link https://github.com/coderius - My github. See more my packages here...
* @link https://coderius.biz.ua/ - My dev. blog
*
*
* Contact email: sunrise4fun@gmail.com - Have suggestions, contact me |:=)
*/

Expand All @@ -27,38 +27,37 @@ class SlideDefault extends BaseObject
/**
* @var SwiperSlider widget object that owns this slide.
*/
public $slider;
/**
* @var array the HTML attributes for the slide tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
* Vilue contain all content pasted from tag
*
* @var string
*/
public $value = '';

/**
* Undocumented function
*
* @param string $tag
* @param int $index $index the zero-based index of the data item among the item array returned by [[SwiperSlider::makeHtml]]
* @return string
*/
public function renderSlideHtml($tag, $index)
{
$content = $this->value;
if ($this->value instanceof Closure) {
$content = call_user_func($this->value, $tag, $index, $this);
} else {
$content = $this->value;
}

$options = $this->options;

return Html::tag($tag, $content, $options);
}

}
public $slider;
/**
* @var array the HTML attributes for the slide tag.
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
*/
public $options = [];
/**
* Vilue contain all content pasted from tag
*
* @var string
*/
public $value = '';

/**
* Undocumented function
*
* @param string $tag
* @param int $index $index the zero-based index of the data item among the item array returned by [[SwiperSlider::makeHtml]]
* @return string
*/
public function renderSlideHtml($tag, $index)
{
$content = $this->value;
if ($this->value instanceof Closure) {
$content = call_user_func($this->value, $tag, $index, $this);
} else {
$content = $this->value;
}

$options = $this->options;

return Html::tag($tag, $content, $options);
}
}
37 changes: 20 additions & 17 deletions src/SwiperSlider.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Created on Tue Oct 27 2020
*
*
* @package yii2-extentions
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2010 - 2020 Sergey Coderius
*
* @author Sergey Coderius <sunrise4fun@gmail.com>
* @link https://github.com/coderius - My github. See more my packages here...
* @link https://coderius.biz.ua/ - My dev. blog
*
*
* Contact email: sunrise4fun@gmail.com - Have suggestions, contact me |:=)
*/

Expand Down Expand Up @@ -144,7 +144,7 @@ public function init()
if ($this->slides === null || empty($this->slides)) {
throw new InvalidConfigException("The 'slides' option is required");
}
}
}

/**
* @inheritdoc
Expand All @@ -163,12 +163,13 @@ public function run()
* 'on ' . SwiperSlider::EVENT_AFTER_REGISTER_DEFAULT_ASSET => function(){
* CustomAsset::register($view)
* },
* ...
* ...
* ]);
*
*
* @return void
*/
protected function registerAssets(){
protected function registerAssets()
{
$view = $this->getView();
$this->trigger(self::EVENT_BEFORE_REGISTER_DEFAULT_ASSET);
$dafaultAsset = static::ASSET_DEFAULT;
Expand All @@ -182,14 +183,15 @@ protected function registerAssets(){
*
* @return void
*/
protected function makeHtml(){
protected function makeHtml()
{

//Slides
//S
$slides = [];
$index = 0;
foreach($this->slides as $slide){
if(is_string($slide)){
foreach ($this->slides as $slide) {
if (is_string($slide)) {
$htmlSlide = $this->getHtmlElem(static::SLIDE, [], $slide);
} else {
//Mergin current slide attributes with global widget options styles pasted to all elements on this type
Expand Down Expand Up @@ -226,15 +228,15 @@ protected function makeHtml(){
$content[] = $wrapper;

// And if we need pagination
if($this->showPagination){
if ($this->showPagination) {
$content[] = $pagination;
}

$content[] = $buttonPrev;
$content[] = $buttonNext;

// And if we need scrollbar
if($this->showScrollbar){
if ($this->showScrollbar) {
$content[] = $scrollbar;
}

Expand Down Expand Up @@ -266,7 +268,7 @@ protected function getHtmlElem($itemName, $options = [], $content = '', $tag = '

/**
* Merge options array with default params like `class` and global options pasted when widget created
* Example:
* Example:
* echo SwiperSlider::widget([
* ...
* 'options' => [
Expand All @@ -278,15 +280,16 @@ protected function getHtmlElem($itemName, $options = [], $content = '', $tag = '
* ],
* ...
* ]);
*
*
* In this example we merge options for html elements `container` and `slide` and default created options `class` for them getted
* by function static::getItemCssClass($itemName, false)
*
* @param string $itemName
* @param [type] $options
* @return void
*/
protected function mergeGlobalStyles($itemName, $options){
protected function mergeGlobalStyles($itemName, $options)
{
$options = ArrayHelper::merge(['class' => static::getItemCssClass($itemName, false)], $options);
$style = !empty($this->options['styles'][$itemName]) ? $this->options['styles'][$itemName] : null;
Html::addCssStyle($options, $style);
Expand All @@ -298,7 +301,8 @@ protected function mergeGlobalStyles($itemName, $options){
*
* @return void
*/
protected function registerPluginJs(){
protected function registerPluginJs()
{
$view = $this->getView();
$pluginParams = [];
$pluginParams[] = JsHelper::addString("#" . $this->widgetId);
Expand All @@ -309,5 +313,4 @@ protected function registerPluginJs(){

$view->registerJs($jsVar, \yii\web\View::POS_END);
}

}
}
9 changes: 4 additions & 5 deletions src/SwiperSliderAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Yii;
use yii\web\AssetBundle;

/**
* Asset bundle SwiperSlider
*/
Expand Down Expand Up @@ -54,7 +55,7 @@ public function setupAssets($ext, $paths)
{
$allowedExts = ['css', 'js'];

if(!in_array($ext, $allowedExts)){
if (!in_array($ext, $allowedExts)) {
throw new \InvalidArgumentException("Extention {$ext} not allowed");
}

Expand All @@ -79,7 +80,7 @@ public function setupAssets($ext, $paths)
public static function makePathAssets($ext, $paths, $pref = false)
{
$p = [];
foreach($paths as $path){
foreach ($paths as $path) {
$p[] = $pref ? "{$path}.{$pref}.{$ext}" : "{$path}.{$ext}";
}

Expand All @@ -95,12 +96,10 @@ public static function register($view, $cdn = false)
{
$bundle = parent::register($view);

if($cdn){
if ($cdn) {
$bundle->fromCdn($cdn);
}

return $bundle;
}

}

9 changes: 5 additions & 4 deletions tests/AssetManager.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Created on Fri Oct 30 2020
*
*
* @package yii2-extentions
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2010 - 2020 Sergey Coderius
*
* @author Sergey Coderius <sunrise4fun@gmail.com>
* @link https://github.com/coderius - My github. See more my packages here...
* @link https://coderius.biz.ua/ - My dev. blog
*
*
* Contact email: sunrise4fun@gmail.com - Have suggestions, contact me |:=)
*/

Expand All @@ -27,11 +27,12 @@ class AssetManager extends \yii\web\AssetManager
/**
* @inheritdoc
*/
public function hash($path) {
public function hash($path)
{
if (!isset($this->_hashes[$path])) {
$this->_hashes[$path] = $this->_counter++;
}

return $this->_hashes[$path];
}
}
}
8 changes: 3 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Created on Sun Nov 01 2020
*
*
* @package yii2-extentions
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @copyright Copyright (c) 2010 - 2020 Sergey Coderius
*
* @author Sergey Coderius <sunrise4fun@gmail.com>
* @link https://github.com/coderius - My github. See more my packages here...
* @link https://coderius.biz.ua/ - My dev. blog
*
*
* Contact email: sunrise4fun@gmail.com - Have suggestions, contact me |:=)
*/

Expand Down Expand Up @@ -142,6 +142,4 @@ protected function getVendorPath()
{
return dirname(__DIR__) . '/vendor';
}


}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

Yii::setAlias('@tests', __DIR__);
Yii::setAlias('@coderius/swiperslider', __DIR__ . '/../src');
Yii::setAlias('@coderius/swiperslider', __DIR__ . '/../src');
2 changes: 1 addition & 1 deletion tests/compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public function expectExceptionMessageRegExp($messageRegExp)
}
}
}
}
}
Loading