search.js 1.9 KB

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