# wt-security/2.2.2/htdocs/js/main.js

WebTotem Security, version 2.2.2. 260 lines.

- Page: https://pluginprobe.com/plugins/wt-security/2.2.2/code/htdocs/js/main.js
- Raw: https://pluginprobe.com/plugins/wt-security/2.2.2/raw/htdocs/js/main.js
- Modified: 2020-10-06T09:33:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wt-security/2.2.2/code/htdocs/js/main.js#L10-L20`.

```javascript
// Гамбургер (адаптивное меню)
const burgerEl = document.querySelector(".wtotem_burger");
const menuEl = document.querySelector(".wtotem_nav");
const bodyEl = document.getElementsByTagName("body")[0];

burgerEl.addEventListener("click", () => {
    burgerEl.classList.toggle("active");
    menuEl.classList.toggle("active");
    // Добавляет body overflow hidden при открытой менюшки
    bodyEl.classList.toggle("lock");
});
function removeAlert() {
    var alertNode = document.getElementById('wtotem_alert');

    if (alertNode) {
        alertNode.parentNode.removeChild(alertNode);
    }
}

function tlite(t){document.addEventListener("mouseover",function(e){var i=e.target,n=t(i);n||(n=(i=i.parentElement)&&t(i)),n&&tlite.show(i,n,!0)})}tlite.show=function(t,e,i){var n="data-tlite";e=e||{},(t.tooltip||function(t,e){function o(){tlite.hide(t,!0)}function l(){r||(r=function(t,e,i){function n(){o.className="tlite tlite-"+r+s;var e=t.offsetTop,i=t.offsetLeft;o.offsetParent===t&&(e=i=0);var n=t.offsetWidth,l=t.offsetHeight,d=o.offsetHeight,f=o.offsetWidth,a=i+n/2;o.style.top=("s"===r?e-d-10:"n"===r?e+l+10:e+l/2-d/2)+"px",o.style.left=("w"===s?i:"e"===s?i+n-f:"w"===r?i+n+10:"e"===r?i-f-10:a-f/2)+"px"}var o=document.createElement("span"),l=i.grav||t.getAttribute("data-tlite")||"n";o.innerHTML=e,t.appendChild(o);var r=l[0]||"",s=l[1]||"";n();var d=o.getBoundingClientRect();return"s"===r&&d.top<0?(r="n",n()):"n"===r&&d.bottom>window.innerHeight?(r="s",n()):"e"===r&&d.left<0?(r="w",n()):"w"===r&&d.right>window.innerWidth&&(r="e",n()),o.className+=" tlite-visible",o}(t,d,e))}var r,s,d;return t.addEventListener("mousedown",o),t.addEventListener("mouseleave",o),t.tooltip={show:function(){d=t.title||t.getAttribute(n)||d,t.title="",t.setAttribute(n,""),d&&!s&&(s=setTimeout(l,i?150:1))},hide:function(t){if(i===t){s=clearTimeout(s);var e=r&&r.parentNode;e&&e.removeChild(r),r=void 0}}}}(t,e)).show()},tlite.hide=function(t,e){t.tooltip&&t.tooltip.hide(e)},"undefined"!=typeof module&&module.exports&&(module.exports=tlite);

window.onload = function() {
    // init tooltip with class js--tooltip
    tlite(el => {
        return {
            el: el.classList.contains('js--tooltip'), grav: 'sw',
        }
    });
};


async function attacksMap() {


    var labels = waf_attacksMap['countries'];
    new Chart(document.getElementById("firewall"), {
        type: "horizontalBar",

        data: {
            labels: labels,
            datasets: [
                {
                    backgroundColor: "#3D50DF",
                    data: waf_attacksMap['attacks'],
                },
            ],
        },
        options: {
            cornerRadius: 3,
            maintainAspectRatio: false,
            scales: {
                yAxes: [
                    {
                        barPercentage: 0.6,
                        stacked: true,
                        gridLines: {
                            display: true,
                        },
                    },
                ],
                xAxes: [
                    {
                        gridLines: {
                            display: false,
                        },
                    },
                ],
            },
            legend: {
                display: false,
            },
        },
    });

    const fill = (country) => {
        svg._groups[0][0].childNodes[0].childNodes.forEach((e) => {
            if (e.__data__.properties.name === country) {
                d3.select(e).style("fill", "#3D50DF");
            }
        });
    };
// The svg
    var svg = d3.select("#firewallMap"),
        width = +svg.attr("width"),
        height = +svg.attr("height");

// Map and projection
    var path = d3.geoPath();
    var projection = d3
        .geoMercator()
        .scale(60)
        .center([0, 0])
        .translate([210, 220]);

// Load external data and boot
    d3.queue().defer(d3.json, map_json).await(ready);

    function ready(error, topo) {

        // Draw the map
        svg.append("g")
            .selectAll("path")
            .data(topo.features)
            .enter()
            .append("path")
            // draw each country
            .attr("d", d3.geoPath().projection(projection))
            // set the color of each country
            .attr("fill", function () {
                return "#5E6977";
            })
            .style("stroke", "transparent")
            .attr("class", function () {
                return "Country";
            });
        labels.map((e) => {
            fill(e);
        });
    }


    Chart.elements.Rectangle.prototype.draw = function () {
        function t(t) {
            return s[(f + t) % 4];
        }
        var r,
            e,
            i,
            o,
            _,
            h,
            l,
            a,
            b = this._chart.ctx,
            d = this._view,
            n = d.borderWidth,
            u = this._chart.config.options.cornerRadius;
        if (
            (u < 0 && (u = 0),
            void 0 === u && (u = 0),
                d.horizontal
                    ? ((r = d.base),
                        (e = d.x),
                        (i = d.y - d.height / 2),
                        (o = d.y + d.height / 2),
                        (_ = e > r ? 1 : -1),
                        (h = 1),
                        (l = d.borderSkipped || "left"))
                    : ((r = d.x - d.width / 2),
                        (e = d.x + d.width / 2),
                        (i = d.y),
                        (_ = 1),
                        (h = (o = d.base) > i ? 1 : -1),
                        (l = d.borderSkipped || "bottom")),
                n)
        ) {
            var T = Math.min(Math.abs(r - e), Math.abs(i - o)),
                v = (n = n > T ? T : n) / 2,
                g = r + ("left" !== l ? v * _ : 0),
                c = e + ("right" !== l ? -v * _ : 0),
                C = i + ("top" !== l ? v * h : 0),
                w = o + ("bottom" !== l ? -v * h : 0);
            g !== c && ((i = C), (o = w)),
            C !== w && ((r = g), (e = c));
        }
        b.beginPath(),
            (b.fillStyle = d.backgroundColor),
            (b.strokeStyle = d.borderColor),
            (b.lineWidth = n);
        var s = [
                [r, o],
                [r, i],
                [e, i],
                [e, o],
            ],
            f = ["bottom", "left", "top", "right"].indexOf(l, 0);
        -1 === f && (f = 0);
        var q = t(0);
        b.moveTo(q[0], q[1]);
        for (var m = 1; m < 4; m++)
            (q = t(m)),
                (nextCornerId = m + 1),
            4 == nextCornerId && (nextCornerId = 0),
                (nextCorner = t(nextCornerId)),
                (width = s[2][0] - s[1][0]),
                (height = s[0][1] - s[1][1]),
                (x = s[1][0]),
                (y = s[1][1]),
            (a = u) > Math.abs(height) / 2 &&
            (a = Math.floor(Math.abs(height) / 2)),
            a > Math.abs(width) / 2 &&
            (a = Math.floor(Math.abs(width) / 2)),
                height < 0
                    ? ((x_tl = x),
                        (x_tr = x + width),
                        (y_tl = y + height),
                        (y_tr = y + height),
                        (x_bl = x),
                        (x_br = x + width),
                        (y_bl = y),
                        (y_br = y),
                        b.moveTo(x_bl + a, y_bl),
                        b.lineTo(x_br - a, y_br),
                        b.quadraticCurveTo(x_br, y_br, x_br, y_br - a),
                        b.lineTo(x_tr, y_tr + a),
                        b.quadraticCurveTo(x_tr, y_tr, x_tr - a, y_tr),
                        b.lineTo(x_tl + a, y_tl),
                        b.quadraticCurveTo(x_tl, y_tl, x_tl, y_tl + a),
                        b.lineTo(x_bl, y_bl - a),
                        b.quadraticCurveTo(x_bl, y_bl, x_bl + a, y_bl))
                    : width < 0
                    ? ((x_tl = x + width),
                        (x_tr = x),
                        (y_tl = y),
                        (y_tr = y),
                        (x_bl = x + width),
                        (x_br = x),
                        (y_bl = y + height),
                        (y_br = y + height),
                        b.moveTo(x_bl + a, y_bl),
                        b.lineTo(x_br - a, y_br),
                        b.quadraticCurveTo(x_br, y_br, x_br, y_br - a),
                        b.lineTo(x_tr, y_tr + a),
                        b.quadraticCurveTo(x_tr, y_tr, x_tr - a, y_tr),
                        b.lineTo(x_tl + a, y_tl),
                        b.quadraticCurveTo(x_tl, y_tl, x_tl, y_tl + a),
                        b.lineTo(x_bl, y_bl - a),
                        b.quadraticCurveTo(x_bl, y_bl, x_bl + a, y_bl))
                    : (b.moveTo(x + a, y),
                        b.lineTo(x + width - a, y),
                        b.quadraticCurveTo(
                            x + width,
                            y,
                            x + width,
                            y + a
                        ),
                        b.lineTo(x + width, y + height - a),
                        b.quadraticCurveTo(
                            x + width,
                            y + height,
                            x + width - a,
                            y + height
                        ),
                        b.lineTo(x + a, y + height),
                        b.quadraticCurveTo(
                            x,
                            y + height,
                            x,
                            y + height - a
                        ),
                        b.lineTo(x, y + a),
                        b.quadraticCurveTo(x, y, x + a, y));
        b.fill(), n && b.stroke();
    };
}
if (typeof waf_attacksMap !== 'undefined') {
    attacksMap();
}


```
