This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.fancy-photoset.js
85 lines (85 loc) · 2.87 KB
/
jquery.fancy-photoset.js
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
/*!
* Project: fancy-photoset
* Description: A jQuery plugin for viewing Flickr Photostreams in a Fancybox gallery
* Author: Phil Cohen
* License: MIT
* Copyright: (c) 2010-2011 Phil Cohen (http://phlippers.net)
*
* Version: 0.5.0
* Requires jQuery 1.4.2+, Fancybox 1.3.1+
* Docs: http://phlippers.net/code/fancy-photoset
*/
;(function($, window, document) {
var FancyPhotoset, defaults, pluginName;
pluginName = "fancyPhotoset";
defaults = {
apiKey: "",
photosetId: "",
small: "square",
large: "medium",
captions: true,
firstOnly: false,
fancybox: {}
};
FancyPhotoset = (function() {
function FancyPhotoset(element, options) {
this.element = element;
this.options = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
FancyPhotoset.prototype.init = function() {
var domId, element, jsonUrl, options;
options = this.options;
element = $(this.element);
domId = "fancyPhotoset-" + options.photosetId;
jsonUrl = "http://api.flickr.com/services/rest/?" + "method=flickr.photosets.getPhotos&" + ("api_key=" + options.apiKey + "&") + ("photoset_id=" + options.photosetId + "&") + "extras=url_sq,url_t,url_s,url_m,url_o&" + "format=json&jsoncallback=?";
element.append(($("<ul/>")).attr("id", domId).addClass("fancyPhotoset"));
return $.getJSON(jsonUrl, function(data) {
$.each(data.photoset.photo, function(index, photo) {
var anchor, image;
image = ($("<img/>")).attr({
src: FancyPhotoset.prototype.urlFor(photo, {
size: options.small
}),
title: photo.title,
alt: photo.title
});
anchor = ($("<a/>")).attr({
href: FancyPhotoset.prototype.urlFor(photo, {
size: options.large
}),
rel: "flickr-" + options.photosetId,
title: photo.title
});
anchor.html(image).fancybox(options.fancybox);
if (options.captions) {
image.after(($("<span/>")).addClass("caption").text(photo.title));
}
return element.find("ul").append(($("<li/>")).html(anchor));
});
if (options.firstOnly) {
return element.find("li").not(":first").hide();
}
});
};
FancyPhotoset.prototype.urlFor = function(photo, options) {
return {
square: photo.url_sq,
thumbnail: photo.url_t,
small: photo.url_s,
medium: photo.url_m,
original: photo.url_o
}[options.size];
};
return FancyPhotoset;
})();
return $.fn[pluginName] = function(options) {
return this.each(function() {
if (!$.data(this, "plugin_" + pluginName)) {
return $.data(this, "plugin_" + pluginName, new FancyPhotoset(this, options));
}
});
};
})(jQuery, window, document);