Skip to content

Commit e1dd657

Browse files
committed
Implements a new CTK.Carousel() widget.
git-svn-id: svn://cherokee-project.com/CTK/trunk@5438 5dc97367-97f1-0310-9951-d761b3857238
1 parent 9c9aece commit e1dd657

6 files changed

Lines changed: 196 additions & 1 deletion

File tree

CTK/Carousel.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# CTK: Cherokee Toolkit
4+
#
5+
# Authors:
6+
# Alvaro Lopez Ortega <alvaro@alobbs.com>
7+
#
8+
# Copyright (C) 2009 Alvaro Lopez Ortega
9+
#
10+
# This program is free software; you can redistribute it and/or
11+
# modify it under the terms of version 2 of the GNU General Public
12+
# License as published by the Free Software Foundation.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with this program; if not, write to the Free Software
21+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22+
# 02110-1301, USA.
23+
#
24+
25+
from Box import Box
26+
from List import List
27+
from Link import Link
28+
from RawHTML import RawHTML
29+
30+
HEADERS = [
31+
'<script type="text/javascript" src="/CTK/js/carousel.js"></script>'
32+
]
33+
34+
JS_INIT = """
35+
$("#%(id)s").Carousel();
36+
"""
37+
38+
class Carousel (Box):
39+
def __init__ (self, props_={}):
40+
props = props_.copy()
41+
if 'class' in props:
42+
props['class'] += " carousel"
43+
else:
44+
props['class'] = "carousel"
45+
46+
Box.__init__ (self, props.copy())
47+
self.images = List ({'class': 'overview'})
48+
self.pager = List ({'class': 'pager'})
49+
50+
Box.__iadd__ (self, Link (None, RawHTML("%s"%(_('left'))), {'class': "buttons prev"}))
51+
Box.__iadd__ (self, self.images)
52+
Box.__iadd__ (self, Link (None, RawHTML("%s"%(_('right'))), {'class': "buttons next"}))
53+
Box.__iadd__ (self, self.pager)
54+
55+
def __iadd__ (self, widget):
56+
link = Link (None, RawHTML ("%s" %(len(self.images.child) +1)))
57+
58+
self.images += widget
59+
self.pager += link
60+
self.pager[-1].props['class'] = 'pagenum'
61+
62+
return self
63+
64+
def Render (self):
65+
render = Box.Render (self)
66+
67+
render.headers += HEADERS
68+
render.js += JS_INIT %({'id': self.id})
69+
70+
return render
71+

CTK/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ AjaxUpload.py \
5353
i18n.py \
5454
Init.py \
5555
Paginator.py \
56-
StarRating.py
56+
StarRating.py \
57+
Carousel.py
5758

5859
EXTRA_DIST = \
5960
$(ctk_DATA)

CTK/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
from AjaxUpload import AjaxUpload
7070
from Paginator import Paginator
7171
from StarRating import StarRating
72+
from Carousel import Carousel
7273

7374
# Comodity
7475
from cgi import escape as escape_html

static/css/CTK.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,3 +830,5 @@ tr.panel-selected td div.row_content .sel-actions {
830830
.ui-stars-star-hover a:hover {background-position:0 -64px; }
831831
.ui-stars-star-disabled,.ui-stars-star-disabled a {cursor:default!important;}
832832
.ui-stars-star-disabled.ui-stars-star-hover a:hover { background-position:0 -48px; }
833+
834+
.carousel .selected { background: #f00; }

static/js/Carousel.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/* CTK: Cherokee Toolkit
2+
*
3+
* Authors:
4+
* Alvaro Lopez Ortega <alvaro@alobbs.com>
5+
*
6+
* Copyright (C) 2010 Alvaro Lopez Ortega
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of version 2 of the GNU General Public
10+
* License as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20+
* 02110-1301, USA.
21+
*/
22+
23+
(function($) {
24+
var Carousel = function (element) {
25+
var obj = this; // Object {}
26+
var self = $(element); // $(<div>)
27+
28+
// PRIVATE
29+
//
30+
function set_item (num) {
31+
for (var n=0; n<obj.child_num; n++) {
32+
if (n == num) {
33+
obj.$child.eq(n).show();
34+
obj.$pager_child.eq(n).addClass('selected');
35+
} else {
36+
obj.$child.eq(n).hide();
37+
obj.$pager_child.eq(n).removeClass('selected');
38+
}
39+
}
40+
41+
if (num == 0) {
42+
obj.$prev.hide();
43+
} else {
44+
obj.$prev.show();
45+
}
46+
47+
if (num == obj.child_num -1) {
48+
obj.$next.hide();
49+
} else {
50+
obj.$next.show();
51+
}
52+
53+
obj.current = num;
54+
}
55+
56+
function advance_step (val) {
57+
var new_current = obj.current + val;
58+
59+
if ((new_current >= 0) &&
60+
(new_current < obj.child_num))
61+
{
62+
set_item (new_current);
63+
}
64+
}
65+
66+
function pager_click_cb() {
67+
set_item (parseInt ($(this).text()) -1);
68+
}
69+
70+
// PUBLIC
71+
//
72+
this.init = function (self, options) {
73+
obj.$pager = self.find('.pager');
74+
obj.$pager_child = obj.$pager.children();
75+
obj.$prev = self.find('.prev');
76+
obj.$next = self.find('.next');
77+
obj.$child = self.find('.overview').children();
78+
obj.child_num = obj.$child.length;
79+
obj.current = 0;
80+
81+
obj.$prev.bind ('click', function(){ advance_step (-1); })
82+
obj.$next.bind ('click', function(){ advance_step (+1); })
83+
84+
obj.$pager_child.each (function() {
85+
$(this).bind ('click', pager_click_cb);
86+
});
87+
88+
set_item (0);
89+
}
90+
};
91+
92+
$.fn.Carousel = function (options) {
93+
var self = this;
94+
return this.each (function() {
95+
if ($(this).data('carousel')) return;
96+
var carousel = new Carousel (this);
97+
$(this).data('carousel', carousel);
98+
carousel.init (self, options);
99+
});
100+
};
101+
})(jQuery);

tests/test15.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import CTK
4+
5+
def default():
6+
carousel = CTK.Carousel()
7+
carousel += CTK.Image ({'src': "http://www.fancydressfast.com/images/R881051.jpg"})
8+
carousel += CTK.Image ({'src': "http://2.bp.blogspot.com/_j1nA6ZV_0EU/SoGvD5XbyaI/AAAAAAAAAbE/bjD-vBJY6Eo/s400/cherokee_nectarine.jpg"})
9+
carousel += CTK.Image ({'src': "http://rlv.zcache.com/cherokee_indians_middle_springfield_missouri_tshirt-p235011080071166412yboh_400.jpg"})
10+
carousel += CTK.Image ({'src': "http://img1.tradeget.com/globalpackersmovers/1D5JQV6B1car_transportation.jpg"})
11+
12+
page = CTK.Page()
13+
page += CTK.RawHTML('<h1>Demo</h1>')
14+
page += carousel
15+
page += CTK.RawHTML('FIN')
16+
return page.Render()
17+
18+
CTK.publish ('', default)
19+
CTK.run (port=8000)

0 commit comments

Comments
 (0)