Lexiconga/js/min/dictionaryBuilder.js

1 line
26 KiB
JavaScript

function AddWord(){var e=htmlEntities(document.getElementById("word").value).trim(),t=htmlEntities(document.getElementById("pronunciation").value).trim(),n=htmlEntities(document.getElementById("partOfSpeech").value).trim(),i=htmlEntities(document.getElementById("simpleDefinition").value).trim(),r=htmlEntities(document.getElementById("longDefinition").value),o=document.getElementById("errorMessage"),a="",c=document.getElementById("updateConflict");if(""==e||""==i&&""==r)""==e?(a+="Word cannot be blank",a+=""==i&&""==r?" and you need at least one definition.":"."):""==i&&""==r&&(a+="You need at least one definition.");else{var s=currentDictionary.settings.allowDuplicates?-1:WordIndex(e);if(s>=0)if(WordAtIndexWasChanged(s,e,t,n,i,r)){document.getElementById("newWordButtonArea").style.display="none",DisableForm(""),c.style.display="block";var d="<span id='updateConflictMessage'>\""+e+'" is already in the dictionary';d+=currentDictionary.words[s].name!=e?' as "'+currentDictionary.words[s].name+'", and your dictionary is set to ignore case.':".",d+="<br>Do you want to update it to what you have set above?</span>",d+='<button type="button" id="updateConfirmButton" onclick="UpdateWord('+s+", '"+htmlEntities(e)+"', '"+htmlEntities(t)+"', '"+htmlEntities(n)+"', '"+htmlEntities(i)+"', '"+htmlEntities(r)+"'); return false;\">Yes, Update it</button>",d+=' <button type="button" id="updateCancelButton" onclick="CloseUpdateConflictArea(\'\'); return false;">No, Leave it</button>',c.innerHTML=d}else a='"'+e+'" is already in the dictionary exactly as it is written above',currentDictionary.words[s].name!=e&&(a+=". (Your dictionary is currently set to ignore case.)");else currentDictionary.words.push({name:e,pronunciation:t,partOfSpeech:n.length>0?n:" ",simpleDefinition:i,longDefinition:r,wordId:currentDictionary.nextWordId++}),SaveAndUpdateWords("new"),FocusAfterAddingNewWord(),NewWordNotification(e);o.innerHTML=""}o.innerHTML=a}function ShowWordEditForm(e){var t=e.toString(),n=currentDictionary.words[e],i='<form id="editForm'+t+'"> <h2>Editing '+htmlEntitiesParse(n.name)+'</h2> <label><span>Word</span> <input type="text" id="word'+t+'" value="'+htmlEntitiesParse(n.name)+'" onkeydown="SubmitWordOnCtrlEnter(this)" /> </label> <label><span>Pronunciation <a class="clickable inline-button" href="/ipa_character_picker/" target="_blank" title="IPA Character Picker backed up from http://r12a.github.io/pickers/ipa/">IPA Characters</a></span> <input type="text" id="pronunciation'+t+'" value="'+htmlEntitiesParse(n.pronunciation)+'" onkeydown="SubmitWordOnCtrlEnter(this)" /> </label> <label><span>Part of Speech</span> <select id="partOfSpeech'+t+'" onkeydown="SubmitWordOnCtrlEnter(this)"></select> </label> <label><span>Equivalent Word(s)</span> <input type="text" id="simpleDefinition'+t+'" value="'+htmlEntitiesParse(n.simpleDefinition)+'" onkeydown="SubmitWordOnCtrlEnter(this)" /> </label> <label><span>Explanation/Long Definition <span id="showFullScreenTextbox" class="clickable inline-button" onclick="ShowFullScreenTextbox(\'longDefinition'+t+"', 'Explanation/Long Definition')\">Maximize</span></span> <textarea id=\"longDefinition"+t+'" class="longDefinition" onkeydown="SubmitWordOnCtrlEnter(this)">'+htmlEntitiesParse(n.longDefinition)+'</textarea> </label> <span id="errorMessage'+t+'"></span> <div id="editWordButtonArea'+t+'" style="display: block;"> <button type="button" onclick="EditWord(\''+t+'\'); return false;">Edit Word</button> <button type="button" onclick="CancelEditForm('+t+'); return false;">Cancel</button> </div> <div id="updateConflict'+t+'" style="display: none;"></div> </form>';document.getElementById("entry"+t).innerHTML=i,SetPartsOfSpeech("partOfSpeech"+t),document.getElementById("partOfSpeech"+t).value=htmlEntitiesParse(n.partOfSpeech)}function CancelEditForm(e){document.getElementById("entry"+e.toString()).innerHTML=DictionaryEntry(e).replace("<entry id='entry"+e.toString()+"'>","").replace("</entry>","")}function EditWord(e){var t=htmlEntities(document.getElementById("word"+e).value).trim(),n=htmlEntities(document.getElementById("pronunciation"+e).value).trim(),i=htmlEntities(document.getElementById("partOfSpeech"+e).value).trim(),r=htmlEntities(document.getElementById("simpleDefinition"+e).value).trim(),o=htmlEntities(document.getElementById("longDefinition"+e).value),a=document.getElementById("errorMessage"+e),c="",s=document.getElementById("updateConflict"+e);WordAtIndexWasChanged(e,t,n,i,r,o)?(document.getElementById("editWordButtonArea"+e).style.display="none",DisableForm(e),s.style.display="block",s.innerHTML="<span id='updateConflictMessage"+e+"'>Do you really want to change the word \""+currentDictionary.words[parseInt(e)].name+'" to what you have set above?</span><br>',s.innerHTML+='<button type="button" id="updateConfirmButton'+e+'" onclick="UpdateWord('+e+", '"+htmlEntities(t)+"', '"+htmlEntities(n)+"', '"+htmlEntities(i)+"', '"+htmlEntities(r)+"', '"+htmlEntities(o)+"'); return false;\">Yes, Update it</button>",s.innerHTML+='<button type="button" id="updateCancelButton'+e+'" onclick="CloseUpdateConflictArea(\''+e+"'); return false;\">No, Leave it</button>"):(c='No change has been made to "'+t+'"',currentDictionary.words[parseInt(e)].name!=t&&(c+=". (Your dictionary is currently set to ignore case.)")),a.innerHTML=c}function UpdateWord(e,t,n,i,r,o){currentDictionary.words[e].name=t,currentDictionary.words[e].pronunciation=n,currentDictionary.words[e].partOfSpeech=i.length>0?i:" ",currentDictionary.words[e].simpleDefinition=r,currentDictionary.words[e].longDefinition=o,SaveAndUpdateWords("update",e),window.scroll(savedScroll.x,savedScroll.y),wordFormIsLocked()||FocusAfterAddingNewWord()}function DeleteWord(e){var t=new XMLHttpRequest;t.open("POST","/php/ajax_dictionarymanagement.php?action=worddelete"),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){return 4==t.readyState&&200==t.status?("deleted successfully"!=t.responseText&&"not signed in"!=t.responseText||(currentDictionary.words.splice(e,1),SaveWords(!1)),console.log(t.responseText),!0):!1},t.send("dict="+currentDictionary.externalID.toString()+"&word="+currentDictionary.words[e].wordId.toString())}function ShowDictionary(){var e=GetSelectedFilters(),t=[],n=htmlEntitiesParseForSearchEntry(document.getElementById("searchBox").value),i=document.getElementById("searchOptionWord").checked,r=document.getElementById("searchOptionSimple").checked,o=document.getElementById("searchOptionLong").checked,a=!document.getElementById("searchCaseSensitive").checked,c=document.getElementById("searchIgnoreDiacritics").checked;if(""!=n&&(i||r||o)){var s=[],d=htmlEntitiesParseForSearch(JSON.stringify(currentDictionary));a&&(n=n.toLowerCase()),c&&(n=removeDiacritics(n),d=removeDiacritics(d)),i&&s.push("contains("+(a?"name":'translate(name, "", "")')+', "'+n+'")'),r&&s.push("contains("+(a?"simpleDefinition":'translate(simpleDefinition, "", "")')+', "'+n+'")'),o&&s.push("contains("+(a?"longDefinition":'translate(longDefinition, "", "")')+', "'+n+'")');var l=JSON.parse(d);t=JSON.search(l,"//words["+s.join(" or ")+"]/wordId")}var u=document.getElementById("dictionaryName");u.innerHTML=htmlEntitiesParse(currentDictionary.name)+" Dictionary",loggedIn&&currentDictionary.settings.isPublic&&(u.innerHTML+="<a href='/"+currentDictionary.externalID+"' target='_blank' id='dictionaryShareLink' class='clickable' title='Share Dictionary'>&#10150;</a>");var p=document.getElementById("dictionaryDescription");p.innerHTML=marked(htmlEntitiesParse(currentDictionary.description));var y=document.getElementById("theDictionary"),m="",D=0;if(currentDictionary.words.length>0)for(var g=0;g<currentDictionary.words.length;g++)(0==e.length||e.length>0&&e.indexOf(currentDictionary.words[g].partOfSpeech)>-1)&&(""==n||""!=n&&(i||r||o)&&t.indexOf(currentDictionary.words[g].wordId)>=0)&&(currentDictionary.words[g].hasOwnProperty("pronunciation")||(currentDictionary.words[g].pronunciation=""),currentDictionary.words[g].hasOwnProperty("wordId")||(currentDictionary.words[g].wordId=g+1),m+=DictionaryEntry(g),D++);else m="There are no entries in the dictionary.";y.innerHTML=m,ShowFilterWordCount(D)}function DictionaryEntry(e){var t=regexParseForSearch(document.getElementById("searchBox").value),n=document.getElementById("searchOptionWord").checked,i=document.getElementById("searchOptionSimple").checked,r=document.getElementById("searchOptionLong").checked,o=!document.getElementById("searchCaseSensitive").checked,a=document.getElementById("searchIgnoreDiacritics").checked,c=new RegExp("("+(a?removeDiacritics(t)+"|"+t:t)+")","g"+(o?"i":"")),s=wordPronunciation=wordPartOfSpeech=wordSimpleDefinition=wordLongDefinition="";return s+=""!=t&&n?htmlEntitiesParse(currentDictionary.words[e].name).replace(c,"<searchTerm>$1</searchterm>"):currentDictionary.words[e].name.toString(),""!=currentDictionary.words[e].pronunciation&&(wordPronunciation+=marked(htmlEntitiesParse(currentDictionary.words[e].pronunciation)).replace("<p>","").replace("</p>",""))," "!=currentDictionary.words[e].partOfSpeech&&""!=currentDictionary.words[e].partOfSpeech&&(wordPartOfSpeech+=currentDictionary.words[e].partOfSpeech.toString()),""!=currentDictionary.words[e].simpleDefinition&&(""!=t&&i?wordSimpleDefinition+=htmlEntitiesParse(currentDictionary.words[e].simpleDefinition).replace(c,"<searchTerm>$1</searchterm>"):wordSimpleDefinition+=currentDictionary.words[e].simpleDefinition.toString()),""!=currentDictionary.words[e].longDefinition&&(""!=t&&r?wordLongDefinition+=marked(htmlEntitiesParse(currentDictionary.words[e].longDefinition).replace(c,"<searchTerm>$1</searchterm>")):wordLongDefinition+=marked(htmlEntitiesParse(currentDictionary.words[e].longDefinition))),DictionaryEntryTemplate({name:s,pronunciation:wordPronunciation,partOfSpeech:wordPartOfSpeech,simpleDefinition:wordSimpleDefinition,longDefinition:wordLongDefinition,wordId:currentDictionary.words[e].wordId.toString()},currentDictionary.settings.isComplete?!1:e)}function ManagementArea(e){var t="<div class='management'>";return t+="<span class='clickable editButton' onclick='ShowWordEditForm("+e+")'>Edit</span>",t+="<span class='clickable deleteButton' onclick='document.getElementById(\"delete"+e+'Confirm").style.display = "block";\'>Delete</span>',t+="<div class='deleteConfirm' id='delete"+e+"Confirm' style='display:none;'>Are you sure you want to delete this entry?<br><br>",t+="<span class='clickable deleteCancelButton' onclick='document.getElementById(\"delete"+e+'Confirm").style.display = "none";\'>No</span>',t+="<span class='clickable deleteConfirmButton' onclick='DeleteWord("+e+")'>Yes</span>",t+="</div>",t+="</div>"}function DictionaryEntryTemplate(e,t){t="undefined"!=typeof t?t:!1;var n="<entry id='entry";return t!==!1&&(n+=t.toString()),n+="'><a name='"+e.wordId+"'></a>",loggedIn&&currentDictionary.settings.isPublic&&(n+="<a href='/"+currentDictionary.externalID+"/"+e.wordId+"' target='_blank' class='wordLink clickable' title='Share Word' style='margin-left:5px;'>&#10150;</a>"),n+="<a href='#"+e.wordId+"' class='wordLink clickable' title='Link Within Page'>&#x1f517;</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>"),t!==!1&&(n+=ManagementArea(t)),n+="</entry>"}function SaveSettings(){""!=htmlEntities(document.getElementById("dictionaryNameEdit").value)&&(currentDictionary.name=htmlEntities(document.getElementById("dictionaryNameEdit").value)),currentDictionary.description=htmlEntities(document.getElementById("dictionaryDescriptionEdit").value),CheckForPartsOfSpeechChange(),currentDictionary.settings.allowDuplicates=document.getElementById("dictionaryAllowDuplicates").checked,currentDictionary.settings.caseSensitive=document.getElementById("dictionaryCaseSensitive").checked,currentDictionary.settings.sortByEquivalent=document.getElementById("dictionarySortByEquivalent").checked,currentDictionary.settings.isComplete=document.getElementById("dictionaryIsComplete").checked,document.getElementById("dictionaryIsPublic")&&(currentDictionary.settings.isPublic=document.getElementById("dictionaryIsPublic").checked),HideSettingsWhenComplete(),SaveAndUpdateDictionary(!0),LoadUserDictionaries()}function EmptyWholeDictionary(){confirm("This will delete the entire current dictionary. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")&&CreateNewDictionary()}function CreateNewDictionary(){ResetDictionaryToDefault(),SaveAndUpdateDictionary(!1),SetPartsOfSpeech(),HideSettings(),ShowSettings(),document.getElementById("dictionaryNameEdit").focus()}function DeleteCurrentDictionary(){if(confirm("This will delete the current dictionary from the database. If you do not have a backed up export, you will lose it forever!\n\nDo you still want to delete?")){ResetDictionaryToDefault();var e=new XMLHttpRequest;e.open("POST","/php/ajax_dictionarymanagement.php?action=delete"),e.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.onreadystatechange=function(){return 4==e.readyState&&200==e.status?(e.responseText.length<31?(console.log(e.responseText),CreateNewDictionary()):(HideSettings(),ShowDictionaryDeleteMenu(e.responseText),0==document.getElementById("loadAfterDelete").options.length&&(document.getElementById("loadAfterDeleteScreen").style.display="none",CreateNewDictionary())),!0):!1},e.send()}}function ResetDictionaryToDefault(){currentDictionary=JSON.parse(defaultDictionaryJSON)}function SaveAndUpdateWords(e,t){var n="";"all"==e?n=JSON.stringify(currentDictionary.words):"update"==e?n=JSON.stringify(currentDictionary.words[t]):"new"==e&&(n=JSON.stringify(currentDictionary.words[currentDictionary.words.length-1]));var i=new XMLHttpRequest;i.open("POST","/php/ajax_dictionarymanagement.php?action=word"+e+"&dict="+currentDictionary.externalID.toString()+"&nextwordid="+currentDictionary.nextWordId.toString()),i.setRequestHeader("Content-Type","application/json; charset=UTF-8"),i.onreadystatechange=function(){return 4==i.readyState&&200==i.status?(SaveWords(),ClearForm(),console.log(i.responseText),!0):!1},i.send(n)}function SaveWords(){currentDictionary.settings.sortByEquivalent?currentDictionary.words.sort(dynamicSort(["simpleDefinition","partOfSpeech"])):currentDictionary.words.sort(dynamicSort(["name","partOfSpeech"])),SaveDictionary(!1),ProcessLoad()}function SaveAndUpdateDictionary(e){SaveDictionary(!0),ShowDictionary(),e||ClearForm(),CloseUpdateConflictArea("")}function SaveDictionary(e){e&&SendDictionary(),localStorage.setItem("dictionary",JSON.stringify(currentDictionary)),SavePreviousDictionary()}function SendDictionary(){var e="",t="";currentDictionary.externalID>0?(e="update",t=DataToSend(!1)):(e="new",t=DataToSend(!0));var n=new XMLHttpRequest;n.open("POST","/php/ajax_dictionarymanagement.php?action="+e),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.onreadystatechange=function(){return 4==n.readyState&&200==n.status?("updated successfully"==n.responseText?(console.log(n.responseText),LoadUserDictionaries(),ProcessLoad()):isNaN(parseInt(n.responseText))?console.log(n.responseText):(currentDictionary.externalID=parseInt(n.responseText),currentDictionary.words.length>0&&SaveAndUpdateWords("all"),LoadUserDictionaries(),ProcessLoad(),console.log("saved "+parseInt(n.responseText).toString()+" successfully")),!0):!1},n.send(t)}function DataToSend(e){e="undefined"!=typeof e&&null!=e?e:!1;var t="";return 0==currentDictionary.externalID?(t="name="+encodeURIComponent(currentDictionary.name)+"&description="+encodeURIComponent(currentDictionary.description)+"&words="+encodeURIComponent(JSON.stringify(currentDictionary.words)),t+="&nextwordid="+currentDictionary.nextWordId+"&allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")+"&casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0"),t+="&partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)+"&sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")+"&iscomplete="+(currentDictionary.settings.isComplete?"1":"0")+"&ispublic="+(currentDictionary.settings.isPublic?"1":"0")):((e||currentDictionary.name!=previousDictionary.name)&&(t+="name="+encodeURIComponent(currentDictionary.name)),(e||currentDictionary.description!=previousDictionary.description)&&(t+=(""==t?"":"&")+"description="+encodeURIComponent(currentDictionary.description)),(e||currentDictionary.nextWordId!=previousDictionary.nextWordId)&&(t+=(""==t?"":"&")+"nextwordid="+currentDictionary.nextWordId),(e||currentDictionary.settings.allowDuplicates!=previousDictionary.allowDuplicates)&&(t+=(""==t?"":"&")+"allowduplicates="+(currentDictionary.settings.allowDuplicates?"1":"0")),(e||currentDictionary.settings.caseSensitive!=previousDictionary.caseSensitive)&&(t+=(""==t?"":"&")+"casesensitive="+(currentDictionary.settings.caseSensitive?"1":"0")),(e||currentDictionary.settings.partsOfSpeech!=previousDictionary.partsOfSpeech)&&(t+=(""==t?"":"&")+"partsofspeech="+encodeURIComponent(currentDictionary.settings.partsOfSpeech)),(e||currentDictionary.settings.sortByEquivalent!=previousDictionary.sortByEquivalent)&&(t+=(""==t?"":"&")+"sortbyequivalent="+(currentDictionary.settings.sortByEquivalent?"1":"0")),(e||currentDictionary.settings.isComplete!=previousDictionary.isComplete)&&(t+=(""==t?"":"&")+"iscomplete="+(currentDictionary.settings.isComplete?"1":"0")),(e||currentDictionary.settings.isPublic!=previousDictionary.isPublic)&&(t+=(""==t?"":"&")+"ispublic="+(currentDictionary.settings.isPublic?"1":"0"))),t}function LoadDictionary(){LoadLocalDictionary();var e=new XMLHttpRequest;e.open("GET","/php/ajax_dictionarymanagement.php?action=load"),e.onreadystatechange=function(){4==e.readyState&&200==e.status&&("no dictionaries"==e.responseText?(currentDictionary.externalID=0,currentDictionary.settings.isPublic=!1,SendDictionary(!0)):e.responseText.length<60?console.log(e.responseText):(currentDictionary=JSON.parse(e.responseText),SaveDictionary(!1))),ProcessLoad()},e.send()}function ChangeDictionary(e){e="undefined"!=typeof e&&null!=e?e:document.getElementById("userDictionaries"),currentDictionary.externalID!=e.value&&e.options.length>0&&(ShowInfoWithText("<h1>Loading "+e.options[e.selectedIndex].text+"...</h1>"),HideSettings(),ChangeDictionaryToId(e.value,function(e){"no dictionaries"==e?(console.log(e),SendDictionary(!1)):e.length<60?console.log(e):(currentDictionary=JSON.parse(e),SaveDictionary(!1),ProcessLoad(),LoadUserDictionaries(),HideInfo())}))}function ChangeDictionaryToId(e,t){var n=new XMLHttpRequest;n.open("POST","/php/ajax_dictionarymanagement.php?action=switch"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded");var i="newdictionaryid="+e.toString();n.onreadystatechange=function(){4==n.readyState&&200==n.status&&t(n.responseText)},n.send(i)}function LoadLocalDictionary(){if(localStorage.getItem("dictionary")){var e=JSON.parse(localStorage.getItem("dictionary"));(e.words.length>0||"A new dictionary."!=e.description||"New"!=e.name)&&(currentDictionary=JSON.parse(localStorage.getItem("dictionary"))),e=null}}function ProcessLoad(){currentDictionary.hasOwnProperty("nextWordId")||(currentDictionary.nextWordId=currentDictionary.words.length+1),HideSettingsWhenComplete(),ShowDictionary(),SetPartsOfSpeech(),currentDictionary.settings.isComplete&&(document.getElementById("wordEntryForm").style.display="none"),SavePreviousDictionary()}function SavePreviousDictionary(){previousDictionary={name:currentDictionary.name,description:currentDictionary.description,nextWordId:currentDictionary.nextWordId,allowDuplicates:currentDictionary.settings.allowDuplicates,caseSensitive:currentDictionary.settings.caseSensitive,partsOfSpeech:currentDictionary.settings.partsOfSpeech,sortByEquivalent:currentDictionary.settings.sortByEquivalent,isComplete:currentDictionary.settings.isComplete,isPublic:currentDictionary.settings.isPublic}}function ExportDictionary(){var e=removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g,"");""==e&&(e="export"),download(e+".dict",localStorage.getItem("dictionary"))}function ExportWords(){if(currentDictionary.words.length>0){var e=removeDiacritics(stripHtmlEntities(currentDictionary.name)).replace(/\W/g,"");""==e&&(e="export"),e+="_words";for(var t="word,pronunciation,part of speech,equivalent,explanation\n",n=0;n<currentDictionary.words.length;n++){var i='"'+htmlEntitiesParse(currentDictionary.words[n].name).trim().replace(/\"/g,'""')+'"',r='"'+htmlEntitiesParse(currentDictionary.words[n].pronunciation).trim().replace(/\"/g,'""')+'"',o='"'+htmlEntitiesParse(currentDictionary.words[n].partOfSpeech).trim().replace(/\"/g,'""')+'"',a='"'+htmlEntitiesParse(currentDictionary.words[n].simpleDefinition).trim().replace(/\"/g,'""')+'"',c='"'+htmlEntitiesParse(currentDictionary.words[n].longDefinition).replace(/\"/g,'""')+'"';t+=i+","+r+","+o+","+a+","+c+"\n"}download(e+".csv",t)}else alert("Dictionary must have at least 1 word to export.")}function ImportDictionary(){if(currentDictionary.externalID>0||confirm("Importing this dictionary will overwrite your current one, making it impossible to retrieve if you have not already exported it! Do you still want to import?")){if(!window.FileReader)return alert("Your browser is not supported"),!1;var e=new FileReader;if(document.getElementById("importFile").files.length>0){var t=document.getElementById("importFile").files[0];e.readAsText(t),e.onloadend=function(){if(e.result&&e.result.length){var t=JSON.parse(e.result);if(t.hasOwnProperty("name")&&t.hasOwnProperty("description")&&t.hasOwnProperty("words")&&t.hasOwnProperty("settings"))currentDictionary=JSON.parse(e.result),currentDictionary.externalID=0,currentDictionary.settings.isPublic=!1,SaveDictionary(!0),ProcessLoad(),HideInfo(),HideSettings(),document.getElementById("importFile").value="",NewNotification('Successfully Imported the "'+currentDictionary.name+'" Dictionary.');else{var n="File is missing:";t.hasOwnProperty("name")||(n+=" name"),t.hasOwnProperty("description")||(n+=" description"),t.hasOwnProperty("words")||(n+=" words"),t.hasOwnProperty("settings")||(n+=" settings"),alert("Uploaded file is not compatible.\n\n"+n)}t=null}else alert("Upload Failed");e=null}}else alert("You must add a file to import.")}}function ImportWords(){if(currentDictionary.externalID>0||confirm("This will add words in a correctly formatted CSV file to your currently loaded dictionary. Do you still want to import?")){if(!window.FileReader)return alert("Your browser is not supported"),!1;if(document.getElementById("importWordsCSV").files.length>0){var e=document.getElementById("importWordsCSV").files[0],t=document.getElementById("importOptions");t.innerHTML="<h3>Importing Words...</h3>";var n=0,i=0;Papa.parse(e,{header:!0,step:function(e,r){if(n++,e.data[0].word.trim().length>0&&(e.data[0].equivalent.trim().length>0||e.data[0].explanation.trim().length>0)||0==e.errors.length){var o=htmlEntities(e.data[0].word).trim(),a=htmlEntities(e.data[0].pronunciation).trim(),c=htmlEntities(e.data[0]["part of speech"]).trim().length>0?htmlEntities(e.data[0]["part of speech"]).trim():" ",s=htmlEntities(e.data[0].equivalent).trim(),d=htmlEntities(e.data[0].explanation).trim(),l=currentDictionary.nextWordId++;currentDictionary.words.push({name:o,pronunciation:a,partOfSpeech:c,simpleDefinition:s,longDefinition:d,wordId:l});var u=DictionaryEntryTemplate(currentDictionary.words[currentDictionary.words.length-1]);t.innerHTML+=u,i++}else if(e.data[0].word.trim().length>0)for(var p=0;p<e.errors.length;p++)t.innerHTML+="<p>Error on record #"+n.toString()+": "+e.errors[p].message+"</p>";document.getElementById("infoPage").scrollTop=document.getElementById("infoPage").scrollHeight},complete:function(e){SaveAndUpdateWords("all"),t.innerHTML+="<p>The file has finished importing "+i.toString()+" words.</p>",NewNotification("Imported "+i.toString()+" words."),document.getElementById("importOptions").scrollTop=document.getElementById("importOptions").scrollHeight,document.getElementById("numberOfWordsInDictionary").innerHTML=currentDictionary.words.length.toString()}})}else alert("You must add a file to import.")}}function WordIndex(e,t){for(var n=0;n<currentDictionary.words.length;n++)if(!t&&!currentDictionary.settings.caseSensitive&&currentDictionary.words[n].name.toLowerCase()==e.toLowerCase()||currentDictionary.settings.caseSensitive&&currentDictionary.words[n].name==e||t&&currentDictionary.words[n].wordId==e)return n;return-1}function WordAtIndexWasChanged(e,t,n,i,r,o){return!currentDictionary.settings.caseSensitive&&currentDictionary.words[parseInt(e)].name.toLowerCase()!=t.toLowerCase()||currentDictionary.settings.caseSensitive&&currentDictionary.words[parseInt(e)].name!=t||currentDictionary.words[parseInt(e)].pronunciation!=n||currentDictionary.words[parseInt(e)].partOfSpeech!=i||currentDictionary.words[parseInt(e)].simpleDefinition!=r||currentDictionary.words[parseInt(e)].longDefinition!=o}function CheckForPartsOfSpeechChange(){htmlEntities(document.getElementById("dictionaryPartsOfSpeechEdit").value)!=currentDictionary.settings.partsOfSpeech&&""!=htmlEntities(document.getElementById("dictionaryPartsOfSpeechEdit").value)&&(currentDictionary.settings.partsOfSpeech=htmlEntities(document.getElementById("dictionaryPartsOfSpeechEdit").value),SetPartsOfSpeech())}var publicName="Someone",currentDictionary={name:"New",description:"A new dictionary.",createdBy:publicName,words:[],nextWordId:1,settings:{allowDuplicates:!1,caseSensitive:!1,partsOfSpeech:"Noun,Adjective,Verb,Adverb,Preposition,Pronoun,Conjunction",sortByEquivalent:!1,isComplete:!1,isPublic:!1},externalID:0},defaultDictionaryJSON=JSON.stringify(currentDictionary),previousDictionary={},savedScroll={x:0,y:0};