Removed md5 from search, renamed code var to hash

This commit is contained in:
Tobias Reich 2015-02-27 22:39:07 +01:00
parent 138bf714c5
commit 1490dcbe9e
6 changed files with 29 additions and 21 deletions

View File

@ -13,6 +13,13 @@ function search($database, $settings, $term) {
$return['albums'] = '';
# Initialize return var
$return = array(
'photos' => null,
'albums' => null,
'hash' => ''
);
# Photos
$query = Database::prepare($database, "SELECT id, title, tags, public, star, album, thumbUrl FROM ? WHERE title LIKE '%?%' OR description LIKE '%?%' OR tags LIKE '%?%'", array(LYCHEE_TABLE_PHOTOS, $term, $term, $term));
$result = $database->query($query);
@ -48,6 +55,9 @@ function search($database, $settings, $term) {
}
# Hash
$return['hash'] = md5(json_encode($return));
return $return;
}

View File

@ -3,7 +3,6 @@
"private": true,
"dependencies": {
"jQuery": "~2.1.3",
"js-md5": "~1.1.0",
"mousetrap": "~1.4.6",
"basicContext": "~2.0.2",
"basicModal": "~2.0.3"

View File

@ -59,7 +59,6 @@ paths.main = {
],
scripts: [
'bower_components/jQuery/dist/jquery.min.js',
'bower_components/js-md5/js/md5.min.js',
'bower_components/mousetrap/mousetrap.min.js',
'bower_components/mousetrap/plugins/global-bind/mousetrap-global-bind.min.js',
'bower_components/basicContext/dist/basicContext.min.js',

View File

@ -201,9 +201,9 @@ lychee.load = function() {
} else {
// Trash albums.json when filled with search results
if (search.code!=='') {
if (search.hash!==null) {
albums.json = null;
search.code = '';
search.hash = null;
}
// Trash data

View File

@ -5,15 +5,15 @@
search = {
code: null
hash: null
}
search.find = function(term) {
var albumsData = '',
photosData = '',
code;
var albumsData = '',
photosData = '',
html = '';
clearTimeout($(window).data('timeout'));
$(window).data('timeout', setTimeout(function() {
@ -24,8 +24,8 @@ search.find = function(term) {
// Build albums
if (data&&data.albums) {
albums.json = { content: data.albums };
$.each(albums.json.content, function() {
albums.json = { albums: data.albums };
$.each(albums.json.albums, function() {
albums.parse(this);
albumsData += build.album(this);
});
@ -43,28 +43,28 @@ search.find = function(term) {
// 2. Only photos found
// 3. Only albums found
// 4. Albums and photos found
if (albumsData===''&&photosData==='') code = 'error';
else if (albumsData==='') code = build.divider('Photos') + photosData;
else if (photosData==='') code = build.divider('Albums') + albumsData;
else code = build.divider('Photos') + photosData + build.divider('Albums') + albumsData;
if (albumsData===''&&photosData==='') html = 'error';
else if (albumsData==='') html = build.divider('Photos') + photosData;
else if (photosData==='') html = build.divider('Albums') + albumsData;
else html = build.divider('Photos') + photosData + build.divider('Albums') + albumsData;
// Only refresh view when search results are different
if (search.code!==md5(code)) {
if (search.hash!==data.hash) {
$('.no_content').remove();
lychee.animate('.album, .photo', 'contentZoomOut');
lychee.animate('.divider', 'fadeOut');
search.code = md5(code);
search.hash = data.hash;
setTimeout(function() {
if (code==='error') {
if (html==='error') {
lychee.content.html('');
$('body').append(build.no_content('magnifying-glass'));
} else {
lychee.content.html(code);
lychee.content.html(html);
lychee.animate('.album, .photo', 'contentZoomIn');
$('img[data-type!="svg"]').retina();
}
@ -86,13 +86,13 @@ search.reset = function() {
$('#search').val('');
$('.no_content').remove();
if (search.code!=='') {
if (search.hash!==null) {
// Trash data
albums.json = null;
album.json = null;
photo.json = null;
search.code = '';
search.hash = null;
lychee.animate('.divider', 'fadeOut');
albums.load();

View File

@ -21,7 +21,7 @@ visible.photo = function() {
}
visible.search = function() {
if (search.code!==null&&search.code!=='') return true;
if (search.hash!==null) return true;
return false;
}