var actLang = "cs";
var doc = document.querySelector("html");
if (doc && doc.hasAttribute("lang")) {
actLang = doc.getAttribute("lang");
}
var actual = {
chapter: 0, item: 0, thumb: null,
svg: null, path: null, cons: [], graphics: null, control: null, dragged: false
}
var displayMode = "normal";
var svgNS = "http://www.w3.org/2000/svg";
var xlinkNS = "http://www.w3.org/1999/xlink";
var PF = {
startWidth: 800,
startHeight: 700,
bgImage: null,
markers: null,
connectors: null,
graphics: null,
markerCS: null,
markerEN: null,
markerLAT: null,
cx: 0,
cy: 0,
actualChapter: -1,
gray: false,
lastURL: ""
}
var sections = ["toc", "thumbs", "single"]
var displayMode = "normal"
var i18n = {
cs: {
system: "systém",
sex: "pohlavní systém",
toc_chapter_title: "Přejít na kapitolu",
toc_section_title: "Přejít na sekci",
chapter_prev: "Předchozí kapitola",
chapter_next: "Následující kapitola",
thumbs_title: "Náhledy",
thumbs_goto: "Zobrazit náhledy",
item_prev: "Přechozí preparát",
item_next: "Následující preparát"
},
en: {
system: "system",
sex: "reproductive system",
toc_chapter_title: "Go to chapter",
toc_section_title: "Go to section",
chapter_prev: "Previous chapter",
chapter_next: "Next chapter",
thumbs_title: "Thumbnails",
thumbs_goto: "Go to thumbnails",
item_prev: "Previous preparate",
item_next: "Next preparate"
}
}
window.addEventListener("load", init)
var baseurl = this.location.href;
var basedir = baseurl.substring(0, baseurl.lastIndexOf("/"));
var maxCid = -1; // maximalni id kapitoly
function init(evt) {
PF.bgImage = document.getElementById("edit-image");
PF.graphics = document.querySelector("g.graphics");
PF.connectors = document.querySelector("g.connectors");
PF.markers = document.querySelector(".edit-desc");
PF.titleCS = document.getElementById("edit-title-cs");
PF.titleEN = document.getElementById("edit-title-en");
PF.descCS = document.getElementById("edit-desc-cs");
PF.descEN = document.getElementById("edit-desc-en");
PF.markerCS = document.getElementById("edit-marker-cs");
PF.markerEN = document.getElementById("edit-marker-en");;
PF.markerLAT = document.getElementById("edit-marker-lat");;
actual.svg = document.querySelector(".edit-cons");
window.addEventListener("keydown", resolveKeys);
sortItems();
}
function resolveURL() {
var chapter = -1;
var sect = -1;
var item = -1;
if (baseurl.indexOf("?") > -1) {
var end = baseurl.substring(baseurl.indexOf("?")+1);
var attrs = end.match(/[^\&]+=[^\&]+/g);
if (attrs) {
for (var i = 0; i < attrs.length; i++) {
var attr = attrs[i];
var name = attr.substring(0,attr.indexOf("="));
var val = attr.substring(attr.indexOf("=")+1);
if (name == "chapter") {
chapter = parseInt(val);
}
if (name == "item") {
item = parseInt(val);
}
if (name == "section") {
sect = parseInt(val);
}
if (name == "gray") {
PF.gray = true;
}
}
}
baseurl = baseurl.substring(0, baseurl.indexOf("?"))
}
if (chapter != -1) {
showChapter(chapter);
if (sect > 0) {
showSubsection(sect);
}
if (item > -1) {
showPreparate(item);
}
}
//new DragDivScroll('preparat');
else {
showSection("toc");
// generateToc();
}
}
function generateToc() {
var list = document.querySelector("ul.toc");
list.innerHTML = "";
var out = ""
for (var i = 0; i < chapters.length; i++) {
var chap = chapters[i];
out += "
" + chap.label + " " + chap[actLang] + ""
}
list.innerHTML = out;
resolveURL();
}
function showSection(sid) {
var sect = document.getElementById(sid)
if (sect && sect.classList.contains("hidden")) {
sect.classList.remove("hidden");
}
}
function hideSection(sid) {
var sect = document.getElementById(sid)
if (sect && !sect.classList.contains("hidden")) {
sect.classList.add("hidden");
}
}
function hltab(uzel) {
var tabs = uzel.parentNode.getElementsByTagName("LI");
for (var i =0; i < tabs.length; i++) {
tabs[i].className = (tabs[i] == uzel) ? "active" : ""
}
}
function showToc() {
showSection("toc");
hideSection("thumbs");
//hideSection("single");
}
function nextChapter() {
if (PF.actualChapter < chapters.length-1) {
PF.actualChapter++;
showChapter(PF.actualChapter)
}
}
function prevChapter() {
if (PF.actualChapter > 0) {
PF.actualChapter--;
showChapter(PF.actualChapter)
}
}
function showChapter(evt) {
hideSection("intro");
if (actual.mode != "big") {
showSection("header");
showSection("thumbs");
showSection("chapter-desc");
}
if (document.getElementById("text").classList.contains("big")) {
shrink("toc");
expand("thumbs");
}
var index = 0,
subindex = 0;
if (typeof evt == "number") {
index = evt;
} else {
var ixs = evt.currentTarget.getAttribute("data-ix").split("_");
index = parseInt(ixs[0]);
if (ixs.length > 1) {
subindex = parseInt(ixs[1]);
}
}
var tabs = document.querySelectorAll(".toc li");
if (PF.actualChapter != undefined && PF.actualChapter > -1) {
tabs[PF.actualChapter].classList.remove("actual")
}
tabs[index].classList.add("actual");
if (!chapters || chapters.length < index + 1) return;
PF.actualChapter = index;
actualSection = subindex;
var chapter = chapters[index];
var vystup = ""
/*
if (index > 0) {
vystup += ""
} else {
vystup += ""
}
*/
vystup += (PF.actualChapter + 1) + " " + chapter[actLang];
var grayer = document.getElementById("grayer");
grayer.checked = PF.gray
//"";
//vystup += grayer;
/*
if (index < chapters.length - 1) {
vystup += ""
} else {
vystup += ""
}
*/
document.getElementById("chaptitle").innerHTML = vystup;
var desc = chapter["intro" + actLang.toUpperCase()];
desc = replaceEntities(desc);
desc = desc.replace(/([\s\d>])um([<\.\s\,\)])/g, "$1µm$2");
desc = desc.replace(/([\s])([ksvziou])([\s])/gi, "$1$2 " );
desc = replaceGreek(desc);
document.getElementById("chapter-desc").innerHTML = desc;
//µ
out = "";
if (chapter.subs && chapter.subs.length > 0) {
for (var i = 0; i < chapter.subs.length; i++) {
var sub = subtitle.appendChild(document.createElement("span"));
sub.className = "subitem";
if (subindex == i) {
sub.classList.add("actual");
}
sub.setAttribute("data-index", i);
sub.addEventListener("click", changeSection);
sub.innerHTML = chapter.subs[i][actLang];
}
}
//showSubsection(subindex);
generateThumbs(index)
}
function replaceEntities(text) {
var t2 = text.replace(/\>/g,">");
t2 = t2.replace(/\</g,"<");
return t2;
}
function replaceGreek(text) {
var t2 = text;
var pairs = [
["alpha", "α"],
["beta", "β"],
["gamma", "γ"],
["delta", "δ"],
["epsilon", "ε"],
["zeta", "ζ"],
["theta", "θ"],
["iota", "ι"],
["kappa", "κ"],
["lambda", "λ"],
["mu", "μ"],
["nu", "ν"],
["xi", "ξ"],
["omicron", "ο"],
["pi", "π"],
["rho", "ρ"],
["sigma", "σ"],
["tau", "τ"],
["upsilon", "υ"],
["phi", "φ"],
["chi", "χ"],
["psi", "ψ"],
["omega", "ω"],
["eta", "η"],
["micro", "µ"],
["Alpha", "Α"],
["Beta", "Β"],
["Gamma", "Γ"],
["Delta", "Δ"],
["Epsilon", "Ε"],
["Zeta", "Ζ"],
["Eta", "Η"],
["Theta", "Θ"],
["Iota", "Ι"],
["Kappa", "Κ"],
["Lambda", "Λ"],
["Mu", "Μ"],
["Nu", "Ν"],
["Xi", "Ξ"],
["Omicron", "Ο"],
["Pi", "Π"],
["Rho", "Ρ"],
["Sigma", "Σ"],
["Tau", "Τ"],
["Upsilon", "Υ"],
["Phi", "Φ"],
["Chi", "Χ"],
["Psi", "Ψ"],
["Omega", "Ω"],
];
for (var i = 0; i < pairs.length ;i++) {
t2 = t2.replace(new RegExp("\\\\" + pairs[i][0], "g"), pairs[i][1]);
}
return t2;
}
function showSubsection(index) {
var subs = document.querySelectorAll("#subtitle .subitem");
if (actualSection > -1) {
subs[actualSection].classList.remove("actual");
}
subs[index].classList.add("actual");
actualSection = index;
generateThumbs(index);
PF.lastURL = baseurl + "?chapter=" + PF.actualChapter + "§ion=" + actualSection;
if (PF.gray) {
PF.lastURL += "&gray=true"
}
history.pushState({}, popis, PF.lastURL);
}
function changeSection(evt) {
var sub = evt.currentTarget;
var index = parseInt(sub.getAttribute("data-index"));
if (index != actualSection) {
//actualSection = index;
showSubsection(index);
}
}
function toggleGray(check) {
var thumbs = document.getElementById("thumbs");
var prep = document.getElementById("preparat");
if (!check.checked) {
thumbs.classList.remove("gray");
prep.classList.remove("gray");
PF.gray = false;
PF.lastURL = PF.lastURL.replace("&gray=true", "");
}
else {
thumbs.classList.add("gray");
prep.classList.add("gray");
PF.gray = true;
PF.lastURL += "&gray=true";
}
setLangUrl(PF.lastURL);
history.pushState({}, "", PF.lastURL);
}
/* ************************* generovani prehledu nahledu */
function generateThumbs(index) {
addMode("thumbnails");
actualPrep = 0;
showSection("thumbs");
//hideSection("single");
var thumbs = document.getElementById("thumbs");
if (PF.gray && !thumbs.classList.contains("gray")) {
thumbs.classList.add("gray");
}
var vystup = ""; //