| 1 |
// Гамбургер (адаптивное меню) |
| 2 |
const burgerEl = document.querySelector(".wtotem_burger"); |
| 3 |
const menuEl = document.querySelector(".wtotem_nav"); |
| 4 |
const bodyEl = document.getElementsByTagName("body")[0]; |
| 5 |
|
| 6 |
burgerEl.addEventListener("click", () => { |
| 7 |
burgerEl.classList.toggle("active"); |
| 8 |
menuEl.classList.toggle("active"); |
| 9 |
// Добавляет body overflow hidden при открытой менюшки |
| 10 |
bodyEl.classList.toggle("lock"); |
| 11 |
}); |
| 12 |
function removeAlert() { |
| 13 |
var alertNode = document.getElementById('wtotem_alert'); |
| 14 |
|
| 15 |
if (alertNode) { |
| 16 |
alertNode.parentNode.removeChild(alertNode); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
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); |
| 21 |
|
| 22 |
window.onload = function() { |
| 23 |
// init tooltip with class js--tooltip |
| 24 |
tlite(el => { |
| 25 |
return { |
| 26 |
el: el.classList.contains('js--tooltip'), grav: 'sw', |
| 27 |
} |
| 28 |
}); |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
async function attacksMap() { |
| 33 |
|
| 34 |
var labels = waf_attacksMap['countries']; |
| 35 |
new Chart(document.getElementById("firewall"), { |
| 36 |
type: "horizontalBar", |
| 37 |
|
| 38 |
data: { |
| 39 |
labels: labels, |
| 40 |
datasets: [ |
| 41 |
{ |
| 42 |
backgroundColor: "#3D50DF", |
| 43 |
data: waf_attacksMap['attacks'], |
| 44 |
}, |
| 45 |
], |
| 46 |
}, |
| 47 |
options: { |
| 48 |
cornerRadius: 3, |
| 49 |
maintainAspectRatio: false, |
| 50 |
scales: { |
| 51 |
yAxes: [ |
| 52 |
{ |
| 53 |
barPercentage: 0.6, |
| 54 |
stacked: true, |
| 55 |
gridLines: { |
| 56 |
display: true, |
| 57 |
}, |
| 58 |
}, |
| 59 |
], |
| 60 |
xAxes: [ |
| 61 |
{ |
| 62 |
gridLines: { |
| 63 |
display: false, |
| 64 |
}, |
| 65 |
}, |
| 66 |
], |
| 67 |
}, |
| 68 |
legend: { |
| 69 |
display: false, |
| 70 |
}, |
| 71 |
}, |
| 72 |
}); |
| 73 |
|
| 74 |
const fill = (country) => { |
| 75 |
svg._groups[0][0].childNodes[0].childNodes.forEach((e) => { |
| 76 |
if (e.__data__.properties.name === country) { |
| 77 |
d3.select(e).style("fill", "#3D50DF"); |
| 78 |
} |
| 79 |
}); |
| 80 |
}; |
| 81 |
// The svg |
| 82 |
var svg = d3.select("#firewallMap"), |
| 83 |
width = +svg.attr("width"), |
| 84 |
height = +svg.attr("height"); |
| 85 |
|
| 86 |
// Map and projection |
| 87 |
var path = d3.geoPath(); |
| 88 |
var projection = d3 |
| 89 |
.geoMercator() |
| 90 |
.scale(60) |
| 91 |
.center([0, 0]) |
| 92 |
.translate([210, 220]); |
| 93 |
|
| 94 |
// Load external data and boot |
| 95 |
d3.queue().defer(d3.json, map_json).await(ready); |
| 96 |
|
| 97 |
function ready(error, topo) { |
| 98 |
|
| 99 |
// Draw the map |
| 100 |
svg.append("g") |
| 101 |
.selectAll("path") |
| 102 |
.data(topo.features) |
| 103 |
.enter() |
| 104 |
.append("path") |
| 105 |
// draw each country |
| 106 |
.attr("d", d3.geoPath().projection(projection)) |
| 107 |
// set the color of each country |
| 108 |
.attr("fill", function () { |
| 109 |
return "#5E6977"; |
| 110 |
}) |
| 111 |
.style("stroke", "transparent") |
| 112 |
.attr("class", function () { |
| 113 |
return "Country"; |
| 114 |
}); |
| 115 |
labels.map((e) => { |
| 116 |
fill(e); |
| 117 |
}); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
Chart.elements.Rectangle.prototype.draw = function () { |
| 122 |
function t(t) { |
| 123 |
return s[(f + t) % 4]; |
| 124 |
} |
| 125 |
var r, |
| 126 |
e, |
| 127 |
i, |
| 128 |
o, |
| 129 |
_, |
| 130 |
h, |
| 131 |
l, |
| 132 |
a, |
| 133 |
b = this._chart.ctx, |
| 134 |
d = this._view, |
| 135 |
n = d.borderWidth, |
| 136 |
u = this._chart.config.options.cornerRadius; |
| 137 |
if ( |
| 138 |
(u < 0 && (u = 0), |
| 139 |
void 0 === u && (u = 0), |
| 140 |
d.horizontal |
| 141 |
? ((r = d.base), |
| 142 |
(e = d.x), |
| 143 |
(i = d.y - d.height / 2), |
| 144 |
(o = d.y + d.height / 2), |
| 145 |
(_ = e > r ? 1 : -1), |
| 146 |
(h = 1), |
| 147 |
(l = d.borderSkipped || "left")) |
| 148 |
: ((r = d.x - d.width / 2), |
| 149 |
(e = d.x + d.width / 2), |
| 150 |
(i = d.y), |
| 151 |
(_ = 1), |
| 152 |
(h = (o = d.base) > i ? 1 : -1), |
| 153 |
(l = d.borderSkipped || "bottom")), |
| 154 |
n) |
| 155 |
) { |
| 156 |
var T = Math.min(Math.abs(r - e), Math.abs(i - o)), |
| 157 |
v = (n = n > T ? T : n) / 2, |
| 158 |
g = r + ("left" !== l ? v * _ : 0), |
| 159 |
c = e + ("right" !== l ? -v * _ : 0), |
| 160 |
C = i + ("top" !== l ? v * h : 0), |
| 161 |
w = o + ("bottom" !== l ? -v * h : 0); |
| 162 |
g !== c && ((i = C), (o = w)), |
| 163 |
C !== w && ((r = g), (e = c)); |
| 164 |
} |
| 165 |
b.beginPath(), |
| 166 |
(b.fillStyle = d.backgroundColor), |
| 167 |
(b.strokeStyle = d.borderColor), |
| 168 |
(b.lineWidth = n); |
| 169 |
var s = [ |
| 170 |
[r, o], |
| 171 |
[r, i], |
| 172 |
[e, i], |
| 173 |
[e, o], |
| 174 |
], |
| 175 |
f = ["bottom", "left", "top", "right"].indexOf(l, 0); |
| 176 |
-1 === f && (f = 0); |
| 177 |
var q = t(0); |
| 178 |
b.moveTo(q[0], q[1]); |
| 179 |
for (var m = 1; m < 4; m++) |
| 180 |
(q = t(m)), |
| 181 |
(nextCornerId = m + 1), |
| 182 |
4 == nextCornerId && (nextCornerId = 0), |
| 183 |
(nextCorner = t(nextCornerId)), |
| 184 |
(width = s[2][0] - s[1][0]), |
| 185 |
(height = s[0][1] - s[1][1]), |
| 186 |
(x = s[1][0]), |
| 187 |
(y = s[1][1]), |
| 188 |
(a = u) > Math.abs(height) / 2 && |
| 189 |
(a = Math.floor(Math.abs(height) / 2)), |
| 190 |
a > Math.abs(width) / 2 && |
| 191 |
(a = Math.floor(Math.abs(width) / 2)), |
| 192 |
height < 0 |
| 193 |
? ((x_tl = x), |
| 194 |
(x_tr = x + width), |
| 195 |
(y_tl = y + height), |
| 196 |
(y_tr = y + height), |
| 197 |
(x_bl = x), |
| 198 |
(x_br = x + width), |
| 199 |
(y_bl = y), |
| 200 |
(y_br = y), |
| 201 |
b.moveTo(x_bl + a, y_bl), |
| 202 |
b.lineTo(x_br - a, y_br), |
| 203 |
b.quadraticCurveTo(x_br, y_br, x_br, y_br - a), |
| 204 |
b.lineTo(x_tr, y_tr + a), |
| 205 |
b.quadraticCurveTo(x_tr, y_tr, x_tr - a, y_tr), |
| 206 |
b.lineTo(x_tl + a, y_tl), |
| 207 |
b.quadraticCurveTo(x_tl, y_tl, x_tl, y_tl + a), |
| 208 |
b.lineTo(x_bl, y_bl - a), |
| 209 |
b.quadraticCurveTo(x_bl, y_bl, x_bl + a, y_bl)) |
| 210 |
: width < 0 |
| 211 |
? ((x_tl = x + width), |
| 212 |
(x_tr = x), |
| 213 |
(y_tl = y), |
| 214 |
(y_tr = y), |
| 215 |
(x_bl = x + width), |
| 216 |
(x_br = x), |
| 217 |
(y_bl = y + height), |
| 218 |
(y_br = y + height), |
| 219 |
b.moveTo(x_bl + a, y_bl), |
| 220 |
b.lineTo(x_br - a, y_br), |
| 221 |
b.quadraticCurveTo(x_br, y_br, x_br, y_br - a), |
| 222 |
b.lineTo(x_tr, y_tr + a), |
| 223 |
b.quadraticCurveTo(x_tr, y_tr, x_tr - a, y_tr), |
| 224 |
b.lineTo(x_tl + a, y_tl), |
| 225 |
b.quadraticCurveTo(x_tl, y_tl, x_tl, y_tl + a), |
| 226 |
b.lineTo(x_bl, y_bl - a), |
| 227 |
b.quadraticCurveTo(x_bl, y_bl, x_bl + a, y_bl)) |
| 228 |
: (b.moveTo(x + a, y), |
| 229 |
b.lineTo(x + width - a, y), |
| 230 |
b.quadraticCurveTo( |
| 231 |
x + width, |
| 232 |
y, |
| 233 |
x + width, |
| 234 |
y + a |
| 235 |
), |
| 236 |
b.lineTo(x + width, y + height - a), |
| 237 |
b.quadraticCurveTo( |
| 238 |
x + width, |
| 239 |
y + height, |
| 240 |
x + width - a, |
| 241 |
y + height |
| 242 |
), |
| 243 |
b.lineTo(x + a, y + height), |
| 244 |
b.quadraticCurveTo( |
| 245 |
x, |
| 246 |
y + height, |
| 247 |
x, |
| 248 |
y + height - a |
| 249 |
), |
| 250 |
b.lineTo(x, y + a), |
| 251 |
b.quadraticCurveTo(x, y, x + a, y)); |
| 252 |
b.fill(), n && b.stroke(); |
| 253 |
}; |
| 254 |
} |
| 255 |
|
| 256 |
window.onload = function() { |
| 257 |
if (typeof waf_attacksMap !== 'undefined') { |
| 258 |
attacksMap(); |
| 259 |
} |
| 260 |
}; |
| 261 |
|