Lexiconga/js/min/publicView.js

1 line
5.4 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=publicDictionary.name+" Dictionary";var u=document.getElementById("dictionaryBy");u.innerHTML="created by "+publicDictionary.createdBy;var h=document.getElementById("incompleteNotice");publicDictionary.settings.isComplete||(h.innerHTML="<em>Note: This dictionary is not yet complete and is likely to change.</em>");var y=document.getElementById("dictionaryDescription");y.innerHTML=marked(htmlEntitiesParseForMarkdown(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?htmlEntities(htmlEntitiesParse(publicDictionary.words[e].name).replace(l,"<searchterm>$1</searchterm>")).replace(/&lt;(\/?)searchterm&gt;/g,"<$1searchterm>"):publicDictionary.words[e].name.toString(),""!=publicDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParseForMarkdown(publicDictionary.words[e].pronunciation)).replace(/<\/?p>/g,""))," "!=publicDictionary.words[e].partOfSpeech&&""!=publicDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=publicDictionary.words[e].partOfSpeech.toString()),""!=publicDictionary.words[e].simpleDefinition&&(""!=n&&r?wordSimpleDefinition+=htmlEntities(htmlEntitiesParse(publicDictionary.words[e].simpleDefinition).replace(l,"<searchterm>$1</searchterm>")).replace(/&lt;(\/?)searchterm&gt;/g,"<$1searchterm>"):wordSimpleDefinition+=publicDictionary.words[e].simpleDefinition.toString()),""!=publicDictionary.words[e].longDefinition&&(""!=n&&o?wordLongDefinition+=marked(htmlEntitiesParseForMarkdown(htmlEntities(htmlEntitiesParse(publicDictionary.words[e].longDefinition).replace(l,"<searchterm>$1</searchterm>")))).replace(/&lt;(\/?)searchterm&gt\;/g,"<$1searchterm>"):wordLongDefinition+=marked(htmlEntitiesParseForMarkdown(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)}}