nextcloud/apps/gallery/js/sharing.js

58 lines
2.3 KiB
JavaScript
Raw Normal View History

2012-03-24 21:35:16 +04:00
$(document).ready(function() {
2012-05-07 18:46:35 +04:00
$.getJSON(OC.filePath('gallery', 'ajax', 'sharing.php'), {operation: 'get_gallery', token: TOKEN}, albumClickHandler);
2012-03-24 21:35:16 +04:00
});
var paths = [];
var counter = 0;
function returnTo(num) {
while (num != counter) {
paths.pop();
$('.breadcrumbelement:last').remove();
counter--;
}
path = '';
for (var e in paths) path += '/' + paths[e];
2012-05-07 18:46:35 +04:00
$.getJSON(OC.filePath('gallery', 'ajax', 'sharing.php'), {operation: 'get_gallery', token: TOKEN, path: path}, function(r) {
2012-03-24 21:35:16 +04:00
albumClickHandler(r);
});
}
function albumClickHandler(r) {
var element = $('div#gallery_list');
element.html('');
2012-05-07 18:46:35 +04:00
var album_template = '<div class="gallery_box"><div><a rel="images"><img src="' + OC.filePath('gallery', 'ajax', 'sharing.php') + '?token='+TOKEN+'&operation=get_album_thumbnail&albumname=IMGPATH"></a></div><h1></h1></div>';
2012-03-24 21:35:16 +04:00
for (var i in r.albums) {
var a = r.albums[i];
var local = $(album_template.replace('IMGPATH', encodeURIComponent(a)));
local.attr('title', a);
$('h1', local).html(a);
element.append(local);
}
$('div.gallery_box').each(function(i, element) {
$(element).click(function() {
paths.push($(this).attr('title'));
path = '';
for (var e in paths) path += '/' + paths[e];
2012-05-07 18:46:35 +04:00
$.getJSON(OC.filePath('gallery', 'ajax', 'sharing.php'), {operation: 'get_gallery', token: TOKEN, path: path}, function(r) {
2012-03-24 21:35:16 +04:00
var name = paths[paths.length-1];
counter++;
var d = '<span class="breadcrumbelement" onclick="javascript:returnTo('+counter+');return false;">'+name+'</span>';
d = $(d).addClass('inside');
$('#breadcrumb').append(d);
albumClickHandler(r);
});
});
});
var pat = '';
for (var a in paths) pat += '/'+paths[a];
2012-05-07 18:46:35 +04:00
var photo_template = '<div class="gallery_box"><div><a rel="images" href="*HREF*" target="_blank"><img src="' + OC.filePath('gallery', 'ajax', 'sharing.php') + '?token='+TOKEN+'&operation=get_thumbnail&img=IMGPATH"></a></div></div>';
2012-03-24 21:35:16 +04:00
for (var a in r.photos) {
2012-05-07 18:46:35 +04:00
var local = photo_template.replace('IMGPATH', encodeURIComponent(r.photos[a])).replace('*HREF*', OC.filePath('gallery', 'ajax', 'sharing.php') + '?token='+TOKEN+'&operation=get_photo&photo='+encodeURIComponent(r.photos[a]));
2012-03-24 21:35:16 +04:00
element.append(local);
}
}