PageSourceSearch

https://kundenportal.stadtwerke-celle.de/powercommerce/csit3/fo/po…/bootstrap.cookie-consent-settings.js

js stadtwerke-celle.de collected 2026-10-02 18:09:58 UTC 7,622 bytes, 192 lines download raw bytes

1/**
2 * Author and copyright: Stefan Haack (https://shaack.com)
3 * Repository: https://github.com/shaack/bootstrap-cookie-consent-settings
4 * License: MIT, see file 'LICENSE'
5 */
6
7const sh = {bccs: {}}
8
9function BootstrapCookieConsentSettings(props) {
10    const modalId = "bccs-modal"
11    const self = this
12    let detailedSettingsShown = false
13    this.props = {
14        autoShowDialog: true, // disable autoShowModal on the privacy policy and legal notice pages, to make these pages readable
15        contentURL: "/powercommerce/ref/fo/portal/cookieDialog",
16        cookieName: "cookie-settings",  // the name of the cookie in which the configuration is stored as JSON
17        cookieStorageDays: 365, // the duration the cookie configuration is stored on the client
18        postSelectionCallback: undefined // callback function, called after the user has made his selection
19    }
20    for (const property in props) {
21        // noinspection JSUnfilteredForInLoop
22        this.props[property] = props[property]
23    }
24        const Cookie = {
25        set: function (name, value, days) {
26            let expires = ""
27            if (days) {
28                const date = new Date()
29                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
30                expires = "; expires=" + date.toUTCString()
31            }
32            document.cookie = name + "=" + (value || "") + expires + "; Path=/; SameSite=Strict;"
33        },
34        get: function (name) {
35            const nameEQ = name + "="
36            const ca = document.cookie.split(';')
37            for (let i = 0; i < ca.length; i++) {
38                let c = ca[i]
39                while (c.charAt(0) === ' ') {
40                    c = c.substring(1, c.length)
41                }
42                if (c.indexOf(nameEQ) === 0) {
43                    return c.substring(nameEQ.length, c.length)
44                }
45            }
46            return undefined
47        }
48    }
49    const Events = {
50        documentReady: function (onDocumentReady) {
51            if (document.readyState !== 'loading') {
52                onDocumentReady()
53            } else {
54                document.addEventListener('DOMContentLoaded', onDocumentReady)
55            }
56        }
57    }
58
59    function showDialog() {
60        Events.documentReady(function () {
61            this.modal = document.getElementById(modalId)
62            if (!self.modal) {
63                self.modal = document.createElement("div")
64                self.modal.id = modalId
65                self.modal.setAttribute("class", "modal fade")
66                self.modal.setAttribute("tabindex", "-1")
67                self.modal.setAttribute("role", "dialog")
68                self.modal.setAttribute("aria-labelledby", modalId)
69                document.body.append(self.modal)
70                self.$modal = $(self.modal)
71                if (self.props.postSelectionCallback) {
72                    self.$modal.on("hidden.bs.modal", function () {
73                        self.props.postSelectionCallback()
74                    })
75                }
76                // load content
77                $.get(self.props.contentURL)
78                    .done(function (data) {
79                        self.modal.innerHTML = data
80                        $(self.modal).modal({
81                            backdrop: "static",
82                            keyboard: false
83                        })
84                        self.$buttonAgreeRequired = $("#bccs-buttonAgreeRequired")
85                        self.$buttonAgreeAll = $("#bccs-buttonAgreeAll")
86						self.$requiredHeading = $('#bccs-required-heading');
87						self.$checkboxRequired = $('#bccs-checkboxRequired');
88						self.$analysesHeading = $('#bccs-analyses-heading');
89						self.$checkboxAnalyses = $('#bccs-checkboxAnalyses');
90						
91                        updateOptionsFromCookie()
92                        $("#bccs-options").on("hide.bs.collapse", function () {
93                            detailedSettingsShown = false
94                        }).on("show.bs.collapse", function () {
95                            detailedSettingsShown = true
96                        })
97                        self.$buttonAgreeRequired.click(function () {
98                            agreeRequired()
99                        })
100                        self.$buttonAgreeAll.click(function () {
101                            agreeAll()
102                        })
103                        self.$modal.modal("show");
104						self.$checkboxAnalyses.click(function (event) {
105						});
106						self.$requiredHeading.click(function (event) {
107							if (event.target.localName != 'div')
108    							return;
109                            $('#requiredDetails').collapse('toggle');
110                        })
111						self.$analysesHeading.click(function (event) {
112							if (event.target.localName != 'div')
113    							return;
114                            $('#analysesDetails').collapse('toggle');
115                        })
116                    })
117                    .fail(function () {
118                        console.error("You probably need to set `contentURL` in the props")
119                        console.error("see documentation at https://github.com/shaack/bootstrap-cookie-banner")
120                    })
121            } else {
122				updateOptionsFromCookie()
123                self.$modal.modal("show")
124            }
125        }.bind(this))
126    }
127
128    function updateOptionsFromCookie() {
129        const settings = self.getSettings()
130        if (settings) {
131            for (let setting in settings) {
132                const $checkbox = self.$modal.find("#bccs-options .bccs-option[data-name='" + setting + "'] input[type='checkbox']")
133                // noinspection JSUnfilteredForInLoop
134                $checkbox.prop("checked", settings[setting])
135            }
136        }
137    }
138
139    function gatherOptions(required) {
140        const $options = self.$modal.find("#bccs-options .bccs-option")
141        const options = {}
142        for (let i = 0; i < $options.length; i++) {
143            const option = $options[i]
144            const name = option.getAttribute("data-name")
145            if (name === "required") {
146                options[name] = true
147            } else if (!required) {
148                options[name] = true
149            } else {
150                options[name] = false
151            }
152        }
153        return options
154    }
155
156 	function agreeRequired() {
157        Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(true)), self.props.cookieStorageDays)
158        self.$modal.modal("hide")
159    }
160
161    function agreeAll() {
162        Cookie.set(self.props.cookieName, JSON.stringify(gatherOptions(false)), self.props.cookieStorageDays)
163        self.$modal.modal("hide")
164    }
165
166    // init
167    if (Cookie.get(this.props.cookieName) === undefined && this.props.autoShowDialog) {
168        showDialog();
169    }
170
171    // API
172    this.show = function () {
173        showDialog()
174    }
175    this.getSettings = function (optionName) {
176        const cookie = Cookie.get(self.props.cookieName)
177        if (cookie) {
178            const settings = JSON.parse(Cookie.get(self.props.cookieName))
179            if (optionName === undefined) {
180                return settings
181            } else {
182                if (settings) {
183                    return settings[optionName]
184                } else {
185                    return false
186                }
187            }
188        } else {
189            return undefined
190        }
191    }
192}

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.