Skip to content

Commit

Permalink
Add broken tooltip feature
Browse files Browse the repository at this point in the history
  • Loading branch information
compupro committed Nov 30, 2018
1 parent dbcbf07 commit a8f13e4
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions latin_annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,42 @@ class Word {
this.HTMLelement.className = "wordElement";
this.HTMLelement.innerHTML = (wordString == "\n") ? "<br />" : wordString;
this.HTMLelement.id = this.wordID;

var self = this;
this.HTMLelement.addEventListener("click", function(){
self.clicked();
});
this.HTMLelement.addEventListener("mouseover", function(){
self.mousedover();
});
this.HTMLelement.addEventListener("mouseout", function(){
self.hideTooltip();
});

document.getElementById("wordElementContainer").appendChild(this.HTMLelement);
}


mousedover(){
if (this.definition == null){
this.getWordDefinitions(false, false, null, true)
} else {
this.showTooltip();
}
}

showTooltip(){
var tooltip = document.createElement("div");
tooltip.id = "tooltip";
var meaning = document.createTextNode(this.getSelectedEntry().meaning);
tooltip.appendChild(meaning);
document.getElementById("wordElementContainer").appendChild(tooltip);
}

hideTooltip(){
var tooltip = document.getElementById("tooltip");
tooltip.remove();
}

//When the word's wordElement gets clicked, this runs.
clicked(){
currentPassage.clearHighlights();
Expand All @@ -94,7 +121,7 @@ class Word {
this.updateDefinitionView();
this.checkSentenceAgreement();
} else {
this.getWordDefinitions(true, true, null);
this.getWordDefinitions(true, true, null, false);
}
}

Expand Down Expand Up @@ -190,7 +217,7 @@ class Word {

/*Gets word definitions as an XML document which is passed to updateWordDefinition()
Optionally runs updateView and/or checkSentenceAgreement if set. I would have used callbacks for that but it didn't work.*/
getWordDefinitions(updateView, checkSentenceAgreement, otherWord){
getWordDefinitions(updateView, checkSentenceAgreement, otherWord, showTooltip){
var x = new XMLHttpRequest();
x.open("GET", ALPHEIOS_PERL_URL+this.wordNoPunctuation, true);

Expand All @@ -211,6 +238,9 @@ class Word {
self.agree();
}
}
if (showTooltip){
self.showTooltip();
}
}
}
x.send(null);
Expand Down Expand Up @@ -279,7 +309,7 @@ class Word {
if (wordObj.sentence == this.sentence && wordID != this.wordID &&
wordObj.wordString != "\n"){
if (wordObj.definition == null){
wordObj.getWordDefinitions(false, false, this.getSelectedInfl());
wordObj.getWordDefinitions(false, false, this.getSelectedInfl(), false);
} else if (wordObj.agreesWith(this.getSelectedInfl())){
wordObj.agree();
}
Expand Down Expand Up @@ -413,6 +443,12 @@ class Word {
this.HTMLelement.classList.add("agrees");
}

getSelectedEntry(){
var entryNumber = this.definition.selectedEntry;
var entry = this.definition.entries[entryNumber];
return entry;
}

getSelectedInfl(){
var entryNumber = this.definition.selectedEntry;
var inflNumber = this.definition.selectedInfl;
Expand Down

0 comments on commit a8f13e4

Please sign in to comment.