Lexiconga/js/min/publicView.js

1 line
5.1 KiB
JavaScript

function IsValidPublicDicitonary(){return"string"!=typeof publicDictionary}function ShowPublicDictionary(e){if(e="undefined"!=typeof e?e:!1,IsValidPublicDicitonary()){var i=e?[]:GetSelectedFilters(),n=[],t=e?"":htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value),r=e?null:document.getElementById("searchOptionWord").checked,o=e?null:document.getElementById("searchOptionSimple").checked,c=e?null:document.getElementById("searchOptionLong").checked,a=e?null:!document.getElementById("searchCaseSensitive").checked,l=e?null:document.getElementById("searchIgnoreDiacritics").checked;if(!e&&""!=t&&(r||o||c)){var d=[],s=htmlEntitiesParseForSearch(JSON.stringify(publicDictionary));a&&(t=t.toLowerCase()),l&&(t=removeDiacritics(t),s=removeDiacritics(s)),r&&d.push("contains("+(a?"name":'translate(name, "", "")')+', "'+t+'")'),o&&d.push("contains("+(a?"simpleDefinition":'translate(simpleDefinition, "", "")')+', "'+t+'")'),c&&d.push("contains("+(a?"longDefinition":'translate(longDefinition, "", "")')+', "'+t+'")');var p=JSON.parse(s);n=JSON.search(p,"//words["+d.join(" or ")+"]/wordId")}var m=document.getElementById("dictionaryName");m.innerHTML=htmlEntitiesParse(publicDictionary.name)+" Dictionary";var u=document.getElementById("dictionaryBy");u.innerHTML="created by "+htmlEntitiesParse(publicDictionary.createdBy);var y=document.getElementById("incompleteNotice");publicDictionary.settings.isComplete||(y.innerHTML="<em>Note: This dictionary is not yet complete and is likely to change.</em>");var h=document.getElementById("dictionaryDescription");h.innerHTML=marked(htmlEntitiesParse(publicDictionary.description));var D=document.getElementById("theDictionary"),f="",g=0;if(publicDictionary.words.length>0)for(var w=0;w<publicDictionary.words.length;w++)(0==i.length||i.length>0&&i.indexOf(publicDictionary.words[w].partOfSpeech)>-1)&&(""==t||""!=t&&(r||o||c)&&n.indexOf(publicDictionary.words[w].wordId)>=0)&&(publicDictionary.words[w].hasOwnProperty("pronunciation")||(publicDictionary.words[w].pronunciation=""),publicDictionary.words[w].hasOwnProperty("wordId")||(publicDictionary.words[w].wordId=w+1),f+=PublicDictionaryEntry(w,e),g++);else f="There are no entries in the dictionary.";D.innerHTML=f,e||ShowFilterWordCount(g)}else document.getElementById("dictionaryContainer").innerHTML=publicDictionary}function PublicDictionaryEntry(e,i){var n=i?"":regexParseForSearch(document.getElementById("searchBox").value),t=i?!1:document.getElementById("searchOptionWord").checked,r=i?!1:document.getElementById("searchOptionSimple").checked,o=i?!1:document.getElementById("searchOptionLong").checked,c=i?!1:!document.getElementById("searchCaseSensitive").checked,a=i?!1:document.getElementById("searchIgnoreDiacritics").checked,l=new RegExp("("+(a?removeDiacritics(n)+"|"+n:n)+")","g"+(c?"i":"")),d=wordPronunciation=wordPartOfSpeech=wordSimpleDefinition=wordLongDefinition="";return d+=""!=n&&t?htmlEntitiesParse(publicDictionary.words[e].name).replace(l,"<searchTerm>$1</searchterm>"):publicDictionary.words[e].name.toString(),""!=publicDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParse(publicDictionary.words[e].pronunciation)).replace("<p>","").replace("</p>","")),""!=publicDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=publicDictionary.words[e].partOfSpeech.toString()),""!=publicDictionary.words[e].simpleDefinition&&(""!=n&&r?wordSimpleDefinition+=htmlEntitiesParse(publicDictionary.words[e].simpleDefinition).replace(l,"<searchTerm>$1</searchterm>"):wordSimpleDefinition+=publicDictionary.words[e].simpleDefinition.toString()),""!=publicDictionary.words[e].longDefinition&&(""!=n&&o?wordLongDefinition+=marked(htmlEntitiesParse(publicDictionary.words[e].longDefinition).replace(l,"<searchTerm>$1</searchterm>")):wordLongDefinition+=marked(htmlEntitiesParse(publicDictionary.words[e].longDefinition))),PublicDictionaryEntryTemplate({name:d,pronunciation:wordPronunciation,partOfSpeech:wordPartOfSpeech,simpleDefinition:wordSimpleDefinition,longDefinition:wordLongDefinition,wordId:publicDictionary.words[e].wordId.toString()},!1)}function PublicDictionaryEntryTemplate(e,i){i="undefined"!=typeof i?i:!1;var n="<entry id='entry";return i!==!1&&(n+=i.toString()),n+="'><a href='/"+publicDictionary.id+"/"+e.wordId+"' class='wordLink clickable' title='Share Word'>&#10150;</a>",n+="<word>"+e.name+"</word>",""!=e.pronunciation&&(n+="<pronunciation>"+e.pronunciation+"</pronunciation>"),""!=e.partOfSpeech&&(n+="<partofspeech>"+e.partOfSpeech+"</partofspeech>"),n+="<br>",""!=e.simpleDefinition&&(n+="<simpledefinition>"+e.simpleDefinition+"</simpledefinition>"),""!=e.longDefinition&&(n+="<longdefinition>"+e.longDefinition+"</longdefinition>"),i!==!1&&(n+=ManagementArea(i)),n+="</entry>"}function SetPublicPartsOfSpeech(){for(var e=document.getElementById("filterOptions"),i=htmlEntitiesParse(publicDictionary.settings.partsOfSpeech).trim().split(","),n=0;n<i.length;n++){var t=i[n].trim(),r=document.createElement("label");r.appendChild(document.createTextNode(t+" ")),r["part-of-speech"]=t,r.className="filterOption";var o=document.createElement("input");o.type="checkbox",o.onchange=function(){ShowPublicDictionary()},r.appendChild(o),e.appendChild(r)}}