-
Notifications
You must be signed in to change notification settings - Fork 46
/
example.js
100 lines (81 loc) · 2.71 KB
/
example.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*globals $, jQuery, CSPhotoSelector */
$(document).ready(function () {
var selector, logActivity, callbackAlbumSelected, callbackPhotoUnselected, callbackSubmit;
var buttonOK = $('#CSPhotoSelector_buttonOK');
var o = this;
/* --------------------------------------------------------------------
* Photo selector functions
* ----------------------------------------------------------------- */
fbphotoSelect = function(id) {
// if no user/friend id is sent, default to current user
if (!id) id = 'me';
callbackAlbumSelected = function(albumId) {
var album, name;
album = CSPhotoSelector.getAlbumById(albumId);
// show album photos
selector.showPhotoSelector(null, album.id);
};
callbackAlbumUnselected = function(albumId) {
var album, name;
album = CSPhotoSelector.getAlbumById(albumId);
};
callbackPhotoSelected = function(photoId) {
var photo;
photo = CSPhotoSelector.getPhotoById(photoId);
buttonOK.show();
logActivity('Selected ID: ' + photo.id);
};
callbackPhotoUnselected = function(photoId) {
var photo;
album = CSPhotoSelector.getPhotoById(photoId);
buttonOK.hide();
};
callbackSubmit = function(photoId) {
var photo;
photo = CSPhotoSelector.getPhotoById(photoId);
logActivity('<br><strong>Submitted</strong><br> Photo ID: ' + photo.id + '<br>Photo URL: ' + photo.source + '<br>');
};
// Initialise the Photo Selector with options that will apply to all instances
CSPhotoSelector.init({debug: true});
// Create Photo Selector instances
selector = CSPhotoSelector.newInstance({
callbackAlbumSelected : callbackAlbumSelected,
callbackAlbumUnselected : callbackAlbumUnselected,
callbackPhotoSelected : callbackPhotoSelected,
callbackPhotoUnselected : callbackPhotoUnselected,
callbackSubmit : callbackSubmit,
maxSelection : 1,
albumsPerPage : 6,
photosPerPage : 200,
autoDeselection : true
});
// reset and show album selector
selector.reset();
selector.showAlbumSelector(id);
}
/* --------------------------------------------------------------------
* Click events
* ----------------------------------------------------------------- */
$("#btnLogin").click(function (e) {
e.preventDefault();
FB.login(function (response) {
if (response.authResponse) {
$("#login-status").html("Logged in");
} else {
$("#login-status").html("Not logged in");
}
}, {scope:'user_photos'});
});
$("#btnLogout").click(function (e) {
e.preventDefault();
FB.logout();
$("#login-status").html("Not logged in");
});
$(".photoSelect").click(function (e) {
e.preventDefault();
fbphotoSelect();
});
logActivity = function (message) {
$("#results").append('<div>' + message + '</div>');
};
});