{% extends 'base.html.twig' %}
{% block title %}{{ channel.name|capitalize }}{% endblock %}
{% block body_class %}photoview{% endblock %}
{% block top_title %}{% endblock %}
{% block top_menu %}
<span style="color: #ddd">{{ channel.name|capitalize }}</span>
<span class="divider"> / </span>
<span class="date" id="image-timestamp" data-timestamp="{{ channel.lastUploadAt.timestamp }}">{{ channel.lastUploadAt ? channel.lastUploadAt|date('Y-m-d H:i') : 'not yet' }}</span>
{% if app.user == channel.user %}
<span class="divider"> / </span>
<a href="{{ path('channel_edit', {'id': channel.id}) }}">channel</a>
{% endif %}
<span class="divider"> / </span>
{% endblock %}
{% block maxbody %}
<style>
picture { display: block; height: 100%; }
video, picture, picture img { max-height: 100%; max-width: 100%; vertical-align: middle; margin: auto; }
html, body { height: 100%; }
.imgbox { display: grid; height: 100%; width: 100%; }
</style>
<div class="imgbox">
<picture id="im">
<source media="screen and (min-width: 2000px)" srcset="{{ channel.dataDirectory }}raw.jpg?{{ channel.lastUploadAt.timestamp }}" type="image/jpeg">
<source srcset="{{ channel.imDirectory }}last.webp?{{ channel.lastUploadAt.timestamp }}" type="image/webp" />
<source srcset="{{ channel.imDirectory }}last.jpg?{{ channel.lastUploadAt.timestamp }}" type="image/jpeg" />
<img src="{{ channel.imDirectory }}last.jpg?{{ channel.lastUploadAt.timestamp }}" alt="{{ channel.name|capitalize }}" />
</picture>
</div>
{% endblock %}
{% block javascripts %}
<script>
let timestamp = document.getElementById('image-timestamp');
setInterval(function() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
let response = this.responseText;
timestamp.setAttribute('data-timestamp', response);
localizeDates();
const regex = /\?\d+/i;
let im = document.getElementById('im');
im.childNodes.forEach(function(item){
console.log(item);
let src = item.getAttribute('src');
if (src) {
item.setAttribute('src', src.replace(regex, '?' + response));
}
let srcset = item.getAttribute('srcset');
if (srcset) {
item.setAttribute('srcset', srcset.replace(regex, '?' + response));
}
});
image.setAttribute('src', '{{ channel.dataDirectory }}last.jpg?' + response);
}
xhttp.open("GET", "{{ path('channel_last', {slug: channel.slug}) }}", true);
xhttp.send();
}, 60*1000);
</script>
{% endblock %}