Skip to content

Commit

Permalink
Merge pull request #602 from collective/issue_414
Browse files Browse the repository at this point in the history
Carousel tile now uses a relative ratio to set its height
  • Loading branch information
rodfersou committed Mar 9, 2016
2 parents 0a9d3fe + 3b97fb2 commit 985d0fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,9 @@ There's a frood who really knows where his towel is.
1.0a13 (unreleased)
^^^^^^^^^^^^^^^^^^^

- Carousel tile now uses a relative ratio to set its height (fixes `#414`_).
[terapyon, hvelarde]

- Remove hard dependency on plone.app.referenceablebehavior as Archetypes is no longer the default framework in Plone 5.
Under Plone < 5.0 you should now explicitly add it to the `eggs` part of your buildout configuration to avoid issues while upgrading.
[hvelarde]
Expand Down Expand Up @@ -736,6 +739,7 @@ There's a frood who really knows where his towel is.
.. _`#411`: https://github.com/collective/collective.cover/issues/411
.. _`#412`: https://github.com/collective/collective.cover/issues/412
.. _`#413`: https://github.com/collective/collective.cover/issues/413
.. _`#414`: https://github.com/collective/collective.cover/issues/414
.. _`#415`: https://github.com/collective/collective.cover/issues/415
.. _`#421`: https://github.com/collective/collective.cover/issues/421
.. _`#423`: https://github.com/collective/collective.cover/issues/423
Expand Down
20 changes: 17 additions & 3 deletions src/collective/cover/tiles/carousel.py
Expand Up @@ -23,9 +23,9 @@
Galleria.loadTheme('++resource++collective.cover/js/galleria.cover_theme.js');
Galleria.run('#galleria-{0}');
var options = {{ height: 1 }};
var options = {{ height: {1} }};
if ($('body').hasClass('template-view')) {{
options.autoplay = {1};
options.autoplay = {2};
}}
Galleria.configure(options);
}});
Expand Down Expand Up @@ -151,14 +151,28 @@ def get_url(self, item):
url = uuids[uuid].get('custom_url')
return url

@property
def get_image_ratio(self):
"""Return image ratio to be used in the carousel.
See: http://galleria.io/docs/options/height/
"""
thumbs = [self.thumbnail(i) for i in self.results()]
# exclude from calculation any item with no image
ratios = [
float(t.height) / float(t.width) for t in thumbs if t is not None]
if not ratios:
return '1'
return str(max(ratios))

def init_js(self):
if self.is_empty():
# Galleria will display scary error messages when it
# cannot find its <div>. So don't start galleria unless
# the <div> is there and has some items in it.
return ''

return INIT_JS.format(self.id, str(self.autoplay()).lower())
return INIT_JS.format(
self.id, self.get_image_ratio, str(self.autoplay()).lower())


class UUIDSFieldDataConverter(BaseDataConverter):
Expand Down

0 comments on commit 985d0fa

Please sign in to comment.