Class ::cookieconsent::CookieConsent

::cookieconsent::CookieConsent[i] create ... \
           [ -class class ] \
           [ -filters filters ] \
           [ -mixins mixins ] \
           [ -object-filters object-filters ] \
           [ -object-mixins object-mixins ] \
           [ -superclasses superclasses ]

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)

    ::cookieconsent::CookieConsent 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":     "",
                                "expiryDays""365"
                            },
                            "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
            }