Skip to content

Commit 5f068ff

Browse files
ebrehaulthvelarde
authored andcommitted
display a collection in a Bootstrap carousel
1 parent 9714fac commit 5f068ff

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

src/collective/cover/tiles/collection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class ICollectionTile(IPersistentCoverTile):
8181
readonly=True,
8282
)
8383

84+
slidemode = schema.Bool(
85+
title=_(u'Slideshow'),
86+
required=False,
87+
)
88+
8489

8590
class CollectionTile(PersistentCoverTile):
8691

@@ -233,3 +238,6 @@ def collection_url(self):
233238

234239
def show_footer(self):
235240
return self._field_is_visible('footer')
241+
242+
def is_slidemode(self):
243+
return self.data.get('slidemode', False)

src/collective/cover/tiles/templates/collection.pt

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
</tal:fields>
4444
</div>
4545

46-
47-
<div class="collection-item" tal:repeat="item results">
46+
<div tal:condition="not:view/is_slidemode"
47+
class="collection-item" tal:repeat="item results">
4848
<tal:items define="obj item/getObject">
4949
<tal:fields repeat="field view/configured_fields">
5050
<tal:image define="thumbnail python:view.thumbnail(obj);"
@@ -100,6 +100,87 @@
100100
</tal:items>
101101
<div class="visualClear"><!-- --></div>
102102
</div>
103+
104+
<div tal:condition="view/is_slidemode">
105+
<div tal:attributes="id string:carousel-${view/data/uuid}"
106+
class="carousel slide" data-ride="carousel">
107+
<!-- Indicators -->
108+
<ol class="carousel-indicators">
109+
<li tal:repeat="index python:range(0, len(results))"
110+
tal:attributes="data-target string:#carousel-${view/data/uuid};
111+
data-slide-to index;
112+
class python:index==0 and 'active' or ''"></li>
113+
</ol>
114+
115+
<!-- Wrapper for slides -->
116+
<div class="carousel-inner" role="listbox">
117+
<tal:loop tal:repeat="item results">
118+
<div tal:define="index repeat/item/index"
119+
tal:attributes="class python:index==0 and 'item active' or 'item'">
120+
<tal:items define="obj item/getObject">
121+
<tal:fields repeat="field view/configured_fields">
122+
<tal:image define="thumbnail python:view.thumbnail(obj);"
123+
condition="python:field['id'] == 'image' and thumbnail">
124+
<a tal:attributes="href obj/absolute_url">
125+
<img tal:attributes="src thumbnail/url;
126+
width thumbnail/width;
127+
height thumbnail/height;
128+
class view/get_image_position;
129+
alt obj/Title;" />
130+
</a>
131+
</tal:image>
132+
133+
<tal:title define="htmltag python:field.get('htmltag', 'h1')"
134+
condition="python:field['id'] == 'title'">
135+
136+
<h1 tal:condition="python:htmltag == 'h1'">
137+
<a tal:attributes="href obj/absolute_url"
138+
tal:content="obj/Title" />
139+
</h1>
140+
141+
<h2 tal:condition="python:htmltag == 'h2'">
142+
<a tal:attributes="href obj/absolute_url"
143+
tal:content="obj/Title" />
144+
</h2>
145+
146+
<h3 tal:condition="python:htmltag == 'h3'">
147+
<a tal:attributes="href obj/absolute_url"
148+
tal:content="obj/Title" />
149+
</h3>
150+
151+
<h4 tal:condition="python:htmltag == 'h4'">
152+
<a tal:attributes="href obj/absolute_url"
153+
tal:content="obj/Title" />
154+
</h4>
155+
156+
</tal:title>
157+
158+
<p class="description"
159+
tal:condition="python:field['id'] == 'description'"
160+
tal:content="obj/Description" />
161+
162+
<p tal:condition="python:field['id'] == 'date'"
163+
tal:content="python:toLocalizedTime(view.Date(item), True)" />
164+
</tal:fields>
165+
</tal:items>
166+
</div>
167+
</tal:loop>
168+
</div>
169+
170+
<!-- Controls -->
171+
<a tal:attributes="href string:#carousel-${view/data/uuid}"
172+
class="left carousel-control" role="button" data-slide="prev">
173+
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
174+
<span class="sr-only">Previous</span>
175+
</a>
176+
<a tal:attributes="href string:#carousel-${view/data/uuid}"
177+
class="right carousel-control" role="button" data-slide="next">
178+
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
179+
<span class="sr-only">Next</span>
180+
</a>
181+
</div>
182+
</div>
183+
103184
<div class="tile-footer" tal:condition="view/show_footer">
104185
<a tal:attributes="href view/collection_url" tal:content="view/data/footer" />
105186
</div>

0 commit comments

Comments
 (0)