feat: 1.2.0 attack intelligence, replay, 30-day history and new interface
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 27s
CI / Dependency audit (push) Successful in 18s
CI / Tests (Linux, race detector) (push) Successful in 58s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 5s

Intelligence: attack families mapped to MITRE ATT&CK, network type from
ASN/rDNS without external APIs, request cadence, sessions with
recon/probe/exploit/access/banned stages, campaigns across IPs, verdict
with reasons, recommended actions, exposure detection (2xx with a body
on sensitive paths), STIX 2.1 export, FCrDNS for search engine bots,
optional Tor exit list.

Data: 30-day retention, twelve ranges plus custom from/to, an on-disk
event log (daily files, hourly gzip members, size cap, corruption and
disk-full tolerant), /events, /period, /metrics with stable per-hour
metrics, an extended /ip/{ip}, and peer /period merged on the hub.

Interface: layout system with fixed card sizes, range picker in the
URL, IP analysis page, Replay page, Geography down to state and city
(Natural Earth admin-1), Live page redesigned with stable metrics and a
reusable attack map. Demo data and documentation screenshots.

Security: bounded and deadline-limited period computations, linear
campaign clustering, singleflight caches, sanitized peer studies, event
query budgets, gzip bomb guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 21:45:59 -03:00
1 parent 8f1ac462d1
commit b7462c14fa
325 files changed
+19117 -1307

No files matched your search

