X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/305485e53a72c278e2b24b754f68df2e4dd71f40..d66f9960d12d739c44a89d1d4e013f52783097e7:/src/wolnelektury/static/js/book_text/references.js diff --git a/src/wolnelektury/static/js/book_text/references.js b/src/wolnelektury/static/js/book_text/references.js new file mode 100644 index 000000000..dcbb3c843 --- /dev/null +++ b/src/wolnelektury/static/js/book_text/references.js @@ -0,0 +1,90 @@ +(function($){$(function(){ + + var interestingReferences = $("#interesting-references").text(); + if (interestingReferences) { + interestingReferences = $.parseJSON(interestingReferences); + } + if (interestingReferences) { + $("settings-references").show(); + } + + + + var map_enabled = false; + var marker = L.marker([0,0]); + var map = null; + + function enable_map() { + if (map_enabled) return; + + map = L.map('reference-map').setView([0, 0], 11); + L.tileLayer('https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png?lang=pl', { + attribution: 'Map data © OpenStreetMap contributors' + }).addTo(map); + + map_enabled = true; + } + function disable_map() { + $("#reference-map").hide('slow'); + } + + + $("#reference-close").on("click", function() { + $("#reference-box").hide(); + }); + + $('a.reference').each(function() { + $this = $(this); + uri = $this.attr('data-uri'); + console.log('check ' + uri); + if (interestingReferences.hasOwnProperty(uri)) { + $this.addClass('interesting'); + ref = interestingReferences[uri]; + + $this.attr('href', ref.wikipedia_link); + $this.attr('target', '_blank'); + } + }); + + + $('a.reference.interesting').on('click', function(event) { + event.preventDefault(); + + $("#reference-box").show(); + + $this = $(this); + uri = $this.attr('data-uri'); + ref = interestingReferences[uri]; + + if (ref.location) { + enable_map(); + + marker.setLatLng(ref.location); + //marker.setContent(ref.label); + marker.bindTooltip(ref.label).openTooltip(); + map.addLayer(marker); + map.panTo(ref.location, { + animate: true, + duration: 1, + }); + } else { + disable_map(); + if (map) { + map.removeLayer(marker); + } + } + + $("#reference-images img").remove(); + if (ref.images) { + $.each(ref.images, function(i, e) { + $i = $(""); + $i.attr('href', e.page); + $('img', $i).attr('src', e.url); + $("#reference-images").append($i); + }) + } + + $("#reference-link").text(ref.label); + $("#reference-link").attr('href', ref.wikipedia_link); + }); +})})(jQuery);