search.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @name search.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. code: null,
  12. find: function(term) {
  13. var params,
  14. albumsData = "",
  15. photosData = "",
  16. code;
  17. clearTimeout($(window).data("timeout"));
  18. $(window).data("timeout", setTimeout(function() {
  19. if ($("#search").val().length!=0) {
  20. params = "search&term=" + term;
  21. lychee.api(params, "json", function(data) {
  22. if (data&&data.albums) {
  23. albums.json = { content: data.albums };
  24. $.each(albums.json.content, function() {
  25. albums.parse(this);
  26. albumsData += build.album(this);
  27. });
  28. }
  29. if (data&&data.photos) {
  30. album.json = { content: data.photos };
  31. $.each(album.json.content, function() {
  32. album.parse(this);
  33. photosData += build.photo(this);
  34. });
  35. }
  36. if (albumsData==""&&photosData=="") code = "error";
  37. else if (albumsData=="") code = build.divider("Photos")+photosData;
  38. else if (photosData=="") code = build.divider("Albums")+albumsData;
  39. else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
  40. if (search.code!=hex_md5(code)) {
  41. $(".no_content").remove();
  42. lychee.animate(".album, .photo", "contentZoomOut");
  43. lychee.animate(".divider", "fadeOut");
  44. search.code = hex_md5(code);
  45. setTimeout(function() {
  46. if (code=="error") $("body").append(build.no_content("search"));
  47. else {
  48. lychee.content.html(code);
  49. lychee.animate(".album, .photo", "contentZoomIn");
  50. }
  51. }, 300);
  52. }
  53. });
  54. } else search.reset();
  55. }, 250));
  56. },
  57. reset: function() {
  58. $("#search").val("");
  59. $(".no_content").remove();
  60. if (search.code!="") {
  61. search.code = "";
  62. lychee.animate(".divider", "fadeOut");
  63. albums.load();
  64. }
  65. }
  66. }