merge forcenet with wikimap, many refinements, incremental loading directly from api

This commit is contained in:
Michael Murtaugh
2019-07-09 17:31:52 +02:00
parent ad3e494d47
commit 5ac253c712
6 changed files with 1276 additions and 966 deletions

120
dist/index.js vendored
View File

@@ -1,18 +1,14 @@
// custom_scroller_menu(
// document.scrollingElement,
// document.getElementById("menubar"),
// document.getElementById("debug"));
var svg = document.querySelector("#svg"),
page = document.querySelector("#page"),
iframe = document.querySelector("iframe#wikiframe"),
cats = document.querySelector("#cats"),
cats_contents = document.querySelector("#cats .body"),
cats_thumb = document.querySelector("#cats .thumb"),
// cats_thumb = document.querySelector("#cats .thumb"),
allcatscb = document.querySelector("input#allcats"),
historycb = document.querySelector("input#history"),
current_title = null,
loaded = false,
// current_title = null,
// loaded = false,
wikibaseurl,
wikibasepat;
@@ -36,99 +32,35 @@ function resize() {
}
resize();
// console.log("mediawikiapi", mediawikiapi);
var symbols = {
"Orientations": "symbols.svg#Orientations",
"Ateliers pluridisciplinaires": "symbols.svg#Ateliers_pluridisciplinaires",
"Cours de soutien à l'orientation": "symbols.svg#Cours_de_soutien_a_l'orientation",
"Cours de soutien spécifique": "symbols.svg#Cours_de_soutien_specifique",
"Cours techniques": "symbols.svg#Cours_techniques",
"Cours théoriques": "symbols.svg#Cours_theoriques",
"Enseignants": "symbols.svg#Enseignants",
"default": "symbols.svg#Main"
};
var map = new app.Map(symbols);
var map = new app.Map({
apiurl: "/mw/api.php",
symbols: "src/legend.json",
svg: "#svg",
categorylabel: "Catégorie",
categorydiv: "#cats .body"
});
map.init_svg("#svg");
async function doload () {
console.log("loading map");
await map.load_json("data/sitemap.json");
console.log("map.init");
await map.init();
console.log("map.init: done");
// await map.load_json("data/sitemap.json");
// console.log("loading categories");
// await map.load_cats("data/cats.json", cats_contents);
await map.load_legend("src/legend.json", cats_contents);
console.log("LOADED!");
loaded = true;
if (current_title) {
map.set_active_title(current_title);
}
}
// await map.load_legend("src/legend.json", cats_contents);
// loaded = true;
map.on("page", function (title) {
console.log("map.page", title);
var url = wiki_title_to_url(title);
iframe.src = url;
})
// async function doload() {
// map.set_active_node(startpage.value);
// }
function strip_fragment (href) {
var spos = href.indexOf("#");
if (spos >= 0) {
return href.substr(0, href.indexOf("#"))
}
return href;
}
function url_to_wiki_title (href) {
href = strip_fragment(href);
var m = wikibasepat.exec(href);
if (m !== null) {
return decodeURI(m[1]).replace(/_/g, " ");
}
console.log("m", m);
}
function wiki_title_to_url (title) {
return wikibaseurl+encodeURI(title.replace(/ /g, "_"));
map.on("page", function (page) {
// console.log("map.page", page.title);
var url = page.url();
if (iframe.src !== url) {
// console.log("setting iframe src to", url);
iframe.src = url;
}
})
}
window.addEventListener("DOMContentLoaded", doload);
function strip_title_from_wiki_url (url) {
return url.substr(0, url.lastIndexOf("/")+1);
}
iframe.addEventListener("load", function () {
var href = strip_fragment(iframe.contentWindow.location.href);
if (!wikibaseurl) {
wikibaseurl = strip_title_from_wiki_url(href);
wikibasepat = new RegExp(wikibaseurl+"(.+)");
}
console.log("iframe loaded", href);
var title = url_to_wiki_title(href);
console.log("title", title);
if (title) {
current_title = title;
if (loaded) {
map.set_active_title(title);
}
}
// attempt to map url to wiki page title and update the map if it is one
map.set_active_url(iframe.contentWindow.location.href);
});
cats_thumb.addEventListener("click", function () {
cats.classList.toggle("expanded");
});
// allcats checkbox
// match current state & respond to change events
// console.log("setting checked to", cats.classList.contains("showall"))
allcatscb.checked = cats.classList.contains("showall");
allcatscb.addEventListener("change", function () {
// console.log("allcats", allcatscb);
if (allcatscb.checked) {
cats.classList.add("showall")
} else {
cats.classList.remove("showall")
}
})
historycb.addEventListener("change", function () {
// console.log("history", historycb.checked);
map.set_show_history(historycb.checked);
})