[common] Fix generation of tips, fix work for other languages

This commit is contained in:
JuliaSvinareva 2021-06-24 18:19:35 +03:00
parent db54743eca
commit 609cca232b
2 changed files with 41 additions and 13 deletions

View file

@ -50,11 +50,12 @@ Common.UI.HintManager = new(function() {
var _lang = 'en', var _lang = 'en',
_arrAlphabet = [], _arrAlphabet = [],
_arrEnAlphabet = [], _arrEnAlphabet = [],
_arrQwerty = [],
_arrEnQwerty = [],
_isAlt = false, _isAlt = false,
_hintVisible = false, _hintVisible = false,
_currentLevel = 0, _currentLevel = 0,
_currentSection = document, _currentSection = document,
_controls = [],
_currentControls = [], _currentControls = [],
_currentHints = [], _currentHints = [],
_inputLetters = ''; _inputLetters = '';
@ -118,15 +119,21 @@ Common.UI.HintManager = new(function() {
}; };
var _getControls = function() { var _getControls = function() {
/*if (!_controls[_currentLevel]) {
_controls[_currentLevel] = $('[data-hint=' + (_currentLevel) + ']').toArray();
}*/
_controls[_currentLevel] = $(_currentSection).find('[data-hint=' + (_currentLevel) + ']').toArray();
_currentControls = []; _currentControls = [];
var arr = _controls[_currentLevel]; var arr = $(_currentSection).find('[data-hint=' + (_currentLevel) + ']').toArray();
var visibleItems = arr.filter(function (item) { var visibleItems = arr.filter(function (item) {
return $(item).is(':visible'); return $(item).is(':visible');
}); });
var visibleItemsWithTitle = $(_currentSection).find('[data-hint-title][data-hint=' + (_currentLevel) + ']').toArray().filter(function (item) {
return $(item).is(':visible');
});
if (visibleItems.length === visibleItemsWithTitle.length) { // all buttons have data-hint-title
visibleItems.forEach(function (item) {
var el = $(item);
_currentControls.push(el);
});
return;
}
var _arrLetters = []; var _arrLetters = [];
if (visibleItems.length > _arrAlphabet.length) { if (visibleItems.length > _arrAlphabet.length) {
_arrLetters = _getLetters(visibleItems.length); _arrLetters = _getLetters(visibleItems.length);
@ -134,17 +141,19 @@ Common.UI.HintManager = new(function() {
_arrLetters = [..._arrAlphabet]; _arrLetters = [..._arrAlphabet];
} }
var usedLetters = []; var usedLetters = [];
if ((_currentSection.nodeType === 9 && $(['data-hint-title']).length > 0) || if ($(_currentSection).find('[data-hint-title]').length > 0) {
(_currentSection.nodeType !== 9 && _currentSection.find('[data-hint-title]').length > 0)) {
visibleItems.forEach(function (item) { visibleItems.forEach(function (item) {
var el = $(item); var el = $(item);
var title = el.attr('data-hint-title'); var title = el.attr('data-hint-title');
if (title) { if (title) {
var ind = _arrEnAlphabet.indexOf(title.toLowerCase()); var ind = _arrEnAlphabet.indexOf(title.toLowerCase());
usedLetters.push(ind); if (ind === -1) { // we have already changed
if (_lang !== 'en') { usedLetters.push(_arrAlphabet.indexOf(title.toLowerCase()));
console.log(_arrLetters[ind]); } else {
el.attr('data-hint-title', _arrLetters[ind].toUpperCase()); usedLetters.push(ind);
if (_lang !== 'en') {
el.attr('data-hint-title', _arrLetters[ind].toUpperCase());
}
} }
} }
}); });
@ -280,7 +289,14 @@ Common.UI.HintManager = new(function() {
} }
} else { } else {
var curr; var curr;
_inputLetters = _inputLetters + String.fromCharCode(e.keyCode).toUpperCase(); var curLetter = _lang === 'en' ? String.fromCharCode(e.keyCode) : e.key;
if (_lang !== 'en' && _arrAlphabet.indexOf(curLetter.toLowerCase()) === -1) {
var ind = _arrEnQwerty.indexOf(curLetter.toLowerCase());
if (ind !== -1) {
curLetter = _arrQwerty[ind];
}
}
_inputLetters = _inputLetters + curLetter.toUpperCase();
for (var i = 0; i < _currentControls.length; i++) { for (var i = 0; i < _currentControls.length; i++) {
var item = _currentControls[i]; var item = _currentControls[i];
if (item.attr('data-hint-title') === _inputLetters) { if (item.attr('data-hint-title') === _inputLetters) {
@ -337,6 +353,12 @@ Common.UI.HintManager = new(function() {
_arrAlphabet = langsJson[_lang]; _arrAlphabet = langsJson[_lang];
_arrEnAlphabet = langsJson['en']; _arrEnAlphabet = langsJson['en'];
}); });
Common.Utils.loadConfig('../../common/main/resources/alphabetletters/qwertyletters.json', function (langsJson) {
_arrQwerty = langsJson[_lang];
if (_lang !== 'en') {
_arrEnQwerty = langsJson['en'];
}
});
}; };
var _needCloseMenu = function () { var _needCloseMenu = function () {

View file

@ -0,0 +1,6 @@
{
"en": ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "z", "x", "c", "v", "b", "n", "m"],
"ru": ["й", "ц", "у", "к", "е", "н", "г", "ш", "щ", "з", "х", "ъ", "ф", "ы", "в", "а", "п", "р", "о", "л", "д", "ж", "э", "я", "ч", "с", "м", "и", "т", "ь", "б", "ю"],
"de": ["q", "w", "e", "r", "t", "z", "u", "i", "o", "p", "ü", "a", "s", "d", "f", "g", "h", "j", "k", "l", "ö", "ä", "z", "x", "c", "v", "b", "n", "m"],
"fr": ["a", "z", "e", "r", "t", "y", "u", "i", "o", "p", "q", "s", "d", "f", "g", "h", "j", "k", "l", "m", "w", "x", "c", "v", "b", "n"]
}