mirror of
https://github.com/aljazceru/twentyone-world.github.io.git
synced 2025-12-18 19:14:21 +01:00
123 lines
4.1 KiB
HTML
123 lines
4.1 KiB
HTML
---
|
|
layout: default
|
|
title: Twentyone.World
|
|
---
|
|
|
|
<link rel="stylesheet" type="text/css" href="/css/jquery.qtip.css">
|
|
<script type="text/javascript" src="/js/jquery.qtip.min.js"></script>
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(function () {
|
|
// Colors
|
|
const cOrange = '#F79621';
|
|
const cGray = '#333';
|
|
const cWhite = '#777';
|
|
const cDarkGray = '#222';
|
|
const cDarkOrange = '#735000';
|
|
const cDarkWhite = '#555';
|
|
|
|
// initialize tooltips
|
|
$.fn.qtip.defaults.style.classes = 'ui-tooltip-bootstrap';
|
|
$.fn.qtip.defaults.style.def = false;
|
|
|
|
var map = kartograph.map('#map');
|
|
|
|
map.loadMap('map/world.svg', function () {
|
|
map.addLayer('countries', {
|
|
id: 'bg',
|
|
styles: {
|
|
stroke: '#000',
|
|
'stroke-width': 6.15,
|
|
'stroke-linejoin': 'round'
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: 'data/countries.json',
|
|
dataType: 'json',
|
|
success: function (countries) {
|
|
|
|
var basedCountries = countries.filter(function hasLink(c) {
|
|
var hasLink = c.link ? true : false;
|
|
return hasLink;
|
|
});
|
|
var basedCountryCodes = basedCountries.map(function(c) {
|
|
return c.alpha3;
|
|
});
|
|
function isBased(iso) {
|
|
return basedCountryCodes.includes(iso);
|
|
}
|
|
function getColor(iso) {
|
|
let country = countries.find(c => c.alpha3 == iso);
|
|
if (country && country.link) {
|
|
return country.external ? cWhite : cOrange;
|
|
}
|
|
return cGray;
|
|
}
|
|
function basedName(iso) {
|
|
let country = countries.find(c => c.alpha3 == iso);
|
|
if (country && country.country && country.name) {
|
|
return country.country + ": " + country.name;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
map.addLayer('countries', {
|
|
title: function (d) {
|
|
if (isBased(d.iso)) {
|
|
return basedName(d.iso);
|
|
} else {
|
|
return d.name;
|
|
}
|
|
},
|
|
styles: {
|
|
stroke: cDarkGray,
|
|
fill: cGray
|
|
},
|
|
mouseenter: function (d, path) {
|
|
if (!isBased(d.iso)) {
|
|
path.attr('fill', Math.random() < 0.5 ? cDarkOrange : cDarkWhite );
|
|
}
|
|
return;
|
|
},
|
|
mouseleave: function (d, path) {
|
|
if (!isBased(d.iso)) {
|
|
path.animate({ fill: getColor(d.iso) }, 1000);
|
|
}
|
|
return;
|
|
},
|
|
click: function (d, path) {
|
|
let country = countries.find(c => c.alpha3 == d.iso);
|
|
if (country.link) {
|
|
window.open(country.link);
|
|
} else {
|
|
window.open('/fork');
|
|
}
|
|
}
|
|
});
|
|
|
|
map.getLayer('countries').style('fill', function (data) {
|
|
return getColor(data.iso);
|
|
});
|
|
}
|
|
});
|
|
|
|
}, { padding: -5 });
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
<center><small>{{ site.tagline }}</small></center>
|
|
|
|
<div id="map" style="margin:1em 0;">
|
|
</div>
|
|
|
|
<center>
|
|
<a href="/fork">
|
|
<button type="button" class="btn btn-primary btn-large btn-custom">What the Fork?</button>
|
|
</a>
|
|
</center>
|