Skip to content

Commit

Permalink
BUGFIX allow for disabling jQuery and flexslider.min.js for indipende…
Browse files Browse the repository at this point in the history
…nt inclusion (#212)

* BUGFIX allow for disabling jQuery and flexslider.min.js for indipendent inclusion

resolves #210

* BUGFIX allow for disabling jQuery and flexslider.min.js for indipendent inclusion

* BUGFIX allow for disabling jQuery and flexslider.min.js for indipendent inclusion

* BUGFIX allow for disabling jQuery and flexslider.min.js for indipendent inclusion

* BUGFIX allow for disabling jQuery and flexslider.min.js for indipendent inclusion

Co-authored-by: Nic Horstmeier <nhrostmeier@gmail.com>
  • Loading branch information
muskie9-opensource and Nic Horstmeier committed Sep 7, 2022
1 parent 11b7793 commit 0acce14
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@
"images",
"thirdparty"
]
}
},
"config": {
"process-timeout": 600,
"allow-plugins": {
"composer/installers": true,
"silverstripe/recipe-plugin": true,
"silverstripe/vendor-plugin": true
}
}
}
40 changes: 9 additions & 31 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
28 changes: 22 additions & 6 deletions src/ORM/FlexSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
*/
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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: '',
Expand All @@ -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() . ",
Expand All @@ -259,7 +275,7 @@ public function getCustomScript()
},
before: " . $before . ',
after: ' . $after . ',
slideshowSpeed: ' . $speed . '
slideshowSpeed: ' . $speed . '
});
}
})
Expand Down
2 changes: 0 additions & 2 deletions templates/Includes/FlexSlider.ss
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@
<% end_if %>
</div>
<% end_if %>
<% require javascript('silverstripe/admin: thirdparty/jquery/jquery.js') %>
<% require javascript('dynamic/flexslider: thirdparty/flexslider/jquery.flexslider-min.js') %>

0 comments on commit 0acce14

Please sign in to comment.