X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/0f43b6ba435ae72565f7a1ccd942edfabc9d6d97..9b31d2bc42b0e1239609cd92c532dfd345e48d0f:/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 index 6abd103d4..7a14905c0 100644 --- a/src/wolnelektury/static/js/book_text/references.js +++ b/src/wolnelektury/static/js/book_text/references.js @@ -10,20 +10,24 @@ } var map_enabled = false; - var marker = L.circleMarker([0,0]); + var marker = null; var map = null; - function enable_map() { - $("#reference-map").show('slow'); + function enable_map(callback) { + if (!$("#reference-map").length) return; - if (map_enabled) return; - - map = L.map('reference-map').setView([0, 0], 11); - L.tileLayer('https://tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=a8a97f0ae5134403ac38c1a075b03e15', { - attribution: 'Maps © Thunderforest, Data © OpenStreetMap contributors' - }).addTo(map); - - map_enabled = true; + if (!map_enabled) { + map = L.map('reference-map').setView([0, 0], 11); + L.tileLayer('https://tile.thunderforest.com/neighbourhood/{z}/{x}/{y}.png?apikey=a8a97f0ae5134403ac38c1a075b03e15', { + attribution: 'Maps © Thunderforest, Data © OpenStreetMap contributors' + }).addTo(map); + marker = L.circleMarker([0,0]); + map_enabled = true; + } + $("#reference-map").show('slow', () => { + map.invalidateSize(); + callback(); + }); } function disable_map() { $("#reference-map").hide('slow'); @@ -46,8 +50,12 @@ $this.addClass('interesting'); ref = interestingReferences[uri]; - $this.attr('href', ref.wikipedia_link); - $this.attr('target', '_blank'); + if (ref.wikipedia_link) { + $this.attr('href', ref.wikipedia_link); + $this.attr('target', '_blank'); + } else { + $this.removeAttr('href') + } } }); @@ -62,7 +70,7 @@ ref = interestingReferences[uri]; if (ref.location) { - enable_map(); + enable_map(() => { let newLoc = [ ref.location[0], @@ -79,6 +87,7 @@ animate: true, duration: 1, }); + }); } else { disable_map(); if (map) { @@ -101,8 +110,14 @@ } $("#reference-link").text(ref.label); - $("#reference-link").attr('href', ref.wikipedia_link); + if (ref.wikipedia_link) { + $("#reference-link").attr('href', ref.wikipedia_link); + } else { + $('#reference-link').removeAttr('href'); + } + $("#reference-print").attr('href', '/mapa/ulotka/' + ref.id); + _paq.push(['trackEvent', 'html', 'reference']); }); @@ -168,6 +183,9 @@ left: nx, right: right }); + $elem.css({ + display: "block" + }); if (!$elem.data('attach-bottom')) { ny = y - $elem.height() - 10; } else { @@ -180,9 +198,6 @@ left: leftoffset - 6 }); - $elem.css({ - display: "block" - }); } function closeNoteBox() { @@ -216,23 +231,12 @@ if ($(this).parents('#footnotes').length) return; event.preventDefault(); - - - let x = $(this).width() / 2, y = 0; - let elem = $(this); - while (elem.attr('id') != 'book-text') { - let p = $(elem).position(); - x += p.left; - y += p.top; - elem = elem.parent(); - } href = $(this).attr('href').substr(1); content = $("[name='" + href + "']").next().next().html(); if (!content) return; $("#annotation-content").html(content); $("#footnote-link").attr('href', '#' + href) - putNoteAt($('#annotation-box'), this); event.stopPropagation(); }); @@ -616,6 +620,10 @@ }); $('a.anchor').on('click', function(e) { + // Workaround for bad TOC markers. + if ($(this).closest('#toc').length) return; + if ($(this).closest('.toc').length) return; + if ($(this).closest('#wltoc').length) return; e.preventDefault(); let sel = window.getSelection(); @@ -623,7 +631,7 @@ let range = document.createRange(); let $p = $(this).nextAll('.paragraph').first() - range.selectNode($p[0]); + range.selectNodeContents($p[0]); sel.addRange(range); qbox.showForSelection(sel); @@ -667,14 +675,15 @@ history.pushState({}, '', anchor); }, }); + return true; } } } scrollToAnchor(window.location.hash) - $('#toc, #themes, #book-text, #annotation').on('click', 'a', function(event) { - event.preventDefault(); - scrollToAnchor($(this).attr('href')); + $('#toc, #themes, #book-text, #annotation, .scroll').on('click', 'a', function(event) { + if (scrollToAnchor($(this).attr('href'))) { + event.preventDefault(); + } }); - })})(jQuery);