This repository was archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflickrbrowser.js
More file actions
55 lines (51 loc) · 2.54 KB
/
Copy pathflickrbrowser.js
File metadata and controls
55 lines (51 loc) · 2.54 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
(function($) {
Drupal.behaviors.flickrbrowser = {
attach: function (context, settings) {
// Get the flickr api key from drupal settings
api_key = $(Drupal.settings.flickrbrowser);
// When the select list is changed grab the photos and display them to the user
$('.flickrbrowser select').change(function() {
var $clicked = $(this);
$clicked.parents('.flickrbrowser').find('.photo-selector').empty();
if ($clicked.val() != "") {
$.getJSON("http://api.flickr.com/services/rest/?jsoncallback=?", { // flickr json call
method: "flickr.photosets.getPhotos",
photoset_id: $clicked.val(), // ID of the photoset
extras: "url_sq",
format: "json",
api_key: api_key[0].api_key // API key from Drupal.settings
}, function(data) {
var photos = '<ul id="' + data.photoset.id + '" class="photos">';
$.each(data.photoset.photo, function (i, item) {
photos += '<li><img id="' + item.id + '" src="' + item.url_sq + '" title="' + item.title + '"/></li>';
//$("<img/>").attr("src", item.url_sq).appendTo($(this).parents('.flickrbrowser').find('.photo-selector'));
});
photos += '</ul>';
$clicked.parents('.flickrbrowser').find('.photo-selector').append(photos); // Add the photos to the selector div
$clicked.parents('.flickrbrowser').find('ul.photos').quickPager({pageSize: 20}); // Initialize the quickPager
});
}
});
// When the remove link is clicked, unset the photo id, hide the link and show the browser
$('.flickrbrowser-wrapper .photo-remove a.remove-selected').click(function() {
var $parent = $(this).parents('.flickrbrowser-wrapper');
$parent.find('.flickr-id').attr('value', '');
$parent.find('.photo-selected').empty();
$parent.find('.photo-remove').hide();
$parent.find('.flickrbrowser').show();
$parent.find('.flickrbrowser select').val('');
});
// When an image is clicked update the hidden id value and remove all the other images
$('.photo-selector ul.photos img').live('click', function() {
var $clicked = $(this);
var $parent = $(this).parents('.flickrbrowser-wrapper');
var id = $(this).attr('id');
$parent.find('.flickr-id').attr('value', id);
$parent.find('.photo-selector').empty();
$parent.find('.photo-selected').empty().append($("<img/>").attr('src', $clicked.attr('src')).attr('title', $clicked.attr('title')));
$parent.find('.photo-remove').show();
$parent.find('.flickrbrowser').hide();
});
}
};
})(jQuery);