-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Conversation
align-items: center; | ||
} | ||
|
||
.switch-lang__button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
У меня вообще была идея сделать инструмент по проверке БЭМа без бэма🙈
function setLanguage(buttonSwithLanguage) { | ||
|
||
if (buttonSwithLanguage.checked) { | ||
insertUrlParam('language', 'ru'); | ||
} | ||
else { | ||
insertUrlParam('language', 'en'); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я обычно пишу быстрый выход для таких функций, это позволяет меньше вложенностей читать
if (!history.pushState) {
return
}
language === 'ru' && (buttonSwithLanguage.checked = true); | ||
|
||
buttonSwithLanguage && buttonSwithLanguage.addEventListener('input', () => { | ||
setLanguage(buttonSwithLanguage); | ||
validate(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
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%; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пустая строка в конце
No description provided.