+446 -109
View File
@@ -14,14 +14,29 @@
'geo.back': 'Back',
'geo.back.hint': 'Back (Esc)',
'geo.map.label': 'Map of attack origins. Use the list to choose a country.',
'geo.map.country.label': 'Map of {country} with the cities that attack the most',
'geo.lead.world': '{events} from {ips} across {countries}, in the last {range}; {top} leads with {pct}.',
'geo.lead.country': '{country} originated {events} from {ips} in the last {range}; {region} leads with {pct}.',
'geo.lead.country.flat': '{country} originated {events} from {ips} in the last {range}.',
'geo.lead.region': '{region} ({country}) originated {events} from {ips} in the last {range}; {city} leads with {pct}.',
'geo.lead.region.flat': '{region} ({country}) originated {events} from {ips} in the last {range}.',
'geo.lead.empty': 'No geolocated attacks in the last {range}.',
'geo.lead.empty.country': 'No attacks from {country} in the last {range}.',
'geo.map.country.label': 'Map of {of} with the cities that attack the most',
'geo.lead.world': '{events} from {ips} across {countries} {range}; {top} leads with {pct}.',
'geo.lead.country': '{country} originated {events} from {ips} {range}; {region} leads with {pct}.',
'geo.lead.country.flat': '{country} originated {events} from {ips} {range}.',
'geo.lead.region': '{region} ({country}) originated {events} from {ips} {range}; {city} leads with {pct}.',
'geo.lead.region.flat': '{region} ({country}) originated {events} from {ips} {range}.',
'geo.lead.empty': 'No geolocated attacks {range}.',
'geo.lead.city': '{city} ({region}, {country}) originated {events} from {ips} {range}, {pct} of {region}.',
'geo.lead.empty.region': 'No attacks from {region} ({country}) {range}.',
'geo.lead.empty.city': 'No attacks from {city}, {region} {range}.',
'geo.legend.state': 'Events per state / region (log scale)',
'geo.map.state.label': 'Map of {of} by state or region. Use the list to choose one.',
'geo.map.region.label': 'Map of {region} ({country}) with its cities',
'geo.unmapped': '{events} come from regions that are not drawn on the map.',
'geo.cities.in': 'Cities in {region}',
'geo.cats.in': 'Attack categories in {region}',
'geo.ips.city': 'Top IPs in {city}',
'geo.ips.city.none': 'None of the top IPs of this region are in this city.',
'geo.ips.city.note': 'Only the region\'s top IPs are listed.',
'geo.all_cities': 'All cities',
'geo.pick.city': 'Show IPs from {name}: {events}',
'geo.tip.nodata': 'No events in this range',
'geo.lead.empty.country': 'No attacks from {of} {range}.',
'geo.u.events.one': '{n} event', 'geo.u.events.other': '{n} events',
'geo.u.ips.one': '{n} IP', 'geo.u.ips.other': '{n} IPs',
'geo.u.countries.one': '{n} country', 'geo.u.countries.other': '{n} countries',
@@ -31,6 +46,7 @@
'geo.tip.region': 'Region',
'geo.countries': 'Countries',
'geo.regions': 'States / regions',
'geo.regions.of': 'States / regions of {of}',
'geo.cities': 'Cities',
'geo.cats': 'Attack categories',
'geo.ips': 'Top IPs',
@@ -59,14 +75,29 @@
'geo.back': 'Voltar',
'geo.back.hint': 'Voltar (Esc)',
'geo.map.label': 'Mapa das origens dos ataques. Use a lista para escolher um país.',
'geo.map.country.label': 'Mapa de {country} com as cidades que mais atacam',
'geo.lead.world': '{events} de {ips} em {countries}, nas últimas {range}; {top} lidera com {pct}.',
'geo.lead.country': '{country} originou {events} de {ips} nas últimas {range}; {region} lidera com {pct}.',
'geo.lead.country.flat': '{country} originou {events} de {ips} nas últimas {range}.',
'geo.lead.region': '{region} ({country}) originou {events} de {ips} nas últimas {range}; {city} lidera com {pct}.',
'geo.lead.region.flat': '{region} ({country}) originou {events} de {ips} nas últimas {range}.',
'geo.lead.empty': 'Nenhum ataque geolocalizado nas últimas {range}.',
'geo.lead.empty.country': 'Nenhum ataque de {country} nas últimas {range}.',
'geo.map.country.label': 'Mapa {of} com as cidades que mais atacam',
'geo.lead.world': '{events} de {ips} em {countries} {range}; {top} lidera com {pct}.',
'geo.lead.country': '{country} originou {events} de {ips} {range}; {region} lidera com {pct}.',
'geo.lead.country.flat': '{country} originou {events} de {ips} {range}.',
'geo.lead.region': '{region} ({country}) originou {events} de {ips} {range}; {city} lidera com {pct}.',
'geo.lead.region.flat': '{region} ({country}) originou {events} de {ips} {range}.',
'geo.lead.empty': 'Nenhum ataque geolocalizado {range}.',
'geo.lead.city': '{city} ({region}, {country}) originou {events} de {ips} {range}, {pct} de {region}.',
'geo.lead.empty.region': 'Nenhum ataque de {region} ({country}) {range}.',
'geo.lead.empty.city': 'Nenhum ataque de {city}, {region} {range}.',
'geo.legend.state': 'Eventos por estado / região (escala log)',
'geo.map.state.label': 'Mapa {of} por estado ou região. Use a lista para escolher um.',
'geo.map.region.label': 'Mapa de {region} ({country}) com as cidades',
'geo.unmapped': '{events} vêm de regiões que não estão desenhadas no mapa.',
'geo.cities.in': 'Cidades de {region}',
'geo.cats.in': 'Categorias de ataque em {region}',
'geo.ips.city': 'IPs que mais atacam em {city}',
'geo.ips.city.none': 'Nenhum dos IPs que mais atacam esta região está nesta cidade.',
'geo.ips.city.note': 'Só os IPs que mais atacam a região são listados.',
'geo.all_cities': 'Todas as cidades',
'geo.pick.city': 'Mostrar IPs de {name}: {events}',
'geo.tip.nodata': 'Sem eventos neste período',
'geo.lead.empty.country': 'Nenhum ataque {of} {range}.',
'geo.u.events.one': '{n} evento', 'geo.u.events.other': '{n} eventos',
'geo.u.ips.one': '{n} IP', 'geo.u.ips.other': '{n} IPs',
'geo.u.countries.one': '{n} país', 'geo.u.countries.other': '{n} países',
@@ -76,6 +107,7 @@
'geo.tip.region': 'Região',
'geo.countries': 'Países',
'geo.regions': 'Estados / regiões',
'geo.regions.of': 'Estados / regiões {of}',
'geo.cities': 'Cidades',
'geo.cats': 'Categorias de ataque',
'geo.ips': 'IPs que mais atacam',
@@ -133,11 +165,48 @@
return dn.of(cc) || cc;
} catch (e) { return cc; }
}
function regionName(r) { return r ? r : t('geo.unknown'); }
// DB-IP names stay the API key; the shown name comes from the admin-1 file in the UI language when it has one
// pt-BR: "de" contracted with the country's article ("do Brasil", "da Alemanha", "dos Estados Unidos");
// countries without an article ("de Portugal") and any other language fall back to "de <name>" / the bare name
var PT_ART = {};
[['do', 'BR CA MX JP CL EC UY PY PE GB PA SN CG GA KE NE SD TD TG YE LB IQ IR KW QA BH EG AF BT NP PK VN ZW MW LA KH AZ'],
['da', 'AR DE FR CN IN RU ES IT CO BO VE AU ZA KR KP DK NO SE FI PL UA TR GR HU RO BG CH AT IE IS NZ ID AL AM GE LT LV EE SK SI HR RS BA MK MD CZ LY DZ ET ER SO SY JO BE CD CI NG TN MY ZM DO SA CR TH'],
['dos', 'US NL AE'], ['das', 'PH BS SC MV KM']].forEach(function (g) { g[1].split(' ').forEach(function (cc) { PT_ART[cc] = g[0]; }); });
function ofCountry(cc) {
var n = countryName(cc);
if (lang !== 'pt-BR') return n;
return (PT_ART[cc] || 'de') + ' ' + n;
}
function regionName(r) {
if (!r) return t('geo.unknown');
if (A1) {
var i = a1Match(A1, r), lb = i >= 0 && A1.regions[i].label;
if (lb) return (lang === 'pt-BR' ? lb.pt : lb.en) || r;
}
return r;
}
function catLabel(c) { var k = 'geo.cat.' + c, v = t(k); return v && v !== k ? v : c; }
function catCls(c) { return CAT_CLASS[c] ? 'geo-c-' + c : 'geo-c-other'; }
function rangeLabel(r) { return t('geo.range.' + (RANGES[r] ? r : '24h')); }
// the real slice, as the shell words it ("the last 6 hours", "from 1 Nov to 5 Nov")
function rangeLabel(r) {
try { if (typeof U.rangeLabel === 'function') { var x = U.rangeLabel({ inline: true }); if (x) return x; } } catch (e) { /* fallback */ }
return t('geo.range.' + (RANGES[r] ? r : '24h'));
}
function sum(o) { var s = 0; for (var k in o) s += o[k]; return s; }
function isNum(n) { return typeof n === 'number' && isFinite(n); }
// Name matching between DB-IP region names and the admin-1 files. These two functions are the
// same as in scripts/gen-admin1.mjs (the files carry names ready for them); keep them identical.
var STOP = {};
('province provincia department departamento region regional state county district governorate municipality parish prefecture oblast oblisi kray republic city of the de del la el and autonomous canton division zone voivodeship commune raion okrug territory')
.split(' ').forEach(function (w) { STOP[w] = 1; });
function normStrict(s) {
return String(s).normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/&/g, ' and ')
.replace(/\([^)]*\)/g, ' ').replace(/['’`ʼ]/g, '').replace(/[^a-z0-9]+/g, ' ').trim();
}
function normLoose(s) {
return normStrict(s).split(' ').filter(function (w) { return w && !STOP[w]; }).join(' ');
}
// ---------------------------------------------------------------- geometry
var world = null, bboxCache = {};
@@ -176,42 +245,115 @@
return out;
}
// ---------------------------------------------------------------- admin-1 (states) files
// admin1-<cc>.json: regions with path in a local projection of the country (x=(lon-lon0)*kx,
// y=(lat1-lat)*ky). They are drawn inside a group whose transform maps them onto the world map's
// coordinates, so the page keeps a single viewBox for every level.
var a1index = null, a1files = {};
var PATH_OK = /^[MmLlZz0-9 .\-]*$/;
function fetchJSON1(url) {
return fetch(url, { credentials: 'same-origin' }).then(function (r) { return r.ok ? r.json() : null; });
}
function a1Index() {
if (!a1index) a1index = fetchJSON1('/admin1-index.json').then(function (j) {
var m = {}; ((j && j.cc) || []).forEach(function (c) { if (/^[A-Z]{2}$/.test(c)) m[c] = 1; }); return m;
}).catch(function () { return {}; });
return a1index;
}
function prepA1(a) {
if (!a || !Array.isArray(a.regions) || !a.proj || !isNum(a.proj.kx) || !isNum(a.proj.ky) || !isNum(a.proj.lon0) || !isNum(a.proj.lat1) ||
!Array.isArray(a.bbox) || !Array.isArray(a.main)) return null;
a.regions = a.regions.filter(function (r) { return r && typeof r.path === 'string' && PATH_OK.test(r.path) && Array.isArray(r.b); });
a.strict = Object.create(null); a.loose = Object.create(null); a.memo = Object.create(null);
a.regions.forEach(function (r, i) {
var names = Array.isArray(r.names) ? r.names.slice() : [];
names.push(r.name);
names.forEach(function (n) {
if (typeof n !== 'string') return;
var s = normStrict(n), l = normLoose(n);
if (s && !(s in a.strict)) a.strict[s] = i;
if (l && !(l in a.loose)) a.loose[l] = i;
});
});
return a.regions.length > 1 ? a : null;
}
function a1Load(cc) {
if (!a1files[cc]) a1files[cc] = a1Index().then(function (m) {
return m[cc] ? fetchJSON1('/admin1-' + cc.toLowerCase() + '.json') : null;
}).then(prepA1).catch(function () { return null; });
return a1files[cc];
}
function a1Match(a, name) {
if (!name) return -1;
if (name in a.memo) return a.memo[name];
var s = normStrict(name), l = normLoose(name), i = -1;
if (s in a.strict) i = a.strict[s]; else if (l in a.loose) i = a.loose[l];
a.memo[name] = i;
return i;
}
function a1Tf(a) {
return { sx: (world.w / 360) / a.proj.kx, sy: (world.h / LAT_SPAN) / a.proj.ky, tx: projX(a.proj.lon0), ty: projY(a.proj.lat1) };
}
function a1Box(a, b) { var f = a1Tf(a); return [f.tx + b[0] * f.sx, f.ty + b[1] * f.sy, f.tx + b[2] * f.sx, f.ty + b[3] * f.sy]; }
// longitudes of countries across the antimeridian are unwrapped in the files (e.g. -185 for the Aleutians)
function a1Lon(a, lon) {
var lo = a.bbox[0] - 8, hi = a.bbox[2] + 8, ks = [0, -360, 360];
for (var i = 0; i < 3; i++) { var v = lon + ks[i]; if (v >= lo && v <= hi) return v; }
return lon;
}
// ---------------------------------------------------------------- state
var lang = 'en', ctx = null, root = null, ui = null, alive = false;
var S = { cc: '', region: '' };
var data = { world: null, country: null, full: null, error: false, loading: false };
var S = { cc: '', region: '', city: '' };
var data = { world: null, country: null, full: null, a1file: null, error: false, loading: false };
var A1 = null, A1m = null; // active admin-1 file for the shown country and how API regions map onto it
var lastSig = '';
function ctxSig(c) { return JSON.stringify([c.range, c.from, c.to, c.host, c.domain, c.lang]); }
var seq = 0, cache = {}, view = null, anim = 0, cityEls = [], ro = null;
function parseHash() {
var m = /^#\/geo(?:\/([A-Za-z]{2})(?:\/(.*))?)?$/.exec(location.hash || '');
var cc = '', region = '';
// the shell owns the query (#/geo/BR/Pernambuco?r=24h); the page owns the path segments
var raw = location.hash || '', qi = raw.indexOf('?');
if (qi >= 0) raw = raw.slice(0, qi);
var m = /^#\/geo(?:\/([A-Za-z]{2})(?:\/(.*))?)?$/.exec(raw);
var cc = '', region = '', city = '';
if (m && m[1]) {
cc = m[1].toUpperCase();
if (m[2]) { try { region = decodeURIComponent(m[2]); } catch (e) { region = ''; } }
if (m[2]) {
var parts = m[2].split('/');
try { region = decodeURIComponent(parts[0]); } catch (e) { region = ''; }
if (region && parts[1]) { try { city = decodeURIComponent(parts[1]); } catch (e) { city = ''; } }
}
}
return { cc: cc, region: region };
return { cc: cc, region: region, city: city };
}
function writeHash() {
var hsh = '#/geo' + (S.cc ? '/' + S.cc + (S.region ? '/' + encodeURIComponent(S.region) : '') : '');
if (location.hash !== hsh) { try { history.pushState(null, '', hsh); } catch (e) { location.hash = hsh; } }
var segs = S.cc ? [S.cc].concat(S.region ? [S.region].concat(S.city ? [S.city] : []) : []) : [];
var hsh;
if (typeof U.href === 'function') hsh = U.href('geo', segs);
else hsh = '#/geo' + segs.map(function (x) { return '/' + encodeURIComponent(x); }).join('');
// assigning the hash lets the shell update its own state (params, slice) like for any navigation
if (location.hash !== hsh) location.hash = hsh;
}
function go(cc, region, focus) {
function go(cc, region, focus, city) {
if (world && cc && !world.paths[cc]) cc = '';
S.cc = cc || '';
S.region = cc ? (region || '') : '';
S.city = S.region ? (city || '') : '';
writeHash();
load(true);
if (focus && ui) setTimeout(function () { try { ui.lead.focus({ preventScroll: true }); } catch (e) { /* ignore */ } }, 0);
}
function goBack() {
if (S.region) go(S.cc, '', true);
if (S.city) go(S.cc, S.region, true);
else if (S.region) go(S.cc, '', true);
else if (S.cc) go('', '', true);
}
function onHash() {
if (!alive) return;
var p = parseHash();
if (p.cc === S.cc && p.region === S.region) return;
S.cc = p.cc; S.region = p.region;
if (p.cc === S.cc && p.region === S.region && p.city === S.city) return;
S.cc = p.cc; S.region = p.region; S.city = p.city;
load(true);
}
function onKey(e) {
@@ -222,9 +364,13 @@
}
// ---------------------------------------------------------------- data
function key(extra) { return [ctx.range, ctx.host || '', extra || ''].join('|'); }
function sliceParams() {
try { if (typeof U.rangeParams === 'function') { var r = U.rangeParams(); if (r) return r; } } catch (e) { /* fallback */ }
return { range: ctx.range };
}
function key(extra) { return [JSON.stringify(sliceParams()), ctx.host || '', extra || ''].join('|'); }
function fetchJSON(params) {
var p = { range: ctx.range };
var p = sliceParams();
if (ctx.host) p.host = ctx.host;
for (var k in params) p[k] = params[k];
return Promise.resolve(U.api('/api/v1/geo', p));
@@ -242,12 +388,15 @@
if (cc) {
jobs.push(cached(key('c:' + cc), { cc: cc }));
jobs.push(region ? cached(key('r:' + cc + ':' + region), { cc: cc, region: region }) : null);
jobs.push(a1Load(cc));
}
Promise.all(jobs).then(function (r) {
if (my !== seq || !alive) return;
data.world = r[0];
data.full = cc ? r[1] : null;
data.country = cc ? (region ? r[2] : r[1]) : null;
data.a1file = cc ? r[3] : null;
mapA1();
data.loading = false;
render(refit);
}).catch(function () {
@@ -257,6 +406,27 @@
});
}
// Maps the API's regions onto the shapes of the admin-1 file. The map of states is used only when
// most of the country's events fall in regions that exist in the file; otherwise the page keeps
// drawing cities over the country's outline.
function mapA1() {
A1 = null; A1m = null;
var a = data.a1file;
if (!S.cc || !a || !data.full) return;
var ev = [], ips = [], nm = [], best = [], tot = 0, mt = 0;
(data.full.regions || []).forEach(function (r) {
if (!r.name) return;
tot += r.events;
var i = a1Match(a, r.name);
if (i < 0) return;
mt += r.events;
ev[i] = (ev[i] || 0) + r.events; ips[i] = (ips[i] || 0) + (r.ips || 0);
if (!(best[i] >= r.events)) { best[i] = r.events; nm[i] = r.name; }
});
if (tot === 0 || mt / tot >= 0.5) { A1 = a; A1m = { ev: ev, ips: ips, name: nm, tot: tot, mt: mt }; }
}
function selShape() { return A1 && S.region ? a1Match(A1, S.region) : -1; }
// ---------------------------------------------------------------- build
function build(el) {
clear(el);
@@ -270,15 +440,15 @@
var leadBox = h('div', 'lead geo-leadbox'); leadBox.appendChild(lead);
var err = h('div', 'geo-err'); err.setAttribute('role', 'alert'); err.hidden = true;
var errMsg = h('span', '', t('geo.error')), retry = h('button', 'geo-retry', t('geo.retry')); retry.type = 'button';
retry.addEventListener('click', function () { cache = {}; load(false); });
retry.addEventListener('click', function () { cache = {}; a1files = {}; a1index = null; load(false); });
err.appendChild(errMsg); err.appendChild(retry);
var main = h('div', 'geo-main');
var mapPanel = h('section', 'geo-panel geo-mappanel');
var box = h('div', 'geo-map');
var svg = sv('svg', { 'class': 'geo-svg', role: 'img', preserveAspectRatio: 'xMidYMid meet' });
var gC = sv('g', { 'class': 'geo-countries' }), gCity = sv('g', { 'class': 'geo-cities' });
svg.appendChild(gC); svg.appendChild(gCity);
var gC = sv('g', { 'class': 'geo-countries' }), gA = sv('g', { 'class': 'geo-states' }), gCity = sv('g', { 'class': 'geo-cities' });
svg.appendChild(gC); svg.appendChild(gA); svg.appendChild(gCity);
var paths = {};
Object.keys(world.paths).forEach(function (cc) {
var p = sv('path', { d: world.paths[cc], 'class': 'geo-cn', 'data-cc': cc });
@@ -291,7 +461,8 @@
var lg = h('div', 'geo-legend-bar'); lg.setAttribute('aria-hidden', 'true');
var lmin = h('span', '', '1'), lmax = h('span', '', ''), ltx = h('span', 'geo-legend-t', t('geo.legend'));
legend.appendChild(lmin); legend.appendChild(lg); legend.appendChild(lmax); legend.appendChild(ltx);
mapPanel.appendChild(box); mapPanel.appendChild(legend);
var unmapped = h('div', 'geo-note geo-unmapped'); unmapped.hidden = true;
mapPanel.appendChild(box); mapPanel.appendChild(legend); mapPanel.appendChild(unmapped);
var side = h('section', 'geo-panel geo-side');
var sideH = h('h2', '', ''); sideH.tabIndex = -1;
@@ -309,22 +480,41 @@
root.appendChild(top); root.appendChild(leadBox); root.appendChild(err); root.appendChild(main); root.appendChild(detail);
el.appendChild(root);
ui = { nav: nav, back: back, lead: lead, err: err, errMsg: errMsg, retry: retry, svg: svg, gCity: gCity, paths: paths, box: box,
tip: tip, loading: ld, legendMax: lmax, legend: legend, legendBar: lg, side: side, sideH: sideH, sideList: sideList, detail: detail,
pCities: pCities, pCats: pCats, pIps: pIps };
ui = { nav: nav, back: back, lead: lead, err: err, errMsg: errMsg, retry: retry, svg: svg, gA: gA, gCity: gCity, paths: paths, box: box,
tip: tip, loading: ld, legendMax: lmax, legendText: ltx, legend: legend, legendBar: lg, unmapped: unmapped, side: side, sideH: sideH, sideList: sideList,
detail: detail, pCities: pCities, pCats: pCats, pIps: pIps, shapes: [], a1key: '' };
gC.addEventListener('click', function (e) {
var cc = e.target && e.target.getAttribute && e.target.getAttribute('data-cc');
if (cc && hit(cc)) go(cc, '', true);
if (cc && hit(cc) && !(A1 && cc === S.cc)) go(cc, '', true);
});
gC.addEventListener('mousemove', function (e) {
var cc = e.target && e.target.getAttribute && e.target.getAttribute('data-cc');
var r = cc && hit(cc);
if (!r) { ui.tip.hidden = true; return; }
if (!r || (A1 && cc === S.cc)) { ui.tip.hidden = true; return; }
showTip(e, [[flagOf(cc) + ' ' + countryName(cc), ''], [t('geo.tip.events'), nf(r.events)], [t('geo.tip.ips'), nf(r.ips)], [t('geo.tip.hostile'), nf(r.hostile || 0)]]);
});
gC.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
gCity.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
function shapeOf(e) {
var i = e.target && e.target.getAttribute && e.target.getAttribute('data-i');
return i == null ? -1 : parseInt(i, 10);
}
gA.addEventListener('mousemove', function (e) {
var i = shapeOf(e);
if (!A1 || i < 0 || !A1.regions[i]) { ui.tip.hidden = true; return; }
var ev = A1m.ev[i], nm = A1m.name[i] ? regionName(A1m.name[i]) : A1.regions[i].name;
var rows = [[nm, '']];
if (ev) rows.push([t('geo.tip.events'), nf(ev)], [t('geo.tip.ips'), nf(A1m.ips[i] || 0)]);
else rows.push([t('geo.tip.nodata'), '']);
showTip(e, rows);
});
gA.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
gA.addEventListener('click', function (e) {
var i = shapeOf(e);
if (!A1 || i < 0 || !A1m.name[i] || i === selShape()) return;
go(S.cc, A1m.name[i], true);
});
if (window.ResizeObserver) {
ro = new ResizeObserver(function () { if (alive && data.world && !data.error && !anim) { fitNow(); drawCities(); } });
ro.observe(box);
@@ -355,26 +545,55 @@
tip.style.left = x + 'px'; tip.style.top = y + 'px';
}
// The admin-1 layer is rebuilt only when the country changes.
function buildShapes() {
var want = A1 ? S.cc : '';
if (ui.a1key === want) return;
clear(ui.gA); ui.shapes = []; ui.a1key = want;
if (!A1) { ui.gA.removeAttribute('transform'); return; }
var f = a1Tf(A1);
ui.gA.setAttribute('transform', 'translate(' + f.tx.toFixed(3) + ' ' + f.ty.toFixed(3) + ') scale(' + f.sx.toFixed(5) + ' ' + f.sy.toFixed(5) + ')');
A1.regions.forEach(function (r, i) {
var p = sv('path', { d: r.path, 'class': 'geo-st', 'data-i': String(i) });
ui.shapes[i] = p; ui.gA.appendChild(p);
});
}
// ---------------------------------------------------------------- map view
function boxSize() {
var r = ui.box.getBoundingClientRect();
return { w: r.width || 800, h: r.height || 360 };
}
function targetView() {
var sz = boxSize(), asp = sz.w / sz.h, bb, margin = 1.22;
function cityXY(c) { return [projX(A1 ? a1Lon(A1, c.lon) : c.lon), projY(c.lat)]; }
// box (world units) the view should frame, and its margin factor
function targetBox() {
var bb, margin = 1.22;
if (!S.cc) { bb = [0, 0, world.w, world.h]; margin = 1; }
else {
bb = bboxOf(S.cc) || [0, 0, world.w, world.h];
var cs = data.country && data.country.cities;
if (S.region && cs) {
var pts = cs.filter(function (c) { return isNum(c.lat) && isNum(c.lon); });
var si = selShape();
if (A1) { bb = a1Box(A1, A1.main); margin = 1.1; }
if (si >= 0 && A1.regions[si]) { bb = a1Box(A1, A1.regions[si].b); margin = 1.2; }
else if (S.region && data.country && data.country.cities) {
var pts = data.country.cities.filter(function (c) { return isNum(c.lat) && isNum(c.lon); });
if (pts.length) {
var x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9;
pts.forEach(function (c) { var x = projX(c.lon), y = projY(c.lat); x0 = Math.min(x0, x); x1 = Math.max(x1, x); y0 = Math.min(y0, y); y1 = Math.max(y1, y); });
pts.forEach(function (c) { var p = cityXY(c); x0 = Math.min(x0, p[0]); x1 = Math.max(x1, p[0]); y0 = Math.min(y0, p[1]); y1 = Math.max(y1, p[1]); });
bb = [x0, y0, x1, y1]; margin = 1.5;
}
}
}
return { bb: bb, margin: margin };
}
// the map is as tall as the framed area needs (a state is not wide like the world), within limits
function fitAspect() {
if (!S.cc || !world) { ui.box.style.aspectRatio = ''; return; }
var tb = targetBox(), w = Math.max(tb.bb[2] - tb.bb[0], 1), hh = Math.max(tb.bb[3] - tb.bb[1], 1);
var narrow = boxSize().w < 560, a = Math.max(1, Math.min(narrow ? 1.4 : 2.5, w / hh));
ui.box.style.aspectRatio = a.toFixed(3) + ' / 1';
}
function targetView() {
var sz = boxSize(), asp = sz.w / sz.h, tb = targetBox(), bb = tb.bb, margin = tb.margin;
var bw = Math.max(bb[2] - bb[0], 36), bh = Math.max(bb[3] - bb[1], 36 / asp);
var vw = Math.max(bw * margin, bh * margin * asp);
var vh = vw / asp;
@@ -404,7 +623,19 @@
var w = hit(S.cc); if (w && !S.region) return w.ips;
return (d.cities || []).reduce(function (a, c) { return a + (c.ips || 0); }, 0);
}
function isNum(n) { return typeof n === 'number' && isFinite(n); }
function sameCity(a, b) { return !!a && !!b && (a === b || normStrict(a) === normStrict(b)); }
function cityEntry() {
var cs = (data.country && data.country.cities) || [];
if (!S.city) return null;
for (var i = 0; i < cs.length; i++) if (sameCity(cs[i].name, S.city)) return cs[i];
return null;
}
// click on a city (circle or list): inside a region it toggles the city, from the country it opens region and city
function pickCity(c) {
if (!c.name) return;
if (S.region) go(S.cc, S.region, true, sameCity(c.name, S.city) ? '' : c.name);
else if (c.region) go(S.cc, c.region, true, c.name);
}
function drawCities() {
clear(ui.gCity); cityEls = [];
@@ -413,25 +644,53 @@
var sz = boxSize(), upp = view[2] / sz.w, max = 1;
d.cities.forEach(function (c) { if (c.events > max) max = c.events; });
var rmax = sz.w < 560 ? 16 : 26;
var drawn = [];
d.cities.forEach(function (c, i) {
if (!isNum(c.lat) || !isNum(c.lon)) return;
var x = projX(c.lon), y = projY(c.lat);
var p = cityXY(c), x = p[0], y = p[1];
if (x < view[0] - 20 || x > view[0] + view[2] + 20 || y < view[1] - 20 || y > view[1] + view[3] + 20) return;
var r = Math.max(3, rmax * Math.sqrt(c.events / max)) * upp;
var el = sv('circle', { cx: x.toFixed(2), cy: y.toFixed(2), r: r.toFixed(2), 'class': 'geo-city' });
var sel = !!S.city && sameCity(c.name, S.city);
var el = sv('circle', { cx: x.toFixed(2), cy: y.toFixed(2), r: r.toFixed(2), 'class': 'geo-city' + (sel ? ' sel' : '') });
el.addEventListener('mousemove', function (e) {
var rows = [[c.name || t('geo.unknown'), '']];
if (c.region) rows.push([t('geo.tip.region'), c.region]);
if (c.region) rows.push([t('geo.tip.region'), regionName(c.region)]);
rows.push([t('geo.tip.events'), nf(c.events)], [t('geo.tip.ips'), nf(c.ips)]);
showTip(e, rows);
});
el.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
if (c.region && !S.region) {
el.addEventListener('click', function () { go(S.cc, c.region, true); });
if (c.name && (S.region || c.region)) {
el.addEventListener('click', function () { pickCity(c); });
el.classList.add('geo-city-click');
}
cityEls[i] = el; ui.gCity.appendChild(el);
cityEls[i] = el; drawn.push({ c: c, x: x, y: y, r: r, el: el, sel: sel });
});
// larger circles first so small ones stay clickable on top
drawn.sort(function (a, b) { return b.r - a.r; });
drawn.forEach(function (o) {
if (o.sel) { var ring = sv('circle', { cx: o.x.toFixed(2), cy: o.y.toFixed(2), r: (o.r + 5 * upp).toFixed(2), 'class': 'geo-ring' }); ui.gCity.appendChild(ring); }
ui.gCity.appendChild(o.el);
});
if (S.region) drawLabels(drawn, upp);
}
// names of the largest cities (and of the chosen one), skipping those that would overlap
function drawLabels(drawn, upp) {
var fs = 11 * upp, boxes = [], n = 0;
var ord = drawn.slice().sort(function (a, b) { return (b.sel ? 1e12 : b.c.events) - (a.sel ? 1e12 : a.c.events); });
for (var i = 0; i < ord.length && n < 8; i++) {
var o = ord[i], nm = o.c.name;
if (!nm) continue;
var w = nm.length * fs * 0.6, x = o.x + o.r + 3 * upp, y = o.y + fs * 0.35, anchor = 'start';
if (x + w > view[0] + view[2] - 4 * upp) { x = o.x - o.r - 3 * upp; anchor = 'end'; }
var bx = anchor === 'start' ? x : x - w, by = y - fs;
if (bx < view[0] || bx + w > view[0] + view[2] || by < view[1] || by + fs * 1.2 > view[1] + view[3]) continue;
var clash = boxes.some(function (b) { return bx < b[2] && bx + w > b[0] && by < b[3] && by + fs * 1.2 > b[1]; });
if (clash && !o.sel) continue;
boxes.push([bx, by, bx + w, by + fs * 1.2]);
var tx = sv('text', { x: x.toFixed(2), y: y.toFixed(2), 'text-anchor': anchor, 'font-size': fs.toFixed(2), 'stroke-width': (3 * upp).toFixed(2), 'class': 'geo-lbl' + (o.sel ? ' sel' : '') });
tx.textContent = nm;
ui.gCity.appendChild(tx); n++;
}
}
// ---------------------------------------------------------------- render
@@ -446,7 +705,8 @@
function sep() { var s = h('span', 'geo-sep', '›'); s.setAttribute('aria-hidden', 'true'); nav.appendChild(s); }
var parts = [{ txt: t('geo.world'), act: S.cc ? function () { go('', '', true); } : null }];
if (S.cc) parts.push({ txt: flagOf(S.cc) + ' ' + countryName(S.cc), act: S.region ? function () { go(S.cc, '', true); } : null });
if (S.region) parts.push({ txt: regionName(S.region), act: null });
if (S.region) parts.push({ txt: regionName(S.region), act: S.city ? function () { go(S.cc, S.region, true); } : null });
if (S.city) parts.push({ txt: S.city, act: null });
parts.forEach(function (p, i) {
if (i) sep();
var n;
@@ -471,17 +731,28 @@
return;
}
var d = data.country, cn = countryName(S.cc);
if (!d || !d.events) { L.textContent = t('geo.lead.empty.country', { country: cn, range: rl }); return; }
if (!d || !d.events) {
if (S.region) L.textContent = t('geo.lead.empty.region', { region: regionName(S.region), country: cn, range: rl });
else L.textContent = t('geo.lead.empty.country', { of: ofCountry(S.cc), range: rl });
return;
}
var base = { country: cn, events: unit('events', d.events), ips: unit('ips', ipCount(d)), range: rl };
if (S.region) {
var c0 = (d.cities || [])[0];
base.region = regionName(S.region);
if (S.city) {
var ce = cityEntry();
if (!ce) { L.textContent = t('geo.lead.empty.city', { city: S.city, region: base.region, range: rl }); return; }
L.textContent = t('geo.lead.city', { city: S.city, region: base.region, country: cn, events: unit('events', ce.events), ips: unit('ips', ce.ips || 0),
range: rl, pct: pct(ce.events / d.events) });
return;
}
var c0 = (d.cities || [])[0];
if (c0 && c0.name) { base.city = c0.name; base.pct = pct(c0.events / d.events); L.textContent = t('geo.lead.region', base); }
else L.textContent = t('geo.lead.region.flat', base);
return;
}
var r0 = ((d.regions || []).filter(function (r) { return r.name; })[0]);
if (r0 && d.regions.length > 1) { base.region = r0.name; base.pct = pct(r0.events / d.events); L.textContent = t('geo.lead.country', base); }
if (r0 && d.regions.length > 1) { base.region = regionName(r0.name); base.pct = pct(r0.events / d.events); L.textContent = t('geo.lead.country', base); }
else L.textContent = t('geo.lead.country.flat', base);
}
@@ -489,21 +760,48 @@
var cs = (data.world && data.world.countries) || [], max = 1, by = {};
cs.forEach(function (c) { by[c.cc] = c; if (c.events > max) max = c.events; });
var lm = Math.log(1 + max);
ui.legendMax.textContent = nf(max);
var zoomed = !!S.cc;
ui.svg.setAttribute('class', 'geo-svg' + (zoomed ? ' zoomed' : ''));
ui.svg.setAttribute('class', 'geo-svg' + (zoomed ? ' zoomed' : '') + (A1 ? ' a1' : '') + (A1 && S.region ? ' reg' : ''));
Object.keys(ui.paths).forEach(function (cc) {
var p = ui.paths[cc], c = by[cc], cls = 'geo-cn';
// other countries fade while one is shown (fill-opacity, not opacity: big translucent layers glitch in some renderers)
var fade = zoomed && cc !== S.cc ? 0.35 : 1;
if (c) {
cls += ' hit';
p.style.fillOpacity = (0.2 + 0.8 * Math.log(1 + c.events) / lm).toFixed(3);
} else p.style.fillOpacity = '';
p.style.fillOpacity = ((0.2 + 0.8 * Math.log(1 + c.events) / lm) * fade).toFixed(3);
} else p.style.fillOpacity = fade < 1 ? '0.05' : '';
if (cc === S.cc) cls += ' sel';
p.setAttribute('class', cls);
});
ui.legend.hidden = zoomed;
if (S.cc) ui.svg.setAttribute('aria-label', t('geo.map.country.label', { country: countryName(S.cc) }));
else ui.svg.setAttribute('aria-label', t('geo.map.label'));
// states
buildShapes();
var legendKey = 'geo.legend', lmx = max;
ui.unmapped.hidden = true;
if (A1) {
var smax = 1, si = selShape();
A1m.ev.forEach(function (v) { if (v > smax) smax = v; });
var slm = Math.log(1 + smax);
ui.shapes.forEach(function (p, i) {
var v = A1m.ev[i], cls = 'geo-st', fade = si >= 0 && i !== si ? 0.55 : 1;
if (v) { cls += ' hit'; p.style.fillOpacity = ((0.2 + 0.8 * Math.log(1 + v) / slm) * fade).toFixed(3); }
else p.style.fillOpacity = fade < 1 ? '0.08' : '';
if (i === si) cls += ' sel';
else if (si >= 0) cls += ' dim';
p.setAttribute('class', cls);
});
legendKey = 'geo.legend.state'; lmx = smax;
if (A1m.tot > A1m.mt) { ui.unmapped.textContent = t('geo.unmapped', { events: unit('events', A1m.tot - A1m.mt) }); ui.unmapped.hidden = false; }
}
ui.legendMax.textContent = nf(lmx);
ui.legendText.textContent = t(legendKey);
var hasData = A1 ? A1m.ev.some(function (v) { return v > 0; }) : cs.length > 0;
ui.legend.hidden = (zoomed && !A1) || !hasData; // nothing to scale: no "1 - 1" bar
var lbl;
if (!S.cc) lbl = t('geo.map.label');
else if (A1 && S.region) lbl = t('geo.map.region.label', { region: regionName(S.region), country: countryName(S.cc) });
else if (A1) lbl = t('geo.map.state.label', { of: ofCountry(S.cc) });
else lbl = t('geo.map.country.label', { of: ofCountry(S.cc) });
ui.svg.setAttribute('aria-label', lbl);
}
function emptyNote(txt) { return h('div', 'geo-empty', txt); }
@@ -527,6 +825,58 @@
return r;
}
// ranking of the country's regions; the chosen one is highlighted and a click picks it
function regionRows(L, withChip) {
var rs = (data.full && data.full.regions) || [];
if (!rs.length) { L.appendChild(emptyNote(t('geo.empty.list'))); return; }
if (S.region && withChip) {
var all = h('button', 'geo-chip', t('geo.all_regions')); all.type = 'button';
all.addEventListener('click', function () { go(S.cc, '', true); });
L.appendChild(all);
}
var mx = rs[0].events || 1, si = selShape();
rs.forEach(function (r, i) {
var can = !!r.name;
var on = can && (S.region === r.name || (si >= 0 && a1Match(A1, r.name) === si));
var el = row({ rank: i + 1, name: regionName(r.name), sub: unit('ips', r.ips), n: r.events, frac: r.events / mx,
cls: on ? 'on' : '',
pressed: can ? on : null,
label: can ? t('geo.pick.region', { name: regionName(r.name), events: unit('events', r.events) }) : '',
onClick: can ? function () { go(S.cc, on ? '' : r.name, true); } : null });
if (A1 && can) {
var k = a1Match(A1, r.name);
el.addEventListener('mouseenter', function () { if (ui.shapes[k]) ui.shapes[k].classList.add('hl'); });
el.addEventListener('mouseleave', function () { if (ui.shapes[k]) ui.shapes[k].classList.remove('hl'); });
}
L.appendChild(el);
});
}
// ranking of the shown cities; hovering a row highlights its circle
function cityRows(B, limit, withChip) {
var d = data.country, cs = (d && d.cities) || [];
if (!cs.length) { B.appendChild(emptyNote(t('geo.empty.list'))); return; }
if (S.city && withChip) {
var all = h('button', 'geo-chip', t('geo.all_cities')); all.type = 'button';
all.addEventListener('click', function () { go(S.cc, S.region, true); });
B.appendChild(all);
}
var mx = cs[0].events || 1, nocoord = 0;
cs.slice(0, limit).forEach(function (c, i) {
var can = !!c.name && (!!S.region || !!c.region);
var on = !!S.city && sameCity(c.name, S.city);
var r = row({ rank: i + 1, name: c.name || t('geo.unknown'), sub: S.region ? '' : (c.region ? regionName(c.region) : ''), n: c.events, frac: c.events / mx,
cls: on ? 'on' : '', pressed: can && S.region ? on : null,
label: can ? t(S.region ? 'geo.pick.city' : 'geo.city.pick', S.region ? { name: c.name, events: unit('events', c.events) } : { name: c.region }) : '',
onClick: can ? function () { pickCity(c); } : null });
r.addEventListener('mouseenter', function () { if (cityEls[i]) cityEls[i].classList.add('hl'); });
r.addEventListener('mouseleave', function () { if (cityEls[i]) cityEls[i].classList.remove('hl'); });
B.appendChild(r);
});
cs.forEach(function (c) { if (!isNum(c.lat) || !isNum(c.lon)) nocoord++; });
if (nocoord) B.appendChild(h('div', 'geo-note', t(nocoord === 1 ? 'geo.nocoords.one' : 'geo.nocoords.other', { n: nf(nocoord) })));
}
function renderSide() {
var L = ui.sideList; clear(L);
if (!S.cc) {
@@ -541,24 +891,14 @@
});
return;
}
ui.sideH.textContent = t('geo.regions');
var d = data.full;
var rs = (d && d.regions) || [];
if (!rs.length) { L.appendChild(emptyNote(t('geo.empty.list'))); return; }
if (S.region) {
var all = h('button', 'geo-chip', t('geo.all_regions')); all.type = 'button';
all.addEventListener('click', function () { go(S.cc, '', true); });
L.appendChild(all);
if (A1 && S.region) {
// state level: the side list is the state's cities, the regions go below the map
ui.sideH.textContent = t('geo.cities.in', { region: regionName(S.region) });
cityRows(L, 40, true);
return;
}
var mx = rs[0].events || 1;
rs.forEach(function (r, i) {
var can = !!r.name;
L.appendChild(row({ rank: i + 1, name: regionName(r.name), sub: unit('ips', r.ips), n: r.events, frac: r.events / mx,
cls: S.region === r.name && can ? 'on' : '',
pressed: can ? S.region === r.name : null,
label: can ? t('geo.pick.region', { name: r.name, events: unit('events', r.events) }) : '',
onClick: can ? function () { go(S.cc, S.region === r.name ? '' : r.name, true); } : null }));
});
ui.sideH.textContent = t('geo.regions');
regionRows(L, true);
}
function renderDetail() {
@@ -566,26 +906,17 @@
ui.detail.hidden = !show;
if (!show) return;
var d = data.country;
// cities
ui.pCities.h.textContent = t('geo.cities');
// first panel: cities, or (with the state map and a state chosen) the country's regions
var B = ui.pCities.body; clear(B);
var cs = d.cities || [];
if (!cs.length) B.appendChild(emptyNote(t('geo.empty.list')));
else {
var mx = cs[0].events || 1, nocoord = 0;
cs.slice(0, 15).forEach(function (c, i) {
var can = !!c.region && !S.region;
var r = row({ rank: i + 1, name: c.name || t('geo.unknown'), sub: c.region || '', n: c.events, frac: c.events / mx,
label: can ? t('geo.city.pick', { name: c.region }) : '', onClick: can ? function () { go(S.cc, c.region, true); } : null });
r.addEventListener('mouseenter', function () { if (cityEls[i]) cityEls[i].classList.add('hl'); });
r.addEventListener('mouseleave', function () { if (cityEls[i]) cityEls[i].classList.remove('hl'); });
B.appendChild(r);
});
cs.forEach(function (c) { if (!isNum(c.lat) || !isNum(c.lon)) nocoord++; });
if (nocoord) B.appendChild(h('div', 'geo-note', t(nocoord === 1 ? 'geo.nocoords.one' : 'geo.nocoords.other', { n: nf(nocoord) })));
if (A1 && S.region) {
ui.pCities.h.textContent = t('geo.regions.of', { of: ofCountry(S.cc) });
regionRows(B, false);
} else {
ui.pCities.h.textContent = S.region ? t('geo.cities.in', { region: regionName(S.region) }) : t('geo.cities');
cityRows(B, 15, !!S.region);
}
// categories
ui.pCats.h.textContent = t('geo.cats');
ui.pCats.h.textContent = S.region ? t('geo.cats.in', { region: regionName(S.region) }) : t('geo.cats');
B = ui.pCats.body; clear(B);
var cats = d.cats || {}, keys = Object.keys(cats).sort(function (a, b) { return cats[b] - cats[a]; }), tot = sum(cats);
if (!keys.length || !tot) B.appendChild(emptyNote(t('geo.empty.list')));
@@ -602,11 +933,14 @@
B.appendChild(ul);
if (d.hostile || d.suspicious) B.appendChild(h('div', 'geo-note', t('geo.hostile_suspicious', { h: nf(d.hostile || 0), s: nf(d.suspicious || 0) })));
}
// ips
ui.pIps.h.textContent = t('geo.ips');
B = ui.pIps.body; clear(B);
// ips: of the country/region, or of the chosen city (filtered from the region's top IPs)
var ips = ipList(d);
if (!ips.length) B.appendChild(emptyNote(t('geo.empty.list')));
if (S.city) {
ui.pIps.h.textContent = t('geo.ips.city', { city: S.city });
ips = ips.filter(function (x) { return sameCity(x.city, S.city); });
} else ui.pIps.h.textContent = t('geo.ips');
B = ui.pIps.body; clear(B);
if (!ips.length) B.appendChild(emptyNote(t(S.city ? 'geo.ips.city.none' : 'geo.empty.list')));
else ips.slice(0, 12).forEach(function (x) {
var b = h('button', 'geo-ip'); b.type = 'button';
b.setAttribute('aria-label', t('geo.open_ip', { ip: x.ip }));
@@ -623,6 +957,7 @@
if (x.last) { var ago = ''; try { ago = U.fmt.ago(x.last); } catch (e) { ago = ''; } if (ago) b.appendChild(h('span', 'geo-ip-l3', String(ago))); }
B.appendChild(b);
});
if (S.city && ips.length) B.appendChild(h('div', 'geo-note', t('geo.ips.city.note')));
}
function render(refit) {
@@ -631,11 +966,11 @@
ui.err.hidden = !data.error;
ui.loading.hidden = true;
crumbs();
if (data.error || !data.world) { lead(); ui.detail.hidden = true; clear(ui.sideList); clear(ui.gCity); ui.legend.hidden = true;
if (data.error || !data.world) { A1 = null; A1m = null; lead(); ui.detail.hidden = true; clear(ui.sideList); clear(ui.gCity); ui.legend.hidden = true; ui.unmapped.hidden = true; buildShapes();
ui.svg.setAttribute('class', 'geo-svg'); setView(targetView());
Object.keys(ui.paths).forEach(function (cc) { ui.paths[cc].style.fillOpacity = ''; ui.paths[cc].setAttribute('class', 'geo-cn'); });
return; }
colorize(); lead(); renderSide(); renderDetail();
colorize(); lead(); renderSide(); renderDetail(); fitAspect();
clear(ui.gCity); cityEls = [];
var to = targetView();
if (refit === false) { setView(to); drawCities(); }
@@ -650,9 +985,9 @@
mount: function (el, c) {
ctx = c; lang = c.lang || 'en';
world = U.world || window.URUTAU_WORLD;
alive = true; cache = {}; view = null;
alive = true; cache = {}; view = null; A1 = null; A1m = null; lastSig = ctxSig(c);
if (!world || !world.paths) { clear(el); el.appendChild(h('div', 'geo-empty', t('geo.error'))); return; }
var p = parseHash(); S.cc = world.paths[p.cc] ? p.cc : ''; S.region = S.cc ? p.region : '';
var p = parseHash(); S.cc = world.paths[p.cc] ? p.cc : ''; S.region = S.cc ? p.region : ''; S.city = S.region ? p.city : '';
build(el);
window.addEventListener('hashchange', onHash);
window.addEventListener('popstate', onHash);
@@ -660,9 +995,11 @@
load(false);
},
update: function (c) {
var langChanged = (c.lang || 'en') !== lang;
ctx = c; lang = c.lang || 'en';
var langChanged = (c.lang || 'en') !== lang, sig = ctxSig(c), changed = sig !== lastSig;
ctx = c; lang = c.lang || 'en'; lastSig = sig;
if (!alive || !ui) return;
// navigation inside the page (path segments) is driven by the hash, not by update()
if (!changed && !langChanged) return;
cache = {};
if (langChanged) { var el = root.parentNode; build(el); }
load(false);