Are you sure you want to delete the album '$${ albumTitle }' and all of the photos it contains? This action can't be undone!
` } else { @@ -234,11 +234,11 @@ album.delete = function(albumIDs) { album.setTitle = function(albumIDs) { - let oldTitle = '', - msg = '' + let oldTitle = '' + let msg = '' if (!albumIDs) return false - if (albumIDs instanceof Array===false) albumIDs = [albumIDs] + if (albumIDs instanceof Array===false) albumIDs = [ albumIDs ] if (albumIDs.length===1) { @@ -246,18 +246,13 @@ album.setTitle = function(albumIDs) { if (album.json) oldTitle = album.json.title else if (albums.json) oldTitle = albums.getByID(albumIDs).title - if (!oldTitle) oldTitle = '' - } const action = function(data) { - let newTitle = data.title - basicModal.close() - // Set title to Untitled when empty - newTitle = (newTitle==='') ? 'Untitled' : newTitle + let newTitle = data.title if (visible.album()) { @@ -315,7 +310,7 @@ album.setTitle = function(albumIDs) { album.setDescription = function(albumID) { - let oldDescription = album.json.description.replace(/'/g, ''') + let oldDescription = album.json.description const action = function(data) { @@ -365,12 +360,12 @@ album.setPublic = function(albumID, modal, e) { if (modal===true) { - let text = '', - action = {} + let text = '' + let action = {} action.fn = () => { - // setPublic function without showing the modal + // Call setPublic function without showing the modal album.setPublic(album.getID(), false, e) } @@ -393,11 +388,11 @@ album.setPublic = function(albumID, modal, e) { @@ -433,9 +428,8 @@ album.setPublic = function(albumID, modal, e) { } }) - // Active visible by default (public = 0) - if ((album.json.public==='1' && album.json.visible==='1') || (album.json.public==='0')) $('.basicModal .choice input[name="visible"]').click() - if (album.json.downloadable==='1') $('.basicModal .choice input[name="downloadable"]').click() + if (album.json.public==='1' && album.json.visible==='0') $('.basicModal .choice input[name="hidden"]').click() + if (album.json.downloadable==='1') $('.basicModal .choice input[name="downloadable"]').click() $('.basicModal .choice input[name="password"]').on('change', function() { @@ -455,8 +449,8 @@ album.setPublic = function(albumID, modal, e) { album.json.public = '1' // Set visible - if ($('.basicModal .choice input[name="visible"]:checked').length===1) album.json.visible = '1' - else album.json.visible = '0' + if ($('.basicModal .choice input[name="hidden"]:checked').length===1) album.json.visible = '0' + else album.json.visible = '1' // Set downloadable if ($('.basicModal .choice input[name="downloadable"]:checked').length===1) album.json.downloadable = '1' @@ -484,12 +478,12 @@ album.setPublic = function(albumID, modal, e) { // Set data and refresh view if (visible.album()) { - album.json.visible = (album.json.public==='0') ? '0' : album.json.visible + album.json.visible = (album.json.public==='0') ? '1' : album.json.visible album.json.downloadable = (album.json.public==='0') ? '0' : album.json.downloadable album.json.password = (album.json.public==='0') ? '0' : album.json.password view.album.public() - view.album.visible() + view.album.hidden() view.album.downloadable() view.album.password() @@ -515,8 +509,8 @@ album.setPublic = function(albumID, modal, e) { album.share = function(service) { - let link = '', - url = location.href + let link = '' + let url = location.href switch (service) { case 'twitter': @@ -539,8 +533,8 @@ album.share = function(service) { album.getArchive = function(albumID) { - let link, - url = `${ api.path }?function=Album::getArchive&albumID=${ albumID }` + let link = '' + let url = `${ api.path }?function=Album::getArchive&albumID=${ albumID }` if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url) else link = location.href.replace(location.hash, '') + url @@ -553,26 +547,26 @@ album.getArchive = function(albumID) { album.merge = function(albumIDs) { - let title = '', - sTitle = '', - msg = '' + let title = '' + let sTitle = '' + let msg = '' if (!albumIDs) return false - if (albumIDs instanceof Array===false) albumIDs = [albumIDs] + if (albumIDs instanceof Array===false) albumIDs = [ albumIDs ] // Get title of first album if (albums.json) title = albums.getByID(albumIDs[0]).title - if (!title) title = '' - title = title.replace(/'/g, ''') + // Fallback for first album without a title + if (title==='') title = 'Untitled' if (albumIDs.length===2) { // Get title of second album if (albums.json) sTitle = albums.getByID(albumIDs[1]).title - if (!sTitle) sTitle = '' - sTitle = sTitle.replace(/'/g, ''') + // Fallback for second album without a title + if (sTitle==='') sTitle = 'Untitled' msg = lychee.html`Are you sure you want to merge the album '$${ sTitle }' into the album '$${ title }'?
` @@ -596,7 +590,7 @@ album.merge = function(albumIDs) { lychee.error(null, params, data) } else { albums.refresh() - albums.load() + lychee.goto() } }) diff --git a/src/scripts/albums.js b/src/scripts/albums.js index ef6b6d1..26f8ea7 100644 --- a/src/scripts/albums.js +++ b/src/scripts/albums.js @@ -17,7 +17,7 @@ albums.load = function() { if (albums.json===null) { - api.post('Album::getAll', {}, function(data) { + api.post('Albums::get', {}, function(data) { let waitTime = 0 @@ -134,7 +134,7 @@ albums.deleteByID = function(albumID) { if (!albums.json) return false if (!albums.json.albums) return false - var deleted = false + let deleted = false $.each(albums.json.albums, function(i) { diff --git a/src/scripts/api.js b/src/scripts/api.js index 3301dbd..0cbfc15 100644 --- a/src/scripts/api.js +++ b/src/scripts/api.js @@ -5,7 +5,7 @@ api = { - path : 'php/api.php', + path : 'php/index.php', onError : null } @@ -14,11 +14,11 @@ api.post = function(fn, params, callback) { loadingBar.show() - params = $.extend({function: fn}, params) + params = $.extend({ function: fn }, params) const success = (data) => { - setTimeout(() => loadingBar.hide(), 100) + setTimeout(loadingBar.hide, 100) // Catch errors if (typeof data==='string' && data.substring(0, 7)==='Error: ') { @@ -26,18 +26,6 @@ api.post = function(fn, params, callback) { return false } - // Convert 1 to true and an empty string to false - if (data==='1') data = true - else if (data==='') data = false - - // Convert to JSON if string start with '{' and ends with '}' - if (typeof data==='string' && - data.substring(0, 1)==='{' && - data.substring(data.length-1, data.length)==='}') data = $.parseJSON(data) - - // Output response when debug mode is enabled - if (lychee.debugMode) console.log(data) - callback(data) } @@ -52,7 +40,7 @@ api.post = function(fn, params, callback) { type: 'POST', url: api.path, data: params, - dataType: 'text', + dataType: 'json', success, error }) diff --git a/src/scripts/build.js b/src/scripts/build.js index 75cc311..513f39b 100644 --- a/src/scripts/build.js +++ b/src/scripts/build.js @@ -115,16 +115,16 @@ build.photo = function(data) { build.imageview = function(data, visibleControls) { - let html = '', - hasMedium = data.medium!=='' + let html = '' + let hasMedium = data.medium!=='' if (hasMedium===false) { - html += lychee.html`- - + +
Lychee $${ lychee.version } – Update available!
` @@ -141,14 +132,6 @@ lychee.loginDialog = function() { } }) - if (localStorage) { - let localUsername = localStorage.getItem('lychee_username') - if (localUsername!=null && localUsername.length>0) { - $('.basicModal input[name="username"]').val(localUsername) - $('.basicModal input[name="password"]').focus() - } - } - if (lychee.checkForUpdates==='1') lychee.getUpdate() } @@ -161,10 +144,9 @@ lychee.logout = function() { } -lychee.goto = function(url) { +lychee.goto = function(url = '') { - if (url===undefined) url = '#' - else url = '#' + url + url = '#' + url history.pushState(null, null, url) lychee.load() @@ -173,9 +155,9 @@ lychee.goto = function(url) { lychee.load = function() { - let albumID = '', - photoID = '', - hash = document.location.hash.replace('#', '').split('/') + let albumID = '' + let photoID = '' + let hash = document.location.hash.replace('#', '').split('/') $('.no_content').remove() contextMenu.close() @@ -223,6 +205,7 @@ lychee.load = function() { // Show Albums if (visible.photo()) view.photo.hide() + lychee.content.show() albums.load() } @@ -231,9 +214,13 @@ lychee.load = function() { lychee.getUpdate = function() { + const success = function(data) { + if (data.lychee.version>parseInt(lychee.versionCode)) $('.version span').show() + } + $.ajax({ - url : lychee.update_path, - success : function(data) { if (data.lychee.version>parseInt(lychee.version_code)) $('.version span').show() }, + url : lychee.updatePath, + success : success }) } @@ -260,14 +247,14 @@ lychee.setMode = function(mode) { .off('drop') Mousetrap - .unbind('u') - .unbind('s') - .unbind('f') - .unbind('r') - .unbind('d') - .unbind('t') - .unbind(['command+backspace', 'ctrl+backspace']) - .unbind(['command+a', 'ctrl+a']) + .unbind([ 'u' ]) + .unbind([ 's' ]) + .unbind([ 'f' ]) + .unbind([ 'r' ]) + .unbind([ 'd' ]) + .unbind([ 't' ]) + .unbind([ 'command+backspace', 'ctrl+backspace' ]) + .unbind([ 'command+a', 'ctrl+a' ]) if (mode==='public') { @@ -275,7 +262,8 @@ lychee.setMode = function(mode) { } else if (mode==='view') { - Mousetrap.unbind(['esc', 'command+up']) + Mousetrap.unbind([ 'esc', 'command+up' ]) + $('#button_back, a#next, a#previous').remove() $('.no_content').remove() @@ -289,8 +277,8 @@ lychee.setMode = function(mode) { lychee.animate = function(obj, animation) { let animations = [ - ['fadeIn', 'fadeOut'], - ['contentZoomIn', 'contentZoomOut'] + [ 'fadeIn', 'fadeOut' ], + [ 'contentZoomIn', 'contentZoomOut' ] ] if (!obj.jQuery) obj = $(obj) @@ -310,8 +298,8 @@ lychee.animate = function(obj, animation) { lychee.retinize = function(path = '') { - let extention = path.split('.').pop(), - isPhoto = extention!=='svg' + let extention = path.split('.').pop() + let isPhoto = extention!=='svg' if (isPhoto===true) { @@ -329,12 +317,12 @@ lychee.retinize = function(path = '') { lychee.loadDropbox = function(callback) { - if (!lychee.dropbox && lychee.dropboxKey) { + if (lychee.dropbox===false && lychee.dropboxKey!=null && lychee.dropboxKey!=='') { loadingBar.show() - let g = document.createElement('script'), - s = document.getElementsByTagName('script')[0] + let g = document.createElement('script') + let s = document.getElementsByTagName('script')[0] g.src = 'https://www.dropbox.com/static/api/1/dropins.js' g.id = 'dropboxjs' @@ -350,7 +338,7 @@ lychee.loadDropbox = function(callback) { } s.parentNode.insertBefore(g, s) - } else if (lychee.dropbox&&lychee.dropboxKey) { + } else if (lychee.dropbox===true && lychee.dropboxKey!=null && lychee.dropboxKey!=='') { callback() @@ -364,8 +352,8 @@ lychee.loadDropbox = function(callback) { lychee.getEventName = function() { - let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement), - eventName = (touchendSupport===true ? 'touchend' : 'click') + let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement) + let eventName = (touchendSupport===true ? 'touchend' : 'click') return eventName @@ -392,8 +380,8 @@ lychee.html = function(literalSections, ...substs) { // Use raw literal sections: we don’t want // backslashes (\n etc.) to be interpreted - let raw = literalSections.raw, - result = '' + let raw = literalSections.raw + let result = '' substs.forEach((subst, i) => { @@ -416,7 +404,7 @@ lychee.html = function(literalSections, ...substs) { // Take care of last literal section // (Never fails, because an empty template string // produces one literal section, an empty string) - result += raw[raw.length-1] + result += raw[raw.length - 1] return result diff --git a/src/scripts/multiselect.js b/src/scripts/multiselect.js index b9318fe..e9c60e2 100644 --- a/src/scripts/multiselect.js +++ b/src/scripts/multiselect.js @@ -89,8 +89,8 @@ multiselect.resize = function(e) { multiselect.position.bottom === null || multiselect.position.left === null) return false - let newSize = {}, - documentSize = {} + let newSize = {} + let documentSize = {} // Get the position of the mouse let mousePos = { @@ -114,7 +114,7 @@ multiselect.resize = function(e) { // Do not leave the screen newSize.height = mousePos.y - multiselect.position.top - if ((multiselect.position.top+newSize.height)>=documentSize.height) { + if ((multiselect.position.top + newSize.height)>=documentSize.height) { newSize.height -= (multiselect.position.top + newSize.height) - documentSize.height + 2 } @@ -136,7 +136,7 @@ multiselect.resize = function(e) { // Do not leave the screen newSize.width = mousePos.x - multiselect.position.left - if ((multiselect.position.left+newSize.width)>=documentSize.width) { + if ((multiselect.position.left + newSize.width)>=documentSize.width) { newSize.width -= (multiselect.position.left + newSize.width) - documentSize.width + 2 } @@ -167,8 +167,8 @@ multiselect.getSize = function() { if (!visible.multiselect()) return false - let $elem = $('#multiselect'), - offset = $elem.offset() + let $elem = $('#multiselect') + let offset = $elem.offset() return { top : offset.top, @@ -181,9 +181,9 @@ multiselect.getSize = function() { multiselect.getSelection = function(e) { - let tolerance = 150, - ids = [], - size = multiselect.getSize() + let tolerance = 150 + let ids = [] + let size = multiselect.getSize() if (visible.contextMenu()) return false if (!visible.multiselect()) return false @@ -192,19 +192,19 @@ multiselect.getSelection = function(e) { let offset = $(this).offset() - if (offset.top>=(size.top-tolerance) && - offset.left>=(size.left-tolerance) && - (offset.top+206)<=(size.top+size.height+tolerance) && - (offset.left+206)<=(size.left+size.width+tolerance)) { + if (offset.top>=(size.top - tolerance) && + offset.left>=(size.left - tolerance) && + (offset.top + 206)<=(size.top + size.height + tolerance) && + (offset.left + 206)<=(size.left + size.width + tolerance)) { - let id = $(this).data('id') + let id = $(this).data('id') - if (id!=='0' && id!==0 && id!=='f' && id!=='s' && id!=='r' && id!=null) { + if (id!=='0' && id!==0 && id!=='f' && id!=='s' && id!=='r' && id!=null) { - ids.push(id) - $(this).addClass('active') + ids.push(id) + $(this).addClass('active') - } + } } diff --git a/src/scripts/password.js b/src/scripts/password.js index 6b28601..4fc110a 100644 --- a/src/scripts/password.js +++ b/src/scripts/password.js @@ -9,7 +9,7 @@ password = { } -password.get = function(albumID, callback, passwd) { +password.get = function(albumID, callback) { if (lychee.publicMode===false) callback() else if (album.json && album.json.password==='0') callback() @@ -17,17 +17,25 @@ password.get = function(albumID, callback, passwd) { else if (!albums.json && !album.json) { // Continue without password + album.json = { password: true } callback('') - } else if (passwd==null) { - - // Request password - password.getDialog(albumID, callback) - } else { - // Check password + // Request password + + password.getDialog(albumID, callback) + + } + +} + +password.getDialog = function(albumID, callback) { + + const action = (data) => { + + let passwd = data.password let params = { albumID, @@ -48,16 +56,10 @@ password.get = function(albumID, callback, passwd) { } -} - -password.getDialog = function(albumID, callback) { - - const action = (data) => password.get(albumID, callback, data.password) - const cancel = () => { basicModal.close() - if (visible.albums()===false) lychee.goto() + if (!visible.albums()) lychee.goto() } diff --git a/src/scripts/photo.js b/src/scripts/photo.js index c486313..a758948 100644 --- a/src/scripts/photo.js +++ b/src/scripts/photo.js @@ -24,6 +24,21 @@ photo.getID = function() { photo.load = function(photoID, albumID) { + const checkContent = function() { + if (album.json!=null) photo.load(photoID, albumID) + else setTimeout(checkContent, 100) + } + + const checkPasswd = function() { + if (password.value!=='') photo.load(photoID, albumID) + else setTimeout(checkPasswd, 200) + } + + if (album.json==null) { + checkContent() + return false + } + let params = { photoID, albumID, @@ -32,14 +47,9 @@ photo.load = function(photoID, albumID) { api.post('Photo::get', params, function(data) { - const checkPasswd = function() { - if (password.value!=='') photo.load(photoID, albumID) - else setTimeout(checkPasswd, 250) - } - if (data==='Warning: Photo private!') { lychee.content.show() - lychee.goto('') + lychee.goto() return false } @@ -71,8 +81,8 @@ photo.preloadNext = function(photoID) { album.json.content[photoID] && album.json.content[photoID].nextPhoto!='') { - let nextPhoto = album.json.content[photoID].nextPhoto, - url = album.json.content[nextPhoto].url + let nextPhoto = album.json.content[photoID].nextPhoto + let url = album.json.content[nextPhoto].url $('head [data-prefetch]').remove() $('head').append(``) @@ -152,7 +162,7 @@ photo.next = function(animate) { photo.duplicate = function(photoIDs) { if (!photoIDs) return false - if (photoIDs instanceof Array===false) photoIDs = [photoIDs] + if (photoIDs instanceof Array===false) photoIDs = [ photoIDs ] albums.refresh() @@ -171,13 +181,13 @@ photo.duplicate = function(photoIDs) { photo.delete = function(photoIDs) { - let action = {}, - cancel = {}, - msg = '', - photoTitle = '' + let action = {} + let cancel = {} + let msg = '' + let photoTitle = '' if (!photoIDs) return false - if (photoIDs instanceof Array===false) photoIDs = [photoIDs] + if (photoIDs instanceof Array===false) photoIDs = [ photoIDs ] if (photoIDs.length===1) { @@ -192,8 +202,8 @@ photo.delete = function(photoIDs) { action.fn = function() { - let nextPhoto, - previousPhoto + let nextPhoto = null + let previousPhoto = null basicModal.close() @@ -219,8 +229,8 @@ photo.delete = function(photoIDs) { // Go to next photo if there is a next photo and // next photo is not the current one. Show album otherwise. - if (visible.photo() && nextPhoto!=='' && nextPhoto!==photo.getID()) lychee.goto(album.getID() + '/' + nextPhoto) - else if (!visible.albums()) lychee.goto(album.getID()) + if (visible.photo() && nextPhoto!=null && nextPhoto!==photo.getID()) lychee.goto(album.getID() + '/' + nextPhoto) + else if (!visible.albums()) lychee.goto(album.getID()) let params = { photoIDs: photoIDs.join() @@ -269,11 +279,11 @@ photo.delete = function(photoIDs) { photo.setTitle = function(photoIDs) { - let oldTitle = '', - msg = '' + let oldTitle = '' + let msg = '' if (!photoIDs) return false - if (photoIDs instanceof Array===false) photoIDs = [photoIDs] + if (photoIDs instanceof Array===false) photoIDs = [ photoIDs ] if (photoIDs.length===1) { @@ -300,8 +310,8 @@ photo.setTitle = function(photoIDs) { }) let params = { - photoIDs: photoIDs.join(), - title: newTitle + photoIDs : photoIDs.join(), + title : newTitle } api.post('Photo::setTitle', params, function(data) { @@ -335,13 +345,11 @@ photo.setTitle = function(photoIDs) { photo.setAlbum = function(photoIDs, albumID) { - let nextPhoto, - previousPhoto + let nextPhoto = null + let previousPhoto = null if (!photoIDs) return false - if (photoIDs instanceof Array===false) photoIDs = [photoIDs] - - if (visible.photo) lychee.goto(album.getID()) + if (photoIDs instanceof Array===false) photoIDs = [ photoIDs ] photoIDs.forEach(function(id, index, array) { @@ -363,6 +371,11 @@ photo.setAlbum = function(photoIDs, albumID) { albums.refresh() + // Go to next photo if there is a next photo and + // next photo is not the current one. Show album otherwise. + if (visible.photo() && nextPhoto!=null && nextPhoto!==photo.getID()) lychee.goto(album.getID() + '/' + nextPhoto) + else if (!visible.albums()) lychee.goto(album.getID()) + let params = { photoIDs: photoIDs.join(), albumID @@ -416,7 +429,7 @@ photo.setPublic = function(photoID, e) { } basicModal.show({ - body: "This photo is located in a public album. To make this photo private or public, edit the visibility of the associated album.
", + body: 'This photo is located in a public album. To make this photo private or public, edit the visibility of the associated album.
', buttons: { action: { title: 'Show Album', @@ -500,11 +513,11 @@ photo.setDescription = function(photoID) { photo.editTags = function(photoIDs) { - let oldTags = '', - msg = '' + let oldTags = '' + let msg = '' if (!photoIDs) return false - if (photoIDs instanceof Array===false) photoIDs = [photoIDs] + if (photoIDs instanceof Array===false) photoIDs = [ photoIDs ] // Get tags if (visible.photo()) oldTags = photo.json.tags @@ -553,7 +566,7 @@ photo.editTags = function(photoIDs) { photo.setTags = function(photoIDs, tags) { if (!photoIDs) return false - if (photoIDs instanceof Array===false) photoIDs = [photoIDs] + if (photoIDs instanceof Array===false) photoIDs = [ photoIDs ] // Parse tags tags = tags.replace(/(\ ,\ )|(\ ,)|(,\ )|(,{1,}\ {0,})|(,$|^,)/g, ',') @@ -591,14 +604,14 @@ photo.deleteTag = function(photoID, index) { // Save photo.json.tags = tags.toString() - photo.setTags([photoID], photo.json.tags) + photo.setTags([ photoID ], photo.json.tags) } photo.share = function(photoID, service) { - let link = '', - url = photo.getViewLink(photoID) + let link = '' + let url = photo.getViewLink(photoID) switch (service) { case 'twitter': @@ -621,14 +634,14 @@ photo.share = function(photoID, service) { break } - if (link.length!=='') location.href = link + if (link!=='') location.href = link } photo.getArchive = function(photoID) { - let link, - url = `${ api.path }?function=Photo::getArchive&photoID=${ photoID }` + let link + let url = `${ api.path }?function=Photo::getArchive&photoID=${ photoID }` if (location.href.indexOf('index.html')>0) link = location.href.replace(location.hash, '').replace('index.html', url) else link = location.href.replace(location.hash, '') + url diff --git a/src/scripts/search.js b/src/scripts/search.js index af7e142..216c8c8 100755 --- a/src/scripts/search.js +++ b/src/scripts/search.js @@ -19,9 +19,9 @@ search.find = function(term) { api.post('search', { term }, function(data) { - let html = '', - albumsData = '', - photosData = '' + let html = '' + let albumsData = '' + let photosData = '' // Build albums if (data && data.albums) { @@ -47,7 +47,7 @@ search.find = function(term) { 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 + else html = build.divider('Albums') + albumsData + build.divider('Photos') + photosData // Only refresh view when search results are different if (search.hash!==data.hash) { @@ -94,7 +94,7 @@ search.reset = function() { search.hash = null lychee.animate('.divider', 'fadeOut') - albums.load() + lychee.goto() } diff --git a/src/scripts/settings.js b/src/scripts/settings.js index 876ef8b..a28f84a 100644 --- a/src/scripts/settings.js +++ b/src/scripts/settings.js @@ -9,11 +9,11 @@ settings.createConfig = function() { const action = function(data) { - let dbName = data.dbName || '', - dbUser = data.dbUser || '', - dbPassword = data.dbPassword || '', - dbHost = data.dbHost || '', - dbTablePrefix = data.dbTablePrefix || '' + let dbName = data.dbName || '' + let dbUser = data.dbUser || '' + let dbPassword = data.dbPassword || '' + let dbHost = data.dbHost || '' + let dbTablePrefix = data.dbTablePrefix || '' if (dbUser.length<1) { basicModal.error('dbUser') @@ -31,12 +31,12 @@ settings.createConfig = function() { dbTablePrefix } - api.post('Database::createConfig', params, function(data) { + api.post('Config::create', params, function(data) { if (data!==true) { // Connection failed - if (data.indexOf('Warning: Connection failed!')!==-1) { + if (data==='Warning: Connection failed!') { basicModal.show({ body: 'Unable to connect to host database because access was denied. Double-check your host, username and password and ensure that access from your current location is permitted.
', @@ -53,7 +53,7 @@ settings.createConfig = function() { } // Creation failed - if (data.indexOf('Warning: Creation failed!')!==-1) { + if (data==='Warning: Creation failed!') { basicModal.show({ body: 'Unable to create the database. Double-check your host, username and password and ensure that the specified user has the rights to modify and add content to the database.
', @@ -70,7 +70,7 @@ settings.createConfig = function() { } // Could not create file - if (data.indexOf('Warning: Could not create file!')!==-1) { + if (data==='Warning: Could not create file!') { basicModal.show({ body: "Unable to save this configuration. Permission denied in 'data/'. Please set the read, write and execute rights for others in 'data/' and 'uploads/'. Take a look at the readme for more information.
", @@ -140,8 +140,8 @@ settings.createLogin = function() { const action = function(data) { - let username = data.username, - password = data.password + let username = data.username + let password = data.password if (username.length<1) { basicModal.error('username') @@ -204,9 +204,9 @@ settings.setLogin = function() { const action = function(data) { - let oldPassword = data.oldPassword || '', - username = data.username || '', - password = data.password || '' + let oldPassword = data.oldPassword || '' + let username = data.username || '' + let password = data.password || '' if (oldPassword.length<1) { basicModal.error('oldPassword') @@ -269,8 +269,8 @@ settings.setLogin = function() { settings.setSorting = function() { - let sortingPhotos = [], - sortingAlbums = [] + let sortingPhotos = [] + let sortingAlbums = [] const action = function() { diff --git a/src/scripts/sidebar.js b/src/scripts/sidebar.js index f628506..48fb2a9 100644 --- a/src/scripts/sidebar.js +++ b/src/scripts/sidebar.js @@ -30,14 +30,14 @@ sidebar.bind = function() { // event handlers should be removed before binding a new one. // Event Name - let eventName = lychee.getEventName(); + let eventName = lychee.getEventName() sidebar .dom('#edit_title') .off(eventName) .on(eventName, function() { - if (visible.photo()) photo.setTitle([photo.getID()]) - else if (visible.album()) album.setTitle([album.getID()]) + if (visible.photo()) photo.setTitle([ photo.getID() ]) + else if (visible.album()) album.setTitle([ album.getID() ]) }) sidebar @@ -52,7 +52,7 @@ sidebar.bind = function() { .dom('#edit_tags') .off(eventName) .on(eventName, function() { - photo.editTags([photo.getID()]) + photo.editTags([ photo.getID() ]) }) sidebar @@ -114,10 +114,10 @@ sidebar.createStructure.photo = function(data) { if (data==null || data==='') return false - let editable = false, - exifHash = data.takestamp + data.make + data.model + data.shutter + data.aperture + data.focal + data.iso, - structure = {}, - _public = '' + let editable = false + let exifHash = data.takestamp + data.make + data.model + data.shutter + data.aperture + data.focal + data.iso + let structure = {} + let _public = '' // Enable editable when user logged in if (lychee.publicMode===false) editable = true @@ -220,12 +220,12 @@ sidebar.createStructure.album = function(data) { if (data==null || data==='') return false - let editable = false, - structure = {}, - _public = '', - visible = '', - downloadable = '', - password = '' + let editable = false + let structure = {} + let _public = '' + let hidden = '' + let downloadable = '' + let password = '' // Enable editable when user logged in if (lychee.publicMode===false) editable = true @@ -242,14 +242,14 @@ sidebar.createStructure.album = function(data) { } - // Set value for visible + // Set value for hidden switch (data.visible) { - case '0' : visible = 'No' + case '0' : hidden = 'Yes' break - case '1' : visible = 'Yes' + case '1' : hidden = 'No' break - default : visible = '-' + default : hidden = '-' break } @@ -301,7 +301,7 @@ sidebar.createStructure.album = function(data) { type : sidebar.types.DEFAULT, rows : [ { title: 'Public', value: _public }, - { title: 'Visible', value: visible }, + { title: 'Hidden', value: hidden }, { title: 'Downloadable', value: downloadable }, { title: 'Password', value: password } ] @@ -367,8 +367,8 @@ sidebar.render = function(structure) { let renderTags = function(section) { - let _html = '', - editable = '' + let _html = '' + let editable = '' // Add edit-icon to the value when editable if (section.editable===true) editable = build.editIcon('edit_tags') diff --git a/src/scripts/upload.js b/src/scripts/upload.js index 2d473af..46fb1d0 100755 --- a/src/scripts/upload.js +++ b/src/scripts/upload.js @@ -40,16 +40,17 @@ upload.start = { local: function(files) { - let albumID = album.getID(), - error = false, - warning = false + let albumID = album.getID() + let error = false + let warning = false const process = function(files, file) { - let formData = new FormData(), - xhr = new XMLHttpRequest(), - pre_progress = 0, - progress = 0 + let formData = new FormData() + let xhr = new XMLHttpRequest() + let pre_progress = 0 + let progress = 0 + let next_file_started = false const finish = function() { @@ -84,98 +85,83 @@ upload.start = { } - // Check if file is supported - if (file.supported===false) { - - // Skip file - if (file.next!=null) process(files, file.next) - else { - - // Look for supported files - // If zero files are supported, hide the upload after a delay - - let hasSupportedFiles = false - - for (let i = 0; i < files.length; i++) { - - if (files[i].supported===true) { - hasSupportedFiles = true - break - } - - } - - if (hasSupportedFiles===false) setTimeout(finish, 2000) - - } - - return false - - } - formData.append('function', 'Photo::add') formData.append('albumID', albumID) - formData.append('tags', '') formData.append(0, file) xhr.open('POST', api.path) xhr.onload = function() { - let wait = false, - errorText = '' + let data = null + let wait = false + let errorText = '' + + const isNumber = (n) => (!isNaN(parseFloat(n)) && isFinite(n)) + + try { + data = JSON.parse(xhr.responseText) + } catch(e) { + data = '' + } file.ready = true // Set status - if (xhr.status===200 && xhr.responseText==='1') { + if (xhr.status===200 && isNumber(data)) { // Success - $('.basicModal .rows .row:nth-child(' + (file.num+1) + ') .status') + $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status') .html('Finished') .addClass('success') } else { - if (xhr.responseText.substr(0, 6)==='Error:') { + if (data.substr(0, 6)==='Error:') { - errorText = xhr.responseText.substr(6) + ' Please take a look at the console of your browser for further details.' + errorText = data.substr(6) + ' Please take a look at the console of your browser for further details.' error = true // Error Status - $('.basicModal .rows .row:nth-child(' + (file.num+1) + ') .status') + $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status') .html('Failed') .addClass('error') - } else if (xhr.responseText.substr(0, 8)==='Warning:') { + // Throw error + if (error===true) lychee.error('Upload failed. Server returned an error!', xhr, data) - errorText = xhr.responseText.substr(8) + } else if (data.substr(0, 8)==='Warning:') { + + errorText = data.substr(8) warning = true // Warning Status - $('.basicModal .rows .row:nth-child(' + (file.num+1) + ') .status') + $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status') .html('Skipped') .addClass('warning') + // Throw error + if (error===true) lychee.error('Upload failed. Server returned a warning!', xhr, data) + } else { errorText = 'Server returned an unknown response. Please take a look at the console of your browser for further details.' error = true // Error Status - $('.basicModal .rows .row:nth-child(' + (file.num+1) + ') .status') + $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status') .html('Failed') .addClass('error') + // Throw error + if (error===true) lychee.error('Upload failed. Server returned an unkown error!', xhr, data) + } - $('.basicModal .rows .row:nth-child(' + (file.num+1) + ') p.notice') + $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') p.notice') .html(errorText) .show() - // Throw error - if (error===true) lychee.error('Upload failed. Server returned the status code ' + xhr.status + '!', xhr, xhr.responseText) - } // Check if there are file which are not finished @@ -206,18 +192,21 @@ upload.start = { pre_progress = progress } - if (progress>=100) { + if (progress>=100 && next_file_started===false) { // Scroll to the uploading file let scrollPos = 0 - if ((file.num+1)>4) scrollPos = (file.num + 1 - 4) * 40 + if ((file.num + 1)>4) scrollPos = (file.num + 1 - 4) * 40 $('.basicModal .rows').scrollTop(scrollPos) // Set status to processing - $('.basicModal .rows .row:nth-child(' + (file.num+1) + ') .status').html('Processing') + $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status').html('Processing') // Upload next file - if (file.next!=null) process(files, file.next) + if (file.next!=null) { + process(files, file.next) + next_file_started = true + } } @@ -232,21 +221,12 @@ upload.start = { for (let i = 0; i < files.length; i++) { - files[i].num = i - files[i].ready = false - files[i].supported = true + files[i].num = i + files[i].ready = false - if (i < files.length-1) files[i].next = files[i+1] + if (i < files.length-1) files[i].next = files[i + 1] else files[i].next = null - // Check if file is supported - if (files[i].type!=='image/jpeg' && files[i].type!=='image/jpg' && files[i].type!=='image/png' && files[i].type!=='image/gif') { - - files[i].ready = true - files[i].supported = false - - } - } window.onbeforeunload = function() { return 'Lychee is currently uploading!' } @@ -276,15 +256,8 @@ upload.start = { basicModal.close() - let extension = data.link.split('.').pop() - if (extension!=='jpeg' && extension!=='jpg' && extension!=='png' && extension!=='gif' && extension!=='webp') { - loadingBar.show('error', 'File format of link not supported.') - return false - } - files[0] = { - name : data.link, - supported : true + name: data.link } upload.show('Importing URL', files, function() { @@ -363,8 +336,7 @@ upload.start = { let files = [] files[0] = { - name : data.path, - supported : true + name: data.path } upload.show('Importing from server', files, function() { @@ -387,7 +359,7 @@ upload.start = { // Go back to the album overview to show the imported albums if (visible.albums()) lychee.load() - else lychee.goto('') + else lychee.goto() basicModal.close() @@ -473,14 +445,13 @@ upload.start = { links += files[i].link + ',' files[i] = { - name : files[i].link, - supported : true + name : files[i].link } } // Remove last comma - links = links.substr(0, links.length-1) + links = links.substr(0, links.length - 1) upload.show('Importing from Dropbox', files, function() { diff --git a/src/scripts/view.js b/src/scripts/view.js index 099295a..198a4fd 100644 --- a/src/scripts/view.js +++ b/src/scripts/view.js @@ -26,8 +26,8 @@ view.albums = { init: function() { - let smartData = '', - albumsData = '' + let smartData = '' + let albumsData = '' // Smart Albums if (lychee.publicMode===false) { @@ -246,10 +246,10 @@ view.album = { }, - visible: function() { + hidden: function() { - if (album.json.visible==='1') sidebar.changeAttr('visible', 'Yes') - else sidebar.changeAttr('visible', 'No') + if (album.json.visible==='1') sidebar.changeAttr('hidden', 'No') + else sidebar.changeAttr('hidden', 'Yes') }, @@ -271,8 +271,8 @@ view.album = { if ((visible.album() || !album.json.init) && !visible.photo()) { - let structure = sidebar.createStructure.album(album.json), - html = sidebar.render(structure) + let structure = sidebar.createStructure.album(album.json) + let html = sidebar.render(structure) sidebar.dom('.sidebar__wrapper').html(html) sidebar.bind() @@ -408,27 +408,33 @@ view.photo = { lychee.imageview.html(build.imageview(photo.json, visible.header())) - let $nextArrow = lychee.imageview.find('a#next'), - $previousArrow = lychee.imageview.find('a#previous'), - photoID = photo.getID(), - hasNext = album.json && album.json.content && album.json.content[photoID] && album.json.content[photoID].nextPhoto!=='', - hasPrevious = album.json && album.json.content && album.json.content[photoID] && album.json.content[photoID].previousPhoto!=='' + let $nextArrow = lychee.imageview.find('a#next') + let $previousArrow = lychee.imageview.find('a#previous') + let photoID = photo.getID() + let hasNext = album.json && album.json.content && album.json.content[photoID] && album.json.content[photoID].nextPhoto!=='' + let hasPrevious = album.json && album.json.content && album.json.content[photoID] && album.json.content[photoID].previousPhoto!=='' - if (hasNext===false || lychee.viewMode===true) { $nextArrow.hide() } - else { + if (hasNext===false || lychee.viewMode===true) { - let nextPhotoID = album.json.content[photoID].nextPhoto, - nextPhoto = album.json.content[nextPhotoID] + $nextArrow.hide() + + } else { + + let nextPhotoID = album.json.content[photoID].nextPhoto + let nextPhoto = album.json.content[nextPhotoID] $nextArrow.css('background-image', lychee.html`linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("$${ nextPhoto.thumbUrl }")`) } - if (hasPrevious===false || lychee.viewMode===true) { $previousArrow.hide() } - else { + if (hasPrevious===false || lychee.viewMode===true) { - let previousPhotoID = album.json.content[photoID].previousPhoto, - previousPhoto = album.json.content[previousPhotoID] + $previousArrow.hide() + + } else { + + let previousPhotoID = album.json.content[photoID].previousPhoto + let previousPhoto = album.json.content[previousPhotoID] $previousArrow.css('background-image', lychee.html`linear-gradient(to bottom, rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)), url("$${ previousPhoto.thumbUrl }")`) @@ -438,8 +444,8 @@ view.photo = { sidebar: function() { - let structure = sidebar.createStructure.photo(photo.json), - html = sidebar.render(structure) + let structure = sidebar.createStructure.photo(photo.json) + let html = sidebar.render(structure) sidebar.dom('.sidebar__wrapper').html(html) sidebar.bind() diff --git a/src/scripts/view/main.js b/src/scripts/view/main.js index 5f03cbe..329892e 100644 --- a/src/scripts/view/main.js +++ b/src/scripts/view/main.js @@ -11,8 +11,8 @@ lychee.content = $('.content') lychee.getEventName = function() { - let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement), - eventName = (touchendSupport===true ? 'touchend' : 'click') + let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement) + let eventName = (touchendSupport===true ? 'touchend' : 'click') return eventName @@ -39,8 +39,8 @@ lychee.html = function(literalSections, ...substs) { // Use raw literal sections: we don’t want // backslashes (\n etc.) to be interpreted - let raw = literalSections.raw, - result = '' + let raw = literalSections.raw + let result = '' substs.forEach((subst, i) => { @@ -63,7 +63,7 @@ lychee.html = function(literalSections, ...substs) { // Take care of last literal section // (Never fails, because an empty template string // produces one literal section, an empty string) - result += raw[raw.length-1] + result += raw[raw.length - 1] return result @@ -88,7 +88,7 @@ $(document).ready(function() { // Direct Link header.dom('#button_direct').on(eventName, function() { - let link = $('#imageview #image').css('background-image').replace(/"/g,'').replace(/url\(|\)$/ig, '') + let link = $('#imageview img').attr('src').replace(/"/g,'').replace(/url\(|\)$/ig, '') window.open(link, '_newtab') }) @@ -127,8 +127,8 @@ const loadPhotoInfo = function(photoID) { imageview.addClass('fadeIn').show() // Render Sidebar - let structure = sidebar.createStructure.photo(data), - html = sidebar.render(structure) + let structure = sidebar.createStructure.photo(data) + let html = sidebar.render(structure) sidebar.dom('.sidebar__wrapper').html(html) sidebar.bind() diff --git a/src/styles/_animations.scss b/src/styles/_animations.scss index d104dd9..7f8b3d5 100755 --- a/src/styles/_animations.scss +++ b/src/styles/_animations.scss @@ -65,18 +65,6 @@ } } -// PopIn -------------------------------------------------------------- // -@keyframes popIn { - 0% { - opacity: 0; - transform: scale(0); - } - 100% { - opacity: 1; - transform: scale(1); - } -} - // Pulse -------------------------------------------------------------- // @keyframes pulse { 0% { diff --git a/src/styles/_basicContext.custom.scss b/src/styles/_basicContext.custom.scss index 9ef3ed2..7684577 100644 --- a/src/styles/_basicContext.custom.scss +++ b/src/styles/_basicContext.custom.scss @@ -12,7 +12,6 @@ &__item { margin-bottom: 2px; font-size: 14px; - text-shadow: $shadowLight; &--separator { margin: 4px 0; diff --git a/src/styles/_content.scss b/src/styles/_content.scss index 08f3175..07ecaca 100644 --- a/src/styles/_content.scss +++ b/src/styles/_content.scss @@ -146,7 +146,6 @@ margin: 0 5px 0 0; width: 8px; height: 8px; - filter: drop-shadow(0 1px 3px black(.4)); } .album img[data-overlay='false'] + .overlay h1, @@ -185,7 +184,6 @@ fill: #fff; width: 16px; height: 16px; - filter: drop-shadow($shadowLight); } } @@ -225,7 +223,6 @@ left: 50%; padding-top: 20px; color: white(.35); - text-shadow: 0 -1px 0 black(.4); text-align: center; transform: translateX(-50%) translateY(-50%); @@ -234,7 +231,6 @@ margin: 0 0 10px; width: 50px; height: 50px; - filter: drop-shadow(0 -1px 0 black(.4)); } p { diff --git a/src/styles/_header.scss b/src/styles/_header.scss index 96f29fe..f727063 100644 --- a/src/styles/_header.scss +++ b/src/styles/_header.scss @@ -19,7 +19,7 @@ background: none; border-bottom: none; - .header__error { background-color: rgba(10, 10, 10, .99); } + &.header--error { background-color: rgba(10, 10, 10, .99); } } // Toolbars -------------------------------------------------------------- // diff --git a/src/styles/_imageview.scss b/src/styles/_imageview.scss index 31ccd57..24d59fe 100644 --- a/src/styles/_imageview.scss +++ b/src/styles/_imageview.scss @@ -21,21 +21,25 @@ right: 30px; bottom: 30px; left: 30px; - transition: top .3s, right .3s, bottom .3s, left .3s, opacity .2s, transform .2s; + margin: auto; + max-width: calc(100% - 60px); + max-height: calc(100% - 90px); + width: auto; + height: auto; + transition: top .3s, right .3s, bottom .3s, left .3s, max-width .3s, max-height .3s; will-change: transform; - display: flex; - justify-content: center; - align-items: center; - animation-name: zoomIn; animation-duration: .3s; animation-timing-function: $timingBounce; @media (max-width: 640px) { + top: 60px; right: 20px; bottom: 20px; left: 20px; + max-width: calc(100% - 40px); + max-height: calc(100% - 80px); } } @@ -44,20 +48,8 @@ right: 0; bottom: 0; left: 0; - } - - #image > div { - width: 0; - height: 0; - } - - #image img { - position: absolute; max-width: 100%; max-height: 100%; - width: auto; - height: auto; - transform: translate(-50%, -50%); } // Previous/Next Buttons -------------------------------------------------------------- // @@ -113,7 +105,6 @@ .iconic { fill: white(.8); - filter: drop-shadow(0 1px 0 black(.4)); } } diff --git a/src/styles/_message.scss b/src/styles/_message.scss index a38e8b1..f90928c 100644 --- a/src/styles/_message.scss +++ b/src/styles/_message.scss @@ -26,7 +26,6 @@ color: white(.9); font-size: 14px; text-align: left; - text-shadow: $shadow; line-height: 20px; b { @@ -56,7 +55,6 @@ padding: 13px 0 15px; background: black(.02); color: white(.5); - text-shadow: $shadow; border-top: 1px solid black(.2); box-shadow: inset 0 1px 0 white(.02); cursor: default; @@ -85,7 +83,6 @@ width: 100%; background-color: transparent; color: #fff; - text-shadow: $shadow; border: none; // Do not use rgba() for border-bottom // to avoid a blurry line in Safari on non-retina screens @@ -116,7 +113,6 @@ color: white(1); font-size: 14px; font-weight: 700; - text-shadow: $shadow; } label input { @@ -258,7 +254,6 @@ color: #fff; font-size: 16px; font-weight: bold; - text-shadow: $shadow; text-align: center; } diff --git a/src/styles/main.scss b/src/styles/main.scss index e4b9751..f4f6c66 100755 --- a/src/styles/main.scss +++ b/src/styles/main.scss @@ -12,8 +12,7 @@ } // Properties -------------------------------------------------------------- // -$shadowLight : 0 -1px 0 black(.1); -$shadow : 0 -1px 0 black(.2); +$shadow: 0 -1px 0 black(.2); // Colors ------------------------------------------------------------------ // $colorBlue : #2293EC; diff --git a/view.php b/view.php index f051f21..638af87 100644 --- a/view.php +++ b/view.php @@ -25,16 +25,9 @@ # Load required files require(__DIR__ . '/php/define.php'); require(__DIR__ . '/php/autoload.php'); - require(__DIR__ . '/php/modules/misc.php'); - require(LYCHEE_CONFIG_FILE); + require(__DIR__ . '/php/helpers/getGraphHeader.php'); - # Define the table prefix - if (!isset($dbTablePrefix)) $dbTablePrefix = ''; - defineTablePrefix($dbTablePrefix); - - $database = Database::connect($dbHost, $dbUser, $dbPassword, $dbName); - - echo getGraphHeader($database, $_GET['p']); + echo getGraphHeader($_GET['p']); }