Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a button for switching languages #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MaxOrel
Copy link

@MaxOrel MaxOrel commented Aug 11, 2021

No description provided.

align-items: center;
}

.switch-lang__button {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У меня вообще была идея сделать инструмент по проверке БЭМа без бэма🙈

Comment on lines +259 to +268
function setLanguage(buttonSwithLanguage) {

if (buttonSwithLanguage.checked) {
insertUrlParam('language', 'ru');
}
else {
insertUrlParam('language', 'en');
}

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function setLanguage(buttonSwithLanguage) {
if (buttonSwithLanguage.checked) {
insertUrlParam('language', 'ru');
}
else {
insertUrlParam('language', 'en');
}
}
function toggleLanguage() {
insertUrlParam('language', getLanguage() === 'en' ? 'ru' : 'en');
}

@@ -236,6 +247,26 @@ function init() {
errorsContainer = document.querySelector('ul');
}

function insertUrlParam(key, value) {
if (history.pushState) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я обычно пишу быстрый выход для таких функций, это позволяет меньше вложенностей читать

if (!history.pushState) {
  return
}

Comment on lines +234 to +239
language === 'ru' && (buttonSwithLanguage.checked = true);

buttonSwithLanguage && buttonSwithLanguage.addEventListener('input', () => {
setLanguage(buttonSwithLanguage);
validate();
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
language === 'ru' && (buttonSwithLanguage.checked = true);
buttonSwithLanguage && buttonSwithLanguage.addEventListener('input', () => {
setLanguage(buttonSwithLanguage);
validate();
});
if (buttonSwithLanguage) {
buttonSwithLanguage.checked = language === 'ru';
setLanguage(buttonSwithLanguage);
validate();
}
buttonSwithLanguage && buttonSwithLanguage.addEventListener('input', () => {
toggleLanguage();
validate();
});

}
}

function setLanguage(buttonSwithLanguage) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И прогони через преттиер, чтобы бы код одинаковым с точки зрения скобочек, пустых строк и тд


.switch-lang__checkbox-label:active::after {
width: 80%;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пустая строка в конце

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants