PageSourceSearch

https://kulturportal.de/media/scripts/dynamic_list.js

js kulturportal.de collected 2026-09-24 22:23:26 UTC 19,940 bytes, 584 lines download raw bytes

1var DynamicList = {
2
3    init: function (config) {
4        this.$el = config.container;
5        this.$loadMoreBtn = config.loadMoreBtn;
6        this.$itemTmpl = config.item;
7        this.$form = config.form;
8        this.url = config.url;
9        this.useMasonry = config.useMasonry;
10        this.page = 1;
11        this.lastScrollPosition = 0;
12        this.isLoading = false;
13        this.isFirstLoading = true;
14        this.urlHasParameter = config.urlHasParameter;
15        this.pushState = config.pushState || false;
16        this.replaceState = config.replaceState || false;
17        
18        if (typeof this.setupForm === 'function') {
19            this.setupForm();
20        }
21        
22        this.bindForm();
23
24        if (typeof this.bindFormCustom === 'function') {
25            this.bindFormCustom();
26        }
27
28        this.load();
29
30        if (this.useMasonry) {
31            this.initMasonry();
32        }
33
34        this.infiniteScrollEnabled = false;
35        this.isLastPage = false;
36    },
37
38    unbindInfiniteScroll: function () {
39        $(window).unbind('scroll', this.onScroll);
40        this.lastScrollPosition = 0;
41    },
42
43    bindInfiniteScroll: function () {
44        var self = this;
45
46        self.unbindInfiniteScroll();
47
48        if (self.infiniteScrollEnabled === true) {
49            $(window).scroll(this.onScroll.bind(this));
50        } else {
51            this.$loadMoreBtn.unbind('click').on('click', function () {
52                self.infiniteScrollEnabled = true;
53                
54                $(this).fadeOut(0);
55        
56                self.bindInfiniteScroll();
57                var scrollPosition = $(window).scrollTop();
58                self.lastScrollPosition = scrollPosition;
59                self.page += 1;
60                self.load();
61            });
62        }
63    },
64
65    onScroll: function (e) {
66        if (this.isLastPage === false && !$('#blog').hasClass('hide-element')) {
67            var scrollPosition = $(window).scrollTop();
68            if (scrollPosition + $(window).height() > ($(window).height() / 100 * 90) &&
69                    !this.isLoading && this.lastScrollPosition < scrollPosition) {
70                this.lastScrollPosition = scrollPosition;
71                this.page += 1;
72                this.load();
73            }
74        }
75    },
76
77    getUrlParam: function (paramName) {
78        var searchUrl = decodeURIComponent(window.location.search.substring(1));
79        var urlComponents = searchUrl.split('&');
80        // array with a key and a value
81        var urlComponent;
82        var i;
83
84        for (i = 0; i < urlComponents.length; i++) {
85            urlComponent = urlComponents[i].split('=');
86
87            if (urlComponent[0] === paramName) {
88                return urlComponent[1];
89            }
90        }
91
92        return null;
93    },
94
95    bindForm: function () {
96        var self = this;
97
98        self.$form.submit(function () {
99            self.page = 1;
100            self.empty();
101            self.load();
102            return false;
103        });
104
105        $(':input', self.$form).change(function () {
106            self.$form.submit();
107        });
108    },
109    
110    getFormData: function () {
111        var fields = {};
112
113        this.$form.serializeArray().map(function (item) {
114            if (item.value !== "")
115                fields[item.name] = item.value;
116        });
117
118        return fields;
119    },
120    
121    buildPushURL: function (fields) {
122        var url = window.location.pathname;
123        var urlFirstParameter = this.urlHasParameter ? '&' : '?';
124
125        url += urlFirstParameter + 'p=' + this.page;
126        
127        if (!$.isEmptyObject(fields)) {
128            url += '&' + $.param(fields);
129        }
130
131        return url;
132    },
133
134    load: function (callback) {
135        var self = this;
136        var fields = this.getFormData();
137                
138        if (typeof this.filterFormData === 'function') {
139            fields = this.filterFormData(fields);
140        }
141
142        if ($('body').hasClass('page-home') || this.pushState) {
143            let url = this.buildPushURL(fields);
144            
145            // Preserve hash
146            var hash = window.location.hash;
147
148            history.pushState('', document.title, url);
149
150            if (hash) {
151                location.hash = hash;
152            }
153        } else if (this.replaceState) {
154            let url = this.buildPushURL(fields);
155            
156            window.history.replaceState(null, null, url);
157        }
158
159        if (self.isLoading) {
160            return;
161        }
162
163        self.isLoading = true;
164                                
165        self.$loadMoreBtn.removeClass('visible');
166        
167        $(".ajax-loader").show();
168
169        $.ajax({
170            'url': ENV.link_root + self.url,
171            'data': $.extend(
172                    {
173                        'p': self.page,
174                        //       page_name: ENV.page
175                    },
176                    fields
177                    )
178        })
179                .done(function (data) {
180                    $('#blog-ks-nrw-more-button').show();
181                    self.isLastPage = false;
182
183                    if (data.Results.length) {
184                        self.render(data.Results);
185                        
186                        if (self.useMasonry) {
187                            self.reloadMasonry();
188                            setTimeout(function () {
189                                self.reloadMasonry();
190                            }, 250);
191                        }
192                        
193                        if (data.IsLastPage) {
194                            self.isLastPage = true;
195                            self.unbindInfiniteScroll();
196                            $('#blog-kultur-leipzigerraum-more-button').hide();
197                        } else {
198                            self.bindInfiniteScroll();
199                        }
200                    } else if (self.page === 1) {
201                        // first page and no results, show not found message
202                        self.notFound();
203                        if (self.useMasonry)
204                            self.reloadMasonry();
205                        self.isLastPage = true;
206                        self.unbindInfiniteScroll();
207                    }
208
209                    self.showChangedValue();
210
211                    var lastPodcastFileId = null;
212
213                    $('.open-podcast-player').unbind('click').on('click', function () {
214                        var podcastPlayerContainer = $(this).find('.podcast-player');
215                        var podcastPlayerId = $(podcastPlayerContainer).attr('id');
216                        var podcastPlayer = videojs('#' + podcastPlayerId, {
217                            autoplay: true
218                        });
219                        var podcastFileId = $(this).data('podcast-file-id');
220
221                        podcastPlayer.one('ready', function () {
222                            if (typeof _paq.push === 'function') {
223                                _paq.push(['MediaAnalytics::scanForMedia']);
224                            }
225
226                            setTimeout(function () {
227                                console.log(podcastPlayerContainer);
228                                console.log('#' + podcastPlayerId + ' .vjs-play-control');
229
230                                if ($('#' + podcastPlayerId + ' .vjs-playing').length === 0) {
231                                    $('#' + podcastPlayerId + ' .vjs-play-control').click();
232                                }
233                            }, 333);
234                        });
235                        
236                        $(this).find('.podcast-player-container').show();
237
238                        podcastPlayer.one('play', function () {
239                            if (lastPodcastFileId !== podcastFileId) {
240                                lastPodcastFileId = podcastFileId;
241                                doxStatisticRegisterApplicationsFileDownload(podcastFileId);
242                            }
243                        });
244                    });
245                    
246                    // Show load-more button if more results are available
247                    if (data.NbResults > 0 && !data.IsLastPage && !this.infiniteScrollEnabled) {
248                        self.$loadMoreBtn.addClass('visible');
249                    }
250
251                    if (typeof callback === 'function') {
252                        callback(data);
253                    }
254
255                    if (typeof self.onLoad === 'function') {
256                        self.onLoad(data);
257                    }
258
259                    self.isLoading = false;
260                })
261                .fail(CbUx.ajaxErrorEvent)
262                .always(function () {
263                    $(".ajax-loader").hide();
264                });
265    },
266
267    empty: function () {
268        var self = this;
269        
270        self.$el.find(':not(.gutter-sizer)').remove();
271    },
272
273    notFound: function () {
274        var self = this;
275        
276        self.empty();
277        
278        if (self.urlHasParameter) {
279            $('.blog-recommendations-title').remove();
280        } else {
281            self.$el.append('<div class="magazine-results-status">' + ml('list_no_results') + '</div>');
282            $('#blog-kultur-leipzigerraum-more-button').hide();
283        }
284    },
285
286    initMasonry: function () {
287        var self = this;
288        
289        self.$el.imagesLoaded().always(function () {
290            self.$el.masonry({
291                // options
292                itemSelector: '.grid-item',
293                rowHeight: '.grid-item',
294                percentPosition: false,
295                transitionDuration: 5000,
296                gutter: 20,
297                columnWidth: '.grid-item'
298            });
299
300            
301//            self.$el.on('layoutComplete', function (event, items) {
302//                console.log(items.length);
303//
304//                $("#blog .grid-item:even").addClass("second-element");
305//                $("#blog .grid-item:odd").addClass("half-size-right");
306//            });
307        });
308    },
309
310    reloadMasonry: function () {
311        var self = this;
312        
313        self.$el.masonry('reloadItems');
314        
315        self.$el.imagesLoaded().always(function () {
316            self.$el.masonry('layout');
317        });
318    },
319
320    getItemMarkup: function (item) {
321        if (item === null)
322            return '';
323
324        var self = this;
325        var templateHtml = $(self.$itemTmpl).html();
326
327        return Mustache.render(
328                templateHtml,
329                $.extend(
330                        item,
331                        {
332                            PlayButtonLabel: ml('show_film'),
333                            DirectorLabel: ml('director_label'),
334                            ScreenplayLabel: ml('screenplay_label'),
335                            CameraLabel: ml('camera_label'),
336                            ProducerLabel: ml('producer_label')
337                        }
338                )
339                );
340    },
341
342    showChangedValue: function () {
343        var category = '';
344        
345        $.each($('li.category-filter.active'), function (index, item) {
346            if (index > 0) {
347                category += ', ';
348            }
349            category += $(item).html();
350        });
351        $(".category-displayer").html(category);
352
353        var location = '';
354        
355        $.each($('li.location-filter.active'), function (index, item) {
356            if (index > 0) {
357                location += ', ';
358            }
359            location += $(item).html();
360        });
361        
362        $(".location-displayer").html(location);
363    },
364
365    render: function (items) {
366        var self = this;
367
368        $.each(items, function (i, item) {
369            $(self.getItemMarkup(item))
370                    .hide()
371                    .appendTo(self.$el)
372                    .fadeIn(0);
373        });
374
375        $('a.blog-detail-link.link-video').unbind('click').on('click', function (e) {
376            e.stopPropagation();
377            e.preventDefault();
378            
379            var idFilm = $(this).attr('data-video-id');
380            var scrollPosition = $(window).scrollTop();
381//      var imageFilm = $(this).attr('data-video-image');
382//      var videoContainer = $(this).parent().find('.video-player-container');
383
384            function centerHomeFilmLayer() {
385                $('.film-layer__inner').css({
386                    top: Math.round(($(window).height() - $('.film-layer__inner').height()) / 2),
387                    left: Math.round(($(window).width() - $('.film-layer__inner').width()) / 2)
388                });
389            }
390
391            CbUx.showLoader();
392            
393            $.ajax({
394                url: ENV.link_root + '/film.json',
395                cache: false,
396                data: {
397                    id: idFilm
398                }
399            }).done(function (filmdetails) {
400                CbUx.hideLoader();
401                PLAYER.create({
402                    config: 'default',
403                    film: {
404                        id: idFilm,
405                        type: 'film6'
406                    },
407                    video: {
408                        width: 1240,
409                        height: 697,
410                        autoplay: false
411                    }
412                }, function () {
413                    var layer =
414                            '<div class="film-layer">' +
415                            '<div class="film-layer__inner">' +
416                            '<a class="film-layer__video-close owl-film-layer
416-close icon icon-close" href="#"></a>' +
417                            '</div>' +
418                            '</div>';
419                    $(layer).hide().appendTo('body').fadeIn(400);
420                    centerHomeFilmLayer();
421                    $('header .header-fixed-menu').hide();
422                    $('html,body').scrollTop(0);
423                    $(window).resize(centerHomeFilmLayer);
424                    $('.film-layer').on('click', function (e) {
425                        if (!($(e.target).is('.film-layer__inner') ||
426                                $.contains(document.querySelector('.film-layer__inner'), e.target))) {
427                            $(this).fadeOut(400, function () {
428                                $(this).remove();
429                            });
430
431                        }
432                    });
433                    $('.film-layer .film-layer__video-close.owl-film-layer-close').on('click', function (e) {
434                        $('header .header-fixed-menu').show();
435                        $("html,body").animate({scrollTop: scrollPosition}, 300);
436                        $('.film-layer').fadeOut(400, function () {
437                            $(this).remove();
438                        });
439                    });
440                    // player ready
441                    var vjs = this;
442                    $(vjs.contentEl()).appendTo('.film-layer__inner');
443                    vjs.one('play', function () {
444                        $('.film-layer').addClass('film-layer--playing');
445                    });
446                });
447            });
448            
449            return false;
450        });
451
452        if (self.isFirstLoading === true && self.getUrlParam('item') !== null) {
453            var itemId = self.getUrlParam('item');
454            setTimeout(function () {
455                if ($('.card-img[data-item-id="' + itemId + '"]').hasClass('open-podcast-player')) {
456                    console.log('## OPEN PODCAST LAYER ##');
457                    self.openPodcastLayer(itemId);
458                } else {
459                    $('.card-img[data-item-id="' + itemId + '"]').click();
460                }
461            }, 1000);
462        }
463        self.isFirstLoading = false;
464    },
465
466    openPodcastLayer: function (itemId) {
467        var card = $('.card-img[data-item-id="' + itemId + '"]');
468        var podcastLayerTemplate = $('#podcast-layer-template').html();
469
470        var podcastLayer = Mustache.render(podcastLayerTemplate, {
471            Title: $(card).data('title'),
472            Subtitle: $(card).data('subtitle'),
473            Text: $(card).data('text'),
474            DetailLink: $(card).data('detail-lin'),
475            DetailLinkTarget: $(card).data('detail-lin-target'),
476            DetailName: $(card).data('detail-lin-name'),
477            ShareUrl: $(card).data('share-url'),
478            Id: itemId,
479            PodcastUrl: $(card).data('podcast-url'),
480            MediaUrl: $(card).data('media-url'),
481            ShareText: ml('share_film_layer'),
482            CopyTitleText: ml('copy_podcast_layer'),
483            ClosePodcastLayer: ml('close_podcast_layer'),
484            LinkCopiedText: ml('link_copied_text')
485        });
486
487
488
489        centerPodcastLayer2();
490        $(window).resize(centerPodcastLayer2);
491
492
493        var scrollTopPosition = 0;
494        $(window).scroll(function () {
495            scrollTopPosition = $(this).scrollTop();
496        });
497
498        function centerPodcastLayer2() {
499            window_height = $(window).height();
500            view_height = window_height - 112;
501
502            setTimeout(function () {
503
504                podcast_layer_inner_height = $(".podcast-layer__inner").height();
505                offestTop = Math.round((window_height - podcast_layer_inner_height) / 2);
506
507
508                if (offestTop < 112) {
509                    $('.podcast-layer__inner').css({
510                        'top': '112px',
511                        'transform': 'translate(-50%, 0)'
512                    });
513                } else {
514                    $('.podcast-layer__inner').css({
515                        'top': '50%',
516                        'transform': 'translate(-50%, -50%)'
517                    });
518                }
519            }, 50);
520        }
521
522
523        //centerPodcastLayer();
524        //$(window).resize(centerPodcastLayer);
525
526
527//        function centerPodcastLayer() {
528//            topPosition = scrollTopPosition + Math.round(($(window).height() - (620 + $('.podcast-layer-info').height())) / 2);
529//
530//            if (Math.round(($(window).height() < 1050))) {
531//                topPosition = scrollTopPosition + $('.site-header').height();
532//                console.log("ja");
533//
534//            }
535//            $('.podcast-layer__inner').css({
536//                //top: Math.round(($(window).height() - ( $('.film-layer__inner').height() + $('.film-layer
536-info').height())) / 2),
537//                top: topPosition
538//
539//            });
540//            $('.podcast-layer__inner').addClass("no_transform");
541////            console.log("window-height: " + $(window).height());
542////             console.log( "film-layer__inner: " + $('.film-layer__inner').height() );
543////             console.log( "film-layer-info: " + $('.film-layer-info').height() );
544//        }
545
546        console.log(podcastLayer);
547        $(podcastLayer).hide().appendTo('body').fadeIn(400);
548
549        var podcastPlayer = videojs('#podcast-layer-' + itemId, {autoplay: true});
550
551        $('.podcast-layer .podcast-layer__video-close').unbind('click').on('click', function (e) {
552            podcastPlayer.dispose();
553            $('.podcast-layer').remove();
554
555            $('.bg-cover-page').fadeOut(400);
556        });
557
558        podcastPlayer.one('play', function () {
559            doxStatisticRegisterApplicationsFileDownload($(card).data('podcast-file-id'));
560        });
561
562        var copyToClipboard = function (element) {
563
564            var $temp = $("<input>");
565
566            $("body").append($temp);
567            $temp.val($(element).text()).select();
568            document.execCommand("copy");
569            $temp.remove();
570        };
571
572        $('button#copy-link-podcast').unbind('click').on('click', function () {
573            $('.link-copied').css('display', 'block');
574            $('#share-url').select();
575            document.execCommand("copy");
576            $('#share-url').css('display', 'block');
577
578            setTimeout(function () {
579                $('.link-copied').fadeOut(500);
580            }, 2000);
581
582        });
583    }
584};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.