drop.chapril.org-firefoxsend/app/templates/setPasswordSection/index.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

const html = require('choo/html');
const passwordInput = require('../passwordInput');
2018-07-31 20:09:18 +02:00
module.exports = function(state) {
const checked = state.password ? 'checked' : '';
const label = state.password ? 'addPasswordLabel' : 'addPasswordMessage';
2018-02-16 21:56:53 +01:00
return html`
<div class="setPasswordSection">
<div class="checkbox">
<input
2018-07-31 20:09:18 +02:00
class="checkbox__input" id="add-password"
type="checkbox"
2018-07-31 20:09:18 +02:00
${checked}
autocomplete="off"
onchange=${togglePasswordInput}/>
<label class="checkbox__label" for="add-password">
2018-07-31 20:09:18 +02:00
${state.translate(label)}
</label>
</div>
2018-07-31 20:09:18 +02:00
${passwordInput(state)}
</div>`;
function togglePasswordInput(e) {
const unlockInput = document.getElementById('password-input');
const boxChecked = e.target.checked;
document
2018-02-21 21:35:52 +01:00
.querySelector('.passwordInput')
.classList.toggle('passwordInput--hidden', !boxChecked);
2018-07-31 20:09:18 +02:00
const label = document.querySelector('.checkbox__label');
if (boxChecked) {
2018-07-31 20:09:18 +02:00
label.innerHTML = state.translate('addPasswordLabel');
unlockInput.focus();
} else {
2018-07-31 20:09:18 +02:00
label.innerHTML = state.translate('addPasswordMessage');
unlockInput.value = '';
}
}
};