{% if editmode %}
<div class="p-5">
{% include 'areaHeadAndFooter.html.twig' with { 'header': 'STWH: Newsticker' } %}
{% for i in pimcore_block('contentblock').iterator %}
Eintrag
<div class="flex">
<div class="w-1/4">{{ pimcore_numeric('repeat', {"minValue" : 1, "maxValue" : 100, "decimalPrecision" : 0}) }}
mal anzeigen
</div>
<div class="w-3/4">
{{ pimcore_wysiwyg("content", {
"height": 10,
"toolbarGroups": [
{
"name": 'links',
"groups": [ "links"]
}
]}) }}
</div>
</div>
<hr>
{% endfor %}
</div>
{% else %}
<div class="bg-red-600 flex flex-col justify-center" x-data="newsTickerHandler">
<div
class="overflow-hidden bg-red-600 pl-64"
@mouseenter="state.moving = false"
@mouseleave="state.moving = true">
<ul
:style="`transform:translateX(${position}px);padding-left:${offset}px`"
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"
>
<template x-for="(headline, index) in headlines" :key="index">
<li
:id="`news-${index}`"
class="flex px-16 whitespace-nowrap newsentry"
x-html="headline"></li>
</template>
</ul>
</div>
<datalist x-ref="headlines">
{% for i in pimcore_block('contentblock').iterator %}
<option value="{{ pimcore_wysiwyg("content")|striptags('<a>')|replace({"\n": " ", " <a": " <a", "a> ": "a> "})|escape }}">{{ pimcore_numeric('repeat') }}</option>
{% endfor %}
</datalist>
</div>
<script>
function newsTickerHandler() {
return {
state: {
moving: true,
},
headlines: [],
position: 0,
offset: 0,
speed: 25,
pauseOnNextHeadline: 0,
init: async function () {
for(let option of Array.from(this.$refs.headlines.options)){
let i = 0;
do {
console.log(i)
console.log('text', (parseInt(option.text) ?? 0))
console.log(i < (parseInt(option.text) ?? 0))
this.headlines.push(option.value)
i++;
}while(i < (parseInt(option.text) ?? 0))
}
this.$nextTick(() => {
this.start()
})
},
start() {
this.loop = () => {
const first = document.getElementById('news-0').getBoundingClientRect()
if (first.x <= -first.width) {
const newHeadlines = this.headlines
newHeadlines.push(newHeadlines.shift())
this.headlines = newHeadlines
this.offset = this.offset + Math.abs(first.width)
this.$nextTick(() => {
setTimeout(() => {
requestAnimationFrame(this.loop)
}, this.pauseOnNextHeadline)
})
return
}
this.position = this.state.moving ? this.position - this.speed : this.position
setTimeout(() => {
requestAnimationFrame(this.loop)
}, 300)
}
requestAnimationFrame(this.loop)
},
}
}
</script>
<style>
.newsentry a {
text-decoration: underline;
}
</style>
{% endif %}