Updated api.js and build.js (ES2015)

This commit is contained in:
Tobias Reich 2015-07-11 14:16:11 +02:00
parent a0ea271bd6
commit bfe067cc71
5 changed files with 118 additions and 161 deletions

BIN
dist/main.js vendored

Binary file not shown.

BIN
dist/view.js vendored

Binary file not shown.

View File

@ -1,6 +1,6 @@
/**
* @description Takes care of every action albums can handle and execute.
* @copyright 2015 by Tobias Reich
* @description Takes care of every action albums can handle and execute.
* @copyright 2015 by Tobias Reich
*/
albums = {

View File

@ -1,54 +1,50 @@
/**
* @description This module communicates with Lychee's API
* @copyright 2015 by Tobias Reich
* @description This module communicates with Lychee's API
* @copyright 2015 by Tobias Reich
*/
api = {
path: 'php/api.php',
onError: null
path : 'php/api.php',
onError : null
}
api.post = function(fn, params, callback) {
var success,
error;
loadingBar.show()
loadingBar.show();
params = $.extend({function: fn}, params)
params = $.extend({function: fn}, params);
const success = (data) => {
success = function(data) {
setTimeout(function() { loadingBar.hide() }, 100);
setTimeout(() => loadingBar.hide(), 100)
// Catch errors
if (typeof data==='string'&&
data.substring(0, 7)==='Error: ') {
api.onError(data.substring(7, data.length), params, data);
return false;
if (typeof data==='string' && data.substring(0, 7)==='Error: ') {
api.onError(data.substring(7, data.length), params, data)
return false
}
// Convert 1 to true and an empty string to false
if (data==='1') data = true;
else if (data==='') data = 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);
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);
if (lychee.debugMode) console.log(data)
callback(data);
callback(data)
}
error = function(jqXHR, textStatus, errorThrown) {
const error = (jqXHR, textStatus, errorThrown) => {
api.onError('Server error or API not found.', params, errorThrown);
api.onError('Server error or API not found.', params, errorThrown)
}
@ -59,6 +55,6 @@ api.post = function(fn, params, callback) {
dataType: 'text',
success,
error
});
})
}

View File

