var terminy = new Array(); // pole s pojmy
var dictionary = new Array();
var reload = false;
var filter = "de";
var hidden = false;
var ab = new StringBuffer();
var sb = new StringBuffer();
var initialCreation = true;
var partialDiv = null;
var openedDiv = false;
// konstruktor objektu pojmu
function Pojem() {
this.clen = "";
this.gerWord = ""; // german word
this.suffix = ""; // suffix
this.czeWord = ""; // czech word - term_description
}
var viewportheight = 0;
/**
* Set Initial height of displayed dictionary
*/
function setListHeight() {
//var viewportwidth;
// the more standards compliant browsers (mozilla/netscape/opera/IE7)
if (typeof window.innerWidth != 'undefined') {
//viewportwidth = window.innerWidth;
viewportheight = window.innerHeight
} else {
if ((typeof document.documentElement != 'undefined') && (typeof document.documentElement.clientWidth != 'undefined')
&& (document.documentElement.clientWidth != 0)) {
//viewportwidth = document.documentElement.clientWidth;
viewportheight = document.documentElement.clientHeight;
} else {
//viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
viewportheight = document.getElementsByTagName('body')[0].clientHeight;
}
}
document.getElementById("word-list").style.height = viewportheight - 370 + "px";
}
//inicializace aplikace
function init() {
for (var i = 0; i < terms.length; i++) {// načtení pojmů
var termin = new Pojem();
if (terms[i].length == 1) {
terminy.push(terms[i][0]);
} else {
termin.clen = terms[i][0];
termin.gerWord = terms[i][1];
termin.suffix = terms[i][2];
termin.czeWord = terms[i][3];
//insert into "local db"
terminy.push(termin);
}
}
createDictionary();
}
function createOption(i, termin) {
//adding word item
if ((i % 2) == 1 ) {
sb.append("
");
} else {
sb.append("
");
}
/*
var meanings = termin.czeWord.split("|");
var parsed_czech = new StringBuffer();
for (var j = 0; j < meanings.length; j++) {
if (meanings[j].indexOf("^") > 0) {
parsed_czech.append("
");
parsed_czech.append(meanings[j].substring(0, meanings[j].indexOf("^")));
parsed_czech.append(" " + meanings[j].substring(meanings[j].indexOf("^") + 1));
} else {
parsed_czech.append(meanings[j]);
}
if (j < (meanings.length - 1)) {
parsed_czech.append(", ");
}
}
*/
sb.append("
");
sb.append("");
sb.append("" + terminy[i].clen + " | ");
sb.append("");
sb.append("" + terminy[i].gerWord + " ");
sb.append("" + terminy[i].suffix + "");
sb.append(" | ");
sb.append("");
sb.append("" + terminy[i].czeWord + "");
sb.append(" |
");
}
function createLetter(termin) {
sb.append("
" + termin + "
");
if (initialCreation) {
ab.append("
");
ab.append("" + termin + "
");
} else {
document.getElementById('anchor-list').innerHTML = ab.toString();
}
}
function createDictionary() {
for (var i = 0; i < terminy.length; i++) {
if (terminy[i].gerWord) {
createOption(i, terminy[i]);
} else {
//adding main letter item
if (openedDiv) {
partialDiv.innerHTML = sb.toString();
dictionary.push(sb.toString());
sb = new StringBuffer();
//document.getElementById('word-list').appendChild(partialDiv);
} else {
openedDiv = true;
}
createLetter(terminy[i]);
partialDiv = document.createElement("div");
}
}
partialDiv.innerHTML = sb.toString();
dictionary.push(sb.toString());
sb = new StringBuffer();
openedDiv = false;
displayDictionary(0);
}
var redrawAnchors = true;
function displayDictionary(index) {
if (redrawAnchors) {
document.getElementById('anchor-list').innerHTML = ab.toString();
document.getElementById("word-list").innerHTML = "";
redrawAnchors = false;
}
//on the on of calls
if (index == dictionary.length) {
if (document.getElementById("list-loader") != null) {
document.getElementById("list-loader").parentNode.removeChild(document.getElementById("list-loader"));
}
return;
}
partialDiv = document.createElement("div");
partialDiv.innerHTML = dictionary[index];
document.getElementById("word-list").appendChild(partialDiv);
index++;
setTimeout("displayDictionary(" + index + ")", 100);
}
function showLoader() {
var load = new StringBuffer();
load.append("
");
var div = document.createElement("div");
div.id = "list-loader";
div.className = "loader";
document.getElementById("word-list").parentNode.appendChild(div);
//document.getElementById("searchBox")
}
function destroyLoader() {
if (document.getElementById("list-loader") != null) {
document.getElementById("list-loader").parentNode.removeChild(document.getElementById("list-loader"));
}
}
/**
* Scroll to currently selected item. Otherwise skip to next "page" of results
*/
function scrollWord(scrollTo) {
try {
var node = document.getElementById(scrollTo);
var parent = node.parentNode.parentNode;
var xoffset = parent.offsetTop;
var parentCHeight = parent.clientHeight;
var parentSHeight = parent.scrollHeight;
//if(parentSHeight > parentCHeight) {
var nodeHeight = node.clientHeight;
var nodeOffset = node.offsetTop;
var scrollOffset = nodeOffset - xoffset;
var wordTop = document.getElementById('word-list').scrollTop;
//parent.scrollTop = scrollOffset;
if (scrollTo.indexOf("letter") == 0) {
document.getElementById('word-list').scrollTop = scrollOffset;
return;
}
/*
var visibleItem = false;
if (wordTop - scrollOffset < 0) {
visibleItem = Math.abs((wordTop - scrollOffset)) < (viewportheight - 290);
}
if (!visibleItem) {
parent.scrollTop = scrollOffset;
document.getElementById('word-list').scrollTop = scrollOffset;
} else {
if (queryLineIndex > 0) {
scrollToWord();
}
}
*/
} catch (err) {
//empty
alert("Slovník ješte není kompletně zobrazený.");
}
}
var pointerDiv;
var lastQuery = "";
var executeQuery = false;
var completeDictionary = true;
var hiddenOptions = new Array();
function scrollToWord() {
var checkStatus = document.getElementById("translationBox").checked;
var query = getValue("searchBox");
if (lastQuery == query) return;
document.body.style.cursor = "wait";
showLoader();
if (executeQuery) {
unhideAll();
executeQuery = false;
}
if (query == "") {
destroyLoader();
document.body.style.cursor = "default";
return;
}
if (lastQuery != query) {
executeQuery = true;
lastQuery = query;
hiddenOptions = new Array();
var elemId;
var anchorId;
var anchorEl;
for (var i = 0; i < terminy.length; i++) {
//search only among real words, not delimiters
if (terminy[i].gerWord) {
var word;
if (filter == "de") {
word = terminy[i].gerWord.toLowerCase();
} else {
word = terminy[i].czeWord.toLowerCase();
}
if (word.indexOf(query) == -1) {
elemId = "opt" + i;
document.getElementById(elemId).style.display = "none";
hiddenOptions.push(elemId);
} else {
elemId = "opt" + i;
document.getElementById(elemId).style.display = "block";
if (anchorEl.style.display == "none") {
anchorEl.style.display = "block";
document.getElementById(anchorId + "_anchor").style.display = "block";
}
}
} else {
anchorId = "letter_" + terminy[i];
hiddenOptions.push(anchorId);
anchorEl = document.getElementById(anchorId);
document.getElementById(anchorId + "_anchor").style.display = "none";
anchorEl.style.display = "none";
}
}
if (document.getElementById("displayAll") == null) {
var allContent = "
Zobrazit celý slovník
";
var allDiv = document.createElement("div");
allDiv.innerHTML = allContent;
document.getElementById("transHolder").innerHTML = allContent + document.getElementById("transHolder").innerHTML;
}
}
destroyLoader();
document.body.style.cursor = "default";
document.getElementById("translationBox").checked = checkStatus;
}
function unhideAll() {
if (hiddenOptions.length == 0) { return;}
var x = 0;
while (hiddenOptions.length > 0) {
var al = document.getElementById(hiddenOptions.shift())
al.style.display = "block";
}
}
function setFilter(lang) {
if (lang == "cz") {
document.getElementById("cz-lang").className = "lang chosen";
document.getElementById("de-lang").className = "lang";
document.getElementById("czech-chosen").className = "czech-arrow";
document.getElementById("ger-chosen").className = "";
document.getElementById("searchButton").value = "Hledat";
document.getElementById("translationText").innerHTML = "Skrýt překlad";
} else {
document.getElementById("de-lang").className = "lang chosen";
document.getElementById("cz-lang").className = "lang";
document.getElementById("czech-chosen").className = "";
document.getElementById("ger-chosen").className = "german-arrow";
document.getElementById("searchButton").value = "Suche";
document.getElementById("translationText").innerHTML = "Übersetzung schließen";
}
lastQuery = "";
filter = lang;
var hideIt = document.getElementById("translationBox").checked;
if (hideIt) {
if (filter == "cz") {
setClassVisibility(".vis", "visibility", hideIt);
setClassVisibility(".czech-side", "visibility", !hideIt);
} else {
setClassVisibility(".vis", "visibility", !hideIt);
setClassVisibility(".czech-side", "visibility", hideIt);
}
}
}
function keyHandler(e) {
if (!e) var e = window.event;
document.getElementById("searchCloseButton").style.display = "block";
var key = e.charCode ? e.charCode : e.keyCode;
//escape key
if (key == 27) {
clearFilter();
}
//enter key
if (key == 13) {
scrollToWord();
}
}
function clearFilter() {
var input = document.getElementById("searchBox");
//input.value = " ";
document.getElementById("text").focus();
input.value = "";
document.getElementById("searchCloseButton").style.display = "none";
document.getElementById("displayAll").parentNode.removeChild(document.getElementById("displayAll"));
input.focus();
lastQuery = "";
document.getElementById('anchor-list').innerHTML = ab.toString();
unhideAll();
}
function onBlur() {
var obj = document.getElementById("searchBox");
if (obj.value == "") {
//obj.value = "hledané slovo";
document.getElementById("searchCloseButton").style.display = "none";
}
}
function toggleTranslation(clear) {
var element = "visibility";
if (filter == "de") {
className = ".czech-side";
} else {
className = ".vis";
}
var hideIt = document.getElementById("translationBox").checked;
if (hideIt) {
setClassVisibility(className, element, hideIt);
} else {
setClassVisibility(className, element, hideIt);
}
}
function setClassVisibility(className, elem, hideIt) {
var cssRules;
var value = "visible";
if (hideIt) value = "hidden";
//hide elem
for (var S = 0; S < document.styleSheets.length; S++) {
try{
document.styleSheets[S].insertRule(className+' { '+elem+': '+value+'; }',document.styleSheets[S][cssRules].length);
} catch (err) {
try {
document.styleSheets[S].addRule(className,elem+': '+value+';');
} catch(err) {
try {
if (document.styleSheets[S]['rules']) {
cssRules = 'rules';
} else if (document.styleSheets[S]['cssRules']) {
cssRules = 'cssRules';
} else {
//no rules found... browser unknown
}
for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
if (document.styleSheets[S][cssRules][R].selectorText == className) {
if(document.styleSheets[S][cssRules][R].style[elem]){
document.styleSheets[S][cssRules][R].style[elem] = value;
break;
}
}
}
} catch (err){}
}
}
}
}
// 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("");
};
function getValue(nodeId) {
return document.getElementById(nodeId).value;
}
function setHTML(nodeId, retez) {
document.getElementById(nodeId).innerHTML = retez;
}
// 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;
}
};