Skip to content

Commit

Permalink
Merge pull request #71 from muskie9/bugfix/requirements
Browse files Browse the repository at this point in the history
BUGFIX applying flexslider to DataObject won’t call requirement
  • Loading branch information
muskie9 authored Dec 3, 2016
2 parents 815f9dd + d2403cb commit 2a6e429
Showing 1 changed file with 42 additions and 27 deletions.
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));'
);
}
}

0 comments on commit 2a6e429

Please sign in to comment.