diff --git a/bin/ResponsiveTable.adc b/bin/ResponsiveTable.adc index 517cd20..fd4a8dc 100644 Binary files a/bin/ResponsiveTable.adc and b/bin/ResponsiveTable.adc differ diff --git a/changelog.md b/changelog.md index 15d765c..974338e 100755 --- a/changelog.md +++ b/changelog.md @@ -128,4 +128,6 @@ Version #### v4.2.6 - style.css changed for response:hover #### v4.2.7 -- included option for using open response text for loop placeholders \ No newline at end of file +- included option for using open response text for loop placeholders +#### v4.2.8 +- fixed event.target syntax that prevented td.response from being selected if text contained HTML styling \ No newline at end of file diff --git a/config.xml b/config.xml index 5ec4059..518de8b 100755 --- a/config.xml +++ b/config.xml @@ -7,7 +7,7 @@ ResponsiveTable 28609424-856b-40c8-ba88-5b29a439720a - 4.2.7 + 4.2.8 2023-06-09 Askia diff --git a/example/ResponsiveTable.qex b/example/ResponsiveTable.qex index e4ad647..c8e66be 100755 Binary files a/example/ResponsiveTable.qex and b/example/ResponsiveTable.qex differ diff --git a/example/SetValueAjax.qex b/example/SetValueAjax.qex index e6f725d..b01fd24 100644 Binary files a/example/SetValueAjax.qex and b/example/SetValueAjax.qex differ diff --git a/resources/static/responsiveTable.js b/resources/static/responsiveTable.js index c46bcc9..87548f8 100755 --- a/resources/static/responsiveTable.js +++ b/resources/static/responsiveTable.js @@ -94,67 +94,110 @@ * * @param {Object} event Event of the click on the TD or INPUT */ - function clickTable (event, that) { - var el = event.target || event.srcElement; - if (el.className.indexOf('headerRow') >= 0) { - $(that).next().toggle(); - } - if (el.nodeName === 'TD' && el.className.indexOf('response') >= 0) { - if (el.lastElementChild.nodeName == 'LABEL') { - document.getElementById(el.lastElementChild.attributes.for.value).click(); - } else if (el.lastElementChild.nodeName == 'SPAN') { - document.getElementById(el.lastElementChild.dataset.for).click(); +function clickTable (event, that) { + var el = event.target || event.srcElement; + + + if (el && el.nodeName === 'INPUT') { + + if (el.checked) { + addClass(el.parentNode, 'selected'); + manageExclusive(el); + + var other = el.parentElement.querySelector('.otherText, .otherLoopText'); + if (other) other.style.display = "block"; + + } else if ((!el.checked) && (el.attributes.type.value === 'checkbox')) { + removeClass(el.parentNode, 'selected'); + manageExclusive(el); + + var other2 = el.parentElement.querySelector('.otherText, .otherLoopText'); + if (other2) other2.style.display = "none"; + + } + + if (that.accordion && window.innerWidth < that.responsiveWidth ) { + if (el.classList.contains('otherText')) { + addClass(el.parentNode.parentNode, 'selected'); + el.addEventListener("keydown", function() { + displayCheckmark(that.instanceId); + }); } else { - document.getElementById(el.children[2].dataset.for).click(); - } - } else if (el.nodeName === 'SPAN') { - document.getElementById(el.dataset.for).click(); - } else if (el.nodeName === 'IMG' && el.parentNode.parentNode.className.indexOf('response') >= 0) { - event.preventDefault(); - event.stopPropagation(); - document.getElementById(el.parentNode.parentNode.lastElementChild.attributes.for.value).click(); - } else if (el.nodeName === 'INPUT') { - if (el.checked) { - addClass(el.parentNode, 'selected'); - manageExclusive(el); - if (el.parentElement.lastElementChild.children[0]) { - el.parentElement.lastElementChild.children[0].style.display = "block"; - } - } else if ((!el.checked) && (el.attributes.type.value === 'checkbox')) { - removeClass(el.parentNode, 'selected'); - manageExclusive(el); - if (el.parentElement.lastElementChild.children[0]) { - el.parentElement.lastElementChild.children[0].style.display = "none"; + if (el.parentNode.lastElementChild.nodeName != 'DIV') { + setTimeout(function (){ + if (el.classList.contains('askia-exclusive')) { + displayNext(that.instanceId); + } + displayCheckmark(that.instanceId); + }, 150); } } - if (that.accordion && window.innerWidth < that.responsiveWidth ) { - if(el.classList.contains('otherText')) { - addClass(el.parentNode.parentNode, 'selected'); - el.addEventListener("keydown", function() { - displayCheckmark(that.instanceId); - }); - } else { - if (el.parentNode.lastElementChild.nodeName != 'DIV') { - setTimeout(function (){ - if (el.classList.contains('askia-exclusive')) { - displayNext(that.instanceId); - } - displayCheckmark(that.instanceId); - }, 150); - } - } + } + + if (window.askia && + window.arrLiveRoutingShortcut && + window.arrLiveRoutingShortcut.length > 0 && + window.arrLiveRoutingShortcut.indexOf(that.currentQuestion) >= 0) { + askia.triggerAnswer(); + } + return; + } + + + if (el && el.closest) { + var td = el.closest('td.response'); + if (td) { + // Prevent accordion/header click handlers from also firing for this click + event.preventDefault(); + event.stopPropagation(); + + // Prefer span[data-for] + var df = td.querySelector('span[data-for]'); + if (df && df.dataset && df.dataset.for) { + var input = document.getElementById(df.dataset.for); + if (input) { input.click(); } + return; } - if (window.askia && - window.arrLiveRoutingShortcut && - window.arrLiveRoutingShortcut.length > 0 && - window.arrLiveRoutingShortcut.indexOf(that.currentQuestion) >= 0) { - askia.triggerAnswer(); + + // Fallback: label[for] + var lbl = td.querySelector('label[for]'); + if (lbl) { + var input2 = document.getElementById(lbl.getAttribute('for')); + if (input2) { input2.click(); } + return; } - } else if (el.tagName == "P") { - document.getElementById(el.attributes.for.value).click(); + + // Last fallback: first input inside TD + var input3 = td.querySelector('input'); + if (input3) { input3.click(); } + return; } } + + if (el.className && el.className.indexOf('headerRow') >= 0) { + $(that).next().toggle(); + } + + if (el.nodeName === 'TD' && el.className.indexOf('response') >= 0) { + if (el.lastElementChild.nodeName == 'LABEL') { + document.getElementById(el.lastElementChild.attributes.for.value).click(); + } else if (el.lastElementChild.nodeName == 'SPAN') { + document.getElementById(el.lastElementChild.dataset.for).click(); + } else { + document.getElementById(el.children[2].dataset.for).click(); + } + } else if (el.nodeName === 'SPAN') { + document.getElementById(el.dataset.for).click(); + } else if (el.nodeName === 'IMG' && el.parentNode.parentNode.className.indexOf('response') >= 0) { + event.preventDefault(); + event.stopPropagation(); + document.getElementById(el.parentNode.parentNode.lastElementChild.attributes.for.value).click(); + } else if (el.tagName == "P") { + document.getElementById(el.attributes.for.value).click(); + } +} + /** * Calculate the offsetTop *