1<#import "/blaues-gut-portal.web-resources_SERVLET_CONTEXT_/common_macros.ftl" as common>
2
3<#assign layoutService = serviceLocator.findService("com.liferay.portal.kernel.service.LayoutLocalService") />
4<#assign namespace = randomNamespace />
5
6<section class="slider-hero ${(SliderTyp??)?then(SliderTyp.getData(), "")}" id="slider_${namespace}">
7 <div class="slides-list">
8
9 <#list Slide.getSiblings() as curSlide>
10
11 <#assign hasLink = false />
12 <#assign linkTarget = "" />
13 <#assign linkHref= "" />
14 <#assign linkText = "weiterlesen" />
15 <#assign linkTitle = "Artikel weiterlesen" />
16 <#assign slideUniqueId = namespace + '_' + curSlide?index />
17
18
19 <#if curSlide.Headline?? && curSlide.Headline.getData()?has_content>
20 <#assign AltText = curSlide.Headline.getData() />
21 </#if>
22
23 <#assign Copyright = "" />
24 <#if (common.getCopyrightText(curSlide.Image.data)!"") != "">
25 <#assign Copyright = common.getCopyrightTag("",curSlide.Image.data) />
26 </#if>
27
28 <div class="slide" role="group" aria-label="Folie ${curSlide?index + 1} von ${Slide.siblings?size}">
29 <div class="slide-content">
30 <#if (curSlide.Youtube?? && curSlide.Youtube.getData()?has_content) && (curSlide.Image?? && curSlide.Image?has_content)>
31 <#assign videoId = curSlide.Youtube.getData()/>
32
33 <#if videoId?starts_with("http")>
34 <#assign videoId = videoId?split("/")[3]>
35 </#if>
36
37 <div class="slide-content-video video" id="video_${slideUniqueId}">
38 <img src="${common.getScaledImageURL(curSlide.Image.getData())}" data-src="${common.getScaledImageURL(curSlide.Image.getData())}" class="slide__image video-preview-image" id="video-preview-image_${slideUniqueId}" alt="${common.getAltText(curSlide.Image.data, AltText)}" loading="lazy"/>
39 <div class="video-trigger-overlay video-trigger " id="video-trigger_${slideUniqueId}" data-tns-slide="tns1-item${curSlide?index}" data-videoid="${slideUniqueId}" data-source="${videoId}" title="Video abspielen">
40 <p class="text-center video-trigger-overlay-text video-trigger" data-videoid="${slideUniqueId}" >
41 Um das Video zu sehen, müssen Sie dieses Feld durch einen Klick aktivieren. Dadurch werden
42 Informationen an Youtube übermittelt und unter Umständen dort verarbeitet. Bitte beachten Sie unsere
43 Hinweise und Informationen zum <a href="/datenschutz" target="_blank"
44 class="no-icon">Datenschutz</a>.
45 </p>
46 <span class="icon-bg icon-bg--play video-trigger" data-videoid="${slideUniqueId}" ></span>
47 </div>
48 <div class="video-layer" style="display: none" id="video-layer_${slideUniqueId}">
49 <iframe class="video-frame" src="about:blank" allowfullscreen="" height="530" id="iframe_${slideUniqueId}"></iframe>
50 </div>
51 </div>
52 <#elseif (curSlide.Panopto_Link?? && curSlide.Panopto_Link.getData()?has_content)>
53 <#assign panoptoId = getPanoptoId(curSlide.Panopto_Link.getData()) />
54
55 <#if panoptoId?has_content>
56 <div class="slide-content-video video panopto-video" id="video_${slideUniqueId}">
57 <div class="embed-container">
58 <iframe
59 src="https://videoplattform.lubw.baden-wuerttemberg.de/Panopto/Pages/Embed.aspx?id=${panoptoId}&autoplay=false&offerviewer=false&showtitle=true&showbrand=false&start=0&interactivity=none"
60 title="${AltText}"
61 >
62 </iframe>
63 </div>
64 </div>
65 </#if>
66 <#else>
67 <div class="slide-content-image image-with-caption">
68 <img src="${common.getScaledImageURL(curSlide.Image.getData())}" data-src="${common.getScaledImageURL(curSlide.Image.getData())}" class="slide__image" alt="${common.getAltText(curSlide.Image.data, AltText)}" loading="lazy"/>
69 ${Copyright}
70 </div>
71 </#if>
72 </div>
73 </div>
74
75 </#list>
76 </div>
77</section>
78
79<script>
80
81 var updateIframeHeight = function() {
82 var dwidth = window.innerWidth;
83 var videoHeight = dwidth*0.5625;
84
85 /*
86 if (dwidth > 1600) {
87 videoHeight = dwidth*0.40;
88 }
89 */
90
91 var videoFrames = document.getElementsByClassName('video-frame');
92 for (var i=0; i < videoFrames.length;i++) {
93 videoFrames[i].setAttribute('height',videoHeight);
94 videoFrames[i].style.height = videoHeight+'px';
95 }
96 }
97
98 var updateVideoWrapper = function () {
99
100 var triggers = document.getElementsByClassName('video-trigger');
101
102 for (var i=0; i < triggers.length;i++) {
103 triggers[i].addEventListener('click',function(e) {
104
105 var triggersTarget = this.getAttribute('data-videoid');
106 var tnsSlide = this.getAttribute('data-tns-slide');
107
108 var youtubeId = document.querySelector("#" + tnsSlide + ' #video-trigger_'+triggersTarget).getAttribute('data-source');
109 var videoLayer = document.querySelector("#" + tnsSlide + ' #video-layer_'+triggersTarget);
110 var iframe = document.querySelector("#" + tnsSlide + ' #iframe_'+triggersTarget);
111 iframe.setAttribute('src', 'https://www.youtube-nocookie.com/embed/' + youtubeId + '?autoplay=1&rel=0&cc_load_policy=1&modestbranding=0&enablejsapi=1');
112
113 document.querySelector("#" + tnsSlide + ' #video-preview-image_'+triggersTarget).style.display='none';
114 document.querySelector("#" + tnsSlide + ' #video-trigger_'+triggersTarget).style.display='none';
115 videoLayer.style.display='block';
116 });
117 }
118 };
119
120 window.addEventListener("load", function () {
121 updateVideoWrapper();
122 updateIframeHeight();
123 });
124
125 window.addEventListener("resize", function () {
126 updateIframeHeight();
127 });
128
129 // Liferay.on('endNavigate', updateVideoWrapper);
130 // $(document).ready(updateVideoWrapper);
131
132 window.addEventListener("load", function () {
133 function ${namespace}_updateInfo(info) {
134 for (var i = 0; i < info.navItems.length; i++) {
135 info.navItems[i].setAttribute('aria-label','Folie ' + (i+1));
136 }
137
138 info.navItems[info.navCurrentIndex].setAttribute('aria-label','Folie ' + (info.navCurrentIndex + 1) + ' (aktuell)');
139
140 info.controlsContainer.setAttribute('aria-label', 'Navigationselemente');
141 info.prevButton.setAttribute('aria-label','zur vorhergehenden Folie springen');
142 info.nextButton.setAttribute('aria-label','zur nächsten Folie springen');
143 info.navContainer.setAttribute('aria-label','Auswahl der Folien')
144 }
145
146 const imgStyle = document.querySelector('.image-slider-style');
147
148 var slider = tns({
149 container: '#slider_${namespace} .slides-list',
150 items: 1,
151 slideBy: 'page',
152 center: true,
153 controlsPosition: 'bottom',
154 navPosition: 'bottom',
155 touch: true,
156 mouseDrag: true,
157 freezable: true,
158 speed: 600,
159 loop: false,
160 arrowKeys: true,
161 lazyload: true,
162 autoHeight: true,
163 lazyloadSelector: '.slide__image',
164 autoplay: !!imgStyle,
165 autoplayHoverPause: true,
166 autoplayTimeout: 3500,
167 autoplayText: [
168 "▶",
169 "❚❚"
170 ],
171 controlsText: ['<span class="icon-bg icon-bg--arrow2-left"></span>','<span class="icon-bg icon-bg--arrow2-right"></span>'],
172 onInit: function (info) {
173 ${namespace}_updateInfo(info);
174 }
175 });
176
177 slider.events.on('indexChanged', function(info) {
178 ${namespace}_updateInfo(info);
179 });
180
181 slider.events.on('transitionStart', function(info, eventName) {
182 var currentSlideId = '#tns1-item' + info.navCurrentIndex;
183
184 var otherSlides = info.container.querySelectorAll('.tns-item:not(' + currentSlideId + ')')
185
186 otherSlides.forEach(function(slide) {
187 var iframe = slide.querySelector( 'iframe');
188
189 if (iframe != null) {
190 var src = iframe.getAttribute('src');
191 if (src) {
192 if ((src.indexOf('youtube.com/embed') != -1) || (src.indexOf('youtube-nocookie.com/embed') != -1)) {
193 iframe.contentWindow.postMessage(JSON.stringify({
194 'event': 'command',
195 'func': 'pauseVideo',
196 'args': []
197 }), "*");
198 }
199 }
200 }
201 });
202 });
203 const mediaQuery = window.matchMedia('(max-width: 767px)')
204 if (mediaQuery.matches) {
205 const bulletList = document.querySelectorAll('.slider-hero .tns-nav');
206
207 bulletList.forEach(bullet => {
208 const slider = bullet.previousElementSibling.getBoundingClientRect();
209 const bulletNav = bullet.getBoundingClientRect();
210
211 const bulletNavTop = bulletNav.top;
212 const sliderTop = slider.top;
213
214 const arrowsPos = bulletNavTop - sliderTop - 5;
215
216 const prev = bullet.nextElementSibling.children[0];
217 const prevBtnWidth = prev.clientWidth;
218 const next = bullet.nextElementSibling.children[1];
219
220 const sliderControls = bullet.nextElementSibling;
221 const firstBulletLeftSpace = bullet.firstElementChild.offsetLeft;
222 const firstBulletWidth = bullet.firstElementChild.clientWidth;
223 const lastBulletLeftSpace = bullet.lastElementChild.offsetLeft;
224
225 const nextBtnPos = lastBulletLeftSpace + 59;
226 const prevBtnPos = firstBulletLeftSpace - prevBtnWidth - firstBulletWidth - 87;
227
228 const playPauseBtn = bullet.parentElement.firstElementChild;
229 const playPauseBtnLeftPos = lastBulletLeftSpace + 15;
230
231 sliderControls.style.top = arrowsPos + 'px';
232
233 next.style.left = nextBtnPos + 'px';
234
235 prev.style.left = prevBtnPos + 'px';
236
237 playPauseBtn.style.left = playPauseBtnLeftPos + 'px';
238
239 console.log(sliderControls.style.top);
240 });
241 }
242 });
243</script>
244
245<#function getPanoptoId url>
246 <#local result = url?matches("https?://videoplattform\\.lubw\\.baden-wuerttemberg\\.de/Panopto/Pages/(?:Embed|Viewer).aspx\\?id=(\\S*)$") />
247
248 <#if result>
249 <#return result?groups[1] />
250 </#if>
251
252 <#return "" />
253</#function>