don't rely on hardcoded DOM tree structure in section's applies-to

This commit is contained in:
tophf 2018-07-03 09:34:23 +03:00
parent 997eacc64a
commit 0ed701a9d9

View File

@ -125,7 +125,7 @@ function addSection(event, section) {
div.classList.toggle('has-regexp', show); div.classList.toggle('has-regexp', show);
appliesTo.oninput = appliesTo.oninput || show && (event => { appliesTo.oninput = appliesTo.oninput || show && (event => {
if (event.target.matches('.applies-value') && if (event.target.matches('.applies-value') &&
$('.applies-type', event.target.parentElement).value === 'regexp') { $('.applies-type', event.target.closest('.applies-to-item')).value === 'regexp') {
regExpTester.update(getRegExps()); regExpTester.update(getRegExps());
} }
}); });
@ -171,9 +171,7 @@ function addAppliesTo(list, name, value) {
} else { } else {
e = template.appliesToEverything.cloneNode(true); e = template.appliesToEverything.cloneNode(true);
} }
$('.add-applies-to', e).addEventListener('click', function () { $('.add-applies-to', e).addEventListener('click', () => addAppliesTo(list));
addAppliesTo(this.parentNode.parentNode);
}, false);
list.appendChild(e); list.appendChild(e);
} }
@ -403,8 +401,8 @@ function getSectionsHashes() {
} }
function removeAppliesTo(event) { function removeAppliesTo(event) {
const appliesTo = event.target.parentNode; const appliesTo = event.target.closest('.applies-to-item');
const appliesToList = appliesTo.parentNode; const appliesToList = appliesTo.closest('.applies-to-list');
removeAreaAndSetDirty(appliesTo); removeAreaAndSetDirty(appliesTo);
if (!appliesToList.hasChildNodes()) { if (!appliesToList.hasChildNodes()) {
addAppliesTo(appliesToList); addAppliesTo(appliesToList);
@ -437,7 +435,7 @@ function removeAreaAndSetDirty(area) {
} }
}); });
updateTitle(); updateTitle();
area.parentNode.removeChild(area); area.remove();
} }
function makeSectionVisible(cm) { function makeSectionVisible(cm) {