Class ::cookieconsent::CookieConsent

::cookieconsent::CookieConsent[i] create ... \
           [ -compliance-type (default "inform") ] \
           [ -default-palette (default "popup {text #fff background #004570} button {text #000 background #f1d600}") ] \
           [ -dismiss-button-text (default "#cookie-consent.dismiss-button-text#") ] \
           [ -expiryDays:integer (default "365") ] \
           [ -layout (default "block") ] \
           [ -learn-more-link (default "https://cookiesandyou.com/") ] \
           [ -message-text (default "#cookie-consent.message#") ] \
           [ -palette (default "default") ] \
           [ -policy-link-text (default "#cookie-consent.policy-link-text#") ] \
           [ -position (default "pushdown") ] \
           [ -subsite_id:required subsite_id:required ]

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
Defined in packages/cookie-consent/tcl/cookie-consent-procs.tcl

Class Relations

  • class: ::nx::Class[i]
  • superclass: ::nx::Object[i]
::nx::Class create ::cookieconsent::CookieConsent \
     -superclass ::nx::Object

Methods (to be applied on instances)

  • render_js (scripted, public)

     <instance of cookieconsent::CookieConsent[i]> render_js

    Perform the actual rendering of the cookie consent widget.

    Partial Call Graph (max 5 caller/called nodes):
    %3 test_cookie_consent__setup cookie_consent__setup (test cookie-consent) cookieconsent::CookieConsent instproc render_js cookieconsent::CookieConsent instproc render_js test_cookie_consent__setup->cookieconsent::CookieConsent instproc render_js test_create_form_with_form_instance create_form_with_form_instance (test xowiki) test_create_form_with_form_instance->cookieconsent::CookieConsent instproc render_js lang::util::localize lang::util::localize (public) cookieconsent::CookieConsent instproc render_js->lang::util::localize

    Testcases:
    cookie_consent__setup, create_form_with_form_instance
    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