Widget:Map: различия между версиями
Xunto (обсуждение | вклад) |
Xunto (обсуждение | вклад) |
||
| Строка 33: | Строка 33: | ||
load("/resources/map/jquery-jvectormap-2.0.3.min.js"); | load("/resources/map/jquery-jvectormap-2.0.3.min.js"); | ||
load("/resources/map/test_map.js"); | load("/resources/map/test_map.js"); | ||
| − | + | ||
| − | + | $('#world-map').vectorMap({ | |
| − | + | map: 'test_map', | |
| − | + | onRegionClick: function(e, code) { | |
| − | + | var page = state_map[code.toLowerCase()]; | |
| − | + | if (page) window.open("/page/" + page); | |
| − | + | }, | |
| − | + | onRegionTipShow: function(e, tip, code){ | |
| − | + | var page = state_map[code.toLowerCase()]; | |
| − | + | if (page) tip.html(page) | |
| − | + | else tip.html(code); | |
| − | + | } | |
| − | } | + | }); |
| − | } | + | |
} | } | ||
Версия 05:34, 29 июля 2019
<link rel="stylesheet" href="/resources/map/jquery-jvectormap-2.0.3.css" type="text/css" media="screen"/>
<script> var data = ""; var state_map = {};
function processData(d) { while (d.length > 0) { var s = d.indexOf("("); var e = d.indexOf(")");
var page = d.substring(0, s - 1).trim(); var map = d.substring(s + 1, e).split(",")[0].trim();
d = d.substr(e + 3);
state_map[map.toLowerCase()] = page; } }
function load(src) { var refs = document.getElementsByTagName('script'); var ref = refs[refs.length - 1]; var js = document.createElement('script'); js.type = 'text/javascript'; js.async = true; js.src = src; ref.parentNode.insertBefore(js, ref.nextSibling); }
function run_map () { load("/resources/map/jquery-jvectormap-2.0.3.min.js"); load("/resources/map/test_map.js");
$('#world-map').vectorMap({ map: 'test_map', onRegionClick: function(e, code) { var page = state_map[code.toLowerCase()]; if (page) window.open("/page/" + page); }, onRegionTipShow: function(e, tip, code){ var page = state_map[code.toLowerCase()]; if (page) tip.html(page) else tip.html(code); } });
}
processData(data);
if(window.addEventListener){ window.addEventListener('load', run_map) } else{ window.attachEvent('onload', run_map) } </script>