2013-05-03 11:57:08 +00:00
|
|
|
/**
|
2014-01-22 10:12:51 +00:00
|
|
|
* @name Search Module
|
|
|
|
* @description Searches through your photos and albums.
|
|
|
|
* @author Tobias Reich
|
|
|
|
* @copyright 2014 by Tobias Reich
|
2013-05-03 11:57:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
search = {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
code: null,
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
find: function(term) {
|
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
var params,
|
|
|
|
albumsData = "",
|
|
|
|
photosData = "",
|
|
|
|
code;
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
clearTimeout($(window).data("timeout"));
|
|
|
|
$(window).data("timeout", setTimeout(function() {
|
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if ($("#search").val().length!==0) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
params = "search&term=" + term;
|
2014-01-22 10:12:51 +00:00
|
|
|
lychee.api(params, function(data) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
if (data&&data.albums) {
|
|
|
|
albums.json = { content: data.albums };
|
|
|
|
$.each(albums.json.content, function() {
|
|
|
|
albums.parse(this);
|
|
|
|
albumsData += build.album(this);
|
|
|
|
});
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
if (data&&data.photos) {
|
|
|
|
album.json = { content: data.photos };
|
|
|
|
$.each(album.json.content, function() {
|
|
|
|
album.parse(this);
|
|
|
|
photosData += build.photo(this);
|
|
|
|
});
|
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (albumsData===""&&photosData==="") code = "error";
|
|
|
|
else if (albumsData==="") code = build.divider("Photos")+photosData;
|
|
|
|
else if (photosData==="") code = build.divider("Albums")+albumsData;
|
2013-05-03 11:57:08 +00:00
|
|
|
else code = build.divider("Photos")+photosData+build.divider("Albums")+albumsData;
|
|
|
|
|
2014-04-01 19:33:29 +00:00
|
|
|
if (search.code!==md5(code)) {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-06-17 18:40:04 +00:00
|
|
|
$(".no_content").remove();
|
|
|
|
|
2013-05-03 11:57:08 +00:00
|
|
|
lychee.animate(".album, .photo", "contentZoomOut");
|
|
|
|
lychee.animate(".divider", "fadeOut");
|
|
|
|
|
2014-04-01 19:33:29 +00:00
|
|
|
search.code = md5(code);
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-08 17:50:31 +00:00
|
|
|
setTimeout(function() {
|
2013-06-17 18:40:04 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (code==="error") $("body").append(build.no_content("search"));
|
2013-06-17 18:40:04 +00:00
|
|
|
else {
|
|
|
|
lychee.content.html(code);
|
|
|
|
lychee.animate(".album, .photo", "contentZoomIn");
|
2014-02-02 14:37:14 +00:00
|
|
|
$("img[data-type!='svg']").retina();
|
2013-06-17 18:40:04 +00:00
|
|
|
}
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-08 17:50:31 +00:00
|
|
|
}, 300);
|
2013-05-03 11:57:08 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else search.reset();
|
|
|
|
|
|
|
|
}, 250));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
|
|
|
|
$("#search").val("");
|
2013-06-17 18:40:04 +00:00
|
|
|
$(".no_content").remove();
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2014-01-22 10:12:51 +00:00
|
|
|
if (search.code!=="") {
|
2013-05-03 11:57:08 +00:00
|
|
|
|
2013-09-03 09:59:30 +00:00
|
|
|
search.code = "";
|
2013-05-03 11:57:08 +00:00
|
|
|
lychee.animate(".divider", "fadeOut");
|
|
|
|
albums.load();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-25 22:37:05 +00:00
|
|
|
};
|