PageSourceSearch

https://huisartsenpostenoostbrabant.nl/wp-content/themes/hap-base/assets/js/notices.js

js huisartsenpostenoostbrabant.nl collected 2026-10-04 21:54:27 UTC 4,692 bytes, 160 lines download raw bytes

1/**
2 * Notice Banner System
3 * Checks for active notices every minute and updates the display
4 */
5
6(function($) {
7    'use strict';
8
9    let noticeCheckInterval;
10    const NOTICE_CONTAINER_ID = 'notice-container';
11    const CHECK_INTERVAL = 60000; // 1 minute in milliseconds
12
13    /**
14     * Initialize the notice system
15     */
16    function initNoticeSystem() {
17        // Check notices immediately
18        checkNotices();
19
20        // Set up interval to check every minute
21        noticeCheckInterval = setInterval(checkNotices, CHECK_INTERVAL);
22    }
23
24    /**
25     * Check for active notices via REST API
26     */
27    function checkNotices() {
28        $.ajax({
29            url: hapBase.restUrl + 'hap-base/v1/notices',
30            type: 'GET',
31            dataType: 'json',
32            success: function(response) {
33                updateNoticeDisplay(response);
34            },
35            error: function(xhr, status, error) {
36                console.error('Error fetching notices:', error);
37            }
38        });
39    }
40
41    /**
42     * Update the notice display based on API response
43     */
44    function updateNoticeDisplay(response) {
45        const container = $('#' + NOTICE_CONTAINER_ID);
46        
47        if (container.length) {
48            if (response.count > 0 && response.html) {
49                // Show notices
50                container.html(response.html).show();
51                
52                // Initialize accordion functionality for new notices
53                initAccordion();
54            } else {
55                // Hide notices
56                container.hide();
57            }
58        }
59    }
60
61    /**
62     * Initialize accordion functionality for notices
63     */
64    function initAccordion() {
65        $('#' + NOTICE_CONTAINER_ID + ' .accordion__button').off('click').on('click', function() {
66            const button = $(this);
67            const content = button.siblings('.message__more');
68            const noticeId = button.closest('.message').data('notice-id') || button.closest('.message').index();
69            
70            if (content.is(':hidden')) {
71                content.show();
72                button.addClass('accordion__button--open');
73                // Save open state
74                saveAccordionState(noticeId, true);
75            } else {
76                content.hide();
77                button.removeClass('accordion__button--open');
78                // Save closed state
79                saveAccordionState(noticeId, false);
80            }
81        });
82        
83        // Restore accordion states
84        restoreAccordionStates();
85    }
86
87    /**
88     * Save accordion state to localStorage
89     */
90    function saveAccordionState(noticeId, isOpen) {
91        const states = getAccordionStates();
92        states[noticeId] = isOpen;
93        localStorage.setItem('hap_notice_accordion_states', JSON.stringify(states));
94    }
95
96    /**
97     * Get accordion states from localStorage
98     */
99    function getAccordionStates() {
100        const states = localStorage.getItem('hap_notice_accordion_states');
101        return states ? JSON.parse(states) : {};
102    }
103
104    /**
105     * Restore accordion states from localStorage
106     */
107    function restoreAccordionStates() {
108        const states = getAccordionStates();
109        
110        $('#' + NOTICE_CONTAINER_ID + ' .message').each(function(index) {
111            const message = $(this);
112            const noticeId = message.data('notice-id') || index;
113            const button = message.find('.accordion__button');
114            const content = message.find('.message__more');
115            const icon = button.find('.accordion__icon');
116            
117            if (states[noticeId] === true) {
118                content.show();
119                button.addClass('accordion__button--active accordion__button--open');
120                if (icon.length) {
121                    icon.addClass('accordion__icon--active');
122                }
123            }
124        });
125    }
126
127    /**
128     * Stop the notice checking interval
129     */
130    function stopNoticeChecking() {
131        if (noticeCheckInterval) {
132            clearInterval(noticeCheckInterval);
133        }
134    }
135
136    /**
137     * Manual check for notices (can be called from outside)
138     */
139    function manualCheckNotices() {
140        checkNotices();
141    }
142
143    // Initialize when document is ready
144    $(document).ready(function() {
145        initNoticeSystem();
146    });
147
148    // Clean up on page unload
149    $(window).on('beforeunload', function() {
150        stopNoticeChecking();
151    });
152
153    // Expose functions globally if needed
154    window.hapNotices = {
155        check: manualCheckNotices,
156        stop: stopNoticeChecking,
157        init: initNoticeSystem
158    };
159
160})(jQuery);

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.