Title: Embeds: Use the click handler's own event parameter - #13293
Title: Embeds: Use the click handler's own event parameter#13293itzmekhokan wants to merge 2 commits into
Conversation
`linkClickHandler()` checked modifier keys against the global `event` rather than its `e` parameter. Any script in the embed template that declares a top-level `var event` shadows `window.event`, so the check reads `undefined` and passes — a Cmd/Ctrl + click on a link inside an embed then navigates the top window instead of opening a new tab.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
I agree with @westonruter that it would be good to rename the variable to the self documenting event. There are some other event handlers within the file that also use e, so it would be good to change them all to be consistent.
Rename the `e` parameter to `event` in every handler in `embed-template.js`, rather than reading the modifier keys off `e` in `linkClickHandler()`. The parameter now shadows `window.event`, so the modifier key check is no longer affected by a top-level `var event` in the embed template, and the name matches the existing `onMessage( event )` handler.
There was a problem hiding this comment.
Pull request overview
Fixes modifier-key detection in the embed template’s link click handler by using the handler’s own event object (instead of the global event accessor), preventing Cmd/Ctrl+click from being incorrectly preventDefault()’d and forcing top-window navigation.
Changes:
- Update
linkClickHandler()to read modifier keys from itseventparameter and use that parameter consistently. - Rename other event handler parameters from
etoeventfor consistency across the file. - Add a JSDoc
@paramannotation tolinkClickHandler().
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
linkClickHandler()insrc/js/_enqueues/lib/embed-template.jsread modifier keys from the globaleventrather than the handler's own parameter. A Cmd/Ctrl + click on a link inside an embed therefore calledpreventDefault()and navigated the top window instead of opening a new tab, defeating r49202.window.eventis an accessor onWindow.prototype. The embed template inlines its script into the document's global scope, so any script there declaring a top-levelvar eventshadows the accessor with an own property and the check readsundefined. Naming the handler's parametereventbinds the check to the real event object.Every handler in the file is renamed from
etoeventfor consistency, as requested in review. There is no QUnit coverage for this file to extend.Trac ticket: https://core.trac.wordpress.org/ticket/65978
Use of AI Tools