Skip to content

Commit

Permalink
Added OwlCarousel widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Jan 6, 2017
1 parent 4030710 commit badb46a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/widgets/OwlCarousel.php
@@ -0,0 +1,57 @@
<?php

namespace hiqdev\themes\obaju\widgets;

use hiqdev\themes\obaju\OwlCarouselAsset;
use yii\base\Widget;
use yii\helpers\Html;
use yii\web\JsExpression;
use yii\web\View;

class OwlCarousel extends Widget
{
/**
* Items (div, a, img, span, li etc.)
* @var array
*/
public $items = [];

/**
* Container element (div, ul etc.)
* @var string
*/
public $containerTag = 'div';

/**
* Call the plugin function and your carousel is ready.
* @var string
*/
public $pluginInit = '$(".owl-carousel").owlCarousel();';

/**
* Only the class owl-carousel is mandatory to apply proper styles
* NOTE: The owl-theme class is optional, but without it, you will need to style navigation features on your own.
* @var array
*/
protected $defaultContainerOptions = ['class' => 'owl-carousel owl-theme'];

public $containerOptions = [];

public function run()
{
$this->initCarouselJs();
$out = Html::beginTag($this->containerTag, array_merge($this->containerOptions, $this->defaultContainerOptions));
foreach ($this->items as $item) {
$out .= $item;
}
$out .= Html::endTag($this->containerTag);

return $out;
}

public function initCarouselJs()
{
OwlCarouselAsset::register($this->view);
$this->view->registerJs(new JsExpression($this->pluginInit), View::POS_READY);
}
}

0 comments on commit badb46a

Please sign in to comment.