search.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = "";
  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. lychee.animate(".album, .photo", "contentZoomOut");
  27. lychee.animate(".divider", "fadeOut");
  28. $.timer(300,function(){
  29. lychee.content.attr("data-search", code);
  30. lychee.content.html(code);
  31. lychee.animate(".album, .photo", "contentZoomIn");
  32. });
  33. }
  34. });
  35. } else search.reset();
  36. }, 250));
  37. },
  38. reset: function() {
  39. $("#search").val("");
  40. if (lychee.content.attr("data-search")!="") {
  41. lychee.content.attr("data-search", "");
  42. lychee.animate(".divider", "fadeOut");
  43. albums.load();
  44. }
  45. }
  46. }