001.
002.
003.
004.
005.
006.
007.
008.
(
function
($) {
009.
$.fn.flickrGallery =
function
(options) {
010.
011.
var
defaults = {
012.
galleryHeight :
'auto'
,
013.
userFlickr :
'false'
,
014.
useFlickrLargeSize:
'false'
,
015.
flickrAPIKey:
''
,
016.
photosetID:
''
,
017.
per_page: 30,
018.
useHoverIntent:
'false'
,
019.
useLightBox:
'false'
020.
};
021.
var
options = $.extend(defaults, options);
022.
023.
return
this
.each(
function
() {
024.
obj = $(
this
);
025.
026.
027.
function
makeGallery(){
028.
029.
030.
var
flickrLargeImg;
031.
var
theCaption;
032.
var
container;
033.
var
stepCount;
034.
var
count = 1;
035.
var
totalImageCount = 0;
036.
var
currentImageCount = 1;
037.
thumbs = obj.find(
'ul'
);
038.
thumbs.addClass(
'galleryUL'
);
039.
040.
041.
if
( options.useFlickr ==
'true'
) {
042.
obj.prepend(
'<div class="largeImageWrap"><div class="largeImage_nextPage"></div><div class="largeImage_prevPage"></div><a href="" class="largeImage_flickrLink" target="_blank"><span>Flickr</span></a><div class="largeImage_prev"><span>Prev</span></div><div class="largeImage_next"><span>Next</span></div><div class="largeImage"></div><div class="caption"></div></div>'
);
043.
}
else
{
044.
obj.prepend(
'<div class="largeImageWrap"><div class="largeImage_prev"><span>Prev</span></div><div class="largeImage_next"><span>Next</span></div><div class="largeImage"></div><div class="caption"></div></div>'
);
045.
};
046.
047.
var
largeImageWrap = obj.find(
'.largeImageWrap'
);
048.
var
nextPage = obj.find(
'.largeImage_nextPage'
);
049.
var
prevPage = obj.find(
'.largeImage_prevPage'
);
050.
var
nextImg = obj.find(
'.largeImage_next'
);
051.
var
prevImg = obj.find(
'.largeImage_prev'
);
052.
var
largeImageFlickrLink = obj.find(
'.largeImage_flickrLink'
);
053.
var
largeImage = obj.find(
'.largeImage'
);
054.
var
imgCaption = obj.find(
'.caption'
);
055.
056.
057.
058.
059.
if
( options.galleryHeight !=
'auto'
) {
060.
var
theHeight = parseFloat(options.galleryHeight);
061.
largeImageWrap.animate({ height: theHeight+
'px'
}, 600) ;
062.
}
063.
064.
065.
if
( options.useFlickr ==
'true'
) {
066.
thumbs.children().click(
function
(){
067.
return
false
;
068.
});
069.
};
070.
071.
072.
073.
thumbs.wrap(
'<div class="sliderGallery"></div>'
);
074.
var
sliderGallery = obj.find(
'.sliderGallery'
);
075.
sliderGallery.wrap(
'<div class="sliderGallery_Wrap"></div>'
);
076.
var
sliderGalleryWrap = obj.find(
'.sliderGallery_Wrap'
);
077.
sliderGallery.append(
'<div class="slider"><div class="handle"></div></div>'
);
078.
var
theSlider = obj.find(
'.slider'
);
079.
var
theHandle = obj.find(
'.handle'
);
080.
count = 1;
081.
totalImageCount = 0;
082.
currentImageCount = 1;
083.
obj.find(
'.galleryUL img'
).each(
function
(){
084.
var
IESRC = $(
this
).attr(
'src'
);
085.
$(
this
).attr(
'src'
,IESRC);
086.
$(
this
).attr(
'id'
,
'galleryThumb_'
+count);
087.
count++;
088.
totalImageCount++;
089.
});
090.
091.
092.
nextPage.click(
function
(){
093.
currentPage = parseFloat($(obj).find(
'input:eq(0)'
).val());
094.
totalPages = parseFloat($(obj).find(
'input:eq(1)'
).val());
095.
nextPage = currentPage + 1;
096.
if
( nextPage > totalPages ) {
097.
nextPage = 1;
098.
};
099.
$(theSlider, container).slider(
"destroy"
);
100.
sliderGalleryWrap.hide();
101.
$(obj).children().slideUp();
102.
obj.slideUp(
'slow'
,
function
(){
103.
obj.empty();
104.
obj.flickr({
105.
api_key: options.flickrAPIKey,
106.
type:
'photoset'
,
107.
photoset_id: options.photosetID,
108.
thumb_size:
'm'
,
109.
per_page: options.per_page,
110.
page: nextPage,
111.
callback:
function
(){
112.
makeGallery();
113.
}
114.
});
115.
obj.slideDown();
116.
});
117.
});
118.
119.
120.
prevPage.click(
function
(){
121.
currentPage = parseFloat($(obj).find(
'input:eq(0)'
).val());
122.
totalPages = parseFloat($(obj).find(
'input:eq(1)'
).val());
123.
prevPage = currentPage - 1;
124.
if
( prevPage == 0 ) {
125.
prevPage = totalPages;
126.
};
127.
$(theSlider, container).slider(
"destroy"
);
128.
sliderGalleryWrap.hide();
129.
$(obj).children().slideUp();
130.
obj.slideUp(
'slow'
,
function
(){
131.
obj.empty();
132.
obj.flickr({
133.
api_key: options.flickrAPIKey,
134.
type:
'photoset'
,
135.
photoset_id: options.photosetID,
136.
thumb_size:
'm'
,
137.
per_page: options.per_page,
138.
page: prevPage,
139.
callback:
function
(){
140.
makeGallery();
141.
}
142.
});
143.
obj.slideDown();
144.
});
145.
});
146.
147.
148.
149.
function
calcHeight() {
150.
largeImage.fadeOut(
function
(){
151.
function
doHeight(){
152.
largeImage.fadeIn(
function
(){
153.
var
imgHeight = largeImage.find(
'img'
).height();
154.
var
captionHeight = imgCaption.height();
155.
largeImage.find(
'img'
).css({
156.
position:
''
,
157.
visibility:
'visible'
,
158.
display:
'none'
159.
});
160.
if
( options.galleryHeight ==
'auto'
) {
161.
largeImageWrap.animate({
162.
height: imgHeight+captionHeight+
'px'
163.
},
function
(){ largeImage.find(
'img'
).fadeIn(); imgCaption.fadeIn(); });
164.
}
else
{
165.
largeImage.find(
'img'
).fadeIn();
166.
imgCaption.fadeIn();
167.
};
168.
169.
});
170.
slideValue = currentImageCount-1;
171.
slideValue = slideValue * stepCount;
172.
$(theSlider, container).slider(
"moveTo"
,slideValue);
173.
};
174.
$(
this
).find(
'img'
).remove();
175.
imgCaption.empty();
176.
var
i =
new
Image();
177.
if
( options.useFlickr ==
'true'
) {
178.
if
( options.useFlickrLargeSize ==
'true'
) {
179.
flickrLargeImg = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'href'
);
180.
flickrLink = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'title'
)
181.
theCaption = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'alt'
);
182.
i.onload = doHeight;
183.
i.src = flickrLargeImg;
184.
largeImage.append(i);
185.
}
else
{
186.
flickrLink = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'title'
);
187.
theCaption = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'alt'
);
188.
i.onload = doHeight;
189.
i.src = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'src'
);
190.
largeImage.append(i);
191.
flickrLargeImg = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'href'
);
192.
if
( options.useLightBox ==
'true'
) {
193.
largeImage.find(
'img'
).wrap(
'<a href="'
+flickrLargeImg+
'" title="'
+theCaption+
'"></a>'
);
194.
largeImage.find(
'a'
).lightBox();
195.
};
196.
}
197.
largeImageFlickrLink.attr(
'href'
,flickrLink);
198.
largeImage.find(
'img'
).addClass(
''
+currentImageCount+
''
);
199.
}
else
{
200.
thumbs.find(
'#galleryThumb_'
+currentImageCount).clone().css(
'opacity'
,1).appendTo(largeImage);
201.
theCaption = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'title'
);
202.
doHeight();
203.
};
204.
imgCaption.append(theCaption).hide();
205.
largeImage.find(
'img'
).css({
206.
position:
'absolute'
,
207.
visibility:
'hidden'
,
208.
display:
'block'
209.
}).addClass(
''
+currentImageCount+
''
).attr(
'title'
,theCaption);
210.
});
211.
};
212.
213.
214.
215.
216.
obj.find(
'div.sliderGallery'
).each(
function
(){
217.
container = $(
this
);
218.
var
ul = thumbs;
219.
var
itemsWidth = ul.innerWidth() - container.outerWidth();
220.
var
totalCount = totalImageCount;
221.
totalCount = parseFloat(totalCount-1);
222.
stepCount = itemsWidth/totalCount;
223.
var
division = itemsWidth / totalCount;
224.
var
theValue = 0;
225.
$(theSlider, container).slider({
226.
min: 0,
227.
max: itemsWidth,
228.
handle: theHandle,
229.
steps:totalCount,
230.
stop:
function
(event, ui) {
231.
ul.animate({
'left'
: ui.value * -1}, 500);
232.
theValue = ui.value;
233.
},
234.
slide:
function
(event, ui) {
235.
ul.css(
'left'
, ui.value * -1);
236.
}
237.
});
238.
obj.find(
'.galleryUL img'
).click(
function
(){
239.
var
clickThumb = $(
this
);
240.
var
startCount = 0;
241.
var
theCaption = $(
this
).attr(
'title'
);
242.
currentImageCount = $(
this
).attr(
'id'
);
243.
currentImageCount = parseFloat(currentImageCount.split(
"_"
,2)[1]);
244.
calcHeight();
245.
});
246.
});
247.
248.
249.
250.
251.
function
startHeight() {
252.
imgCaption.append(theCaption).hide();
253.
largeImage.find(
'img'
).css({
254.
position:
''
,
255.
visibility:
'visible'
,
256.
display:
'none'
257.
});
258.
largeImage.find(
'img'
).addClass(
''
+currentImageCount+
''
).attr(
'title'
,theCaption);
259.
largeImage.show(
function
(){
260.
imgHeight = largeImage.find(
'img'
).height();
261.
captionHeight = imgCaption.height();
262.
if
( options.galleryHeight ==
'auto'
) {
263.
largeImageWrap.animate({
264.
height: imgHeight+captionHeight+
'px'
265.
},
'slow'
,
'swing'
,
266.
function
(){
267.
largeImage.css({ visibility:
'visible'
});
268.
imgCaption.fadeIn();
269.
largeImage.find(
'img'
).fadeIn(300,
function
(){
270.
sliderGallery.hide().wrapInner(
'<div id="sliderGalleryInnerWrap"></div>'
);
271.
var
sliderGalleryInnerWrap = obj.find(
'#sliderGalleryInnerWrap'
);
272.
sliderGalleryInnerWrap.hide();
273.
sliderGalleryWrap.show();
274.
sliderGallery.slideDown(
'slow'
,
function
(){
275.
sliderGalleryInnerWrap.fadeIn();
276.
});
277.
});
278.
});
279.
}
else
{
280.
largeImage.css({ visibility:
'visible'
});
281.
largeImage.find(
'img'
).fadeIn(
'slow'
,
function
(){
282.
sliderGallery.hide().wrapInner(
'<div id="sliderGalleryInnerWrap"></div>'
);
283.
var
sliderGalleryInnerWrap = obj.find(
'#sliderGalleryInnerWrap'
);
284.
sliderGalleryInnerWrap.hide();
285.
sliderGalleryWrap.show();
286.
sliderGallery.slideDown(
'slow'
,
function
(){
287.
sliderGalleryInnerWrap.fadeIn(
'slow'
);
288.
});
289.
});
290.
imgCaption.fadeIn(
'slow'
);
291.
};
292.
});
293.
};
294.
sliderGalleryWrap.hide();
295.
largeImage.hide().css({visibility:
'hidden'
});
296.
var
i =
new
Image();
297.
if
( options.useFlickr ==
'true'
) {
298.
if
( options.useFlickrLargeSize ==
'true'
) {
299.
flickrLargeImg = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'href'
);
300.
flickrLink = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'title'
)
301.
theCaption = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'alt'
);
302.
i.onload = startHeight;
303.
i.src = flickrLargeImg;
304.
largeImage.append(i);
305.
}
else
{
306.
flickrLargeImg = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'href'
);
307.
flickrLink = thumbs.find(
'#galleryThumb_'
+currentImageCount).parent().attr(
'title'
)
308.
thumbs.find(
'#galleryThumb_'
+currentImageCount).clone().appendTo(largeImage);
309.
theCaption = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'alt'
);
310.
if
( options.useLightBox ==
'true'
) {
311.
largeImage.find(
'img'
).wrap(
'<a href="'
+flickrLargeImg+
'" title="'
+theCaption+
'"></a>'
);
312.
largeImage.find(
'a'
).lightBox();
313.
}
314.
startHeight();
315.
}
316.
largeImageFlickrLink.attr(
'href'
,flickrLink);
317.
largeImage.find(
'img'
).addClass(
''
+currentImageCount+
''
);
318.
}
else
{
319.
thumbs.find(
'#galleryThumb_'
+currentImageCount).clone().appendTo(largeImage);
320.
theCaption = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'title'
);
321.
startHeight();
322.
};
323.
324.
if
( options.useHoverIntent ==
'false'
) {
325.
largeImageWrap.hover(
function
(){
326.
prevImg.fadeIn();
327.
nextImg.fadeIn();
328.
largeImageFlickrLink.fadeIn();
329.
nextPage.fadeIn();
330.
prevPage.fadeIn();
331.
},
function
(){
332.
obj.find(
'.largeImage_prev'
).fadeOut();
333.
obj.find(
'.largeImage_next'
).fadeOut();
334.
obj.find(
'.largeImage_flickrLink'
).fadeOut();
335.
obj.find(
'.largeImage_prevPage'
).fadeOut();
336.
obj.find(
'.largeImage_nextPage'
).fadeOut();
337.
});
338.
$(thumbs).children().find(
'img'
).hover(
function
(){
339.
$(
this
).animate({ opacity: 1 }, 300);
340.
},
function
(){
341.
$(
this
).animate({ opacity: .7 }, 300);
342.
});
343.
}
else
{
344.
function
hoverOn() {
345.
prevImg.fadeIn();
346.
nextImg.fadeIn();
347.
largeImageFlickrLink.fadeIn();
348.
nextPage.fadeIn();
349.
prevPage.fadeIn();
350.
};
351.
function
hoverOff() {
352.
obj.find(
'.largeImage_prev'
).fadeOut();
353.
obj.find(
'.largeImage_next'
).fadeOut();
354.
obj.find(
'.largeImage_flickrLink'
).fadeOut();
355.
obj.find(
'.largeImage_prevPage'
).fadeOut();
356.
obj.find(
'.largeImage_nextPage'
).fadeOut();
357.
};
358.
var
config = {
359.
sensitivity: 3,
360.
interval: 50,
361.
over: hoverOn,
362.
timeout: 200,
363.
out: hoverOff
364.
};
365.
largeImageWrap.hoverIntent(config);
366.
function
thumbHoverOn() {
367.
$(
this
).animate({ opacity: 1 }, 300);
368.
};
369.
function
thumbHoverOff() {
370.
$(
this
).animate({ opacity: .7 }, 300);
371.
};
372.
var
config2 = {
373.
sensitivity: 1,
374.
interval: 25,
375.
over: thumbHoverOn,
376.
timeout: 50,
377.
out: thumbHoverOff
378.
};
379.
$(thumbs).children().find(
'img'
).hoverIntent(config2);
380.
};
381.
382.
383.
prevImg.click(
function
(){
384.
var
theSRC = largeImage.find(
'img'
).attr(
'src'
);
385.
currentImageCount = largeImage.find(
'img'
).attr(
'class'
);
386.
var
newSRC =
""
;
387.
var
newImage =
""
;
388.
var
fixIE =
""
;
389.
var
prevImageCount = currentImageCount - 1;
390.
if
( prevImageCount < 1 ) {
391.
currentImageCount = totalImageCount;
392.
}
else
{
393.
currentImageCount = prevImageCount;
394.
};
395.
newSRC = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'src'
);
396.
newImage = thumbs.find(
'#galleryThumb_'
+currentImageCount).clone().css(
'opacity'
,1).addClass(
''
+currentImageCount+
''
);
397.
calcHeight();
398.
});
399.
400.
401.
nextImg.click(
function
(){
402.
var
theSRC = largeImage.find(
'img'
).attr(
'src'
);
403.
currentImageCount = largeImage.find(
'img'
).attr(
'class'
);
404.
currentImageCount = parseFloat(currentImageCount);
405.
var
newSRC =
""
;
406.
var
theCaption =
""
;
407.
var
newImage =
""
;
408.
var
nextImageCount = currentImageCount + 1;
409.
if
( nextImageCount > totalImageCount ) {
410.
currentImageCount = 1;
411.
}
else
{
412.
currentImageCount = nextImageCount;
413.
};
414.
newSRC = thumbs.find(
'#galleryThumb_'
+currentImageCount).attr(
'src'
);
415.
newImage = thumbs.find(
'#galleryThumb_'
+currentImageCount).clone().css(
'opacity'
,1).addClass(
''
+currentImageCount+
''
);
416.
calcHeight();
417.
});
418.
};
419.
420.
421.
if
( options.useFlickr ==
'true'
) {
422.
obj.flickr({
423.
api_key: options.flickrAPIKey,
424.
type:
'photoset'
,
425.
photoset_id: options.photosetID,
426.
thumb_size:
'm'
,
427.
per_page: options.per_page,
428.
page: 1,
429.
callback:
function
(){
430.
makeGallery();
431.
}
432.
});
433.
}
else
{
434.
makeGallery();
435.
};
436.
});
437.
};
438.
})(jQuery);