albums.js 2.5 KB

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