Add combobox in js test

This commit is contained in:
Alexey
2022-09-22 21:53:34 +03:00
parent 82b5b08dfc
commit 35cbbe2fb1
2 changed files with 61 additions and 27 deletions

View File

@ -9,7 +9,42 @@
<form>
<textarea id = "textarea"></textarea>
<button type = "submit">OK</button>
<input type = "file" id = "dictionary-file">
<select name = "combobox" id = "combobox">
<option></option>
<option value = "bg_BG">bg_BG</option>
<option value = "ca_ES">ca_ES</option>
<option value = "da_DK">da_DK</option>
<option value = "de_AT">de_AT</option>
<option value = "de_CH">de_CH</option>
<option value = "de_DE">de_DE</option>
<option value = "el_GR">el_GR</option>
<option value = "en_AU">en_AU</option>
<option value = "en_GB">en_GB</option>
<option value = "en_US">en_US</option>
<option value = "es_ES">es_ES</option>
<option value = "fr_FR">fr_FR</option>
<option value = "gl_ES">gl_ES</option>
<option value = "hr_HR">hr_HR</option>
<option value = "hu_HU">hu_HU</option>
<option value = "id_ID">id_ID</option>
<option value = "it_IT">it_IT</option>
<option value = "lv_LV">lv_LV</option>
<option value = "mn_MN">mn_MN</option>
<option value = "nb_NO">nb_NO</option>
<option value = "nl_NL">nl_NL</option>
<option value = "nn_NO">nn_NO</option>
<option value = "pl_PL">pl_PL</option>
<option value = "pt_BR">pt_BR</option>
<option value = "pt_PT">pt_PT</option>
<option value = "ro_RO">ro_RO</option>
<option value = "ru_RU">ru_RU</option>
<option value = "sk_SK">sk_SK</option>
<option value = "sl_SI">sl_SI</option>
<option value = "sr_Cyrl_RS">sr_Cyrl_RS</option>
<option value = "sr_Latn_RS">sr_Latn_RS</option>
<option value = "sv_SE">sv_SE</option>
<option value = "uk_UA">uk_UA</option>
</select>
</form>
<script src = "../deploy/hyphen.js"></script>
<script src = "main.js"></script>

View File

@ -1,39 +1,38 @@
(function (window, undefined){
var textarea = document.getElementById("textarea");
var form = document.querySelector("form");
var control = document.getElementById("dictionary-file");
var combobox = document.getElementById("combobox");
var application = undefined;
var lang = undefined;
control.addEventListener("change", function(event) {
var file = control.files[0];
lang = file.name;
var reader = new FileReader();
reader.readAsText(file);
if(application == undefined) {
application = hyphenCreateApplication(Module);
}
reader.onload = function() {
hyphenLoadDictionary(Module, application, reader.result, lang);
};
}, false);
form.onsubmit = function(event) {
event.preventDefault();
var text = textarea.value.split("\n").join(" ").split(" ");
if(combobox.value == "") {
return;
}
if(application == undefined) {
application = hyphenCreateApplication(Module);
}
for(var i = 0; i < text.length; i++) {
var hyphens = hyphenWord(Module, application, text[i].toLowerCase(), lang);
console.log(hyphens);
var lang = combobox.value;
var text = textarea.value.split("\n").join(" ").split(" ");
var request = new XMLHttpRequest();
var path = '../../../../../../dictionaries/' + lang + '/' + 'hyph_' + lang + '.dic';
request.open('GET', path, true);
request.send(null);
request.onload = function () {
var dict = request.responseText;
hyphenLoadDictionary(Module, application, dict, lang);
for(var i = 0; i < text.length; i++) {
var hyphens = hyphenWord(Module, application, text[i].toLowerCase(), lang);
console.log(hyphens);
}
}
event.preventDefault();
}
})(self, undefined);