var historie = new Array() // pole s spoupností procházených pojmů - historie var max_historie = 10; // limit historie var historie_actual = -1; // ukazatel aktuální pojmu při procházení hstorie var terminy = new Array(); // pole s pojmy var lineDelimiter = "$" // oddělovač řádků // konstruktor objektu pojmu function Pojem() { this.title = ""; // název this.subtitle = "" // podtitul this.description = ""; // obsah pojmu this.refs = new Array(); // příbuzné pojmy } //inicializace aplikace function init() { actualTerm = -1; for (var i = 0; i < term.length; i++) {// načtení pojmů var termin = new Pojem() termin.title = term[i][0]; termin.subtitle = term[i][1] termin.description = term[i][2] termin.refs = term[i][3]; terminy.push(termin); } // terminy.sort(sortByTitle); var variables = location.search; if (variables.indexOf('?pojem=') == 0) { var trm = variables.substr(7); trm = decodeURIComponent(trm); trm = trm.split('+').join(' '); showTermNamed(trm); } else { showTerm(0, true); } showList(""); } // uložení pojmu do hisorie function putToHistory(index) { if (historie.length == max_historie) { historie.shift() } historie.push(index); setActualHistory(historie.length-1) } // nastavení aktuálního pojmu v historii function setActualHistory(index) { historie_actual = index; var history_prev = document.getElementById("history_prev"); var history_next = document.getElementById("history_next"); if (index == 0) { // zablokovani predchoziho talcitka history_prev.src = "../design/l_inactive.png" } if (index > 0) { history_prev.src = "../design/l_active.png" } if (index == historie.length-1) { //zabokovani dalsiho tlacitka history_next.src = "../design/r_inactive.png"; } if (index < historie.length-1 && historie.length > 1) { //odblokovani dalsiho tlacitka history_next.src = "../design/r_active.png"; } } // přechod na předcházející pojem v historii function goPrev() { if (historie_actual > 0) { showTerm(historie[--historie_actual],false) setActualHistory(historie_actual) } } // přechod na následující pojem v historii function goNext() { if (historie_actual < historie.length-1 ) { showTerm(historie[++historie_actual], false) setActualHistory(historie_actual) } } // zobrazení index-tého pojmu toHistory - ukazatel, jestli se má uložit do historie (true/false) function showTerm(index, toHistory) { if (toHistory) putToHistory(index) showNode("info") var pojem = terminy[index] setHTML("desc_title", pojem.title); setHTML("desc_subtitle", pojem.subtitle); setHTML("termdescription", wikify(pojem.description)); setHTML("refs", createRelated(index)); actualTerm = index; } // rozsekání řetězce na jednotlivé řádky function delinearize(retez) { var radky = retez.split(lineDelimiter) return radky.join("\n"); } // vybere položku seznamu s daným názvem function selectListItem(jmeno) { var seznam = document.getElementById("seznam"); if (seznam != null) { var itemId = -1; for (var i = 0; i < seznam.length; i++) { if (seznam.options[i].text == jmeno) { itemId = i; break; } } seznam.selectedIndex = itemId; } } // zobrazení pojmu s daným názvem function showTermNamed(jmeno) { var termExists = false; for (var i = 0; i < terminy.length; i++) { if (terminy[i].title == jmeno) { showTerm(i, true); selectListItem(jmeno); termExists = true; actualTerm = i; break; } } if (!termExists) { alert("Termín není v databázi."); if (actualTerm == -1) { showTerm(0, true); } } } // JavaScript StringBuffer umožňující spojování řetězců mnohem rychleji než // operátor "+", znatelné především v IE function StringBuffer() { this.buffer = []; } StringBuffer.prototype.append = function append(string) { this.buffer.push(string); return this; }; StringBuffer.prototype.toString = function toString() { return this.buffer.join(""); }; // převedení pojmu z wiki-sekvence na HTML pro zobrazení pojmu function wikify(retez) { var pozice = 0; var buf = new StringBuffer(); var radky = retez.split(lineDelimiter) for (var i =0; i< radky.length; i++) { //alert("Radek " + i + ": " + radky[i]) if (radky[i] == "") continue; buf.append("

