Skip to content

Commit e8d3b5b

Browse files
bug #59292 [WebProfilerBundle] Fix event delegation on links inside toggles (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [WebProfilerBundle] Fix event delegation on links inside toggles | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT In #57525, the security panel’s authenticator tab got updated with dumps in toggles. Issue is, we currently call `stopPropagation` when link are clicked to avoid closing the toggle, but dumps handle links click using event delegation. That means when you click on a `sf-dump-toggle`, the event cannot reach the `sf-dump` because its propagation is stopped. This PR handles this case by checking if a link is present in the DOM between the toggle and the element which was clicked. It also leverages the `currentTarget` property to get the clicked toggle. Commits ------- 241597d2d47 [WebProfilerBundle] Fix event delegation on links inside toggles
2 parents 87d26c2 + ef38e01 commit e8d3b5b

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

Resources/assets/js/exception.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,17 @@
145145
}
146146

147147
addEventListener(toggles[i], 'click', function(e) {
148-
e.preventDefault();
148+
var toggle = e.currentTarget;
149149

150-
if ('' !== window.getSelection().toString()) {
151-
/* Don't do anything on text selection */
150+
if (e.target.closest('a, span[data-clipboard-text], .sf-toggle') !== toggle) {
152151
return;
153152
}
154153

155-
var toggle = e.target || e.srcElement;
154+
e.preventDefault();
156155

157-
/* needed because when the toggle contains HTML contents, user can click */
158-
/* on any of those elements instead of their parent '.sf-toggle' element */
159-
while (!hasClass(toggle, 'sf-toggle')) {
160-
toggle = toggle.parentNode;
156+
if ('' !== window.getSelection().toString()) {
157+
/* Don't do anything on text selection */
158+
return;
161159
}
162160

163161
var element = document.querySelector(toggle.getAttribute('data-toggle-selector'));
@@ -182,22 +180,6 @@
182180
toggle.innerHTML = currentContent !== altContent ? altContent : originalContent;
183181
});
184182

185-
/* Prevents from disallowing clicks on links inside toggles */
186-
var toggleLinks = toggles[i].querySelectorAll('a');
187-
for (var j = 0; j < toggleLinks.length; j++) {
188-
addEventListener(toggleLinks[j], 'click', function(e) {
189-
e.stopPropagation();
190-
});
191-
}
192-
193-
/* Prevents from disallowing clicks on "copy to clipboard" elements inside toggles */
194-
var copyToClipboardElements = toggles[i].querySelectorAll('span[data-clipboard-text]');
195-
for (var k = 0; k < copyToClipboardElements.length; k++) {
196-
addEventListener(copyToClipboardElements[k], 'click', function(e) {
197-
e.stopPropagation();
198-
});
199-
}
200-
201183
toggles[i].setAttribute('data-processed', 'true');
202184
}
203185
})();

0 commit comments

Comments
 (0)