templates/areas/newsticker/view.html.twig line 1

Open in your IDE?
  1. {% if editmode %}
  2.     <div class="p-5">
  3.         {% include 'areaHeadAndFooter.html.twig' with { 'header': 'STWH: Newsticker' } %}
  4.         {% for i in pimcore_block('contentblock').iterator %}
  5.             Eintrag
  6.             <div class="flex">
  7.                 <div class="w-1/4">{{ pimcore_numeric('repeat', {"minValue" : 1, "maxValue" : 100, "decimalPrecision" : 0}) }}
  8.                     mal anzeigen
  9.                 </div>
  10.                 <div class="w-3/4">
  11.                     {{ pimcore_wysiwyg("content", {
  12.                         "height": 10,
  13.                         "toolbarGroups": [
  14.                             {
  15.                                 "name": 'links',
  16.                                 "groups": [ "links"]
  17.                             }
  18.                         ]}) }}
  19.                 </div>
  20.             </div>
  21.             <hr>
  22.         {% endfor %}
  23.     </div>
  24. {% else %}
  25.     <div class="bg-red-600 flex flex-col justify-center" x-data="newsTickerHandler">
  26.         <div
  27.                 class="overflow-hidden bg-red-600 pl-64"
  28.                 @mouseenter="state.moving = false"
  29.                 @mouseleave="state.moving = true">
  30.             <ul
  31.                     :style="`transform:translateX(${position}px);padding-left:${offset}px`"
  32.                     class="flex items-center w-full font-bold max-w-screen whitespace-no-wrap transition-transform duration-300 ease-linear py-6 text-white text-2xl bg-red-600 leading-tight"
  33.             >
  34.                 <template x-for="(headline, index) in headlines" :key="index">
  35.                     <li
  36.                             :id="`news-${index}`"
  37.                             class="flex px-16 whitespace-nowrap newsentry"
  38.                             x-html="headline"></li>
  39.                 </template>
  40.             </ul>
  41.         </div>
  42.         <datalist x-ref="headlines">
  43.             {% for i in pimcore_block('contentblock').iterator %}
  44.                 <option value="{{ pimcore_wysiwyg("content")|striptags('<a>')|replace({"\n": "&nbsp;", " <a": "&nbsp;<a", "a> ": "a>&nbsp;"})|escape }}">{{ pimcore_numeric('repeat') }}</option>
  45.             {% endfor %}
  46.         </datalist>
  47.     </div>
  48.     <script>
  49.         function newsTickerHandler() {
  50.             return {
  51.                 state: {
  52.                     moving: true,
  53.                 },
  54.                 headlines: [],
  55.                 position: 0,
  56.                 offset: 0,
  57.                 speed: 25,
  58.                 pauseOnNextHeadline: 0,
  59.                 init: async function () {
  60.                     for(let option of Array.from(this.$refs.headlines.options)){
  61.                         let i = 0;
  62.                         do {
  63.                             console.log(i)
  64.                             console.log('text', (parseInt(option.text) ?? 0))
  65.                             console.log(i < (parseInt(option.text) ?? 0))
  66.                             this.headlines.push(option.value)
  67.                             i++;
  68.                         }while(i < (parseInt(option.text) ?? 0))
  69.                     }
  70.                     this.$nextTick(() => {
  71.                         this.start()
  72.                     })
  73.                 },
  74.                 start() {
  75.                     this.loop = () => {
  76.                         const first = document.getElementById('news-0').getBoundingClientRect()
  77.                         if (first.x <= -first.width) {
  78.                             const newHeadlines = this.headlines
  79.                             newHeadlines.push(newHeadlines.shift())
  80.                             this.headlines = newHeadlines
  81.                             this.offset = this.offset + Math.abs(first.width)
  82.                             this.$nextTick(() => {
  83.                                 setTimeout(() => {
  84.                                     requestAnimationFrame(this.loop)
  85.                                 }, this.pauseOnNextHeadline)
  86.                             })
  87.                             return
  88.                         }
  89.                         this.position = this.state.moving ? this.position - this.speed : this.position
  90.                         setTimeout(() => {
  91.                             requestAnimationFrame(this.loop)
  92.                         }, 300)
  93.                     }
  94.                     requestAnimationFrame(this.loop)
  95.                 },
  96.             }
  97.         }
  98.     </script>
  99.     <style>
  100.         .newsentry a {
  101.             text-decoration: underline;
  102.         }
  103.     </style>
  104. {% endif %}