diff --git a/_static/accounting.css b/_static/accounting.css index 8eb5e6298..a08136ab6 100644 --- a/_static/accounting.css +++ b/_static/accounting.css @@ -153,3 +153,17 @@ blockquote.highlights { margin-bottom: 0; text-align: center; } + +/* + lists of alternatives +*/ +.alternatives-controls label { + display: block; +} +dl.alternatives > dt, +dl.alternatives > dd { + display: none; +} +dl.alternatives > dd { + margin-left: 0; +} diff --git a/_static/misc.js b/_static/misc.js index c3d559f9a..f139777ff 100644 --- a/_static/misc.js +++ b/_static/misc.js @@ -1,5 +1,52 @@ (function () { document.addEventListener('DOMContentLoaded', function () { + alternatives() + checks_handling(); + }); + + /** alternatives display: + * - prepend control for each
+ * - radio input with link to following dd + * - label is
content + * - hide all first-level dt and dd (CSS) + * - on change + * - hide all dds + * - show dd corresponding to the selected radio + * - automatically select first control on startup + */ + function alternatives() { + $('dl.alternatives').each(function (index) { + var $list = $(this), + $contents = $list.children('dd'); + var $controls = $('
').append( + $list.children('dt').map(function () { + var label = document.createElement('label'), + input = document.createElement('input'); + input.setAttribute('type', 'radio'); + input.setAttribute('name', 'alternatives-' + index); + + var sibling = this; + while ((sibling = sibling.nextSibling) && sibling.nodeType !== 1); + input.content = sibling; + + label.appendChild(input); + label.appendChild(document.createTextNode(' ')); + label.appendChild(document.createTextNode(this.textContent)); + + return label; + })) + .insertBefore($list) + .on('change', 'input', function (e) { + // change event triggers only on newly selected input, not + // on the one being deselected + $contents.css('display', ''); + var content = e.target.content; + content && (content.style.display = 'block'); + }) + .find('input:first').click(); + }); + } + function checks_handling() { var $section = $('.checks-handling'); if (!$section.length) { return; } @@ -9,7 +56,7 @@ while (this.firstChild) { this.removeChild(this.firstChild) } - + $('