dynamic_flickr_feed.html
4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us">
<head>
<title>jCarousel Examples</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<!--
jQuery library
-->
<script type="text/javascript" src="../lib/jquery-1.4.2.min.js"></script>
<!--
jCarousel library
-->
<script type="text/javascript" src="../lib/jquery.jcarousel.min.js"></script>
<!--
jCarousel skin stylesheet
-->
<link rel="stylesheet" type="text/css" href="../skins/ie7/skin.css" />
<!--
Custom styles
-->
<style type="text/css">
#mycarousel.jcarousel-container-horizontal {
width: 272px;
}
#mycarousel .jcarousel-clip-horizontal {
width: 272px;
height: 302px;
}
#mycarousel .jcarousel-item,
#mycarousel .jcarousel-item-placeholder {
width: 270px;
height: 300px;
}
#mycarousel .jcarousel-item-horizontal img {
border: 1px solid #808080;
}
#mycarousel .jcarousel-item-horizontal p {
margin: 5px;
text-align: center;
clear: both;
white-space: wrap;
}
#mycarousel .jcarousel-item-placeholder {
background: transparent url(images/loading.gif) 50% 50% no-repeat;
}
#mycarousel .jcarousel-next {
top: 150px;
right: 5px;
}
#mycarousel .jcarousel-prev {
top: 150px;
left: 5px;
}
#mycarousel form {
margin-top: 10px;
}
#mycarousel form label,
#mycarousel form small {
display: block;
}
</style>
<script type="text/javascript">
var mycarousel_tags = '';
function mycarousel_initCallback(carousel, state)
{
// Do nothing of state is 'reset'
if (state == 'reset')
return;
jQuery('form', carousel.container)
.bind('submit', function(e) {
mycarousel_tags = jQuery('input[type=text]', carousel.container).val();
carousel.reset();
return false;
});
};
function mycarousel_itemLoadCallback(carousel, state)
{
// Only load items if they don't already exist
if (carousel.has(carousel.first, carousel.last)) {
return;
}
jQuery.get(
'dynamic_flickr_feed.php',
{
tags: mycarousel_tags
},
function(data) {
mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, data.items);
},
'json'
);
};
function mycarousel_itemAddCallback(carousel, first, last, items)
{
if (first == 1) {
var plural = items.length == 1 ? '' : 's';
jQuery('.results', carousel.container).html(items.length + ' photo' + plural + ' found');
// Set size
if (items.length == 0) {
// Add a "no results" feedback as first item if items is empty
carousel.size(1);
carousel.add(1, '<p>No results</p>');
return;
} else {
carousel.size(items.length);
}
}
for (var i = first; i <= last; i++) {
if (items[i - 1] == undefined) {
break;
}
carousel.add(i, mycarousel_decodeEntities(items[i - 1].description));
}
};
/**
* Decodes entites.
*/
function mycarousel_decodeEntities(s)
{
return s.replace(/&/g, "&")
.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/</g, "<")
.replace(/>/g, ">");
};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
scroll: 1,
initCallback: mycarousel_initCallback,
itemLoadCallback: mycarousel_itemLoadCallback
});
});
</script>
</head>
<body>
<div id="wrap">
<h1>jCarousel</h1>
<h2>Riding carousels with jQuery</h2>
<h3>Carousel with dynamic content loading via Ajax from the Flickr photo stream</h3>
<p>
The data is loaded dynamically from the <a href="http://www.flickr.com">Flickr</a>
public photos feed (format: <a href="http://api.flickr.com/services/feeds/photos_public.gne?format=json">JSON</a>)
and can be filtered by tags.
</p>
<div id="mycarousel" class="jcarousel-skin-ie7">
<ul>
<!-- The content will be dynamically loaded in here -->
</ul>
<form action="">
<label for="filter">Enter tag(s) to filter the feed<br />(separate multiple by comma)</label>
<input type="text" name="filter-tags" value="" />
<input type="submit" name="filter-submit" value="Filter" />
<small class="results"></small>
</form>
</div>
</div>
</body>
</html>