4
Gallery.currentAlbum = '';
5
Gallery.subAlbums = {};
7
Gallery.displayNames = [];
9
Gallery.sortFunction = function (a, b) {
10
return a.toLowerCase().localeCompare(b.toLowerCase());
13
// fill the albums from Gallery.images
14
Gallery.fillAlbums = function () {
15
var def = new $.Deferred();
16
var token = $('#gallery').data('token');
17
$.getJSON(OC.filePath('gallery', 'ajax', 'getimages.php'), {token: token}).then(function (data) {
18
var albumPath, i, imagePath, parent, path;
19
Gallery.users = data.users;
20
Gallery.displayNames = data.displayNames;
21
for (i = 0; i < data.images.length; i++) {
22
Gallery.images.push(data.images[i].path);
24
Gallery.fillAlbums.fill(Gallery.albums, Gallery.images);
25
Gallery.fillAlbums.fillSubAlbums(Gallery.subAlbums, Gallery.albums);
27
Gallery.fillAlbums.sortAlbums(Gallery.subAlbums);
32
Gallery.fillAlbums.fill = function (albums, images) {
33
var imagePath, albumPath, parent;
35
for (i = 0; i < images.length; i++) {
36
imagePath = images[i];
37
albumPath = OC.dirname(imagePath);
38
if (!albums[albumPath]) {
39
albums[albumPath] = [];
41
parent = OC.dirname(albumPath);
42
while (parent && !albums[parent] && parent !== albumPath) {
44
parent = OC.dirname(parent);
46
albums[albumPath].push(imagePath);
49
Gallery.fillAlbums.fillSubAlbums = function (subAlbums, albums) {
50
var albumPath, parent;
51
for (albumPath in albums) {
52
if (albums.hasOwnProperty(albumPath)) {
53
if (albumPath !== '') {
54
parent = OC.dirname(albumPath);
55
if (albumPath !== parent) {
56
if (!subAlbums[parent]) {
57
subAlbums[parent] = [];
59
subAlbums[parent].push(albumPath);
65
Gallery.fillAlbums.sortAlbums = function (albums) {
67
for (path in albums) {
68
if (albums.hasOwnProperty(path)) {
69
albums[path].sort(Gallery.sortFunction);
74
Gallery.getAlbumInfo = function (album) {
75
if (album === $('#gallery').data('token')) {
78
if (!Gallery.getAlbumInfo.cache[album]) {
79
var def = new $.Deferred();
80
Gallery.getAlbumInfo.cache[album] = def;
81
$.getJSON(OC.filePath('gallery', 'ajax', 'gallery.php'), {gallery: album}, function (data) {
85
return Gallery.getAlbumInfo.cache[album];
87
Gallery.getAlbumInfo.cache = {};
88
Gallery.getImage = function (image) {
89
return OC.filePath('gallery', 'ajax', 'image.php') + '?file=' + encodeURIComponent(image);
91
Gallery.getAlbumThumbnailPaths = function (album) {
93
if (Gallery.albums[album].length) {
94
paths = Gallery.albums[album].slice(0, 10);
96
if (Gallery.subAlbums[album]) {
97
for (var i = 0; i < Gallery.subAlbums[album].length; i++) {
98
if (paths.length < 10) {
99
paths = paths.concat(Gallery.getAlbumThumbnailPaths(Gallery.subAlbums[album][i]));
105
Gallery.share = function (event) {
106
if (!OC.Share.droppedDown) {
107
event.preventDefault();
108
event.stopPropagation();
111
var target = OC.Share.showLink;
112
OC.Share.showLink = function () {
113
var r = target.apply(this, arguments);
114
$('#linkText').val($('#linkText').val().replace('service=files', 'service=gallery'));
119
Gallery.getAlbumInfo(Gallery.currentAlbum).then(function (info) {
120
$('a.share').data('item', info.fileid).data('link', true)
121
.data('possible-permissions', info.permissions).
123
if (!$('#linkCheckbox').is(':checked')) {
124
$('#linkText').hide();
130
Gallery.view.element = null;
131
Gallery.view.clear = function () {
132
Gallery.view.element.empty();
134
Gallery.view.cache = {};
136
Gallery.view.addImage = function (image) {
138
if (Gallery.view.cache[image]) {
139
Gallery.view.element.append(Gallery.view.cache[image]);
140
thumb = Thumbnail.get(image);
144
link.addClass('image loading');
145
link.attr('data-path', image);
146
link.attr('href', Gallery.getImage(image)).attr('rel', 'album').attr('alt', OC.basename(image)).attr('title', OC.basename(image));
148
thumb = Thumbnail.get(image);
149
thumb.queue().then(function (thumb) {
150
link.removeClass('loading');
154
Gallery.view.element.append(link);
155
Gallery.view.cache[image] = link;
159
Gallery.view.addAlbum = function (path, name) {
160
var link, image, label, thumbs, thumb;
161
name = name || OC.basename(path);
162
if (Gallery.view.cache[path]) {
163
thumbs = Gallery.view.addAlbum.thumbs[path];
164
Gallery.view.element.append(Gallery.view.cache[path]);
165
//event handlers are removed when using clear()
166
Gallery.view.cache[path].click(function () {
167
Gallery.view.viewAlbum(path);
169
Gallery.view.cache[path].mousemove(function (event) {
170
Gallery.view.addAlbum.mouseEvent.call(Gallery.view.cache[path], thumbs, event);
172
thumb = Thumbnail.get(thumbs[0], true);
175
thumbs = Gallery.getAlbumThumbnailPaths(path);
176
Gallery.view.addAlbum.thumbs[path] = thumbs;
178
label = $('<label/>');
179
link.attr('href', '#' + path);
180
link.addClass('album loading');
181
link.click(function () {
182
Gallery.view.viewAlbum(path);
184
link.data('path', path);
185
link.data('offset', 0);
186
link.attr('title', OC.basename(path));
189
thumb = Thumbnail.get(thumbs[0], true);
190
thumb.queue().then(function (image) {
191
link.removeClass('loading');
195
link.mousemove(function (event) {
196
Gallery.view.addAlbum.mouseEvent.call(link, thumbs, event);
199
Gallery.view.element.append(link);
200
Gallery.view.cache[path] = link;
203
Gallery.view.addAlbum.thumbs = {};
205
Gallery.view.addAlbum.mouseEvent = function (thumbs, event) {
206
var mousePos = event.pageX - $(this).offset().left,
207
offset = ((Math.floor((mousePos / 200) * thumbs.length - 1) % thumbs.length) + thumbs.length) % thumbs.length, //workaround js modulo "feature" with negative numbers
209
oldOffset = $(this).data('offset');
210
if (offset !== oldOffset && !link.data('loading')) {
211
if (!thumbs[offset]) {
214
var thumb = Thumbnail.get(thumbs[offset], true);
215
link.data('loading', true);
216
thumb.load().then(function (image) {
217
link.data('loading', false);
218
$('img', link).remove();
221
$(this).data('offset', offset);
224
Gallery.view.addAlbum.thumbs = {};
226
Gallery.view.viewAlbum = function (albumPath) {
228
albumPath = $('#gallery').data('token');
230
Thumbnail.queue = [];
231
Gallery.view.clear();
232
Gallery.currentAlbum = albumPath;
234
var i, album, subAlbums, crumbs, path;
235
subAlbums = Gallery.subAlbums[albumPath];
237
for (i = 0; i < subAlbums.length; i++) {
238
Gallery.view.addAlbum(subAlbums[i]);
239
Gallery.view.element.append(' '); //add a space for justify
243
album = Gallery.albums[albumPath];
245
for (i = 0; i < album.length; i++) {
246
Gallery.view.addImage(album[i]);
247
Gallery.view.element.append(' '); //add a space for justify
251
if (albumPath === OC.currentUser) {
252
$('button.share').hide();
254
$('button.share').show();
257
OC.Breadcrumb.clear();
258
var albumName = $('#content').data('albumname');
260
albumName = t('gallery', 'Pictures');
262
OC.Breadcrumb.push(albumName, '#').click(function () {
263
Gallery.view.viewAlbum(OC.currentUser);
265
crumbs = albumPath.split('/');
266
//first entry is username
267
path = crumbs.splice(0, 1);
269
if (path[0] !== OC.currentUser && path[0] !== $('#gallery').data('token')) {
270
path += '/' + crumbs.splice(0, 1);
272
for (i = 0; i < crumbs.length; i++) {
274
path += '/' + crumbs[i];
275
Gallery.view.pushBreadCrumb(crumbs[i], path);
279
if (albumPath === OC.currentUser) {
280
Gallery.view.showUsers();
283
Gallery.getAlbumInfo(Gallery.currentAlbum); //preload album info
286
Gallery.view.pushBreadCrumb = function (text, path) {
287
OC.Breadcrumb.push(text, '#' + path).click(function () {
288
Gallery.view.viewAlbum(path);
292
Gallery.view.showUsers = function () {
293
var i, j, user, head, subAlbums, album;
294
for (i = 0; i < Gallery.users.length; i++) {
295
user = Gallery.users[i];
296
subAlbums = Gallery.subAlbums[user];
298
if (subAlbums.length > 0) {
300
head.text(t('gallery', 'Shared by') + ' ' + Gallery.displayNames[user]);
301
$('#gallery').append(head);
302
for (j = 0; j < subAlbums.length; j++) {
303
album = subAlbums[j];
304
album = Gallery.subAlbums[album][0];//first level sub albums is share source id
305
Gallery.view.addAlbum(album);
306
Gallery.view.element.append(' '); //add a space for justify
313
$(document).ready(function () {
314
Gallery.fillAlbums().then(function () {
315
Gallery.view.element = $('#gallery');
316
OC.Breadcrumb.container = $('#breadcrumbs');
317
window.onhashchange();
318
$('button.share').click(Gallery.share);
321
$('#gallery').on('click', 'a.image', function (event) {
322
var images = $('#gallery').children('a.image');
323
var i = images.index(this),
324
image = $(this).data('path');
325
event.preventDefault();
326
if (location.hash !== image) {
327
location.hash = image;
328
Thumbnail.paused = true;
329
Slideshow.start(images, i);
333
$('#openAsFileListButton').click(function (event) {
334
window.location.href = window.location.href.replace('service=gallery', 'service=files');
337
jQuery.fn.slideShow.onstop = function () {
338
$('#content').show();
339
Thumbnail.paused = false;
340
$(window).scrollTop(Gallery.scrollLocation);
341
location.hash = Gallery.currentAlbum;
342
Thumbnail.concurrent = 3;
346
window.onhashchange = function () {
347
var album = location.hash.substr(1);
349
album = OC.currentUser;
352
album = $('#gallery').data('token');
354
if (Gallery.images.indexOf(album) === -1) {
356
Gallery.view.viewAlbum(decodeURIComponent(album));
358
Gallery.view.viewAlbum(OC.dirname(album));
359
$('#gallery').find('a.image[data-path="' + album + '"]').click();