"); var zasobnik = new Array() //var odkazovy = new Regexp for (var j = 0; j< radky[i].length; j++) { if (radky[i].charAt(j) == "[" && ("i<>".indexOf(radky[i].charAt(j+1)) > -1 ) ) { //pozor, obrazek var zbytek = radky[i].substring(j+1); var obrazek = zbytek.substring(0, zbytek.indexOf("]]")) var alignment = (obrazek.charAt(0) == "i") ? "" : obrazek.charAt(0); var casti = obrazek.split("["); casti[1] = (casti[1].indexOf("]") > -1 ) ? casti[1].substring(0, casti[1].length-1) : casti[1] buf.append("") { buf.append(" class='imgRight'") } if (casti.length == 3) { buf.append(" alt=\"" + casti[2] + "\" title=\"" + casti[2] + "\""); } buf.append(" \/>"); j += obrazek.length +3; continue; } if (radky[i].charAt(j) == "[" && radky[i].charAt(j+1) == "[" ) { //alert("odkaz") var zbytek = radky[i].substring(j+2); var odkaz = zbytek.substring(0, zbytek.indexOf("]]")) var casti = odkaz.split("|"); if (casti.length == 2) { buf.append("" + casti[0] + ""); } if (casti.length == 1) { buf.append("" + casti[0] + ""); } j += odkaz.length +3; continue; } if (radky[i].charAt(j) == "/" && radky[i].charAt(j+1) == "/" ) { if (zasobnik.isLast("em")) { zasobnik.pop(); buf.append(""); } else { zasobnik.push("em"); buf.append(""); } j += 1; continue; } if (radky[i].charAt(j) == "*" && radky[i].charAt(j+1) == "*" ) { if (zasobnik.isLast("strong")) { zasobnik.pop(); buf.append(""); } else { zasobnik.push("strong"); buf.append(""); } j += 1; continue; } buf.append(radky[i].charAt(j)); } buf.append("

"); } return buf.toString(); } // gnerování seznamu příbuzných pojmů function createRelated(index) { var pojmy = term[index][3]; var buf = new StringBuffer(); buf.append("Související hesla: "); for (var i =0; i< pojmy.length; i++) { buf.append("" + pojmy[i] + ""); if (i < pojmy.length -1) buf.append(", "); } return buf.toString(); } function getValue(nodeId) { return document.getElementById(nodeId).value; } function setHTML(nodeId, retez) { document.getElementById(nodeId).innerHTML = retez; } pictures = new Array() actualPicture = 0 // zobrazení seznamu vyhledaných pojmů function showList(filter) { setHTML("list_content", createList(filter)); } // zobrazení seznamu všech pojmů function showAll() { document.getElementById("word_begin").value = ""; document.getElementById("searched_title").value = ""; showList(""); } // vytvoření seznamu pojmů, které začínají řetězcem filter a obsahují řetězec filter2 function createList(filter) { // var filter2 = getValue("searched_title"); // zakomentováno kvůli zrušenému vyhledávání var filter2 = ""; filter = filter.toLowerCase(); filter2 = filter2.toLowerCase(); var buf = new StringBuffer(); buf.append(""); return buf.toString(); } // hledání v názvech pojmů function searchTitles() { setHTML("list_content", createList(getValue("word_begin"))); } // uzávorkování řetězce function quote(retez) { return "\"" + retez + "\""; } // zobrazení uzlu s id="nodeId" function showNode(nodeId) { document.getElementById(nodeId).style.visibility = "visible" } // zjištění, zda retez je poslední prvek pole Array.prototype.isLast = function(retez) { if (this.length == 0) return false; else { if (this[this.length-1] == retez) return true; else return false; } } // nahrazenmí všech výskytů podřetězce stare řetězcem nove String.prototype.replaceAll = function(stare, nove) { var nahrada = new RegExp(stare,"g") return this.replace(nahrada, nove) }