albums.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @description Takes care of every action albums can handle and execute.
  3. * @copyright 2014 by Tobias Reich
  4. */
  5. albums = {}
  6. albums.json = null;
  7. albums.load = function() {
  8. var startTime,
  9. durationTime,
  10. waitTime;
  11. lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomOut');
  12. lychee.animate('.divider', 'fadeOut');
  13. startTime = new Date().getTime();
  14. if (albums.json===null) {
  15. lychee.api('getAlbums', function(data) {
  16. /* Smart Albums */
  17. data.unsortedAlbum = {
  18. id: 0,
  19. title: 'Unsorted',
  20. sysdate: data.unsortedNum + ' photos',
  21. unsorted: '1',
  22. thumb0: data.unsortedThumb0,
  23. thumb1: data.unsortedThumb1,
  24. thumb2: data.unsortedThumb2
  25. };
  26. data.starredAlbum = {
  27. id: 'f',
  28. title: 'Starred',
  29. sysdate: data.starredNum + ' photos',
  30. star: '1',
  31. thumb0: data.starredThumb0,
  32. thumb1: data.starredThumb1,
  33. thumb2: data.starredThumb2
  34. };
  35. data.publicAlbum = {
  36. id: 's',
  37. title: 'Public',
  38. sysdate: data.publicNum + ' photos',
  39. public: '1',
  40. thumb0: data.publicThumb0,
  41. thumb1: data.publicThumb1,
  42. thumb2: data.publicThumb2
  43. };
  44. data.recentAlbum = {
  45. id: 'r',
  46. title: 'Recent',
  47. sysdate: data.recentNum + ' photos',
  48. recent: '1',
  49. thumb0: data.recentThumb0,
  50. thumb1: data.recentThumb1,
  51. thumb2: data.recentThumb2
  52. };
  53. albums.json = data;
  54. // Calculate delay
  55. durationTime = (new Date().getTime() - startTime);
  56. if (durationTime>300) waitTime = 0;
  57. else waitTime = 300 - durationTime;
  58. // Skip delay when opening a blank Lychee
  59. if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0;
  60. if (visible.album()&&lychee.content.html()==='') waitTime = 0;
  61. setTimeout(function() {
  62. view.header.mode('albums');
  63. view.albums.init();
  64. lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomIn');
  65. }, waitTime);
  66. });
  67. } else {
  68. setTimeout(function() {
  69. view.header.mode('albums');
  70. view.albums.init();
  71. lychee.animate('.album:nth-child(-n+50), .photo:nth-child(-n+50)', 'contentZoomIn');
  72. }, 300);
  73. }
  74. }
  75. albums.parse = function(album) {
  76. if (album.password&&lychee.publicMode) {
  77. album.thumb0 = 'src/images/password.svg';
  78. album.thumb1 = 'src/images/password.svg';
  79. album.thumb2 = 'src/images/password.svg';
  80. } else {
  81. if (!album.thumb0) album.thumb0 = 'src/images/no_images.svg';
  82. if (!album.thumb1) album.thumb1 = 'src/images/no_images.svg';
  83. if (!album.thumb2) album.thumb2 = 'src/images/no_images.svg';
  84. }
  85. }
  86. albums.refresh = function() {
  87. albums.json = null;
  88. }