{include file='header'}
<script data-relocate="true">
- $(function() {
- $('#optionValueContainer label').each(function(index, label) {
- var $label = $(label);
- var $id = $label.prop('for');
- if ($id && $id.match(/^userGroupOption/)) {
- var $groupID = $id.replace(/^userGroupOption/, '');
- $label.parents('dl').children('dd').find('input, select, textarea').each(function(index, element) {
- var $element = $(element);
- var $oldName = $element.attr('name');
-
- var $newName = 'values[' + $groupID + ']';
- if ($oldName.substr(-2) == '[]') {
- $newName += '[]';
+console.time('option');
+ (function() {
+ var container = document.getElementById('optionValueContainer');
+ var parent = container.parentNode;
+
+ // using a fragment is inefficient, but prevents strange transitions for booleans caused by checked state lost when changing the name
+ var fragment = document.createDocumentFragment();
+ fragment.appendChild(container);
+
+ var dd, groupId, id, inputElements, isBoolean, label, labels = container.getElementsByTagName('label');
+ for (var i = 0, length = labels.length; i < length; i++) {
+ label = labels[i];
+ id = label.getAttribute('for') || '';
+ if (id.match(/^userGroupOption(\d+)$/)) {
+ groupId = RegExp.$1;
+ dd = label.parentNode.nextElementSibling;
+ if (dd !== null && dd.nodeName === 'DD') {
+ inputElements = dd.querySelectorAll('input, select, textarea');
+ isBoolean = (dd.childElementCount === 1 && dd.children[0].classList.contains('optionTypeBoolean'));
+ for (var j = 0, innerLength = inputElements.length; j < innerLength; j++) {
+ inputElement = inputElements[j];
+ inputElement.name = 'values[' + groupId + ']' + (inputElement.name.slice(-2) === '[]' ? '[]' : '');
+
+ if (isBoolean) {
+ inputElement.checked = (inputElement.getAttribute('checked') === 'checked');
+ id += '_' + groupId;
+ label.removeAttribute('for');
+ inputElement.nextElementSibling.setAttribute('for', id);
+ }
+
+ inputElement.id = id;
}
-
- $element.attr('id', $id).attr('name', $newName);
- });
+ }
}
- });
- });
+ }
+
+ if (parent.childElementCount) {
+ parent.insertBefore(fragment, parent.children[0]);
+ }
+ else {
+ parent.appendChild(fragment);
+ }
+ })();
+console.timeEnd('option');
</script>
<header class="boxHeadline">