Updated lychee.js (ES2015)

This commit is contained in:
Tobias Reich 2015-07-11 16:17:28 +02:00
parent 63b2a2412d
commit 710aa2bf52
2 changed files with 158 additions and 166 deletions

BIN
dist/main.js vendored Executable file → Normal file

Binary file not shown.

View File

@ -32,9 +32,7 @@ lychee = {
lychee.init = function() { lychee.init = function() {
var params; let params = {
params = {
version: lychee.version_code version: lychee.version_code
} }
@ -49,52 +47,51 @@ lychee.init = function() {
// Logged in // Logged in
lychee.sortingPhotos = data.config.sortingPhotos || ''; lychee.sortingPhotos = data.config.sortingPhotos || ''
lychee.sortingAlbums = data.config.sortingAlbums || ''; lychee.sortingAlbums = data.config.sortingAlbums || ''
lychee.dropboxKey = data.config.dropboxKey || ''; lychee.dropboxKey = data.config.dropboxKey || ''
lychee.location = data.config.location || ''; lychee.location = data.config.location || ''
lychee.checkForUpdates = data.config.checkForUpdates || '1'; lychee.checkForUpdates = data.config.checkForUpdates || '1'
// Show dialog when there is no username and password // Show dialog when there is no username and password
if (data.config.login===false) settings.createLogin(); if (data.config.login===false) settings.createLogin()
} else if (data.status===1) { } else if (data.status===1) {
// Logged out // Logged out
lychee.checkForUpdates = data.config.checkForUpdates || '1'; lychee.checkForUpdates = data.config.checkForUpdates || '1'
lychee.setMode('public'); lychee.setMode('public')
} else if (data.status===0) { } else if (data.status===0) {
// No configuration // No configuration
lychee.setMode('public'); lychee.setMode('public')
header.dom().hide(); header.dom().hide()
lychee.content.hide(); lychee.content.hide()
$('body').append(build.no_content('cog')); $('body').append(build.no_content('cog'))
settings.createConfig(); settings.createConfig()
return true; return true
} }
$(window).bind('popstate', lychee.load); $(window).bind('popstate', lychee.load)
lychee.load(); lychee.load()
}); })
} }
lychee.login = function(data) { lychee.login = function(data) {
var user = data.username, let user = data.username,
password = data.password, password = data.password
params;
params = { let params = {
user, user,
password password
} }
@ -104,28 +101,25 @@ lychee.login = function(data) {
if (data===true) { if (data===true) {
// Use 'try' to catch a thrown error when Safari is in private mode // Use 'try' to catch a thrown error when Safari is in private mode
try { localStorage.setItem('lychee_username', user); } try { localStorage.setItem('lychee_username', user) }
catch (err) {} catch (err) {}
window.location.reload(); window.location.reload()
} else { } else {
// Show error and reactive button // Show error and reactive button
basicModal.error('password'); basicModal.error('password')
} }
}); })
} }
lychee.loginDialog = function() { lychee.loginDialog = function() {
var localUsername, let msg = `
msg = '';
msg = `
<p class='signIn'> <p class='signIn'>
<input class='text' name='username' autocomplete='username' type='text' value='' placeholder='username' autocapitalize='off' autocorrect='off'> <input class='text' name='username' autocomplete='username' type='text' value='' placeholder='username' autocapitalize='off' autocorrect='off'>
<input class='text' name='password' autocomplete='current-password' type='password' value='' placeholder='password'> <input class='text' name='password' autocomplete='current-password' type='password' value='' placeholder='password'>
@ -145,95 +139,94 @@ lychee.loginDialog = function() {
fn: basicModal.close fn: basicModal.close
} }
} }
}); })
if (localStorage) { if (localStorage) {
localUsername = localStorage.getItem('lychee_username'); let localUsername = localStorage.getItem('lychee_username')
if (localUsername!==null) { if (localUsername!==null && localUsername.length>0) {
if (localUsername.length>0) $('.basicModal input[name="username"]').val(localUsername); $('.basicModal input[name="username"]').val(localUsername)
$('.basicModal input[name="password"]').focus(); $('.basicModal input[name="password"]').focus()
} }
} }
if (lychee.checkForUpdates==='1') lychee.getUpdate(); if (lychee.checkForUpdates==='1') lychee.getUpdate()
} }
lychee.logout = function() { lychee.logout = function() {
api.post('Session::logout', {}, function() { api.post('Session::logout', {}, function() {
window.location.reload(); window.location.reload()
}); })
} }
lychee.goto = function(url) { lychee.goto = function(url) {
if (url===undefined) url = '#'; if (url===undefined) url = '#'
else url = '#' + url; else url = '#' + url
history.pushState(null, null, url); history.pushState(null, null, url)
lychee.load(); lychee.load()
} }
lychee.load = function() { lychee.load = function() {
var albumID = '', let albumID = '',
photoID = '', photoID = '',
hash = document.location.hash.replace('#', '').split('/'); hash = document.location.hash.replace('#', '').split('/')
$('.no_content').remove(); $('.no_content').remove()
contextMenu.close(); contextMenu.close()
multiselect.close(); multiselect.close()
if (hash[0]!==undefined) albumID = hash[0]; if (hash[0]!==undefined) albumID = hash[0]
if (hash[1]!==undefined) photoID = hash[1]; if (hash[1]!==undefined) photoID = hash[1]
if (albumID && photoID) { if (albumID && photoID) {
// Trash data // Trash data
photo.json = null; photo.json = null
// Show Photo // Show Photo
if (lychee.content.html()===''|| if (lychee.content.html()==='' || ($('#search').length && $('#search').val().length!==0)) {
($('#search').length&&$('#search').val().length!==0)) { lychee.content.hide()
lychee.content.hide(); album.load(albumID, true)
album.load(albumID, true);
} }
photo.load(photoID, albumID); photo.load(photoID, albumID)
} else if (albumID) { } else if (albumID) {
// Trash data // Trash data
photo.json = null; photo.json = null
// Hide sidebar // Hide sidebar
if (visible.sidebar()) sidebar.toggle(); if (visible.sidebar()) sidebar.toggle()
// Show Album // Show Album
if (visible.photo()) view.photo.hide(); if (visible.photo()) view.photo.hide()
if (album.json&&albumID==album.json.id) view.album.title(); if (album.json && albumID==album.json.id) view.album.title()
else album.load(albumID); else album.load(albumID)
} else { } else {
// Trash albums.json when filled with search results // Trash albums.json when filled with search results
if (search.hash!==null) { if (search.hash!==null) {
albums.json = null; albums.json = null
search.hash = null; search.hash = null
} }
// Trash data // Trash data
album.json = null; album.json = null
photo.json = null; photo.json = null
// Hide sidebar // Hide sidebar
if (visible.sidebar()) sidebar.toggle(); if (visible.sidebar()) sidebar.toggle()
// Show Albums // Show Albums
if (visible.photo()) view.photo.hide(); if (visible.photo()) view.photo.hide()
albums.load(); albums.load()
} }
@ -243,31 +236,31 @@ lychee.getUpdate = function() {
$.ajax({ $.ajax({
url : lychee.update_path, url : lychee.update_path,
success: function(data) { if (parseInt(data)>parseInt(lychee.version_code)) $('.version span').show(); } success : function(data) { if (parseInt(data)>parseInt(lychee.version_code)) $('.version span').show() }
}); })
} }
lychee.setTitle = function(title, editable) { lychee.setTitle = function(title, editable) {
document.title = lychee.title + ' - ' + title; document.title = lychee.title + ' - ' + title
header.setEditable(editable); header.setEditable(editable)
header.setTitle(title); header.setTitle(title)
} }
lychee.setMode = function(mode) { lychee.setMode = function(mode) {
$('#button_settings, #button_settings, #button_search, #search, #button_trash_album, #button_share_album, .button_add, .button_divider').remove(); $('#button_settings, #button_settings, #button_search, #search, #button_trash_album, #button_share_album, .button_add, .button_divider').remove()
$('#button_trash, #button_move, #button_share, #button_star').remove(); $('#button_trash, #button_move, #button_share, #button_star').remove()
$(document) $(document)
.off('click', '#title.editable') .off('click', '#title.editable')
.off('touchend', '#title.editable') .off('touchend', '#title.editable')
.off('contextmenu', '.photo') .off('contextmenu', '.photo')
.off('contextmenu', '.album') .off('contextmenu', '.album')
.off('drop'); .off('drop')
Mousetrap Mousetrap
.unbind('u') .unbind('u')
@ -277,21 +270,21 @@ lychee.setMode = function(mode) {
.unbind('d') .unbind('d')
.unbind('t') .unbind('t')
.unbind(['command+backspace', 'ctrl+backspace']) .unbind(['command+backspace', 'ctrl+backspace'])
.unbind(['command+a', 'ctrl+a']); .unbind(['command+a', 'ctrl+a'])
if (mode==='public') { if (mode==='public') {
header.dom('#button_signin, #hostedwith').show(); header.dom('#button_signin, #hostedwith').show()
lychee.publicMode = true; lychee.publicMode = true
} else if (mode==='view') { } else if (mode==='view') {
Mousetrap.unbind(['esc', 'command+up']); Mousetrap.unbind(['esc', 'command+up'])
$('#button_back, a#next, a#previous').remove(); $('#button_back, a#next, a#previous').remove()
$('.no_content').remove(); $('.no_content').remove()
lychee.publicMode = true; lychee.publicMode = true
lychee.viewMode = true; lychee.viewMode = true
} }
@ -299,23 +292,23 @@ lychee.setMode = function(mode) {
lychee.animate = function(obj, animation) { lychee.animate = function(obj, animation) {
var animations = [ let animations = [
['fadeIn', 'fadeOut'], ['fadeIn', 'fadeOut'],
['contentZoomIn', 'contentZoomOut'] ['contentZoomIn', 'contentZoomOut']
]; ]
if (!obj.jQuery) obj = $(obj); if (!obj.jQuery) obj = $(obj)
for (var i = 0; i < animations.length; i++) { for (let i = 0; i < animations.length; i++) {
for (var x = 0; x < animations[i].length; x++) { for (let x = 0; x < animations[i].length; x++) {
if (animations[i][x]==animation) { if (animations[i][x]==animation) {
obj.removeClass(animations[i][0] + ' ' + animations[i][1]).addClass(animation); obj.removeClass(animations[i][0] + ' ' + animations[i][1]).addClass(animation)
return true; return true
} }
} }
} }
return false; return false
} }
@ -324,28 +317,27 @@ lychee.escapeHTML = function(s) {
return s.replace(/&/g, '&amp;') return s.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;') .replace(/"/g, '&quot;')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;'); .replace(/>/g, '&gt;')
} }
lychee.retinize = function(path = '') { lychee.retinize = function(path = '') {
var pixelRatio = window.devicePixelRatio, let pixelRatio = window.devicePixelRatio,
extention = path.split('.').pop(), extention = path.split('.').pop(),
hasRetina = extention!=='svg'; hasRetina = extention!=='svg'
if ((pixelRatio!==undefined&&pixelRatio>1)&& if ((pixelRatio!==undefined && pixelRatio>1) && hasRetina===true) {
(hasRetina===true)) {
path = path.replace(/\.[^/.]+$/, ''); path = path.replace(/\.[^/.]+$/, '')
path = path + '@2x' + '.' + extention; path = path + '@2x' + '.' + extention
} }
return { return {
path, path,
hasRetina hasRetina
}; }
} }
@ -353,32 +345,32 @@ lychee.loadDropbox = function(callback) {
if (!lychee.dropbox && lychee.dropboxKey) { if (!lychee.dropbox && lychee.dropboxKey) {
loadingBar.show(); loadingBar.show()
var g = document.createElement('script'), let g = document.createElement('script'),
s = document.getElementsByTagName('script')[0]; s = document.getElementsByTagName('script')[0]
g.src = 'https://www.dropbox.com/static/api/1/dropins.js'; g.src = 'https://www.dropbox.com/static/api/1/dropins.js'
g.id = 'dropboxjs'; g.id = 'dropboxjs'
g.type = 'text/javascript'; g.type = 'text/javascript'
g.async = 'true'; g.async = 'true'
g.setAttribute('data-app-key', lychee.dropboxKey); g.setAttribute('data-app-key', lychee.dropboxKey)
g.onload = g.onreadystatechange = function() { g.onload = g.onreadystatechange = function() {
var rs = this.readyState; let rs = this.readyState
if (rs&&rs!=='complete'&&rs!=='loaded') return; if (rs && rs!=='complete' && rs!=='loaded') return
lychee.dropbox = true; lychee.dropbox = true
loadingBar.hide(); loadingBar.hide()
callback(); callback()
}; }
s.parentNode.insertBefore(g, s); s.parentNode.insertBefore(g, s)
} else if (lychee.dropbox&&lychee.dropboxKey) { } else if (lychee.dropbox&&lychee.dropboxKey) {
callback(); callback()
} else { } else {
settings.setDropboxKey(callback); settings.setDropboxKey(callback)
} }
@ -387,20 +379,20 @@ lychee.loadDropbox = function(callback) {
lychee.getEventName = function() { lychee.getEventName = function() {
let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement), let touchendSupport = (/Android|iPhone|iPad|iPod/i).test(navigator.userAgent || navigator.vendor || window.opera) && ('ontouchend' in document.documentElement),
eventName = (touchendSupport===true ? 'touchend' : 'click'); eventName = (touchendSupport===true ? 'touchend' : 'click')
return eventName; return eventName
} }
lychee.removeHTML = function(html = '') { lychee.removeHTML = function(html = '') {
if (html==='') return html; if (html==='') return html
var tmp = document.createElement('DIV'); let tmp = document.createElement('DIV')
tmp.innerHTML = html; tmp.innerHTML = html
return tmp.textContent || tmp.innerText; return (tmp.textContent || tmp.innerText)
} }
@ -410,8 +402,8 @@ lychee.error = function(errorThrown, params, data) {
description : errorThrown, description : errorThrown,
params : params, params : params,
response : data response : data
}); })
loadingBar.show('error', errorThrown); loadingBar.show('error', errorThrown)
} }