From 35f37df707032b88ecd52f5fb64d4f6dd417424f Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sat, 11 Jul 2015 16:27:26 +0200 Subject: [PATCH] Updated search.js (ES2015) --- dist/main.js | Bin 180068 -> 180068 bytes src/scripts/search.js | 87 +++++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 43 deletions(-) mode change 100644 => 100755 dist/main.js diff --git a/dist/main.js b/dist/main.js old mode 100644 new mode 100755 index 6a8f25d1133f963a4601cbc14d697cc0d9e5063f..ffb7e6c62c27df2b010a5edefb66cebdb3c8e420 GIT binary patch delta 205 zcmaFzkL$@lu7(!IElgp7)6cwQ)R;aokf~%k?;b|>>9K)KJkwc&m{J(?re_5)Wklv{ z+a{G}=A`HqWaO9RYm{VU7HigOYU-5ODk<68+UBXLf$4mErPQLL{30bQh_F3GQ%Yu8 zW=d+2hEf1Xcd?SDc0NQwzWwz0U?vIaJS&_Er^f{|Ndlcw5zI7k`jjP1cGKNMn6#Kn SG8wFaDbp>NFo{jC4`K?A z%+t0_D$UGE(JRQvFUi*^$;d3$tku-i$+uNfvbD7>QBwocdG<=FMMe2VN>&hIdx)l# z%(Bds)FKU~0FdrtB~9%-h=M%(>G8o#64E7BI2BHh3ucmJESX*r%rucPe>ztPQ#y0L Srq1-jCPuaGvqG3oWdQ&dj6<3L diff --git a/src/scripts/search.js b/src/scripts/search.js index 1a34f3e..0aec1aa 100755 --- a/src/scripts/search.js +++ b/src/scripts/search.js @@ -1,6 +1,6 @@ /** - * @description Searches through your photos and albums. - * @copyright 2015 by Tobias Reich + * @description Searches through your photos and albums. + * @copyright 2015 by Tobias Reich */ search = { @@ -11,89 +11,90 @@ search = { search.find = function(term) { - var albumsData = '', - photosData = '', - html = ''; + clearTimeout($(window).data('timeout')) - clearTimeout($(window).data('timeout')); $(window).data('timeout', setTimeout(function() { if ($('#search').val().length!==0) { api.post('search', { term }, function(data) { + let html = '', + albumsData = '', + photosData = '' + // Build albums - if (data&&data.albums) { - albums.json = { albums: data.albums }; + if (data && data.albums) { + albums.json = { albums: data.albums } $.each(albums.json.albums, function() { - albums.parse(this); - albumsData += build.album(this); - }); + albums.parse(this) + albumsData += build.album(this) + }) } // Build photos - if (data&&data.photos) { - album.json = { content: data.photos }; + if (data && data.photos) { + album.json = { content: data.photos } $.each(album.json.content, function() { - photosData += build.photo(this); - }); + photosData += build.photo(this) + }) } - // 1. No albums and photos found - // 2. Only photos found - // 3. Only albums found - // 4. Albums and photos found - 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; + // 1. No albums and photos + // 2. Only photos + // 3. Only albums + // 4. Albums and photos + 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.hash!==data.hash) { - $('.no_content').remove(); + $('.no_content').remove() - lychee.animate('#content', 'contentZoomOut'); + lychee.animate('#content', 'contentZoomOut') - search.hash = data.hash; + search.hash = data.hash - setTimeout(function() { + setTimeout(() => { if (html==='error') { - lychee.content.html(''); - $('body').append(build.no_content('magnifying-glass')); + lychee.content.html('') + $('body').append(build.no_content('magnifying-glass')) } else { - lychee.content.html(html); - lychee.animate('#content', 'contentZoomIn'); + lychee.content.html(html) + lychee.animate('#content', 'contentZoomIn') } - }, 300); + }, 300) } - }); + }) - } else search.reset(); + } else search.reset() - }, 250)); + }, 250)) } search.reset = function() { - $('#search').val(''); - $('.no_content').remove(); + $('#search').val('') + $('.no_content').remove() if (search.hash!==null) { // Trash data - albums.json = null; - album.json = null; - photo.json = null; - search.hash = null; + albums.json = null + album.json = null + photo.json = null + search.hash = null - lychee.animate('.divider', 'fadeOut'); - albums.load(); + lychee.animate('.divider', 'fadeOut') + albums.load() }