From d2403cbb5cdf45e199a1d6ea1e2d70d38e6ed071 Mon Sep 17 00:00:00 2001 From: Nic Horstmeier Date: Sat, 3 Dec 2016 12:58:43 -0600 Subject: [PATCH] =?UTF-8?q?BUGFIX=20applying=20flexslider=20to=20DataObjec?= =?UTF-8?q?t=20won=E2=80=99t=20call=20requirement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `contentcontrollerInit` is extended on `ContentController` and won’t trigger for a `DataObject`. --- code/FlexSlider.php | 69 +++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/code/FlexSlider.php b/code/FlexSlider.php index 667537a..a14ef2f 100644 --- a/code/FlexSlider.php +++ b/code/FlexSlider.php @@ -84,6 +84,12 @@ 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'); } @@ -91,6 +97,19 @@ public function SlideShow() * 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'; @@ -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));' + ); } }