X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/7dcb126f47bdbc52b9ad33b24386da410ee695b5..b89f3aa7efdc44a9b59b26384862df0f06803a7b:/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 87c806195..3f5b7e37f 100644
--- a/src/wolnelektury/static/js/book_text/references.js
+++ b/src/wolnelektury/static/js/book_text/references.js
@@ -10,10 +10,12 @@
}
var map_enabled = false;
- var marker = L.circleMarker([0,0]);
+ var marker = null;
var map = null;
function enable_map() {
+ if (!$("#reference-map").length) return;
+
$("#reference-map").show('slow');
if (map_enabled) return;
@@ -22,6 +24,7 @@
L.tileLayer('https://tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey=a8a97f0ae5134403ac38c1a075b03e15', {
attribution: 'Maps © Thunderforest, Data © OpenStreetMap contributors'
}).addTo(map);
+ marker = L.circleMarker([0,0]);
map_enabled = true;
}
@@ -139,10 +142,11 @@
leftoffset = x - margin;
} else {
right = '';
-
- // default position.
- leftoffset = 40;
+
leftoffset = $elem.data('default-leftoffset');
+ if (leftoffset === undefined) {
+ leftoffset = $elem.width() / 2;
+ }
nx = x - leftoffset;
@@ -157,12 +161,8 @@
// Do we need to move away from the right?
if (nx + boxwidth > maxx) {
- // ACTUALLY CALCULATE STUFF
- // if maxx - minx < 470 px -- daj z lewej do prawej i już!
-
right = '';
let d = nx + boxwidth - maxx;
- //if (leftoffset + d > $elem.width() - 10) d = $elem.width() - leftoffset - 10;
nx -= d;
leftoffset += d;
}
@@ -171,6 +171,9 @@
left: nx,
right: right
});
+ $elem.css({
+ display: "block"
+ });
if (!$elem.data('attach-bottom')) {
ny = y - $elem.height() - 10;
} else {
@@ -183,9 +186,6 @@
left: leftoffset - 6
});
- $elem.css({
- display: "block"
- });
}
function closeNoteBox() {
@@ -219,23 +219,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();
});
@@ -619,6 +608,9 @@
});
$('a.anchor').on('click', function(e) {
+ // Workaround for bad TOC markers.
+ if ($(this).closest('#toc').length) return;
+ if ($(this).closest('#wltoc').length) return;
e.preventDefault();
let sel = window.getSelection();
@@ -626,7 +618,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);