search.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @description Searches through your photos and albums.
  3. * @copyright 2014 by Tobias Reich
  4. */
  5. search = {
  6. code: null,
  7. find: function(term) {
  8. var params,
  9. albumsData = "",
  10. photosData = "",
  11. code;
  12. clearTimeout($(window).data("timeout"));
  13. $(window).data("timeout", setTimeout(function() {
  14. if ($("#search").val().length!==0) {
  15. params = "search&term=" + term;
  16. lychee.api(params, function(data) {
  17. if (data&&data.albums) {
  18. albums.json = { content: data.albums };
  19. $.each(albums.json.content, function() {
  20. albums.parse(this);
  21. albumsData += build.album(this);
  22. });
  23. }
  24. if (data&&data.photos) {
  25. album.json = { content: data.photos };
  26. $.each(album.json.content, function() {
  27. photosData += build.photo(this);
  28. });
  29. }
  30. if (albumsData===""&&photosData==="") code = "error";
  31. else if (albumsData==="") code = build.divider("Photos")+photosData;
  32. else if (photosData==="") code = build.divider("Albums")+albumsData;
  33. else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
  34. if (search.code!==md5(code)) {
  35. $(".no_content").remove();
  36. lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
  37. lychee.animate(".divider", "fadeOut");
  38. search.code = md5(code);
  39. setTimeout(function() {
  40. if (code==="error") $("body").append(build.no_content("search"));
  41. else {
  42. lychee.content.html(code);
  43. lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
  44. $("img[data-type!='svg']").retina();
  45. }
  46. }, 300);
  47. }
  48. });
  49. } else search.reset();
  50. }, 250));
  51. },
  52. reset: function() {
  53. $("#search").val("");
  54. $(".no_content").remove();
  55. if (search.code!=="") {
  56. // Trash data
  57. albums.json = null;
  58. album.json = null;
  59. photo.json = null;
  60. search.code = "";
  61. lychee.animate(".divider", "fadeOut");
  62. albums.load();
  63. }
  64. }
  65. };