sharing.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. $(document).ready(function() {
  2. $.getJSON(OC.filePath('gallery', 'ajax', 'sharing.php'), {operation: 'get_gallery', token: TOKEN}, albumClickHandler);
  3. });
  4. var paths = [];
  5. var counter = 0;
  6. function returnTo(num) {
  7. while (num != counter) {
  8. paths.pop();
  9. $('.breadcrumbelement:last').remove();
  10. counter--;
  11. }
  12. path = '';
  13. for (var e in paths) path += '/' + paths[e];
  14. $.getJSON(OC.filePath('gallery', 'ajax', 'sharing.php'), {operation: 'get_gallery', token: TOKEN, path: path}, function(r) {
  15. albumClickHandler(r);
  16. });
  17. }
  18. function albumClickHandler(r) {
  19. var element = $('div#gallery_list');
  20. element.html('');
  21. 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>';
  22. for (var i in r.albums) {
  23. var a = r.albums[i];
  24. var local = $(album_template.replace('IMGPATH', encodeURIComponent(a)));
  25. local.attr('title', a);
  26. $('h1', local).html(a);
  27. element.append(local);
  28. }
  29. $('div.gallery_box').each(function(i, element) {
  30. $(element).click(function() {
  31. paths.push($(this).attr('title'));
  32. path = '';
  33. for (var e in paths) path += '/' + paths[e];
  34. $.getJSON(OC.filePath('gallery', 'ajax', 'sharing.php'), {operation: 'get_gallery', token: TOKEN, path: path}, function(r) {
  35. var name = paths[paths.length-1];
  36. counter++;
  37. var d = '<span class="breadcrumbelement" onclick="javascript:returnTo('+counter+');return false;">'+name+'</span>';
  38. d = $(d).addClass('inside');
  39. $('#breadcrumb').append(d);
  40. albumClickHandler(r);
  41. });
  42. });
  43. });
  44. var pat = '';
  45. for (var a in paths) pat += '/'+paths[a];
  46. 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>';
  47. for (var a in r.photos) {
  48. 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]));
  49. element.append(local);
  50. }
  51. }