search.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @name photos.js
  3. * @author Philipp Maurer
  4. * @author Tobias Reich
  5. * @copyright 2013 by Philipp Maurer, Tobias Reich
  6. *
  7. * Search Module
  8. * Searches through your photos and albums.
  9. */
  10. search = {
  11. find: function(term) {
  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, "json", function(data) {
  17. albumsData = "";
  18. if (data&&data.albums) $.each(data.albums, function() { albumsData += build.album(this); });
  19. photosData = "";
  20. if (data&&data.photos) $.each(data.photos, function() { photosData += build.photo(this); });
  21. if (albumsData==""&&photosData=="") code = "error";
  22. else if (albumsData=="") code = build.divider("Photos")+photosData;
  23. else if (photosData=="") code = build.divider("Albums")+albumsData;
  24. else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
  25. if (lychee.content.attr("data-search")!=code) {
  26. $(".no_content").remove();
  27. lychee.animate(".album, .photo", "contentZoomOut");
  28. lychee.animate(".divider", "fadeOut");
  29. $.timer(300,function(){
  30. lychee.content.attr("data-search", code);
  31. if (code=="error") $("body").append(build.no_content("search"));
  32. else {
  33. lychee.content.html(code);
  34. lychee.animate(".album, .photo", "contentZoomIn");
  35. }
  36. });
  37. }
  38. });
  39. } else search.reset();
  40. }, 250));
  41. },
  42. reset: function() {
  43. $("#search").val("");
  44. $(".no_content").remove();
  45. if (lychee.content.attr("data-search")!="") {
  46. lychee.content.attr("data-search", "");
  47. lychee.animate(".divider", "fadeOut");
  48. albums.load();
  49. }
  50. }
  51. }