templates/channel/show.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}{{ channel.name|capitalize }}{% endblock %}
  3. {% block body_class %}photoview{% endblock %}
  4. {% block top_title %}{% endblock %}
  5. {% block top_menu %}
  6.     <span style="color: #ddd">{{ channel.name|capitalize }}</span>
  7.     <span class="divider"> / </span>
  8.     <span class="date" id="image-timestamp" data-timestamp="{{ channel.lastUploadAt.timestamp }}">{{ channel.lastUploadAt ? channel.lastUploadAt|date('Y-m-d H:i') : 'not yet' }}</span>
  9.     {% if app.user == channel.user %}
  10.         <span class="divider"> / </span>
  11.         <a href="{{ path('channel_edit', {'id': channel.id}) }}">channel</a>
  12.     {% endif %}
  13.     <span class="divider"> / </span>
  14. {% endblock %}
  15. {% block maxbody %}
  16.     <style>
  17.         picture { display: block; height: 100%; }
  18.         video, picture, picture img {  max-height: 100%; max-width: 100%; vertical-align: middle; margin: auto; }
  19.         html, body { height: 100%; }
  20.         .imgbox { display: grid; height: 100%; width: 100%; }
  21.     </style>
  22.     <div class="imgbox">
  23.         <picture id="im">
  24.             <source media="screen and (min-width: 2000px)" srcset="{{ channel.dataDirectory }}raw.jpg?{{ channel.lastUploadAt.timestamp }}" type="image/jpeg">
  25.             <source srcset="{{ channel.imDirectory }}last.webp?{{ channel.lastUploadAt.timestamp }}" type="image/webp" />
  26.             <source srcset="{{ channel.imDirectory }}last.jpg?{{ channel.lastUploadAt.timestamp }}" type="image/jpeg" />
  27.             <img src="{{ channel.imDirectory }}last.jpg?{{ channel.lastUploadAt.timestamp }}" alt="{{ channel.name|capitalize }}" />
  28.         </picture>
  29.     </div>
  30. {% endblock %}
  31. {% block javascripts %}
  32. <script>
  33.     let timestamp = document.getElementById('image-timestamp');
  34.     setInterval(function() {
  35.         const xhttp = new XMLHttpRequest();
  36.         xhttp.onload = function() {
  37.             let response = this.responseText;
  38.             timestamp.setAttribute('data-timestamp', response);
  39.             localizeDates();
  40.             const regex = /\?\d+/i;
  41.             let im = document.getElementById('im');
  42.             im.childNodes.forEach(function(item){
  43.                 console.log(item);
  44.                 let src = item.getAttribute('src');
  45.                 if (src) {
  46.                     item.setAttribute('src', src.replace(regex, '?' + response));
  47.                 }
  48.                 let srcset = item.getAttribute('srcset');
  49.                 if (srcset) {
  50.                     item.setAttribute('srcset', srcset.replace(regex, '?' + response));
  51.                 }
  52.             });
  53.             image.setAttribute('src', '{{ channel.dataDirectory }}last.jpg?' + response);
  54.         }
  55.         xhttp.open("GET", "{{ path('channel_last', {slug: channel.slug}) }}", true);
  56.         xhttp.send();
  57.     }, 60*1000);
  58. </script>
  59. {% endblock %}