@ -1,123 +1,93 @@
/**
* @description This module is used to generate HTML-Code.
* @copyright 2015 by Tobias Reich
* @description This module is used to generate HTML-Code.
* @copyright 2015 by Tobias Reich
*/
window.build = {}
build = {}
build.iconic = function(icon, classes) {
build.iconic = function(icon, classes = '') {
var html = '';
classes = classes || '';
html = `
<svg class='iconic ${ classes }'>
<use xlink:href='#${ icon }' />
</svg>
`
return html;
return `<svg class='iconic ${ classes }'><use xlink:href='#${ icon }' /></svg>`
}
build.divider = function(title) {
var html = '';
html = `
<div class='divider'>
<h1>${ title }</h1>
</div>
`
return html;
return `<div class='divider'><h1>${ title }</h1></div>`
}
build.editIcon = function(id) {
var html = '';
html = `<div id='${ id }' class='edit'>${ build.iconic('pencil') }</div>`
return html;
return `<div id='${ id }' class='edit'>${ build.iconic('pencil') }</div>`
}
build.multiselect = function(top, left) {
var html = '';
html = `<div id='multiselect' style='top: ${ top }px; left: ${ left }px;'></div>`
return html;
return `<div id='multiselect' style='top: ${ top }px; left: ${ left }px;'></div>`
}
build.album = function(data) {
if (data===null||data===undefined) return '';
if (data==null) return ''
var html = '';
let { path: thumbPath, hasRetina: thumbRetina } = lychee.retinize(data.thumbs[0])
var {path: thumbPath, hasRetina: thumbRetina} = lychee.retinize(data.thumbs[0]);
html = `
<div class='album' data-id='${ data.id }'>
<img src='${ data.thumbs[2] }' width='200' height='200' alt='thumb' data-retina='false'>
<img src='${ data.thumbs[1] }' width='200' height='200' alt='thumb' data-retina='false'>
<img src='${ thumbPath }' width='200' height='200' alt='thumb' data-retina='${ thumbRetina }'>
<div class='overlay'>
<h1 title='${ data.title }'>${ data.title }</h1>
<a>${ data.sysdate }</a>
</div>
`
let html = `
<div class='album' data-id='${ data.id }'>
<img src='${ data.thumbs[2] }' width='200' height='200' alt='thumb' data-retina='false'>
<img src='${ data.thumbs[1] }' width='200' height='200' alt='thumb' data-retina='false'>
<img src='${ thumbPath }' width='200' height='200' alt='thumb' data-retina='${ thumbRetina }'>
<div class='overlay'>
<h1 title='${ data.title }'>${ data.title }</h1>
<a>${ data.sysdate }</a>
</div>
`
if (lychee.publicMode===false) {
if (data.star==='1') html += `<a class='badge icn-star'>${ build.iconic('star') }</a>`;
if (data.public==='1') html += `<a class='badge icn-share'>${ build.iconic('eye') }</a>`;
if (data.unsorted==='1') html += `<a class='badge'>${ build.iconic('list') }</a>`;
if (data.recent==='1') html += `<a class='badge'>${ build.iconic('clock') }</a>`;
if (data.password==='1') html += `<a class='badge'>${ build.iconic('lock-locked') }</a>`;
if (data.star==='1') html += `<a class='badge icn-star'>${ build.iconic('star') }</a>`
if (data.public==='1') html += `<a class='badge icn-share'>${ build.iconic('eye') }</a>`
if (data.unsorted==='1') html += `<a class='badge'>${ build.iconic('list') }</a>`
if (data.recent==='1') html += `<a class='badge'>${ build.iconic('clock') }</a>`
if (data.password==='1') html += `<a class='badge'>${ build.iconic('lock-locked') }</a>`
}
html += '</div>'
return html;
return html
}
build.photo = function(data) {
if (data===null||data===undefined) return '';
if (data==null) return ''
var html = '';
let { path: thumbPath, hasRetina: thumbRetina } = lychee.retinize(data.thumbUrl)
var {path: thumbPath, hasRetina: thumbRetina} = lychee.retinize(data.thumbUrl);
let html = `
<div class='photo' data-album-id='${ data.album }' data-id='${ data.id }'>
<img src='${ thumbPath }' width='200' height='200' alt='thumb'>
<div class='overlay'>
<h1 title='${ data.title }'>${ data.title }</h1>
`
html = `
<div class='photo' data-album-id='${ data.album }' data-id='${ data.id }'>
<img src='${ thumbPath }' width='200' height='200' alt='thumb'>
<div class='overlay'>
<h1 title='${ data.title }'>${ data.title }</h1>
`
if (data.cameraDate==='1') html += `<a><span title='Camera Date'>${ build.iconic('camera-slr') }</span>${ data.sysdate }</a>`
else html += `<a>${ data.sysdate }</a>`
if (data.cameraDate==='1') html += `<a><span title='Camera Date'>${ build.iconic('camera-slr') }</span>${ data.sysdate }</a>`;
else html += `<a>${ data.sysdate }</a>`;
html += '</div>';
html += '</div>'
if (lychee.publicMode===false) {
if (data.star==='1') html += `<a class='badge iconic-star'>${ build.iconic('star') }</a>`;
if (data.public==='1'&&album.json.public!=='1') html += `<a class='badge iconic-share'>${ build.iconic('eye') }</a>`;
if (data.star==='1') html += `<a class='badge iconic-star'>${ build.iconic('star') }</a>`
if (data.public==='1' && album.json.public!=='1') html += `<a class='badge iconic-share'>${ build.iconic('eye') }</a>`
}
html += '</div>';
html += '</div>'
return html
@ -125,127 +95,118 @@ build.photo = function(data) {
build.imageview = function(data, size, visibleControls) {
if (data===null||data===undefined) return '';
if (data==null) return ''
var html = '';
html = `
<div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>${ build.iconic('caret-left') }</a></div>
<div class='arrow_wrapper arrow_wrapper--next'><a id='next'>${ build.iconic('caret-right') }</a></div>
`
let html = `
<div class='arrow_wrapper arrow_wrapper--previous'><a id='previous'>${ build.iconic('caret-left') }</a></div>
<div class='arrow_wrapper arrow_wrapper--next'><a id='next'>${ build.iconic('caret-right') }</a></div>
`
if (size==='big') {
if (visibleControls===true)
html += `<div id='image' style='background-image: url(${ data.url })'></div>`;
else
html += `<div id='image' style='background-image: url(${ data.url });' class='full'></div>`;
if (visibleControls===true) html += `<div id='image' style='background-image: url(${ data.url })'></div>`
else html += `<div id='image' style='background-image: url(${ data.url });' class='full'></div>`
} else if (size==='medium') {
if (visibleControls===true)
html += `<div id='image' style='background-image: url(${ data.medium })'></div>`;
else
html += `<div id='image' style='background-image: url(${ data.medium });' class='full'></div>`;
if (visibleControls===true) html += `<div id='image' style='background-image: url(${ data.medium })'></div>`
else html += `<div id='image' style='background-image: url(${ data.medium });' class='full'></div>`
} else if (size==='small') {
if (visibleControls===true)
html += `<div id='image' class='small' style='background-image: url(${ data.url }); width: ${ data.width }px; height: ${ data.height }px; margin-top: -${ parseInt(data.height/2-20) }px; margin-left: -${ data.width/2 }px;'></div>`;
else
html += `<div id='image' class='small' style='background-image: url(${ data.url }); width: ${ data.width }px; height: ${ data.height }px; margin-top: -${ parseInt(data.height/2) }px; margin-left: -${ data.width/2 }px;'></div>`;
if (visibleControls===true) html += `<div id='image' class='small' style='background-image: url(${ data.url }); width: ${ data.width }px; height: ${ data.height }px; margin-top: -${ parseInt(data.height/2-20) }px; margin-left: -${ data.width/2 }px;'></div>`
else html += `<div id='image' class='small' style='background-image: url(${ data.url }); width: ${ data.width }px; height: ${ data.height }px; margin-top: -${ parseInt(data.height/2) }px; margin-left: -${ data.width/2 }px;'></div>`
}
return html;
return html
}
build.no_content = function(typ) {
var html;
html = `
<div class='no_content fadeIn'>
${ build.iconic(typ) }
`
let html = `
<div class='no_content fadeIn'>
${ build.iconic(typ) }
`
switch (typ) {
case 'magnifying-glass': html += '<p>No results</p>';
break;
case 'eye': html += '<p>No public albums</p>';
break;
case 'cog': html += '<p>No configuration</p>';
break;
case 'question-mark': html += '<p>Photo not found</p>';
break;
case 'magnifying-glass':
html += '<p>No results</p>'
break
case 'eye':
html += '<p>No public albums</p>'
break
case 'cog':
html += '<p>No configuration</p>'
break
case 'question-mark':
html += '<p>Photo not found</p>'
break
}
html += '</div>';
html += '</div>'
return html;
return html
}
build.uploadModal = function(title, files) {
var html = '',
i = 0,
file = null;
let html = `
<h1>${ title }</h1>
<div class='rows'>
`
html = `
<h1>${ title }</h1>
<div class='rows'>
`
let i = 0
while (i<files.length) {
file = files[i];
let file = files[i]
if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20);
if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length-20, 20)
html += `
<div class='row'>
<a class='name'>${ lychee.escapeHTML(file.name) }</a>
`
html += `
<div class='row'>
<a class='name'>${ lychee.escapeHTML(file.name) }</a>
`
if (file.supported===true) html += `<a class='status'></a>`;
else html += `<a class='status error'>Not supported</a>`;
if (file.supported===true) html += `<a class='status'></a>`
else html += `<a class='status error'>Not supported</a>`
html += `
<p class='notice'></p>
</div>
`
html += `
<p class='notice'></p>
</div>
`
i++;
i++
}
html += '</div>';
html += '</div>'
return html;
return html
}
build.tags = function(tags) {
var html = '',
editTagsHTML = '';
let html = ''
if (tags!=='') {
tags = tags.split(',');
tags = tags.split(',')
tags.forEach(function(tag, index, array) {
html += `<a class='tag'>${ tag }<span data-index='${ index }'>${ build.iconic('x') }</span></a>`
});
})
} else {
html = `<div class='empty'>No Tags</div>`;
html = `<div class='empty'>No Tags</div>`
}
return html;
return html
}