lychee/src/scripts/build.js

225 lines
5.5 KiB
JavaScript
Raw Normal View History

2015-01-31 21:29:31 +00:00
/**
2015-07-11 12:16:11 +00:00
* @description This module is used to generate HTML-Code.
* @copyright 2015 by Tobias Reich
2015-01-31 21:29:31 +00:00
*/
2015-07-11 12:16:11 +00:00
build = {}
2015-01-31 21:29:31 +00:00
2015-07-11 12:16:11 +00:00
build.iconic = function(icon, classes = '') {
2015-01-31 21:29:31 +00:00
let html = ''
html += lychee.html`<svg class='iconic $${ classes }'><use xlink:href='#$${ icon }' /></svg>`
return html
2015-01-31 21:29:31 +00:00
}
build.divider = function(title) {
let html = ''
html += lychee.html`<div class='divider'><h1>$${ title }</h1></div>`
return html
2015-01-31 21:29:31 +00:00
}
build.editIcon = function(id) {
let html = ''
html += lychee.html`<div id='$${ id }' class='edit'>${ build.iconic('pencil') }</div>`
return html
2015-01-31 21:29:31 +00:00
}
build.multiselect = function(top, left) {
return lychee.html`<div id='multiselect' style='top: $${ top }px; left: $${ left }px;'></div>`
2015-01-31 21:29:31 +00:00
}
build.album = function(data) {
let html = ''
2015-01-31 21:29:31 +00:00
let { path: retinaThumbUrl, isPhoto } = lychee.retinize(data.thumbs[0])
2015-01-31 21:29:31 +00:00
html += lychee.html`
<div class='album' data-id='$${ data.id }'>
2016-01-06 16:29:49 +00:00
<img src='$${ data.thumbs[2] }' width='200' height='200' alt='Photo thumbnail' data-overlay='false' draggable='false'>
<img src='$${ data.thumbs[1] }' width='200' height='200' alt='Photo thumbnail' data-overlay='false' draggable='false'>
<img src='$${ data.thumbs[0] }' srcset='$${ retinaThumbUrl } 1.5x' width='200' height='200' alt='Photo thumbnail' data-overlay='$${ isPhoto }' draggable='false'>
<div class='overlay'>
<h1 title='$${ data.title }'>$${ data.title }</h1>
<a>$${ data.sysdate }</a>
</div>
`
2015-01-31 21:29:31 +00:00
if (lychee.publicMode===false) {
html += lychee.html`
<div class='badges'>
<a class='badge $${ (data.star==='1' ? 'badge--visible' : '') } icn-star'>${ build.iconic('star') }</a>
<a class='badge $${ (data.public==='1' ? 'badge--visible' : '') } icn-share'>${ build.iconic('eye') }</a>
<a class='badge $${ (data.unsorted==='1' ? 'badge--visible' : '') }'>${ build.iconic('list') }</a>
<a class='badge $${ (data.recent==='1' ? 'badge--visible' : '') }'>${ build.iconic('clock') }</a>
<a class='badge $${ (data.password==='1' ? 'badge--visible' : '') }'>${ build.iconic('lock-locked') }</a>
</div>
`
2015-01-31 21:29:31 +00:00
}
html += '</div>'
2015-07-11 12:16:11 +00:00
return html
2015-01-31 21:29:31 +00:00
}
build.photo = function(data) {
let html = ''
2015-01-31 21:29:31 +00:00
let { path: retinaThumbUrl } = lychee.retinize(data.thumbUrl)
2015-01-31 21:29:31 +00:00
html += lychee.html`
<div class='photo' data-album-id='$${ data.album }' data-id='$${ data.id }'>
2016-01-06 16:29:49 +00:00
<img src='$${ data.thumbUrl }' srcset='$${ retinaThumbUrl } 1.5x' width='200' height='200' alt='Photo thumbnail' draggable='false'>
<div class='overlay'>
<h1 title='$${ data.title }'>$${ data.title }</h1>
`
if (data.cameraDate==='1') html += lychee.html`<a><span title='Camera Date'>${ build.iconic('camera-slr') }</span>$${ data.sysdate }</a>`
else html += lychee.html`<a>$${ data.sysdate }</a>`
2015-01-31 21:29:31 +00:00
html += `</div>`
2015-01-31 21:29:31 +00:00
if (lychee.publicMode===false) {
html += lychee.html`
<div class='badges'>
<a class='badge $${ (data.star==='1' ? 'badge--visible' : '') } icn-star'>${ build.iconic('star') }</a>
<a class='badge $${ ((data.public==='1' && album.json.public!=='1') ? 'badge--visible' : '') } icn-share'>${ build.iconic('eye') }</a>
</div>
`
2015-01-31 21:29:31 +00:00
}
2015-01-31 21:29:31 +00:00
html += `</div>`
2015-01-31 21:29:31 +00:00
return html
}
build.imageview = function(data, visibleControls) {
2015-01-31 21:29:31 +00:00
2016-01-24 14:16:03 +00:00
let html = ''
let hasMedium = data.medium!==''
2015-01-31 21:29:31 +00:00
if (hasMedium===false) {
2015-01-31 21:29:31 +00:00
html += lychee.html`<img id='image' class='$${ visibleControls===true ? '' : 'full' }' src='$${ data.url }' draggable='false'>`
2015-01-31 21:29:31 +00:00
} else {
2015-01-31 21:29:31 +00:00
html += lychee.html`<img id='image' class='$${ visibleControls===true ? '' : 'full' }' src='$${ data.url }' srcset='$${ data.medium } 1920w, $${ data.url } $${ data.width }w' draggable='false'>`
2015-01-31 21:29:31 +00:00
}
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>
`
2015-07-11 12:16:11 +00:00
return html
2015-01-31 21:29:31 +00:00
}
build.no_content = function(typ) {
let html = ''
html += `
<div class='no_content fadeIn'>
${ build.iconic(typ) }
`
2015-01-31 21:29:31 +00:00
switch (typ) {
2015-07-11 12:16:11 +00:00
case 'magnifying-glass':
html += `<p>No results</p>`
2015-07-11 12:16:11 +00:00
break
case 'eye':
html += `<p>No public albums</p>`
2015-07-11 12:16:11 +00:00
break
case 'cog':
html += `<p>No configuration</p>`
2015-07-11 12:16:11 +00:00
break
case 'question-mark':
html += `<p>Photo not found</p>`
2015-07-11 12:16:11 +00:00
break
2015-01-31 21:29:31 +00:00
}
html += `</div>`
2015-01-31 21:29:31 +00:00
2015-07-11 12:16:11 +00:00
return html
2015-01-31 21:29:31 +00:00
}
build.uploadModal = function(title, files) {
let html = ''
html += lychee.html`
<h1>$${ title }</h1>
<div class='rows'>
`
2015-01-31 21:29:31 +00:00
2015-07-11 12:16:11 +00:00
let i = 0
2015-01-31 21:29:31 +00:00
while (i<files.length) {
2015-07-11 12:16:11 +00:00
let file = files[i]
2015-01-31 21:29:31 +00:00
2016-01-24 14:16:03 +00:00
if (file.name.length>40) file.name = file.name.substr(0, 17) + '...' + file.name.substr(file.name.length - 20, 20)
2015-01-31 21:29:31 +00:00
html += lychee.html`
2015-07-11 12:16:11 +00:00
<div class='row'>
<a class='name'>$${ file.name }</a>
2016-03-21 11:51:51 +00:00
<a class='status'></a>
2015-07-11 12:16:11 +00:00
<p class='notice'></p>
</div>
`
2015-01-31 21:29:31 +00:00
2015-07-11 12:16:11 +00:00
i++
2015-01-31 21:29:31 +00:00
}
html += `</div>`
2015-01-31 21:29:31 +00:00
2015-07-11 12:16:11 +00:00
return html
2015-01-31 21:29:31 +00:00
}
build.tags = function(tags) {
2015-01-31 21:29:31 +00:00
2015-07-11 12:16:11 +00:00
let html = ''
2015-01-31 21:29:31 +00:00
if (tags!=='') {
2015-07-11 12:16:11 +00:00
tags = tags.split(',')
2015-01-31 21:29:31 +00:00
tags.forEach(function(tag, index, array) {
html += lychee.html`<a class='tag'>$${ tag }<span data-index='$${ index }'>${ build.iconic('x') }</span></a>`
2015-07-11 12:16:11 +00:00
})
2015-01-31 21:29:31 +00:00
} else {
2015-07-11 12:16:11 +00:00
html = `<div class='empty'>No Tags</div>`
2015-01-31 21:29:31 +00:00
}
2015-07-11 12:16:11 +00:00
return html
2015-01-31 21:29:31 +00:00
}