diff --git a/README.md b/README.md index ced0147..8774287 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The FlexSlider module allows a developer to attach a [Woothemes FlexSlider](http ## Installation -`composer require dynamic/flexslider ^4.0` +`composer require dynamic/flexslider ^4.2` ## License diff --git a/composer.json b/composer.json index 71d1b4c..49a8371 100644 --- a/composer.json +++ b/composer.json @@ -41,5 +41,13 @@ "images", "thirdparty" ] - } + }, + "config": { + "process-timeout": 600, + "allow-plugins": { + "composer/installers": true, + "silverstripe/recipe-plugin": true, + "silverstripe/vendor-plugin": true + } + } } diff --git a/docs/en/index.md b/docs/en/index.md index d15ec3f..e6bc99a 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -16,39 +16,17 @@ Page: After attaching the DataExtension to your page type or DataObject run a `dev/build`. -#### Adjust slider speed -Adding `FlexSliderSpeed` to the config will adjust the speed of the slider in milliseconds. -Sliders default to 7000 milliseconds, or 7 seconds to show each slide. +##### Disabling Requirements -```yml -Page: - FlexSliderSpeed: 3000 - extensions: - - Dynamic\FlexSlider\ORM\FlexSlider -``` +The Flexslider module allows you control over both your jQuery and flexslider.min.js files. Each file has an independent config option which can be disabled allowing you control over what version (you bring and) include in your project by setting the following config flags: -The object that has FlexSlider applied can also have a method `setFlexSliderSpeed()`. -This will allow for a field to be added to the cms to control speed, or more fine grained control over the speed of the slider. -If `setFlexSliderSpeed()` return 0 or false the slider will fall back to using the config value. -```php -public function setFlexSliderSpeed() -{ - return 3000; -} -``` - -Adjusting the defualt for all sliders can also be done in the config. ```yml -Dynamic\FlexSlider\ORM\FlexSlider: - FlexSliderSpeed: 3000 +My\Page: + jquery_enabled: false + flexslider_enabled: false ``` -### User Guide - -You should now see a "Slides" tab on the page type or DataObject to which you applied the DataExtension. Simply create Slides to be included in the slide show that link to other pages on your website. - -![screen shot](../../images/FlexSliderCMS.png) - -You can inculde FlexSlider in your layout by using `<% include FlexSlider %>` - -![screen shot](../../images/FlexSlider.png) +**Notse** +- The `jquery_enabled` config allows for disabling specifically the jQuery library which is included to support `jquery.flexslider-min.js`. Disalbing this with a `false` value allows you to require your own version. + - You may have to disable `flexslider_enabled` and re-require `dynamic/flexslider:thirdparty/flexslider/jquery.flexslider-min.js` in your project for inclusion order purposes. See the [Inclusion Order](https://docs.silverstripe.org/en/4/developer_guides/templates/requirements/#inclusion-order) documentation for more information. +- The `flexslider_enabled` config is generally for allowing fine tuned placement of the requirement vs replacement, however you can set the value to false and replace with your own flexslider client plugin. \ No newline at end of file diff --git a/src/ORM/FlexSlider.php b/src/ORM/FlexSlider.php index 0617be6..ebc2213 100644 --- a/src/ORM/FlexSlider.php +++ b/src/ORM/FlexSlider.php @@ -62,6 +62,16 @@ class FlexSlider extends DataExtension 'Slides' => SlideImage::class, ]; + /** + * @var bool + */ + private static $jquery_enabled = true; + + /** + * @var bool + */ + private static $flexslider_enabled = true; + /** * */ @@ -194,9 +204,15 @@ public function contentcontrollerInit() { // only call custom script if page has Slides and DataExtension if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) { - if ($this->owner->getSlideShow()->exists()) { - $this->getCustomScript(); + if ($this->owner->config()->get('jquery_enabled')) { + Requirements::javascript('//code.jquery.com/jquery-3.6.1.min.js'); } + + if ($this->owner->getSlideShow()->exists() && $this->owner->config()->get('flexslider_enabled')) { + Requirements::javascript('dynamic/flexslider:thirdparty/flexslider/jquery.flexslider-min.js'); + } + + $this->getCustomScript(); } } @@ -222,13 +238,13 @@ public function getCustomScript() "(function($) { $(document).ready(function(){ jQuery('.flexslider').each(function(index){ - + if(jQuery('.fs-carousel').eq(index).length) { jQuery('.fs-carousel').eq(index).flexslider({ slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean() . ", animation: 'slide', animationLoop: " . $this->owner->obj('Loop')->NiceAsBoolean() . ", - controlNav: " . $this->owner->obj('CarouselControlNav')->NiceAsBoolean() . ", + controlNav: " . $this->owner->obj('CarouselControlNav')->NiceAsBoolean() . ", directionNav: " . $this->owner->obj('CarouselDirectionNav')->NiceAsBoolean() . ", prevText: '', nextText: '', @@ -241,7 +257,7 @@ public function getCustomScript() itemMargin: 10 }); } - + if(jQuery('.flexslider').eq(index).length){ jQuery('.flexslider').eq(index).flexslider({ slideshow: " . $this->owner->obj('Animate')->NiceAsBoolean() . ", @@ -259,7 +275,7 @@ public function getCustomScript() }, before: " . $before . ', after: ' . $after . ', - slideshowSpeed: ' . $speed . ' + slideshowSpeed: ' . $speed . ' }); } }) diff --git a/templates/Includes/FlexSlider.ss b/templates/Includes/FlexSlider.ss index a68ae0e..d848977 100644 --- a/templates/Includes/FlexSlider.ss +++ b/templates/Includes/FlexSlider.ss @@ -32,5 +32,3 @@ <% end_if %> <% end_if %> -<% require javascript('silverstripe/admin: thirdparty/jquery/jquery.js') %> -<% require javascript('dynamic/flexslider: thirdparty/flexslider/jquery.flexslider-min.js') %>