scinote-web/app/assets/javascripts/shared/toggle_visibility.js

19 lines
528 B
JavaScript
Raw Normal View History

2021-05-22 20:41:56 +08:00
(function() {
2021-04-30 19:26:06 +08:00
'use strict';
function initToggleVisibilityListeners() {
2021-05-22 20:41:56 +08:00
$(document).on('change', 'input[data-action="toggle-visibility"]', function({ currentTarget }) {
2021-04-30 19:26:06 +08:00
let toggleId = currentTarget.getAttribute('data-target');
let element = document.getElementById(toggleId);
if (currentTarget.checked) {
element.classList.remove('hidden');
} else {
element.classList.add('hidden');
}
});
}
$(document).one('turbolinks:load', initToggleVisibilityListeners);
2021-05-02 17:36:10 +08:00
}());