diff --git a/src/Elements/SliderElement.php b/src/Elements/SliderElement.php new file mode 100755 index 0000000..032c26c --- /dev/null +++ b/src/Elements/SliderElement.php @@ -0,0 +1,186 @@ + 'Int', + 'SlidesInRow' => 'Int', + 'ImageOriginalSize' => 'Boolean(0)', + ]; + + private static $extensions = [ + FlexSlider::class, + ]; + + private static $owns = [ + 'Slides', + ]; + + private $items; + + public function getType() + { + return self::$singular_name; + } + + protected function ratioSize($size) + { + $count = $this->SlidesInRow; + return ($count > 1) ? $size / $count : $size; + } + + public function getSlideWidth() + { + if ($this->getField('ImageOriginalSize')) { + return null; + } + + return $this->ratioSize(self::config()->get('slide_width')); + } + + public function getSlideHeight() + { + if ($this->getField('ImageOriginalSize')) { + return null; + } + + return $this->ratioSize(self::config()->get('slide_height')); + } + + public function getCMSFields() + { + $fields = parent::getCMSFields(); + + // remove in case you don't need to provide this functionality + $fields->removeByName([ + 'ConfigHD', + 'Animation', + 'Loop', + 'Animate', + 'ThumbnailNav', + 'SliderControlNav', + 'SliderDirectionNav', + 'CarouselControlNav', + 'CarouselDirectionNav', + 'CarouselThumbnailCt', + ]); + + $fields->addFieldsToTab('Root.Settings', [ + CheckboxField::create('ImageOriginalSize', 'Use original image size'), + NumericField::create('Interval', 'Auto-play Interval (sec)'), + NumericField::create('SlidesInRow'), + ]); + + $grid = $fields->dataFieldByName('Slides'); + if ($grid) { + $fields->insertBefore('Slides', LiteralField::create( + 'SlidesNote', + '