From 4353265dcafd44c861ccb1aa42b07d59194bf0e0 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sat, 20 Jun 2020 23:06:10 +1000 Subject: [PATCH] Load cross references into tooltips --- wikinote/jinja2/page_base.html | 2 ++ wikinote/static/js/page.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 wikinote/static/js/page.js diff --git a/wikinote/jinja2/page_base.html b/wikinote/jinja2/page_base.html index fb0b392..041e98a 100644 --- a/wikinote/jinja2/page_base.html +++ b/wikinote/jinja2/page_base.html @@ -36,4 +36,6 @@

{{ page.title }}

{% block page_content %}{% endblock %} + + {% endblock %} diff --git a/wikinote/static/js/page.js b/wikinote/static/js/page.js new file mode 100644 index 0000000..bf634c3 --- /dev/null +++ b/wikinote/static/js/page.js @@ -0,0 +1,32 @@ +/* + WikiNote3 + Copyright © 2020 Lee Yingtong Li (RunasSudo) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +document.querySelectorAll('.tooltip.xref').forEach(function(el) { + el.addEventListener('mouseover', function() { + if (!el.xrefLoaded) { + el.xrefLoaded = true; + + var xhr = new XMLHttpRequest(); + xhr.addEventListener('load', function() { + el.querySelector('.tooltip-content').innerHTML = xhr.responseText; + }) + xhr.open('GET', '/preview/' + el.dataset['xref']); + xhr.send(); + } + }); +});