Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
bb7d8af290
469 files changed
+26426
No files matched your search
@@ -0,0 +1,37 @@
|
||||
(function () {
|
||||
function init() {
|
||||
document.querySelectorAll('[data-password-toggle]').forEach(function (toggle) {
|
||||
var input = document.getElementById(toggle.getAttribute('aria-controls'));
|
||||
var form = toggle.closest('form');
|
||||
if (!input || !form) return;
|
||||
|
||||
function sync() {
|
||||
var empty = input.value === '';
|
||||
toggle.hidden = empty;
|
||||
if (empty && input.type === 'text') {
|
||||
input.type = 'password';
|
||||
toggle.textContent = form.dataset.labelShow;
|
||||
toggle.setAttribute('aria-pressed', 'false');
|
||||
}
|
||||
}
|
||||
|
||||
toggle.addEventListener('click', function () {
|
||||
var show = input.type === 'password';
|
||||
input.type = show ? 'text' : 'password';
|
||||
toggle.textContent = show ? form.dataset.labelHide : form.dataset.labelShow;
|
||||
toggle.setAttribute('aria-pressed', show ? 'true' : 'false');
|
||||
input.focus();
|
||||
});
|
||||
['input', 'change', 'focus'].forEach(function (name) {
|
||||
input.addEventListener(name, sync);
|
||||
});
|
||||
sync();
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user