From 0504757ddd225e89bbba00becedd744a93166dea Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira de Souza Date: Mon, 25 Jul 2016 09:08:35 -0300 Subject: [PATCH] Fix to work with --- CHANGES.rst | 3 ++- src/collective/js/cycle2/resources/utils.js | 14 +++++++++----- src/collective/js/cycle2/resources/utils.min.js | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 05f0dac..c0b6600 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,8 @@ There's a frood who really knows where his towel is. 1.0rc1 (unreleased) ------------------- -- Nothing changed yet. +- Fix to work with `collective.lazyload`. + [rodfersou] 1.0b2 (2016-07-20) diff --git a/src/collective/js/cycle2/resources/utils.js b/src/collective/js/cycle2/resources/utils.js index 0435e93..008d090 100644 --- a/src/collective/js/cycle2/resources/utils.js +++ b/src/collective/js/cycle2/resources/utils.js @@ -43,15 +43,19 @@ }; Cycle2SlideShow.prototype.centerImage = function(img) { if (typeof(img) === 'undefined') { - var img = this.$imgs[0].parentElement; + var img = this.$imgs[0]; if ($(img).hasClass('cycle-sentinel')) { - img = this.$imgs[1].parentElement; + img = this.$imgs[1]; } } - var img_height = $(img).height() + var $img = $(img); + var img_height = $img.height(); + if ($img.hasClass('lazyload')) { + img_height = parseInt($img.attr('height')); + } if (img_height < this.maxHeight) { var margin = parseInt((this.maxHeight - img_height) / 2); - $(img).css('margin-top', margin); + $img.css('margin-top', margin); } }; Cycle2SlideShow.prototype.syncSlideshows = function(e, opts) { @@ -60,7 +64,7 @@ }; Cycle2SlideShow.prototype.cycleBefore = function(e, opts, outSlide, inSlide) { e.preventDefault(); - this.centerImage(inSlide); + this.centerImage(inSlide.children[0]); }; Cycle2SlideShow.prototype.thumbsClick = function(e) { e.preventDefault(); diff --git a/src/collective/js/cycle2/resources/utils.min.js b/src/collective/js/cycle2/resources/utils.min.js index 8410f5d..7f2b7d7 100644 --- a/src/collective/js/cycle2/resources/utils.min.js +++ b/src/collective/js/cycle2/resources/utils.min.js @@ -1 +1 @@ -(function(window,factory){var cycle2SlideShow=factory(window,window.document);window.cycle2SlideShow=cycle2SlideShow;if(typeof module=="object"&&module.exports){module.exports=cycle2SlideShow}})(window,function l(window,document){"use strict";var Cycle2SlideShow=function(){function Cycle2SlideShow(el){$(el).data("cycle2slideshow",this);this.$player=$(".cycle-player",el);this.$thumbsContainer=$(".cycle-carrossel",el);this.$thumbs=$(".cycle-carrossel .thumb-itens",el);this.$imgs=$(".cycle-player img",el);this.$slideshows=$(".cycle-slideshow",el);this.aspectRatio=parseFloat($(el).attr("data-aspect-ratio"));if(isNaN(this.aspectRatio)){this.aspectRatio=3/2}this.maxWidth=this.$player.width();this.maxHeight=this.maxWidth/this.aspectRatio;this.bindEvents();this.fixImageSize();this.centerImage();$(el).fadeTo("slow",1)}Cycle2SlideShow.prototype.bindEvents=function(){this.$player.on("cycle-next cycle-prev",$.proxy(this.syncSlideshows,this));this.$player.on("cycle-before",$.proxy(this.cycleBefore,this));this.$thumbs.on("click",$.proxy(this.thumbsClick,this))};Cycle2SlideShow.prototype.fixImageSize=function(){this.$player.css({width:this.maxWidth,height:this.maxHeight});this.$imgs.css({"max-width":this.maxWidth,"max-height":this.maxHeight})};Cycle2SlideShow.prototype.centerImage=function(img){if(typeof img==="undefined"){var img=this.$imgs[0].parentElement;if($(img).hasClass("cycle-sentinel")){img=this.$imgs[1].parentElement}}var img_height=$(img).height();if(img_height