search.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. photosData += build.photo(this);
  30. });
  31. }
  32. if (albumsData===""&&photosData==="") code = "error";
  33. else if (albumsData==="") code = build.divider("Photos")+photosData;
  34. else if (photosData==="") code = build.divider("Albums")+albumsData;
  35. else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
  36. if (search.code!==md5(code)) {
  37. $(".no_content").remove();
  38. lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomOut");
  39. lychee.animate(".divider", "fadeOut");
  40. search.code = md5(code);
  41. setTimeout(function() {
  42. if (code==="error") $("body").append(build.no_content("search"));
  43. else {
  44. lychee.content.html(code);
  45. lychee.animate(".album:nth-child(-n+50), .photo:nth-child(-n+50)", "contentZoomIn");
  46. $("img[data-type!='svg']").retina();
  47. }
  48. }, 300);
  49. }
  50. });
  51. } else search.reset();
  52. }, 250));
  53. },
  54. reset: function() {
  55. $("#search").val("");
  56. $(".no_content").remove();
  57. if (search.code!=="") {
  58. // Trash data
  59. albums.json = null;
  60. album.json = null;
  61. photo.json = null;
  62. search.code = "";
  63. lychee.animate(".divider", "fadeOut");
  64. albums.load();
  65. }
  66. }
  67. };