Skip to content

Re-add afterLoad to loadNote to improve compatibility#1326

Closed
chriszs wants to merge 1 commit into
MuckRock:mainfrom
chriszs:1325-re-add-afterload-callback-to-loadnote
Closed

Re-add afterLoad to loadNote to improve compatibility#1326
chriszs wants to merge 1 commit into
MuckRock:mainfrom
chriszs:1325-re-add-afterload-callback-to-loadnote

Conversation

@chriszs
Copy link
Copy Markdown

@chriszs chriszs commented Apr 28, 2026

Adds an optional opts argument to loadNote in noteLoader.js, which accepts an afterLoad callback and fires it after the note iframe emits a load event and passes an object with a single property el containing the note's containing element. This is a restoration of a part of the original loadNote's API to improve compatibility with historic custom journalism, which used this to render notes as inline document cite overlays.

The original fired after calling render() on the note, which set its innerHTML. It's a choice to treat the iframe load event as the equivalent (as opposed to say, a resize event). Because we're setting this in a loop, it's a possibility this would call multiple times if the same note were to be rendered multiple times in a document. The original passed a note object, which in addition to el also exposed render() and setElement() as well as some other methods. It's possible that code that depended on one of those would break with this shim, but I'm choosing not to add those at this point.

In local testing, appears to solve the issue posed by the legacy ProPublica piece which prompted this PR.

Closes #1325

Closes MuckRock#1325

Co-authored-by: Copilot <copilot@github.com>
@chriszs chriszs force-pushed the 1325-re-add-afterload-callback-to-loadnote branch from a87e72a to c193cc6 Compare April 28, 2026 11:59
@chriszs
Copy link
Copy Markdown
Author

chriszs commented Apr 28, 2026

Closing until I can work out how to fire this once the iframe is done resizing.

@chriszs chriszs closed this Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-add afterLoad to loadNote for compatibility

1 participant