Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX applying flexslider to DataObject won’t call requirement #71

Merged
merged 1 commit into from
Dec 3, 2016
Merged
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
69 changes: 42 additions & 27 deletions code/FlexSlider.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,32 @@ public function updateCMSFields(FieldList $fields)
*/
public function SlideShow()
{
$owner = $this->owner;

if (!($owner instanceof SiteTree)) {
$this->getCustomScript();
}

return $this->owner->Slides()->filter(array('ShowSlide' => 1))->sort('SortOrder');
}

/**
* add requirements to Page_Controller init()
*/
public function contentcontrollerInit()
{
// only call custom script if page has Slides and DataExtension
if (Object::has_extension($this->owner->ClassName, 'FlexSlider')) {
if ($this->owner->SlideShow()->exists()) {
$this->getCustomScript();
}
}
}

/**
*
*/
public function getCustomScript()
{
// Flexslider options
$animate = ($this->owner->Animate) ? 'true' : 'false';
Expand All @@ -106,33 +125,29 @@ public function contentcontrollerInit()
? $this->owner->setFlexSliderSpeed()
: 7000;

// only call custom script if page has Slides and DataExtension
if (Object::has_extension($this->owner->ClassName, 'FlexSlider')) {
if ($this->owner->Slides()->exists()) {
Requirements::customScript("
(function($) {
$(document).ready(function(){
$('.flexslider').flexslider({
slideshow: ".$animate.",
animation: '".$this->owner->Animation."',
animationLoop: ".$loop.",
controlNav: true,
directionNav: true,
prevText: '',
nextText: '',
pauseOnAction: true,
pauseOnHover: true,
".$sync."
start: function(slider){
$('body').removeClass('loading');
},
before: ".$before.',
after: '.$after.',
slideshowSpeed: '.$speed.'
});
Requirements::customScript("
(function($) {
$(document).ready(function(){
$('.flexslider').flexslider({
slideshow: " . $animate . ",
animation: '" . $this->owner->Animation . "',
animationLoop: " . $loop . ",
controlNav: true,
directionNav: true,
prevText: '',
nextText: '',
pauseOnAction: true,
pauseOnHover: true,
" . $sync . "
start: function(slider){
$('body').removeClass('loading');
},
before: " . $before . ',
after: ' . $after . ',
slideshowSpeed: ' . $speed . '
});
}(jQuery));');
}
}
});
}(jQuery));'
);
}
}