dab-mechanic/templates/article.html

190 lines
5.6 KiB
HTML
Raw Normal View History

2022-08-13 13:16:49 +01:00
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
2022-08-14 17:44:07 +01:00
<title>{{ article.enwiki }} &ndash; dab mechanic</title>
2022-08-13 13:16:49 +01:00
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
2022-08-13 16:25:07 +01:00
<link rel="stylesheet"
href="//en.wikipedia.org/w/load.php?debug=false&amp;lang=en&amp;modules=mediawiki.legacy.commonPrint,shared|skins.vector.styles&amp;only=styles&amp;skin=vector&amp;*">
<link rel="stylesheet" href="//en.wikipedia.org/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector"/>
<link rel="stylesheet" href="//en.wikipedia.org/w/load.php?lang=en&amp;modules=ext.cite.styles&amp;only=styles&amp;skin=vector"/>
2022-08-13 13:16:49 +01:00
<style>
a.disambig { color: #ff8c00; }
a.disambig-highlight { color: #ff8c00; border: 2px solid #ff8c00; }
a.new { color: red; }
2022-08-13 16:25:07 +01:00
#top {
position: fixed;
left: 0px;
right: 0px;
height: 4em;
background: white;
z-index: 0;
}
2022-08-13 13:16:49 +01:00
#article {
2022-08-13 16:25:07 +01:00
padding-left: 40%;
}
.dab-highlight {
border: 2px solid blue;
}
#dabs {
position: fixed;
top: 0em;
left: 0px;
width: 40%;
overflow: auto;
bottom: 0px;
2022-08-13 13:16:49 +01:00
}
.card-highlight {
color: #000 !important;
background-color: #FFD580 !important;
}
</style>
</head>
<body>
2022-08-13 16:25:07 +01:00
<div id="dabs" class="p-3">
2022-08-14 17:44:07 +01:00
<h1>{{ article.enwiki }}</h1>
2022-08-13 16:25:07 +01:00
<div id="save-panel" class="d-none">
2022-08-14 17:44:07 +01:00
<form method="POST" action="{{ article.save_endpoint() }}">
2022-08-13 16:25:07 +01:00
<button class="btn btn-primary" id="save-btn">Save</button>
<span id="edit-count"></span>
<input type="hidden" value="{}" id="save-edits" name="edits">
</form>
</div>
2022-08-14 17:48:19 +01:00
<div>There are {{ article.dab_list | count }} links in the article that need disambiguating.</div>
{% for dab in article.dab_list %}
2022-08-13 16:25:07 +01:00
<div class="card p-1 m-2">
<h3 class="card-title" id="dab-card-title-{{ dab.num }}" onclick="return jump_to({{ dab.num }})">{{ dab.title }}</h3>
<div>
<a href="#" onclick="return jump_to({{ dab.num }})">highlight link</a>
<span class="d-none" id="cancel-{{ dab.num }}">
|
<a href="#" onclick="return cancel_selection({{ dab.num }})">cancel selection</a>
</span>
</div>
2022-08-18 20:48:38 +01:00
<div class="dab-article d-none" id="dab-article-{{ dab.num }}">{{ dab.html | safe }}</div>
2022-08-13 16:25:07 +01:00
</div>
{% endfor %}
2022-08-13 13:16:49 +01:00
</div>
2022-08-13 16:25:07 +01:00
<div id="article" class="pe-3">
2022-08-14 17:48:19 +01:00
<div>{{ article.get_html() | safe }}</div>
2022-08-13 16:25:07 +01:00
</div>
2022-08-13 13:16:49 +01:00
</div>
</div>
<script>
2022-08-13 16:25:07 +01:00
var edit_set = new Set();
var edits = {};
2022-08-14 17:44:07 +01:00
var dab_lookup = {{ article.dab_lookup | tojson }};
var dab_order = {{ article.dab_order | tojson }};
2022-08-13 16:25:07 +01:00
2022-08-13 13:16:49 +01:00
function jump_to(dab_num) {
2022-08-13 16:25:07 +01:00
var highlight_title = "text-bg-primary";
2022-08-18 20:48:38 +01:00
var dab_articles = document.getElementsByClassName("dab-article");
for(var i=0; i<dab_articles.length; i++) {
dab_articles[i].classList.add("d-none");
}
var dab_article = document.getElementById("dab-article-" + dab_num);
dab_article.classList.remove("d-none");
2022-08-13 13:16:49 +01:00
var links = document.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
links[i].classList.remove("disambig-highlight");
}
2022-08-13 16:25:07 +01:00
var card_titles = document.getElementsByClassName("card-title");
for(var i=0; i<card_titles.length; i++) {
card_titles[i].classList.remove(highlight_title);
2022-08-13 13:16:49 +01:00
}
2022-08-13 16:25:07 +01:00
var card_title = document.getElementById("dab-card-title-" + dab_num);
card_title.classList.add(highlight_title);
2022-08-13 13:16:49 +01:00
var link = document.getElementById("dab-" + dab_num);
link.scrollIntoView();
link.classList.add("disambig-highlight")
return false;
}
2022-08-13 16:25:07 +01:00
function clear_dab_highlight(dab_num) {
var dab_article = document.getElementById("dab-article-" + dab_num);
var links = dab_article.querySelectorAll("a");
for(var i=0; i<links.length; i++) {
links[i].classList.remove("dab-highlight");
}
}
function update_edit_count() {
var save_panel = document.getElementById("save-panel")
if (edit_set.size) {
save_panel.classList.remove("d-none");
var edit_count = edit_set.size == 1 ? "1 edit" : edit_set.size + " edits";
document.getElementById("edit-count").textContent = edit_count;
} else {
save_panel.classList.add("d-none");
document.getElementById("edit-count").textContent = "";
}
}
function update_edits() {
2022-08-14 17:44:07 +01:00
var saves = dab_order.filter(t => edits[t]).map(t => [t, edits[t]]);
2022-08-13 16:25:07 +01:00
var save_edits = document.getElementById("save-edits");
2022-08-14 17:44:07 +01:00
save_edits.value = JSON.stringify(saves);
2022-08-13 16:25:07 +01:00
}
function select_dab(element, dab_num) {
jump_to(dab_num);
document.getElementById("cancel-" + dab_num).classList.remove("d-none");
var title = element.getAttribute("title");
edits[dab_lookup[dab_num]] = title;
edit_set.add(dab_num);
update_edits();
update_edit_count();
clear_dab_highlight(dab_num);
var dab_article = document.getElementById("dab-article-" + dab_num);
var links = dab_article.querySelectorAll("a");
for(var i=0; i<links.length; i++) {
links[i].classList.remove("dab-highlight");
}
var title = element.getAttribute("title");
element.classList.add("dab-highlight");
console.log(title, dab_num);
return false;
}
function cancel_selection(dab_num) {
delete edits[dab_lookup[dab_num]];
document.getElementById("cancel-" + dab_num).classList.add("d-none");
clear_dab_highlight(dab_num);
edit_set.delete(dab_num);
update_edits();
update_edit_count();
return false;
}
2022-08-13 13:16:49 +01:00
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
</body>
</html>