2015-11-28 07:17:52 +01:00
/* global markdown */
2015-10-30 22:56:05 +01:00
/* global Defiant */
2015-11-02 18:28:43 +01:00
2015-11-04 22:12:39 +01:00
var publicName = "Someone" ;
2015-10-26 22:50:09 +01:00
var currentDictionary = {
name : "New" ,
2015-10-28 06:41:01 +01:00
description : "A new dictionary." ,
2015-11-05 00:43:52 +01:00
createdBy : publicName ,
2015-10-26 05:41:25 +01:00
words : [ ] ,
2015-11-08 00:24:50 +01:00
nextWordId : 1 ,
2015-10-26 05:41:25 +01:00
settings : {
2015-10-30 18:38:41 +01:00
allowDuplicates : false ,
2015-10-26 05:41:25 +01:00
caseSensitive : false ,
2015-10-27 23:36:24 +01:00
partsOfSpeech : "Noun,Adjective,Verb,Adverb,Preposition,Pronoun,Conjunction" ,
2015-11-07 18:40:28 +01:00
sortByEquivalent : false ,
2015-12-22 01:52:56 +01:00
isComplete : false ,
isPublic : false
2015-11-26 00:08:24 +01:00
} ,
externalID : 0
2015-10-26 22:50:09 +01:00
}
var defaultDictionaryJSON = JSON . stringify ( currentDictionary ) ; //Saves a stringifyed default dictionary.
2015-11-26 00:08:24 +01:00
var previousDictionary = { } ;
2015-10-26 22:50:09 +01:00
var savedScroll = {
x : 0 ,
y : 0
2015-10-26 05:41:25 +01:00
}
function AddWord ( ) {
2015-11-07 18:40:28 +01:00
var word = htmlEntities ( document . getElementById ( "word" ) . value ) . trim ( ) ;
var pronunciation = htmlEntities ( document . getElementById ( "pronunciation" ) . value ) . trim ( ) ;
var partOfSpeech = htmlEntities ( document . getElementById ( "partOfSpeech" ) . value ) . trim ( ) ;
var simpleDefinition = htmlEntities ( document . getElementById ( "simpleDefinition" ) . value ) . trim ( ) ;
2015-10-26 22:50:09 +01:00
var longDefinition = htmlEntities ( document . getElementById ( "longDefinition" ) . value ) ;
2016-06-07 19:44:36 +02:00
// var editIndex = htmlEntities(document.getElementById("editIndex").value);
2015-10-26 22:50:09 +01:00
var errorMessageArea = document . getElementById ( "errorMessage" ) ;
var errorMessage = "" ;
var updateConflictArea = document . getElementById ( "updateConflict" ) ;
2015-10-27 23:36:24 +01:00
2015-10-26 05:41:25 +01:00
if ( word != "" && ( simpleDefinition != "" || longDefinition != "" ) ) {
2015-10-30 20:23:04 +01:00
var wordIndex = ( ! currentDictionary . settings . allowDuplicates ) ? WordIndex ( word ) : - 1 ;
2015-10-26 22:50:09 +01:00
2016-06-07 19:44:36 +02:00
if ( wordIndex >= 0 ) {
2015-11-07 07:51:44 +01:00
if ( WordAtIndexWasChanged ( wordIndex , word , pronunciation , partOfSpeech , simpleDefinition , longDefinition ) ) {
2015-12-17 02:13:45 +01:00
document . getElementById ( "newWordButtonArea" ) . style . display = "none" ;
DisableForm ( ) ;
2015-10-26 22:50:09 +01:00
updateConflictArea . style . display = "block" ;
2015-10-27 23:36:24 +01:00
var updateConflictText = "<span id='updateConflictMessage'>\"" + word + "\" is already in the dictionary" ;
if ( currentDictionary . words [ wordIndex ] . name != word ) {
updateConflictText += " as \"" + currentDictionary . words [ wordIndex ] . name + "\", and your dictionary is set to ignore case." ;
} else {
updateConflictText += "."
}
updateConflictText += "<br>Do you want to update it to what you have set above?</span>" ;
2015-11-07 07:51:44 +01:00
updateConflictText += ' < button type = "button" id = "updateConfirmButton" \
2015-11-10 22:51:36 +01:00
onclick = " UpdateWord ( ' + wordIndex + ' , \ '' + htmlEntities ( word ) + '\', \'' + htmlEntities ( pronunciation ) + '\', \'' + htmlEntities ( partOfSpeech ) + '\', \'' + htmlEntities ( simpleDefinition ) + '\', \'' + htmlEntities ( longDefinition ) + '\' ) ; \
2015-11-07 07:51:44 +01:00
return false ; " > Yes , Update it < / b u t t o n > ' ;
2016-06-07 19:44:36 +02:00
updateConflictText += ' <button type="button" id="updateCancelButton" onclick="CloseUpdateConflictArea(\'newWordButtonArea\', \'updateConflict\'); return false;">No, Leave it</button>' ;
2015-10-27 23:36:24 +01:00
updateConflictArea . innerHTML = updateConflictText ;
2015-10-26 22:50:09 +01:00
} else {
2015-10-27 23:36:24 +01:00
errorMessage = "\"" + word + "\" is already in the dictionary exactly as it is written above" ;
if ( currentDictionary . words [ wordIndex ] . name != word ) {
errorMessage += ". (Your dictionary is currently set to ignore case.)"
}
2015-10-26 05:41:25 +01:00
}
} else {
2016-06-10 20:35:57 +02:00
currentDictionary . words . push ( { name : word , pronunciation : pronunciation , partOfSpeech : ( ( partOfSpeech . length > 0 ) ? partOfSpeech : " " ) , simpleDefinition : simpleDefinition , longDefinition : longDefinition , wordId : currentDictionary . nextWordId ++ } ) ;
2015-11-10 01:53:01 +01:00
FocusAfterAddingNewWord ( ) ;
NewWordNotification ( word ) ;
2015-10-30 22:56:05 +01:00
SaveAndUpdateDictionary ( false ) ;
2015-10-26 05:41:25 +01:00
}
2015-10-26 22:50:09 +01:00
errorMessageArea . innerHTML = "" ;
2015-10-26 05:41:25 +01:00
} else {
if ( word == "" ) {
2015-10-26 22:50:09 +01:00
errorMessage += "Word cannot be blank" ;
2015-10-26 05:41:25 +01:00
if ( simpleDefinition == "" && longDefinition == "" ) {
2015-10-26 22:50:09 +01:00
errorMessage += " and you need at least one definition." ;
2015-10-26 05:41:25 +01:00
} else {
2015-10-26 22:50:09 +01:00
errorMessage += "." ;
2015-10-26 05:41:25 +01:00
}
} else if ( simpleDefinition == "" && longDefinition == "" ) {
2015-10-26 22:50:09 +01:00
errorMessage += "You need at least one definition."
2015-10-26 05:41:25 +01:00
}
}
2015-10-27 23:36:24 +01:00
2015-10-26 22:50:09 +01:00
errorMessageArea . innerHTML = errorMessage ;
2015-10-26 05:41:25 +01:00
}
2016-06-07 19:44:36 +02:00
function ShowWordEditForm ( index ) {
var indexString = index . toString ( ) ; // Variable for reduced processing
var word = currentDictionary . words [ index ] ; // Reference for easier reading
var editForm = '<form id="editForm' + indexString + ' " > \
< h2 > Editing ' + htmlEntitiesParse(word.name) + ' < / h 2 > \
< label > < span > Word < / s p a n > \
< input type = "text" id = "word' + indexString + '" value = "' + htmlEntitiesParse(word.name) + '" onkeydown = "SubmitWordOnCtrlEnter(this)" / > \
< / l a b e l > \
< label > < span > Pronunciation < a class = "helperlink" href = "/ipa_character_picker/" target = "_blank" title = "IPA Character Picker backed up from http://r12a.github.io/pickers/ipa/" > IPA Characters < / a > < / s p a n > \
< input type = "text" id = "pronunciation' + indexString + '" value = "' + htmlEntitiesParse(word.pronunciation) + '" onkeydown = "SubmitWordOnCtrlEnter(this)" / > \
< / l a b e l > \
< label > < span > Part of Speech < / s p a n > \
2016-06-10 20:35:57 +02:00
< select id = "partOfSpeech' + indexString + '" onkeydown = "SubmitWordOnCtrlEnter(this)" > < / s e l e c t > \
2016-06-07 19:44:36 +02:00
< / l a b e l > \
< label > < span > Equivalent Word ( s ) < / s p a n > \
< input type = "text" id = "simpleDefinition' + indexString + '" value = "' + htmlEntitiesParse(word.simpleDefinition) + '" onkeydown = "SubmitWordOnCtrlEnter(this)" / > \
< / l a b e l > \
< label > < span > Explanation / Long Definition < span id = "showFullScreenTextbox" class = "clickable" onclick = "ShowFullScreenTextbox(\'longDefinition' + indexString + '\', \'Explanation/Long Definition\')" > Maximize < / s p a n > < / s p a n > \
< textarea id = "longDefinition' + indexString + '" onkeydown = "SubmitWordOnCtrlEnter(this)" > ' + htmlEntitiesParse(word.longDefinition) + ' < / t e x t a r e a > \
< / l a b e l > \
< span id = "errorMessage' + indexString + '" > < / s p a n > \
< div id = "editWordButtonArea' + indexString + '" style = "display: block;" > \
< button type = "button" onclick = "EditWord(\'' + indexString + '\'); return false;" > Edit Word < / b u t t o n > < b u t t o n t y p e = " b u t t o n " o n c l i c k = " C a n c e l E d i t F o r m ( ' + i n d e x S t r i n g + ' ) ; r e t u r n f a l s e ; " > C a n c e l < / b u t t o n > \
< / d i v > \
< div id = "updateConflict' + indexString + '" style = "display: none;" > < / d i v > \
< / f o r m > ' ;
document . getElementById ( "entry" + indexString ) . innerHTML = editForm ;
SetPartsOfSpeech ( "partOfSpeech" + indexString ) ;
2016-06-10 20:35:57 +02:00
document . getElementById ( "partOfSpeech" + indexString ) . value = htmlEntitiesParse ( word . partOfSpeech ) ;
2016-06-07 19:44:36 +02:00
}
2015-10-26 22:50:09 +01:00
2016-06-07 19:44:36 +02:00
function CancelEditForm ( index ) {
document . getElementById ( "entry" + index . toString ( ) ) . innerHTML = DictionaryEntry ( index ) . replace ( "<entry id='entry" + index . toString ( ) + "'>" , "" ) . replace ( "</entry>" , "" ) ;
}
2015-10-26 22:50:09 +01:00
2016-06-07 19:44:36 +02:00
function EditWord ( indexString ) {
var word = htmlEntities ( document . getElementById ( "word" + indexString ) . value ) . trim ( ) ;
var pronunciation = htmlEntities ( document . getElementById ( "pronunciation" + indexString ) . value ) . trim ( ) ;
var partOfSpeech = htmlEntities ( document . getElementById ( "partOfSpeech" + indexString ) . value ) . trim ( ) ;
var simpleDefinition = htmlEntities ( document . getElementById ( "simpleDefinition" + indexString ) . value ) . trim ( ) ;
var longDefinition = htmlEntities ( document . getElementById ( "longDefinition" + indexString ) . value ) ;
// var editIndex = htmlEntities(document.getElementById("editIndex").value);
var errorMessageArea = document . getElementById ( "errorMessage" + indexString ) ;
var errorMessage = "" ;
var updateConflictArea = document . getElementById ( "updateConflict" + indexString ) ;
if ( WordAtIndexWasChanged ( indexString , word , pronunciation , partOfSpeech , simpleDefinition , longDefinition ) ) {
document . getElementById ( "editWordButtonArea" + indexString ) . style . display = "none" ;
DisableForm ( ) ;
updateConflictArea . style . display = "block" ;
updateConflictArea . innerHTML = "<span id='updateConflictMessage" + indexString + "'>Do you really want to change the word \"" + currentDictionary . words [ parseInt ( indexString ) ] . name + "\" to what you have set above?</span>" ;
updateConflictArea . innerHTML += '<button type="button" id="updateConfirmButton' + indexString + ' " \
onclick = " UpdateWord ( ' + indexString + ' , \ '' + htmlEntities ( word ) + '\', \'' + htmlEntities ( pronunciation ) + '\', \'' + htmlEntities ( partOfSpeech ) + '\', \'' + htmlEntities ( simpleDefinition ) + '\', \'' + htmlEntities ( longDefinition ) + '\' ) ; \
return false ; " > Yes , Update it < / b u t t o n > ' ;
updateConflictArea . innerHTML += '<button type="button" id="updateCancelButton' + indexString + '" onclick="CloseUpdateConflictArea(\'editWordButtonArea' + indexString + '\',\'updateConflict' + indexString + '\'); return false;">No, Leave it</button>' ;
} else {
errorMessage = "No change has been made to \"" + word + "\"" ;
if ( currentDictionary . words [ parseInt ( indexString ) ] . name != word ) {
errorMessage += ". (Your dictionary is currently set to ignore case.)" ;
}
}
2015-10-26 22:50:09 +01:00
2016-06-07 19:44:36 +02:00
errorMessageArea . innerHTML = errorMessage ;
2015-10-26 22:50:09 +01:00
}
2015-11-07 07:51:44 +01:00
function UpdateWord ( wordIndex , word , pronunciation , partOfSpeech , simpleDefinition , longDefinition ) {
2015-10-26 22:50:09 +01:00
currentDictionary . words [ wordIndex ] . name = word ;
2015-11-07 07:51:44 +01:00
currentDictionary . words [ wordIndex ] . pronunciation = pronunciation ;
2016-06-10 20:35:57 +02:00
currentDictionary . words [ wordIndex ] . partOfSpeech = ( ( partOfSpeech . length > 0 ) ? partOfSpeech : " " ) ;
2015-10-26 05:41:25 +01:00
currentDictionary . words [ wordIndex ] . simpleDefinition = simpleDefinition ;
currentDictionary . words [ wordIndex ] . longDefinition = longDefinition ;
2016-03-11 16:14:13 +01:00
2015-10-30 22:56:05 +01:00
SaveAndUpdateDictionary ( ) ;
2015-10-26 22:50:09 +01:00
window . scroll ( savedScroll . x , savedScroll . y ) ;
2016-03-11 16:14:13 +01:00
2016-03-18 17:12:06 +01:00
if ( ! wordFormIsLocked ( ) ) {
FocusAfterAddingNewWord ( ) ;
}
2015-10-26 22:50:09 +01:00
}
function DeleteWord ( index ) {
if ( document . getElementById ( "editIndex" ) . value != "" )
ClearForm ( ) ;
currentDictionary . words . splice ( index , 1 ) ;
2015-10-30 22:56:05 +01:00
SaveAndUpdateDictionary ( true ) ;
2015-10-26 05:41:25 +01:00
}
2015-10-30 22:56:05 +01:00
function ShowDictionary ( ) {
2016-05-27 01:37:37 +02:00
var filters = GetSelectedFilters ( ) ;
2015-10-28 05:54:27 +01:00
2015-10-30 22:56:05 +01:00
var searchResults = [ ] ;
2015-12-03 00:03:23 +01:00
var search = htmlEntitiesParseForSearchEntry ( document . getElementById ( "searchBox" ) . value ) ;
var searchByWord = document . getElementById ( "searchOptionWord" ) . checked ;
var searchBySimple = document . getElementById ( "searchOptionSimple" ) . checked ;
var searchByLong = document . getElementById ( "searchOptionLong" ) . checked ;
var searchIgnoreCase = ! document . getElementById ( "searchCaseSensitive" ) . checked ; //It's easier to negate case here instead of negating it every use since ignore case is default.
var searchIgnoreDiacritics = document . getElementById ( "searchIgnoreDiacritics" ) . checked ;
if ( search != "" && ( searchByWord || searchBySimple || searchByLong ) ) {
2015-11-07 07:51:44 +01:00
var xpath = [ ] ;
2015-12-03 00:03:23 +01:00
var searchDictionaryJSON = htmlEntitiesParseForSearch ( JSON . stringify ( currentDictionary ) ) ;
if ( searchIgnoreCase ) {
search = search . toLowerCase ( ) ;
2015-10-30 20:23:04 +01:00
}
2015-12-03 00:03:23 +01:00
if ( searchIgnoreDiacritics ) {
search = removeDiacritics ( search ) ;
searchDictionaryJSON = removeDiacritics ( searchDictionaryJSON ) ;
2015-10-30 20:23:04 +01:00
}
2015-12-03 00:03:23 +01:00
if ( searchByWord ) {
xpath . push ( 'contains(' + ( ( searchIgnoreCase ) ? 'name' : 'translate(name, "", "")' ) + ', "' + search + '")' ) ;
2015-10-30 20:23:04 +01:00
}
2015-12-03 00:03:23 +01:00
if ( searchBySimple ) {
xpath . push ( 'contains(' + ( ( searchIgnoreCase ) ? 'simpleDefinition' : 'translate(simpleDefinition, "", "")' ) + ', "' + search + '")' ) ;
}
if ( searchByLong ) {
xpath . push ( 'contains(' + ( ( searchIgnoreCase ) ? 'longDefinition' : 'translate(longDefinition, "", "")' ) + ', "' + search + '")' ) ;
}
var searchDictionary = JSON . parse ( searchDictionaryJSON ) ;
searchResults = JSON . search ( searchDictionary , '//words[' + xpath . join ( ' or ' ) + ']/wordId' ) ;
2015-10-30 20:23:04 +01:00
}
2015-10-26 22:50:09 +01:00
var dictionaryNameArea = document . getElementById ( "dictionaryName" ) ;
dictionaryNameArea . innerHTML = htmlEntitiesParse ( currentDictionary . name ) + " Dictionary" ;
2015-10-28 22:53:59 +01:00
var dictionaryDescriptionArea = document . getElementById ( "dictionaryDescription" ) ;
2015-12-01 21:15:37 +01:00
dictionaryDescriptionArea . innerHTML = marked ( htmlEntitiesParse ( currentDictionary . description ) ) ;
2015-10-28 22:53:59 +01:00
2015-10-26 05:41:25 +01:00
var dictionaryArea = document . getElementById ( "theDictionary" ) ;
var dictionaryText = "" ;
2016-01-18 20:14:36 +01:00
var numberOfWordsDisplayed = 0 ;
2015-10-26 05:41:25 +01:00
2015-10-26 22:50:09 +01:00
if ( currentDictionary . words . length > 0 ) {
for ( var i = 0 ; i < currentDictionary . words . length ; i ++ ) {
2016-05-27 01:37:37 +02:00
if ( filters . length == 0 || ( filters . length > 0 && filters . indexOf ( currentDictionary . words [ i ] . partOfSpeech ) > - 1 ) ) {
2015-12-03 00:03:23 +01:00
if ( search == "" || ( search != "" && ( searchByWord || searchBySimple || searchByLong ) && searchResults . indexOf ( currentDictionary . words [ i ] . wordId ) >= 0 ) ) {
2015-11-08 00:24:50 +01:00
if ( ! currentDictionary . words [ i ] . hasOwnProperty ( "pronunciation" ) ) {
2015-11-07 07:51:44 +01:00
currentDictionary . words [ i ] . pronunciation = "" ; //Account for new property
}
2015-11-08 00:24:50 +01:00
if ( ! currentDictionary . words [ i ] . hasOwnProperty ( "wordId" ) ) {
currentDictionary . words [ i ] . wordId = i + 1 ; //Account for new property
}
2015-10-30 20:23:04 +01:00
dictionaryText += DictionaryEntry ( i ) ;
2016-01-18 20:14:36 +01:00
numberOfWordsDisplayed ++ ;
2015-10-30 20:23:04 +01:00
}
2015-10-28 05:54:27 +01:00
}
2015-10-26 22:50:09 +01:00
}
} else {
dictionaryText = "There are no entries in the dictionary."
}
2015-10-26 05:41:25 +01:00
2015-10-26 22:50:09 +01:00
dictionaryArea . innerHTML = dictionaryText ;
2016-01-18 20:14:36 +01:00
ShowFilterWordCount ( numberOfWordsDisplayed ) ;
2015-10-26 22:50:09 +01:00
}
2015-10-26 05:41:25 +01:00
2015-10-26 22:50:09 +01:00
function DictionaryEntry ( itemIndex ) {
2015-12-22 01:52:56 +01:00
displayPublic = ( typeof displayPublic !== 'undefined' && displayPublic != null ) ? displayPublic : false ;
2016-06-07 19:44:36 +02:00
var entryText = "<entry id='entry" + itemIndex . toString ( ) + "'><a name='" + currentDictionary . words [ itemIndex ] . wordId + "'></a><a href='#" + currentDictionary . words [ itemIndex ] . wordId + "' class='wordLink clickable'>🔗</a>" ;
2015-10-30 23:45:29 +01:00
2016-02-27 18:10:11 +01:00
var searchTerm = regexParseForSearch ( document . getElementById ( "searchBox" ) . value ) ;
2015-12-03 00:03:23 +01:00
var searchByWord = document . getElementById ( "searchOptionWord" ) . checked ;
var searchBySimple = document . getElementById ( "searchOptionSimple" ) . checked ;
var searchByLong = document . getElementById ( "searchOptionLong" ) . checked ;
var searchIgnoreCase = ! document . getElementById ( "searchCaseSensitive" ) . checked ; //It's easier to negate case here instead of negating it every use since ignore case is default.
var searchIgnoreDiacritics = document . getElementById ( "searchIgnoreDiacritics" ) . checked ;
var searchRegEx = new RegExp ( "(" + ( ( searchIgnoreDiacritics ) ? removeDiacritics ( searchTerm ) + "|" + searchTerm : searchTerm ) + ")" , "g" + ( ( searchIgnoreCase ) ? "i" : "" ) ) ;
2015-10-26 05:41:25 +01:00
2015-12-03 00:03:23 +01:00
entryText += "<word>" ;
if ( searchTerm != "" && searchByWord ) {
entryText += htmlEntitiesParse ( currentDictionary . words [ itemIndex ] . name ) . replace ( searchRegEx , "<searchTerm>$1</searchterm>" ) ;
} else {
entryText += currentDictionary . words [ itemIndex ] . name ;
}
entryText += "</word>" ;
2015-11-07 07:51:44 +01:00
if ( currentDictionary . words [ itemIndex ] . pronunciation != "" ) {
2015-12-03 00:03:23 +01:00
entryText += "<pronunciation>" ;
entryText += marked ( htmlEntitiesParse ( currentDictionary . words [ itemIndex ] . pronunciation ) ) . replace ( "<p>" , "" ) . replace ( "</p>" , "" ) ;
entryText += "</pronunciation>" ;
2015-11-07 07:51:44 +01:00
}
2015-10-26 22:50:09 +01:00
if ( currentDictionary . words [ itemIndex ] . partOfSpeech != "" ) {
2015-12-03 00:03:23 +01:00
entryText += "<partofspeech>" ;
entryText += currentDictionary . words [ itemIndex ] . partOfSpeech ;
entryText += "</partofspeech>" ;
2015-10-26 22:50:09 +01:00
}
entryText += "<br>" ;
2015-10-26 05:41:25 +01:00
2015-10-26 22:50:09 +01:00
if ( currentDictionary . words [ itemIndex ] . simpleDefinition != "" ) {
2015-12-03 00:03:23 +01:00
entryText += "<simpledefinition>" ;
if ( searchTerm != "" && searchBySimple ) {
entryText += htmlEntitiesParse ( currentDictionary . words [ itemIndex ] . simpleDefinition ) . replace ( searchRegEx , "<searchTerm>$1</searchterm>" ) ;
} else {
entryText += currentDictionary . words [ itemIndex ] . simpleDefinition ;
}
entryText += "</simpledefinition>" ;
2015-10-26 05:41:25 +01:00
}
2015-10-26 22:50:09 +01:00
if ( currentDictionary . words [ itemIndex ] . longDefinition != "" ) {
2015-12-03 00:03:23 +01:00
entryText += "<longdefinition>" ;
if ( searchTerm != "" && searchByLong ) {
entryText += marked ( htmlEntitiesParse ( currentDictionary . words [ itemIndex ] . longDefinition ) . replace ( searchRegEx , "<searchTerm>$1</searchterm>" ) ) ;
} else {
entryText += marked ( htmlEntitiesParse ( currentDictionary . words [ itemIndex ] . longDefinition ) ) ;
}
entryText += "</longdefinition>" ;
2015-10-26 22:50:09 +01:00
}
2015-10-30 18:38:41 +01:00
if ( ! currentDictionary . settings . isComplete ) {
entryText += ManagementArea ( itemIndex ) ;
}
2015-10-26 22:50:09 +01:00
entryText += "</entry>" ;
return entryText ;
}
function ManagementArea ( itemIndex ) {
var managementHTML = "<div class='management'>" ;
2016-06-07 19:44:36 +02:00
managementHTML += "<span class='clickable editButton' onclick='ShowWordEditForm(" + itemIndex + ")'>Edit</span>" ;
2015-10-28 22:53:59 +01:00
managementHTML += "<span class='clickable deleteButton' onclick='document.getElementById(\"delete" + itemIndex + "Confirm\").style.display = \"block\";'>Delete</span>" ;
2015-10-26 22:50:09 +01:00
2015-10-30 18:38:41 +01:00
managementHTML += "<div class='deleteConfirm' id='delete" + itemIndex + "Confirm' style='display:none;'>Are you sure you want to delete this entry?<br><br>" ;
2015-10-28 22:53:59 +01:00
managementHTML += "<span class='clickable deleteCancelButton' onclick='document.getElementById(\"delete" + itemIndex + "Confirm\").style.display = \"none\";'>No</span>" ;
managementHTML += "<span class='clickable deleteConfirmButton' onclick='DeleteWord(" + itemIndex + ")'>Yes</span>" ;
2015-10-26 22:50:09 +01:00
managementHTML += "</div>" ;
managementHTML += "</div>" ;
return managementHTML ;
}
function SaveSettings ( ) {
2015-10-26 23:21:13 +01:00
if ( htmlEntities ( document . getElementById ( "dictionaryNameEdit" ) . value ) != "" ) {
currentDictionary . name = htmlEntities ( document . getElementById ( "dictionaryNameEdit" ) . value ) ;
}
2015-10-27 23:36:24 +01:00
2015-10-28 06:41:01 +01:00
currentDictionary . description = htmlEntities ( document . getElementById ( "dictionaryDescriptionEdit" ) . value ) ;
2015-10-27 23:36:24 +01:00
CheckForPartsOfSpeechChange ( ) ;
2015-10-30 18:38:41 +01:00
currentDictionary . settings . allowDuplicates = document . getElementById ( "dictionaryAllowDuplicates" ) . checked ;
currentDictionary . settings . caseSensitive = document . getElementById ( "dictionaryCaseSensitive" ) . checked ;
2015-11-07 18:40:28 +01:00
currentDictionary . settings . sortByEquivalent = document . getElementById ( "dictionarySortByEquivalent" ) . checked ;
2015-10-26 22:50:09 +01:00
currentDictionary . settings . isComplete = document . getElementById ( "dictionaryIsComplete" ) . checked ;
2015-12-22 19:20:33 +01:00
if ( document . getElementById ( "dictionaryIsPublic" ) ) {
currentDictionary . settings . isPublic = document . getElementById ( "dictionaryIsPublic" ) . checked ;
}
2015-10-27 23:36:24 +01:00
2015-10-30 18:38:41 +01:00
HideSettingsWhenComplete ( ) ;
2015-10-30 22:56:05 +01:00
SaveAndUpdateDictionary ( true ) ;
2015-12-01 00:08:43 +01:00
LoadUserDictionaries ( ) ;
2015-10-30 18:38:41 +01:00
}
2015-10-26 22:50:09 +01:00
function EmptyWholeDictionary ( ) {
if ( 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?" ) ) {
2015-12-01 00:08:43 +01:00
CreateNewDictionary ( ) ;
2015-10-26 22:50:09 +01:00
}
}
2015-11-28 07:17:52 +01:00
function CreateNewDictionary ( ) {
ResetDictionaryToDefault ( ) ;
SaveAndUpdateDictionary ( false ) ;
SetPartsOfSpeech ( ) ;
HideSettings ( ) ;
}
2015-12-01 00:08:43 +01:00
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 deleteDictionary = new XMLHttpRequest ( ) ;
deleteDictionary . open ( 'POST' , "php/ajax_dictionarymanagement.php?action=delete" ) ;
deleteDictionary . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
deleteDictionary . onreadystatechange = function ( ) {
if ( deleteDictionary . readyState == 4 && deleteDictionary . status == 200 ) {
if ( deleteDictionary . responseText . length < 31 ) {
console . log ( deleteDictionary . responseText ) ;
CreateNewDictionary ( ) ;
} else {
HideSettings ( ) ;
2015-12-02 17:47:17 +01:00
ShowDictionaryDeleteMenu ( deleteDictionary . responseText ) ;
2015-12-01 00:08:43 +01:00
if ( document . getElementById ( "loadAfterDelete" ) . options . length == 0 ) {
document . getElementById ( 'loadAfterDeleteScreen' ) . style . display = 'none' ;
CreateNewDictionary ( ) ;
}
}
return true ;
} else {
return false ;
}
}
deleteDictionary . send ( ) ;
}
}
2015-11-28 07:17:52 +01:00
function ResetDictionaryToDefault ( ) {
currentDictionary = JSON . parse ( defaultDictionaryJSON ) ;
}
2016-02-27 01:18:29 +01:00
function SaveAndUpdateDictionary ( keepFormContents ) {
if ( ! currentDictionary . settings . sortByEquivalent ) {
2016-03-02 18:59:14 +01:00
currentDictionary . words . sort ( dynamicSort ( [ 'name' , 'partOfSpeech' ] ) ) ;
2016-02-27 01:18:29 +01:00
} else {
2016-03-02 18:59:14 +01:00
currentDictionary . words . sort ( dynamicSort ( [ 'simpleDefinition' , 'partOfSpeech' ] ) ) ;
2016-02-27 01:18:29 +01:00
}
SaveDictionary ( true , true ) ;
ShowDictionary ( ) ;
if ( ! keepFormContents ) {
ClearForm ( ) ;
}
2016-06-07 19:44:36 +02:00
CloseUpdateConflictArea ( 'newWordButtonArea' , 'updateConflict' ) ;
2016-02-27 01:18:29 +01:00
}
2015-11-26 00:08:24 +01:00
function SaveDictionary ( sendToDatabase , sendWords ) {
2015-10-26 05:41:25 +01:00
localStorage . setItem ( 'dictionary' , JSON . stringify ( currentDictionary ) ) ;
2015-11-04 22:12:39 +01:00
//Always save local copy of current dictionary, but if logged in also send to database.
2015-11-26 00:08:24 +01:00
if ( sendToDatabase ) {
2015-11-04 22:12:39 +01:00
sendWords = ( typeof sendWords !== 'undefined' ) ? sendWords : false ;
SendDictionary ( sendWords ) ;
}
SavePreviousDictionary ( ) ;
}
function SendDictionary ( sendWords ) {
sendWords = ( typeof sendWords !== 'undefined' ) ? sendWords : false ;
var action = "" ;
var postString = "" ;
if ( currentDictionary . externalID > 0 ) {
action = "update" ;
postString = DataToSend ( sendWords ) ;
} else {
action = "new" ;
2015-12-01 00:08:43 +01:00
postString = DataToSend ( true , true ) ;
2015-11-04 22:12:39 +01:00
}
2015-12-01 00:08:43 +01:00
2015-11-04 22:12:39 +01:00
var sendDictionary = new XMLHttpRequest ( ) ;
sendDictionary . open ( 'POST' , "php/ajax_dictionarymanagement.php?action=" + action ) ;
2015-11-05 00:43:52 +01:00
sendDictionary . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
2015-11-04 22:12:39 +01:00
sendDictionary . onreadystatechange = function ( ) {
if ( sendDictionary . readyState == 4 && sendDictionary . status == 200 ) {
if ( sendDictionary . responseText == "updated successfully" ) {
console . log ( sendDictionary . responseText ) ;
2015-12-01 00:08:43 +01:00
LoadUserDictionaries ( ) ;
ProcessLoad ( ) ;
} else if ( isNaN ( parseInt ( sendDictionary . responseText ) ) ) {
console . log ( sendDictionary . responseText ) ;
} else { // It will only be a number if it is a new dictionary.
2015-11-04 22:12:39 +01:00
currentDictionary . externalID = parseInt ( sendDictionary . responseText ) ;
2015-12-01 00:08:43 +01:00
LoadUserDictionaries ( ) ;
2015-11-05 01:47:54 +01:00
ProcessLoad ( ) ;
2015-11-04 22:12:39 +01:00
console . log ( "saved successfully" ) ;
}
return true ;
} else {
return false ;
}
}
sendDictionary . send ( postString ) ;
}
2015-12-01 00:08:43 +01:00
function DataToSend ( doSendWords , sendAll ) {
sendAll = ( typeof sendAll !== 'undefined' && sendAll != null ) ? sendAll : false ;
2015-11-04 22:12:39 +01:00
var data = "" ;
if ( currentDictionary . externalID == 0 ) {
data = "name=" + encodeURIComponent ( currentDictionary . name ) + "&description=" + encodeURIComponent ( currentDictionary . description ) + "&words=" + encodeURIComponent ( JSON . stringify ( currentDictionary . words ) ) ;
2015-12-01 00:08:43 +01:00
data += "&nextwordid=" + currentDictionary . nextWordId + "&allowduplicates=" + ( ( currentDictionary . settings . allowDuplicates ) ? "1" : "0" ) + "&casesensitive=" + ( ( currentDictionary . settings . caseSensitive ) ? "1" : "0" ) ;
2015-12-22 01:52:56 +01:00
data += "&partsofspeech=" + encodeURIComponent ( currentDictionary . settings . partsOfSpeech ) + "&sortbyequivalent=" + ( ( currentDictionary . settings . sortByEquivalent ) ? "1" : "0" ) + "&iscomplete=" + ( ( currentDictionary . settings . isComplete ) ? "1" : "0" ) + "&ispublic=" + ( ( currentDictionary . settings . isPublic ) ? "1" : "0" ) + "" ;
2015-11-04 22:12:39 +01:00
} else {
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . name != previousDictionary . name ) {
2015-11-04 22:12:39 +01:00
data += "name=" + encodeURIComponent ( currentDictionary . name ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . description != previousDictionary . description ) {
2015-11-04 22:12:39 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "description=" + encodeURIComponent ( currentDictionary . description ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || doSendWords ) {
2015-11-04 22:12:39 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "words=" + encodeURIComponent ( JSON . stringify ( currentDictionary . words ) ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . nextWordId != previousDictionary . nextWordId ) {
data += ( ( data == "" ) ? "" : "&" ) + "nextwordid=" + currentDictionary . nextWordId ;
}
if ( sendAll || currentDictionary . settings . allowDuplicates != previousDictionary . allowDuplicates ) {
2015-11-04 22:12:39 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "allowduplicates=" + ( ( currentDictionary . settings . allowDuplicates ) ? "1" : "0" ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . settings . caseSensitive != previousDictionary . caseSensitive ) {
2015-11-04 22:12:39 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "casesensitive=" + ( ( currentDictionary . settings . caseSensitive ) ? "1" : "0" ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . settings . partsOfSpeech != previousDictionary . partsOfSpeech ) {
2015-11-04 22:12:39 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "partsofspeech=" + encodeURIComponent ( currentDictionary . settings . partsOfSpeech ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . settings . sortByEquivalent != previousDictionary . sortByEquivalent ) {
2015-11-26 00:08:24 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "sortbyequivalent=" + ( ( currentDictionary . settings . sortByEquivalent ) ? "1" : "0" ) ;
}
2015-12-01 00:08:43 +01:00
if ( sendAll || currentDictionary . settings . isComplete != previousDictionary . isComplete ) {
2015-11-04 22:12:39 +01:00
data += ( ( data == "" ) ? "" : "&" ) + "iscomplete=" + ( ( currentDictionary . settings . isComplete ) ? "1" : "0" ) ;
}
2015-12-22 01:52:56 +01:00
if ( sendAll || currentDictionary . settings . isPublic != previousDictionary . isPublic ) {
data += ( ( data == "" ) ? "" : "&" ) + "ispublic=" + ( ( currentDictionary . settings . isPublic ) ? "1" : "0" ) ;
}
2015-11-04 22:12:39 +01:00
}
return data ;
2015-10-26 05:41:25 +01:00
}
function LoadDictionary ( ) {
2015-11-05 00:43:52 +01:00
LoadLocalDictionary ( ) ;
2015-11-26 00:08:24 +01:00
var loadDictionary = new XMLHttpRequest ( ) ;
loadDictionary . open ( 'GET' , "php/ajax_dictionarymanagement.php?action=load" ) ;
loadDictionary . onreadystatechange = function ( ) {
if ( loadDictionary . readyState == 4 && loadDictionary . status == 200 ) {
if ( loadDictionary . responseText == "no dictionaries" ) {
2015-12-22 19:20:33 +01:00
// If there are no dictionaries in the database and there's one in memory, remove the id & public setting and send it as a new one.
2015-12-01 00:08:43 +01:00
currentDictionary . externalID = 0 ;
2015-12-22 19:20:33 +01:00
currentDictionary . settings . isPublic = false ;
2015-12-01 00:08:43 +01:00
SendDictionary ( true ) ;
} else if ( loadDictionary . responseText . length < 60 ) {
console . log ( loadDictionary . responseText ) ;
} else {
2015-11-26 00:08:24 +01:00
currentDictionary = JSON . parse ( loadDictionary . responseText ) ;
SaveDictionary ( false , false ) ;
2015-11-04 22:12:39 +01:00
}
}
2015-12-01 00:08:43 +01:00
ProcessLoad ( ) ;
2015-11-05 00:43:52 +01:00
}
2015-11-26 00:08:24 +01:00
loadDictionary . send ( ) ;
2015-11-05 00:43:52 +01:00
}
2015-12-01 00:08:43 +01:00
function ChangeDictionary ( userDictionariesSelect ) {
userDictionariesSelect = ( typeof userDictionariesSelect !== 'undefined' && userDictionariesSelect != null ) ? userDictionariesSelect : document . getElementById ( "userDictionaries" ) ;
if ( currentDictionary . externalID != userDictionariesSelect . value && userDictionariesSelect . options . length > 0 ) {
2015-11-28 07:17:52 +01:00
var changeDictionaryRequest = new XMLHttpRequest ( ) ;
changeDictionaryRequest . open ( 'POST' , "php/ajax_dictionarymanagement.php?action=switch" ) ;
changeDictionaryRequest . setRequestHeader ( "Content-type" , "application/x-www-form-urlencoded" ) ;
var postString = "newdictionaryid=" + userDictionariesSelect . value . toString ( ) ;
changeDictionaryRequest . onreadystatechange = function ( ) {
if ( changeDictionaryRequest . readyState == 4 && changeDictionaryRequest . status == 200 ) {
if ( changeDictionaryRequest . responseText == "no dictionaries" ) {
2015-12-01 00:08:43 +01:00
console . log ( changeDictionaryRequest . responseText ) ;
2015-11-28 07:17:52 +01:00
SendDictionary ( false ) ;
2015-12-01 00:08:43 +01:00
} else if ( changeDictionaryRequest . responseText . length < 60 ) {
2015-11-28 07:17:52 +01:00
console . log ( changeDictionaryRequest . responseText ) ;
2015-12-01 00:08:43 +01:00
} else {
2015-11-28 07:17:52 +01:00
currentDictionary = JSON . parse ( changeDictionaryRequest . responseText ) ;
SaveDictionary ( false , false ) ;
ProcessLoad ( ) ;
2015-12-01 00:08:43 +01:00
LoadUserDictionaries ( ) ;
2015-11-28 07:17:52 +01:00
HideSettings ( ) ;
}
}
}
changeDictionaryRequest . send ( postString ) ;
}
}
2015-11-05 00:43:52 +01:00
function LoadLocalDictionary ( ) {
if ( localStorage . getItem ( 'dictionary' ) ) {
var tmpDictionary = JSON . parse ( localStorage . getItem ( 'dictionary' ) ) ;
2015-12-01 00:08:43 +01:00
if ( tmpDictionary . words . length > 0 || tmpDictionary . description != "A new dictionary." || tmpDictionary . name != "New" ) {
2015-11-05 00:43:52 +01:00
currentDictionary = JSON . parse ( localStorage . getItem ( 'dictionary' ) ) ;
2015-10-26 22:50:09 +01:00
}
2015-11-05 00:43:52 +01:00
tmpDictionary = null ;
2015-10-26 05:41:25 +01:00
}
2015-11-05 00:43:52 +01:00
}
function ProcessLoad ( ) {
2015-11-08 00:24:50 +01:00
if ( ! currentDictionary . hasOwnProperty ( "nextWordId" ) ) {
currentDictionary . nextWordId = currentDictionary . words . length + 1 ;
}
2015-11-25 18:37:03 +01:00
2015-10-30 18:38:41 +01:00
HideSettingsWhenComplete ( ) ;
2015-11-05 01:47:54 +01:00
ShowDictionary ( ) ;
2015-12-17 02:13:45 +01:00
2015-10-27 23:36:24 +01:00
SetPartsOfSpeech ( ) ;
if ( currentDictionary . settings . isComplete ) {
document . getElementById ( "wordEntryForm" ) . style . display = "none" ;
}
2015-10-30 20:23:04 +01:00
2015-11-04 22:12:39 +01:00
SavePreviousDictionary ( ) ;
}
function SavePreviousDictionary ( ) {
// Save non-word data to check if anything has changed (words can identify themselves if changed).
// Used to minimize data pushed to database.
previousDictionary = {
name : currentDictionary . name ,
description : currentDictionary . description ,
2015-12-01 00:08:43 +01:00
nextWordId : currentDictionary . nextWordId ,
2015-11-04 22:12:39 +01:00
allowDuplicates : currentDictionary . settings . allowDuplicates ,
caseSensitive : currentDictionary . settings . caseSensitive ,
partsOfSpeech : currentDictionary . settings . partsOfSpeech ,
2015-11-26 00:08:24 +01:00
sortByEquivalent : currentDictionary . settings . sortByEquivalent ,
2015-12-22 01:52:56 +01:00
isComplete : currentDictionary . settings . isComplete ,
isPublic : currentDictionary . settings . isPublic
2015-11-04 22:12:39 +01:00
} ;
2015-10-26 05:41:25 +01:00
}
2015-10-26 22:50:09 +01:00
function ExportDictionary ( ) {
2016-03-11 20:29:39 +01:00
if ( currentDictionary . words . length > 0 ) {
var downloadName = removeDiacritics ( stripHtmlEntities ( currentDictionary . name ) ) . replace ( /\W/g , '' ) ;
if ( downloadName == "" ) {
downloadName = "export" ;
}
download ( downloadName + ".dict" , localStorage . getItem ( 'dictionary' ) ) ;
} else {
alert ( "Dictionary must have at least 1 word to export." )
2015-10-26 23:21:13 +01:00
}
2015-10-26 22:50:09 +01:00
}
function ImportDictionary ( ) {
2015-12-01 00:08:43 +01:00
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?" ) ) {
2015-11-25 18:37:03 +01:00
if ( ! window . FileReader ) {
alert ( 'Your browser is not supported' ) ;
return false ;
}
2015-10-26 22:50:09 +01:00
2015-11-25 18:37:03 +01:00
var reader = new FileReader ( ) ;
if ( document . getElementById ( "importFile" ) . files . length > 0 ) {
var file = document . getElementById ( "importFile" ) . files [ 0 ] ;
// Read the file
reader . readAsText ( file ) ;
// When it's loaded, process it
reader . onloadend = function ( ) {
if ( reader . result && reader . result . length ) {
var tmpDicitonary = JSON . parse ( reader . result ) ;
if ( tmpDicitonary . hasOwnProperty ( "name" ) && tmpDicitonary . hasOwnProperty ( "description" ) &&
tmpDicitonary . hasOwnProperty ( "words" ) && tmpDicitonary . hasOwnProperty ( "settings" ) )
{
2015-12-01 00:28:21 +01:00
currentDictionary = JSON . parse ( reader . result ) ;
currentDictionary . externalID = 0 ; // Reset external id for imported dictionary.
2015-12-22 19:20:33 +01:00
currentDictionary . settings . isPublic = false ; // Reset public setting for imported dictionary.
2015-12-01 00:28:21 +01:00
SaveDictionary ( true , true ) ;
2015-11-25 18:37:03 +01:00
ProcessLoad ( ) ;
HideSettings ( ) ;
2015-12-01 00:28:21 +01:00
document . getElementById ( "importFile" ) . value = "" ;
2015-11-25 18:37:03 +01:00
} else {
var errorString = "File is missing:" ;
if ( ! tmpDicitonary . hasOwnProperty ( "name" ) )
errorString += " name" ;
if ( ! tmpDicitonary . hasOwnProperty ( "description" ) )
errorString += " description" ;
if ( ! tmpDicitonary . hasOwnProperty ( "words" ) )
errorString += " words" ;
if ( ! tmpDicitonary . hasOwnProperty ( "settings" ) )
errorString += " settings" ;
alert ( "Uploaded file is not compatible.\n\n" + errorString ) ;
}
tmpDicitonary = null ;
2015-10-26 22:50:09 +01:00
} else {
2015-11-25 18:37:03 +01:00
alert ( "Upload Failed" ) ;
2015-10-26 22:50:09 +01:00
}
2015-11-25 18:37:03 +01:00
reader = null ;
2015-10-26 22:50:09 +01:00
}
2015-11-25 18:37:03 +01:00
} else {
alert ( "You must add a file to import." ) ;
2015-10-26 22:50:09 +01:00
}
}
}
2016-06-08 21:43:58 +02:00
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 ) {
alert ( 'Your browser is not supported' ) ;
return false ;
}
if ( document . getElementById ( "importWordsCSV" ) . files . length > 0 ) {
var file = document . getElementById ( "importWordsCSV" ) . files [ 0 ] ;
var resultsArea = document . getElementById ( "importOptions" ) ;
resultsArea . innerHTML = "" ;
2016-06-10 07:27:41 +02:00
var currentRow = 0 ; // Because of the header, the first row of data is always on line 2.
var rowsImported = 0 ;
2016-06-08 21:43:58 +02:00
Papa . parse ( file , {
header : true ,
step : function ( row , parser ) {
2016-06-10 07:27:41 +02:00
currentRow ++ ;
2016-06-10 20:35:57 +02:00
// If there are no errors OR the word and either equivalent or explanation contain data, then import it.
if ( ( row . data [ 0 ] . word . trim ( ) . length > 0 && ( row . data [ 0 ] . equivalent . trim ( ) . length > 0 || row . data [ 0 ] . explanation . trim ( ) . length > 0 ) ) || row . errors . length == 0 ) {
currentDictionary . words . push ( { name : htmlEntities ( row . data [ 0 ] [ "word" ] ) . trim ( ) , pronunciation : htmlEntities ( row . data [ 0 ] [ "pronunciation" ] ) . trim ( ) , partOfSpeech : ( ( htmlEntities ( row . data [ 0 ] [ "part of speech" ] ) . trim ( ) . length > 0 ) ? htmlEntities ( row . data [ 0 ] [ "part of speech" ] ) . trim ( ) : " " ) , simpleDefinition : htmlEntities ( row . data [ 0 ] [ "equivalent" ] ) . trim ( ) , longDefinition : htmlEntities ( row . data [ 0 ] [ "explanation" ] ) . trim ( ) , wordId : currentDictionary . nextWordId ++ } ) ;
2016-06-10 07:27:41 +02:00
resultsArea . innerHTML += "<p>Imported \"" + htmlEntitiesParse ( htmlEntities ( row . data [ 0 ] [ "word" ] ) ) . trim ( ) + "\" successfully</p>" ;
rowsImported ++ ;
2016-06-08 21:43:58 +02:00
} else {
2016-06-10 20:35:57 +02:00
// If it's not just an empty line, give an error.
if ( row . data [ 0 ] . word . trim ( ) . length > 0 ) {
for ( var i = 0 ; i < row . errors . length ; i ++ ) {
resultsArea . innerHTML += "<p>Error on record #" + currentRow . toString ( ) + ": " + row . errors [ i ] . message + "</p>" ;
}
2016-06-10 07:27:41 +02:00
}
2016-06-08 21:43:58 +02:00
}
2016-06-10 07:27:41 +02:00
// Scroll to the bottom.
document . getElementById ( "importOptions" ) . scrollTop = document . getElementById ( "importOptions" ) . scrollHeight ;
2016-06-08 21:43:58 +02:00
} ,
complete : function ( results ) {
SaveAndUpdateDictionary ( ) ;
2016-06-10 07:27:41 +02:00
resultsArea . innerHTML += "<p>The file has finished importing " + rowsImported . toString ( ) + " words.</p>" ;
// Scroll to the bottom.
document . getElementById ( "importOptions" ) . scrollTop = document . getElementById ( "importOptions" ) . scrollHeight ;
document . getElementById ( "numberOfWordsInDictionary" ) . innerHTML = currentDictionary . words . length . toString ( ) ;
2016-06-08 21:43:58 +02:00
}
} ) ;
} else {
alert ( "You must add a file to import." ) ;
}
}
}
2015-10-26 05:41:25 +01:00
function WordIndex ( word ) {
2015-10-30 20:23:04 +01:00
for ( var i = 0 ; i < currentDictionary . words . length ; i ++ )
{
if ( ( ! currentDictionary . settings . caseSensitive && currentDictionary . words [ i ] . name . toLowerCase ( ) == word . toLowerCase ( ) ) ||
( currentDictionary . settings . caseSensitive && currentDictionary . words [ i ] . name == word ) ) {
return i ;
2015-10-26 05:41:25 +01:00
}
}
return - 1 ;
2015-10-26 22:50:09 +01:00
}
2016-02-27 01:18:29 +01:00
function WordAtIndexWasChanged ( indexString , word , pronunciation , partOfSpeech , simpleDefinition , longDefinition ) {
return ( ! currentDictionary . settings . caseSensitive && currentDictionary . words [ parseInt ( indexString ) ] . name . toLowerCase ( ) != word . toLowerCase ( ) ) ||
( currentDictionary . settings . caseSensitive && currentDictionary . words [ parseInt ( indexString ) ] . name != word ) ||
currentDictionary . words [ parseInt ( indexString ) ] . pronunciation != pronunciation ||
currentDictionary . words [ parseInt ( indexString ) ] . partOfSpeech != partOfSpeech ||
currentDictionary . words [ parseInt ( indexString ) ] . simpleDefinition != simpleDefinition ||
currentDictionary . words [ parseInt ( indexString ) ] . longDefinition != longDefinition ;
}
function CheckForPartsOfSpeechChange ( ) {
if ( htmlEntities ( document . getElementById ( "dictionaryPartsOfSpeechEdit" ) . value ) != currentDictionary . settings . partsOfSpeech ) {
if ( htmlEntities ( document . getElementById ( "dictionaryPartsOfSpeechEdit" ) . value ) != "" ) {
currentDictionary . settings . partsOfSpeech = htmlEntities ( document . getElementById ( "dictionaryPartsOfSpeechEdit" ) . value ) ;
SetPartsOfSpeech ( ) ;
}
}
}