documentation/extensions/patchqueue/static/patchqueue.js
Antoine Vandevenne (anv) ebc3e70d0f [APOCALYPSE] Merge all documentations and add a new homemade theme
Co-authored-by: Victor Feyens (vfe) <vfe@odoo.com>
Co-authored-by: Elisabeth Dickinson (edi) <edi@odoo.com>
Co-authored-by: Antoine Vandevenne (anv) <anv@odoo.com>
2021-01-28 19:05:48 +01:00

46 lines
1.7 KiB
JavaScript

function makeRadios(code) {
var fragment = document.createDocumentFragment();
['section', 'diff', 'file'].forEach(function (section, _, a) {
var radio = document.createElement('input');
radio.setAttribute('type', 'radio');
radio.setAttribute('name', 'pq-radio-' + code);
radio.setAttribute('data-section', section);
if (section === 'section') {
radio.checked = true;
}
var label = document.createElement('label');
label.appendChild(radio);
label.appendChild(document.createTextNode(' ' + section));
fragment.appendChild(label);
fragment.appendChild(document.createTextNode(' '));
});
return fragment;
}
document.addEventListener('DOMContentLoaded', function () {
var patches = document.querySelectorAll('.pq-needs-toggle');
for (var i = 0; i < patches.length; ++i) {
var block = document.createElement('div');
block.appendChild(makeRadios(i));
var patch = patches[i];
patch.insertBefore(block, patch.childNodes[0]);
patch.addEventListener('click', function (event) {
var el = event.target;
if (el.nodeName.toUpperCase() !== 'INPUT'
|| !el.hasAttribute('data-section')) {
return;
}
// input < label < div[block] < div.pq-patch
var patch = el.parentNode.parentNode.parentNode;
var classes = patch.className.split(/\s+/)
.filter(function (cls, index, names) {
return !/^pq-show-\w+/.test(cls);
});
classes.push('pq-show-' + el.getAttribute('data-section'));
patch.className = classes.join(' ');
});
}
}, false);