Class ::cookieconsent::CookieConsent (public)
::nx::Class ::cookieconsent::CookieConsent
Defined in packages/cookie-consent/tcl/cookie-consent-procs.tcl
Create the Class for configuring the cookie consent widget. This class requires nx from the next-scripting framework. https://next-scripting.org/xowiki/ which is automatically installed for XOTcl2 via https://openacs.org/xowiki/naviserver-openacs
- Testcases:
- No testcase defined.
Source code: :property {position pushdown};# bottom|top|pushdown|left|right :property {layout block} ;# block|classic|edgeless|wire :property {palette default} ;# default|oacs|honeybee|mono|neon|corporate :property {learn-more-link https://cookiesandyou.com/} :property {default-palette {popup {text #fff background #004570} button {text #000 background #f1d600}}} :property {expiryDays:integer 365} :property {compliance-type inform} ;# inform|opt-out|opt-in :property {message-text "#cookie-consent.message#"} :property {dismiss-button-text "#cookie-consent.dismiss-button-text#"} :property {policy-link-text "#cookie-consent.policy-link-text#"} :property {subsite_id:required} :public method render_js {} { # # Perform the actual rendering of the cookie consent widget. # set static false if {${:position} eq "pushdown"} { set position top set static true } elseif {${:position} in {"left" "right"}} { set position bottom-${:position} } else { set position ${:position} } # # Set up a dictionary for the palette with common # settings: # set d {popup {text #fff} button {text #000}} # # Update the default palette based on the value of the # passed-in palette. # switch ${:palette} { oacs { dict set d popup background \#004570 dict set d button background \#f1d600 } honeybee { dict set d popup background \#000 dict set d button background \#f1d600 } mono { dict set d popup background \#237afc dict set d button background transparent dict set d button text \#fff dict set d button border \#fff } neon { dict set d popup background \#1d8a8a dict set d button background \#62ffaa } corporate { dict set d popup background \#edeff5 dict set d popup text \#838391 dict set d button background \#4b81e8 } default { set d ${:default-palette} } } # # We have to juggle the colors depending on the layout # set buttonBackground [dict get $d button background] set buttonTextColor [dict get $d button text] if {[dict exists $d button border]} { set buttonBorder [dict get $d button border] } else { set buttonBorder $buttonBackground } switch ${:layout} { block - classic - edgeless {set theme ${:layout}} wire { set theme block set buttonBackground transparent set buttonTextColor [dict get $d button background] } } # # Use different cookies dependent on the subsite # set cookie_name "cookieconsent_status-${:subsite_id}" set js [subst { window.addEventListener("load", function(){ window.cookieconsent.initialise({ "palette": { "popup": { "background": "[dict get $d popup background]", "text": "[dict get $d popup text]", }, "button": { "background": "$buttonBackground", "border": "$buttonBorder", "text": "$buttonTextColor" } }, "cookie": { "name": "$cookie_name", "path": "/", "domain": "", "samesite": "lax", "expiryDays": "${:expiryDays}" }, "theme": "$theme", "position": "$position", "static": $static, "content": { "message": "[lang::util::localize ${:message-text}]", "dismiss": "[lang::util::localize ${:dismiss-button-text}]", "link": "[lang::util::localize ${:policy-link-text}]", "href": "${:learn-more-link}", "header": "Cookies used on the website!", "deny": "Decline", "allow": "Allow cookies" } })}); }] return $js }XQL Not present: Generic, PostgreSQL, Oracle