2018-10-12 03:11:57 +00:00
|
|
|
/*global gettext*/
|
2019-05-02 16:43:51 +00:00
|
|
|
(function() {
|
2018-10-12 03:11:57 +00:00
|
|
|
'use strict';
|
2019-05-02 16:43:51 +00:00
|
|
|
var closestElem = function(elem, tagName) {
|
|
|
|
if (elem.nodeName === tagName.toUpperCase()) {
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
if (elem.parentNode.nodeName === 'BODY') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return elem.parentNode && closestElem(elem.parentNode, tagName);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('load', function() {
|
2018-10-12 03:11:57 +00:00
|
|
|
// Add anchor tag for Show/Hide link
|
2019-05-02 16:43:51 +00:00
|
|
|
var fieldsets = document.querySelectorAll('fieldset.collapse');
|
|
|
|
for (var i = 0; i < fieldsets.length; i++) {
|
|
|
|
var elem = fieldsets[i];
|
2018-10-12 03:11:57 +00:00
|
|
|
// Don't hide if fields in this fieldset have errors
|
2019-05-02 16:43:51 +00:00
|
|
|
if (elem.querySelectorAll('div.errors').length === 0) {
|
|
|
|
elem.classList.add('collapsed');
|
|
|
|
var h2 = elem.querySelector('h2');
|
|
|
|
var link = document.createElement('a');
|
|
|
|
link.setAttribute('id', 'fieldsetcollapser' + i);
|
|
|
|
link.setAttribute('class', 'collapse-toggle');
|
|
|
|
link.setAttribute('href', '#');
|
|
|
|
link.textContent = gettext('Show');
|
|
|
|
h2.appendChild(document.createTextNode(' ('));
|
|
|
|
h2.appendChild(link);
|
|
|
|
h2.appendChild(document.createTextNode(')'));
|
2018-10-12 03:11:57 +00:00
|
|
|
}
|
2019-05-02 16:43:51 +00:00
|
|
|
}
|
2019-06-12 04:22:21 +00:00
|
|
|
// Add toggle to hide/show anchor tag
|
2019-05-02 16:43:51 +00:00
|
|
|
var toggleFunc = function(ev) {
|
2019-06-12 04:22:21 +00:00
|
|
|
if (ev.target.matches('.collapse-toggle')) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
var fieldset = closestElem(ev.target, 'fieldset');
|
|
|
|
if (fieldset.classList.contains('collapsed')) {
|
|
|
|
// Show
|
|
|
|
ev.target.textContent = gettext('Hide');
|
|
|
|
fieldset.classList.remove('collapsed');
|
|
|
|
} else {
|
|
|
|
// Hide
|
|
|
|
ev.target.textContent = gettext('Show');
|
|
|
|
fieldset.classList.add('collapsed');
|
|
|
|
}
|
2018-10-12 03:11:57 +00:00
|
|
|
}
|
2019-05-02 16:43:51 +00:00
|
|
|
};
|
2019-06-12 04:22:21 +00:00
|
|
|
var inlineDivs = document.querySelectorAll('fieldset.module');
|
|
|
|
for (i = 0; i < inlineDivs.length; i++) {
|
|
|
|
inlineDivs[i].addEventListener('click', toggleFunc);
|
2019-05-02 16:43:51 +00:00
|
|
|
}
|
2018-10-12 03:11:57 +00:00
|
|
|
});
|
2019-05-02 16:43:51 +00:00
|
|
|
})();
|