PageSourceSearch

https://staatstheater-hannover.de/media/scripts/dynamic_accordion.js

js staatstheater-hannover.de collected 2026-09-24 09:42:51 UTC 15,826 bytes, 430 lines download raw bytes

1$(document).ready(function () {
2
3    //auto scroll to an open accrdion with delay
4    var accordionHash = window.location.hash;
5    if ($('.dynamic-accordion .accordion-button[data-bs-target="' + accordionHash + '"]').length !== 0) {
6        $('.dynamic-accordion .accordion-button[data-bs-target="' + accordionHash + '"]').click();
7
8        setTimeout(function () {
9
10            var button_offset_top = $('.dynamic-accordion .accordion-button[data-bs-target="' + accordionHash + '"]').offset().top;
11
12            $('html,body').animate({
13                scrollTop: button_offset_top - 70
14            }, 300);
15
16        }, 500);
17    }
18
19    // END
20
21    var accordionType = '';
22    if ($('body').hasClass('page-programm') && $('body').find('.accordion-single').length > 0) {
23        console.log('accordion prigramm detail');
24        accordionType = 'normal';
25        
26        
27        $(".accordion-button").on("click", function () {
28            console.log("Click accordion - function 1");
29
30            $(this).removeClass('collapsed');
31            $(this).closest('.accordion-item').find('.accordion-collapse').collapse('toggle');
32
33            $('html,body').animate({
34                scrollTop: $(this).offset().top - 70
35            }, 300);
36        });
37    }
38
39
40    if (($('body').hasClass('page-dynamic') || $('#accordionEnsemble').length !== 0)
41            && $('body').find('.accordion-single').length > 0) {
42        console.log('accordion Initialized');
43
44        var ignoreDynamicAccordionHash = false;
45
46        function handleDynamicAccordionHash() {
47            if (location.hash !== null && location.hash !== "") {
48
49                var elementId = location.hash + ".collapse";
50                console.log(elementId);
51                $(elementId).collapse("show");
52            }
53        }
54
55        $('.collapse:not(.sub_menu)').on('shown.bs.collapse', function (e) {
56            console.log("Click accordion - function 6");
57                    
58            var $card = $(this).closest('.accordion-item');
59            var $open = $($(this).data('parent')).find('.collapse.show');
60            ignoreDynamicAccordionHash = true;
61            location.hash = $(this).attr('id');
62
63            var additionalOffset = 0;
64            if ($card.prevAll().filter($open.closest('.accordion-item')).length !== 0)
65            {
66                additionalOffset = $open.height();
67            }
68
69            var header_height = $('.site-header').outerHeight();
70            $('html,body').animate({
71                scrollTop: $card.offset().top - 60
72            }, 300);
73        });
74
75        $('.collapse').on('hide.bs.collapse', function (e) {
76            ignoreDynamicAccordionHash = true;
77            var scrollPosition = $(window).scrollTop();
78            location.hash = '';
79            $(window).scrollTop(scrollPosition);
80        });
81
82        window.onhashchange = function (e) {
83            if (ignoreDynamicAccordionHash === false) {
84                handleDynamicAccordionHash();
85            }
86            ignoreDynamicAccordionHash = false;
87        };
88        console.log('####### NORMAL ACCORDION #####');
89        handleDynamicAccordionHash();
90
91
92        $(".accordion-button").on("click", function () {
93            console.log("Click accordion - function 2");
94
95//            $(this).removeClass('collapsed');
96//            $(this).closest('.accordion-item').find('.accordion-collapse').collapse('toggle');
97
98//            $('html,body').animate({
99//                scrollTop: $(this).offset().top - 60
100//            }, 300);
101
102            //hide image and show it, after click on accordion button to prevent image moving
103            var accordion_element = $(this).parents().find(".accordion-collapse");
104            var item = $(this).parents().find(".accordion-collapse .media-container-type-accordion-article");
105
106            if (accordion_element.hasClass("show")) {
107                item.removeClass("show_container");
108            } else {
109                setTimeout(function () {
110                    item.addClass("show_container");
111                }, 600);
112            }
113        });
114
115        //hide image and show it, after laoding page with open accordion to prevent image moving
116        setTimeout(function () {
117            $(".accordion-collapse.show .media-container-type-accordion-article").addClass("show_container");
118        }, 600);
119        
120    }
121
122    // ###### DOUBLE ACCORDION/ NESTED ACCORDIONS 
123    if ($('body').hasClass('page-dynamic') && $('body').find('.accordion-double').length > 0) {
124        console.log("accordion-double Initialized");
125        accordionType = 'double';
126
127        //margin top of lvl 3, if lvl 2 accordion butto has more than one line
128        function marginTopAccordion() {
129            $(".double_accordion_header_double_lvl_2").each(function (index) {
130                var h3_butto_height = $(this).find(".accordion_button_double_lvl_2").height();
131
132                var margin_top = h3_butto_height + 52;
133                margin_top = margin_top * -1;
134
135                if (h3_butto_height > 50) {
136
137                    if ($(window).width() >= 1024) {
138                        $(this).find(".accordion_body_double_lvl_3 .nested-accordion").css("margin-top", margin_top);
139                    } else {
140                        $(this).find(".accordion_body_double_lvl_3 .nested-accordion").css("margin-top", "inherit");
141                    }
142                }
143            });
144        }
145
146        marginTopAccordion();
147
148        $(window).resize(function () {
149            setTimeout(function () {
150                marginTopAccordion();
151            }, 500);
152
153        });
154        //END - margin top of lvl 3, if lvl 2 accordion butto has more than one line
155
156
157
158        let suppressFirstLevel = false;
159        let suppressSecondLevel = false;
160        let isOtherAccOpened = false;
161        let IchBinSelberOffen = false;
162
163        let isOtherSecondAccOpened = false;
164        // To keep the main path 
165        const accordionDouble = document.querySelector('.accordion-double');
166        var mainPath = accordionDouble.getAttribute('data-url');
167        console.log('MAIN URL: ', mainPath);
168
169        // #####
170        // open ACC
171        // #####
172        $('.accordion-collapse').on('show.bs.collapse', function () {
173            const ele = $(this);
174            const id = $(this).attr('id');
175            const isNested = $(this).closest('.nested-accordion').length > 0;
176
177            if (isNested) {
178                // Second-level accordion opened
179                suppressFirstLevel = true;
180                console.log('#### Second level opened:', id);
181                location.hash = `#${id}`;
182
183                if ($(".SelfSecondAccordionOpened").length > 0) {
184                    isOtherSecondAccOpened = true;
185                    ele.addClass("isOtherSecondAccOpened");
186                    $(".accordion-collapse").removeClass("SelfSecondAccordionOpened");
187                    ele.addClass("SelfSecondAccordionOpened");
188
189                } else {
190                    ele.addClass("SelfSecondAccordionOpened");
191                }
192
193            } else {
194                if (suppressFirstLevel) {
195                    suppressFirstLevel = false;
196                    return;
197                }
198
199                const pathParts = window.location.pathname.split('/');
200                pathParts[pathParts.length - 1] = id;
201                const newPath = pathParts.join('/');
202
203                const fullUrl = newPath + location.hash;
204                history.replaceState(null, '', fullUrl);
205
206                if ($(".IchBinSelberOffen").length > 0) {
207                    isOtherAccOpened = true;
208                    ele.addClass("isOtherAccOpened");
209                    $(".accordion-collapse").removeClass("IchBinSelberOffen");
210                    ele.addClass("IchBinSelberOffen");
211
212                } else {
213                    ele.addClass("IchBinSelberOffen");
214                }
215
216                console.log({1: "Open", isOtherAccOpened});
217            }
218        });
219
220        // #####
221        // close ACC
222        // #####
223
224        $('.accordion-collapse').on('hide.bs.collapse', function () {
225            const ele = $(this);
226            const id = $(this).attr('id');
227            const isNested = $(this).closest('.nested-accordion').length > 0;
228
229            if (isNested) {
230                // Second-level accordion closed — remove hash if it matches                
231                suppressSecondLevel = true;
232
233                if (ele.hasClass("SelfSecondAccordionOpened") && ele.hasClass("show")) {
234
235                    history.replaceState(null, '', window.location.pathname);
236                    console.log({3: "Close mit Hash", isOtherSecondAccOpened});
237
238                    // oeffnen eines anderen Acc
239                } else if (ele.hasClass("SelfSecondAccordionOpened") && isOtherSecondAccOpened) {
240
241                    ele.removeClass("isOtherSecondAccOpened");
242                    ele.removeClass("show");
243
244                    console.log({2: "Close remove show", isOtherSecondAccOpened});
245                }
246
247            } else {
248
249                // First-level accordion closed — reset to base page
250                if (suppressSecondLevel) {
251                    suppressSecondLevel = false;
252                    return;
253                }
254
255                // schließen des aktiven ACC
256                if (ele.hasClass("IchBinSelberOffen") && ele.hasClass("show")) {
257
258                    const pathParts = window.location.pathname.split('/');
259                    pathParts[pathParts.length - 1] = mainPath;
260                    const basePath = pathParts.join('/');
261                    history.replaceState(null, '', basePath);
262                    ele.removeClass("IchBinSelberOffen");
263
264                    console.log({3: "Close mit Hash", isOtherAccOpened});
265
266                    // oeffnen eines anderen Acc
267                } else if (ele.hasClass("IchBinSelberOffen") && isOtherAccOpened) {
268
269                    ele.removeClass("isOtherAccOpened");
270                    ele.removeClass("show");
271
272                    console.log({2: "Close remove show", isOtherAccOpened});
273                }
274
275                //close child acc if parent acc is closing
276                const collapsibleEls = this.querySelectorAll('.nested-accordion .collapse.show');
277                collapsibleEls.forEach(el => {
278                    el.classList.remove('show');
279                });
280
281                console.log("### querySelectorAll");
282            }
283
284        });
285
286        // Restore state on page load
287        const pathParts = window.location.pathname.split('/');
288        const firstLevel = pathParts[pathParts.length - 1];
289        const secondLevel = window.location.hash.substring(1);
290
291
292        //LGO: auskommentiert, weil es auf /abo-vorteile einen fehler erzeugte, warum auch immer...
293//        if (firstLevel && firstLevel !== mainPath) {
294//            $(`#${firstLevel}`).collapse('show');
295//        }
296//
297        if (secondLevel) {
298            $(`#${secondLevel}`).collapse('show');
299        }
300
301
302
303        $(".nested-accordion .accordion-button").click(function () {
304            console.log("Click accordion - function 3");
305
306            //$(this).removeClass('collapsed');
307            //$(this).closest('.accordion-item').find('.accordion-collapse').collapse('toggle');
308
309            $(this).parent().parent().find(".accordion-collapse").removeClass("show");
310
311
312            //hide image and show it, after click on accordion button to prevent image moving
313            var accordion_element = $(this).parents().find(".accordion-collapse");
314            var item = $(this).parents().find(".accordion-collapse");
315
316            if (accordion_element.hasClass("show")) {
317                item.removeClass("show_container");
318            } else {
319                setTimeout(function () {
320                    item.addClass("show_container");
321                }, 2000);
322            }
323            var button_offset_top = $(this).offset().top;
324
325            setTimeout(function () {
326
327                $('html,body').animate({
328                    scrollTop: button_offset_top - 60
329                }, 300);
330
331            }, 400);
332
333
334        });
335
336
337        //hide image and show it, after laoding page with open accordion to prevent image moving
338        setTimeout(function () {
339            $(".accordion-collapse.show .media-container-type-accordion-article").addClass("show_container");
340        }, 1200);
341    }
342
343    // Documents secure upload
344    $.each($('.article-documents-upload input'), function (index, inputField) {
345        if (inputField) {
346            $('.delete-form-btn-' + $(inputField).val()).on('click', function () {
347                var data = {
348                    m: 'delete_document',
349                    document_id: $(inputField).val()
350                };
351
352                CbUx.showLoader();
353                $.get(ENV.link_root + '/page.json?' + jQuery.param(data), null, function (response) {
354                    location.reload();
355                    CbUx.hideLoader();
356                });
357            });
358        }
359    });
360
361    // #### ACCORDION SEARCH By Tags- Opened accordions style
362
363    $("#accordion-filter .btn-filter").on("click", function () {
364        const filterValue = $(this).data("filter");
365        if (typeof filterValue === "undefined") {
366            console.error("filterValue is undefined. Ensure the data-filter attribute is set.");
367            return;
368        }
369
370        loadAccordion(filterValue);
371    });
372
373    if ($('body').hasClass('page-dynamic') && $('body').find('.accordion-search-tags').length > 0) {
374
375        const params = new URLSearchParams(window.location.search);
376        const keyword = params.get('keyword') || 'all';
377        loadAccordion(keyword);
378    }
379
380    function loadAccordion(keyword) {
381        var currentParams = new URLSearchParams(window.location.search);
382        currentParams.set('keyword', keyword);
383        var url = location.pathname + '?' + currentParams.toString();
384        console.log('##### current url: ', url);
385        history.pushState('', document.title, url);
386        // 
387        var accordionIds = [];
388        const accordions = document.querySelectorAll('.test-dyn-acc-open-article');
389        accordions.forEach((accordion) => {
390            document.getElementById(accordion.id).hidden = false;
391
392            const accordionId = accordion.id.replace(/\D+/g, '');
393            accordionIds.push(parseInt(accordionId, 10)); // cast the string to number 
394        });
395
396        $.ajax({
397            'url': ENV.link_root + '/accordion.json',
398            'data': {
399                'm': 'accordion_search_tags',
400                'accordion_ids': accordionIds,
401                'keyword': keyword,
402                'accordion_type': accordionType
403            }
404        })
405                .done(function (data) {
406                    CbUx.hideLoader();
407                    console.log("API Response:", data); // Debug log
408
409                    if (!$.isEmptyObject(data) && keyword !== 'all') {
410                        console.log('##### Results found', data);
411                        data.forEach((page) => {
412                            var pageId = "acc-search-" + page.PageId;
413                            console.log('### Page Id: ', pageId);
414                            document.getElementById(pageId).hidden = true;
415                        });
416                    } else {
417                        console.log("No results found!!!");
418                    }
419
420                })
421                .fail(function (xhr, status, error) {
422                    CbUx.hideLoader();
423                    self.isLoading = false;
424                    console.error("Failed to load calendar data:", status, error);
425                    console.error("Response:", xhr.responseText);
426                });
427    }
428    // #### END ACCORDION SEARCH By Tags- Opened accordions style
429
430});

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.