Updated albums.js (ES2015)

This commit is contained in:
Tobias Reich 2015-07-11 13:47:43 +02:00
parent 93db87a1f8
commit a0ea271bd6
3 changed files with 76 additions and 77 deletions

BIN
dist/main.js vendored

Binary file not shown.

View File

@ -36,8 +36,7 @@ album.load = function(albumID, refresh) {
if (!refresh) lychee.animate('#content', 'contentZoomOut') if (!refresh) lychee.animate('#content', 'contentZoomOut')
let startTime = new Date().getTime(), let startTime = new Date().getTime()
waitTime = 0
let params = { let params = {
albumID, albumID,
@ -46,6 +45,8 @@ album.load = function(albumID, refresh) {
api.post('Album::get', params, function(data) { api.post('Album::get', params, function(data) {
let waitTime = 0
if (data==='Warning: Album private!') { if (data==='Warning: Album private!') {
if (document.location.hash.replace('#', '').split('/')[1]!=undefined) { if (document.location.hash.replace('#', '').split('/')[1]!=undefined) {
@ -76,7 +77,7 @@ album.load = function(albumID, refresh) {
if (refresh===true) waitTime = 0 if (refresh===true) waitTime = 0
if (!visible.albums() && !visible.photo() && !visible.album()) waitTime = 0 if (!visible.albums() && !visible.photo() && !visible.album()) waitTime = 0
setTimeout(function() { setTimeout(() => {
view.album.init() view.album.init()

View File

@ -11,61 +11,59 @@ albums = {
albums.load = function() { albums.load = function() {
var startTime, let startTime = new Date().getTime()
durationTime,
waitTime;
lychee.animate('#content', 'contentZoomOut'); lychee.animate('#content', 'contentZoomOut')
startTime = new Date().getTime();
if (albums.json===null) { if (albums.json===null) {
api.post('Album::getAll', {}, function(data) { api.post('Album::getAll', {}, function(data) {
/* Smart Albums */ let waitTime = 0
if (lychee.publicMode===false) albums._createSmartAlbums(data.smartalbums);
albums.json = data; // Smart Albums
if (lychee.publicMode===false) albums._createSmartAlbums(data.smartalbums)
albums.json = data
// Calculate delay // Calculate delay
durationTime = (new Date().getTime() - startTime); let durationTime = (new Date().getTime() - startTime)
if (durationTime>300) waitTime = 0; if (durationTime>300) waitTime = 0
else waitTime = 300 - durationTime; else waitTime = 300 - durationTime
// Skip delay when opening a blank Lychee // Skip delay when opening a blank Lychee
if (!visible.albums()&&!visible.photo()&&!visible.album()) waitTime = 0; if (!visible.albums() && !visible.photo() && !visible.album()) waitTime = 0
if (visible.album()&&lychee.content.html()==='') waitTime = 0; if (visible.album() && lychee.content.html()==='') waitTime = 0
setTimeout(function() { setTimeout(() => {
header.setMode('albums'); header.setMode('albums')
view.albums.init(); view.albums.init()
lychee.animate('#content', 'contentZoomIn'); lychee.animate('#content', 'contentZoomIn')
}, waitTime); }, waitTime)
}); })
} else { } else {
setTimeout(function() { setTimeout(() => {
header.setMode('albums'); header.setMode('albums')
view.albums.init(); view.albums.init()
lychee.animate('#content', 'contentZoomIn'); lychee.animate('#content', 'contentZoomIn')
}, 300); }, 300)
} }
} }
albums.parse = function(album) { albums.parse = function(album) {
if (album.password==='1'&&lychee.publicMode===true) { if (album.password==='1' && lychee.publicMode===true) {
album.thumbs[0] = 'src/images/password.svg'; album.thumbs[0] = 'src/images/password.svg'
album.thumbs[1] = 'src/images/password.svg'; album.thumbs[1] = 'src/images/password.svg'
album.thumbs[2] = 'src/images/password.svg'; album.thumbs[2] = 'src/images/password.svg'
} else { } else {
if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg'; if (!album.thumbs[0]) album.thumbs[0] = 'src/images/no_images.svg'
if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg'; if (!album.thumbs[1]) album.thumbs[1] = 'src/images/no_images.svg'
if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg'; if (!album.thumbs[2]) album.thumbs[2] = 'src/images/no_images.svg'
} }
} }
@ -73,36 +71,36 @@ albums.parse = function(album) {
albums._createSmartAlbums = function(data) { albums._createSmartAlbums = function(data) {
data.unsorted = { data.unsorted = {
id: 0, id : 0,
title: 'Unsorted', title : 'Unsorted',
sysdate: data.unsorted.num + ' photos', sysdate : data.unsorted.num + ' photos',
unsorted: '1', unsorted : '1',
thumbs: data.unsorted.thumbs thumbs : data.unsorted.thumbs
}; }
data.starred = { data.starred = {
id: 'f', id : 'f',
title: 'Starred', title : 'Starred',
sysdate: data.starred.num + ' photos', sysdate : data.starred.num + ' photos',
star: '1', star : '1',
thumbs: data.starred.thumbs thumbs : data.starred.thumbs
}; }
data.public = { data.public = {
id: 's', id : 's',
title: 'Public', title : 'Public',
sysdate: data.public.num + ' photos', sysdate : data.public.num + ' photos',
public: '1', public : '1',
thumbs: data.public.thumbs thumbs : data.public.thumbs
}; }
data.recent = { data.recent = {
id: 'r', id : 'r',
title: 'Recent', title : 'Recent',
sysdate: data.recent.num + ' photos', sysdate : data.recent.num + ' photos',
recent: '1', recent : '1',
thumbs: data.recent.thumbs thumbs : data.recent.thumbs
}; }
} }
@ -110,21 +108,21 @@ albums.getByID = function(albumID) {
// Function returns the JSON of an album // Function returns the JSON of an album
if (albumID===undefined||albumID===null) return undefined; if (albumID==null) return undefined
if (!albums.json) return undefined; if (!albums.json) return undefined
if (!albums.json.albums) return undefined; if (!albums.json.albums) return undefined
var json = undefined; let json = undefined
$.each(albums.json.albums, function(i) { $.each(albums.json.albums, function(i) {
let elem = albums.json.albums[i]; let elem = albums.json.albums[i]
if (elem.id==albumID) json = elem; if (elem.id==albumID) json = elem
}); })
return json; return json
} }
@ -132,28 +130,28 @@ albums.deleteByID = function(albumID) {
// Function returns the JSON of an album // Function returns the JSON of an album
if (albumID===undefined||albumID===null) return false; if (albumID==null) return false
if (!albums.json) return false; if (!albums.json) return false
if (!albums.json.albums) return false; if (!albums.json.albums) return false
var deleted = false; var deleted = false
$.each(albums.json.albums, function(i) { $.each(albums.json.albums, function(i) {
if (albums.json.albums[i].id==albumID) { if (albums.json.albums[i].id==albumID) {
albums.json.albums.splice(i, 1); albums.json.albums.splice(i, 1)
deleted = true; deleted = true
return false; return false
} }
}); })
return deleted; return deleted
} }
albums.refresh = function() { albums.refresh = function() {
albums.json = null; albums.json = null
} }