-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provides access to event properties as JSON in relevant widgets #8919
base: master
Are you sure you want to change the base?
Conversation
Confirmed: saqimtiaz has already signed the Contributor License Agreement (see contributing.md) |
✅ Deploy Preview for tiddlywiki-previews ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@Jermolene would appreciate some feedback on this when it is convenient for you, before I work on documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks @saqimtiaz. There doesn't appear to be anything specific about event handling in the copyEventProperties function. Perhaps it should be called something more generic like sanitizeObject or sanitizeJSON?
@Jermolene I had that thought as well and went with the event associated name for now as that is what the testing has focused on. Perhaps |
core/modules/utils/dom/dom.js
Outdated
for(key in obj) { | ||
try{ | ||
copy[key] = safeCopy(obj[key]); | ||
} catch(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this happen? safeCopy
shouldn't throw, should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @CrossEye, thank you for taking a look. Some event properties have the possiblity to throw exceptions when accessed (event.target.contentWindow
for cross-origin iframes for example, or event.relatedTarget at times for the focus event), and in particular I have run across libraries that implement custom events in this manner as well. So the try/catch
is in the interest of robustness.
@CrossEye any thoughts on a more appropriate function name? |
I like |
The new utils function has been renamed to |
This PR adds support to access enumerable event properties as JSON in actions invoked by
$eventcatcher
and$draggable
widgets. This is helpful when access to an event property is needed in actions but not specifically made available as a variable.$tw.utils.copyEventProperties
returns a JSON object representing the event properties while avoiding circular references, functions and DOM elements.$tw.utils.collectDOMVariables
now callscopyEventProperties
, this required nested if statements and the diff looks large but nothing else has changed.$eventcatcher
are cursory and only change where in the flow we call$tw.utils.collectDOMVariables
To Do: