Skip to content

Commit

Permalink
Merge pull request #45 from prezly/fix/qrf-113-fix-twitter-embeds
Browse files Browse the repository at this point in the history
[QRF-113] Add custom logic for iframely embed script
  • Loading branch information
riffbyte authored Oct 7, 2022
2 parents a94beed + 3cfef31 commit 050985e
Show file tree
Hide file tree
Showing 13 changed files with 12 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_narrow_Elements_Bookmark_Big_Vertical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/components/HtmlInjection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ interface Props extends HTMLAttributes<HTMLDivElement> {
onError: () => void;
}

const IFRAMELY_EMBED_SCRIPT_SRC = '//cdn.iframe.ly/embed.js';

export function HtmlInjection(props: Props) {
const { html, onError, ...attrs } = props;

Expand Down Expand Up @@ -46,6 +48,16 @@ function useScripts(html: Props['html'], onError: Props['onError']) {
setScriptAttributes(script, attributes);

script.addEventListener('error', onError);

// Iframely docs advise to insert their embed script before other scripts
if (attributes.src === IFRAMELY_EMBED_SCRIPT_SRC) {
const firstScript = document.body.getElementsByTagName('script')[0];
if (firstScript) {
document.body.insertBefore(script, firstScript);
return;
}
}

document.body.appendChild(script);
});

Expand Down

0 comments on commit 050985e

Please sign in to comment.