aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/utils
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-04-08 17:45:54 +0300
committerGravatar Vitaly Takmazov2023-01-13 10:37:54 +0300
commit89e6b445228529ffddfdacf790ccbda7c7f29fe8 (patch)
tree6067178797681e756623aaf452e3988b5f05ee8a /vnext/src/utils
parentd80c7fe07dfc330c8793adccc7e580479d7275b2 (diff)
Twitter embeds
Diffstat (limited to 'vnext/src/utils')
-rw-r--r--vnext/src/utils/embed.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/vnext/src/utils/embed.js b/vnext/src/utils/embed.js
index 9767b121..d3a76ee5 100644
--- a/vnext/src/utils/embed.js
+++ b/vnext/src/utils/embed.js
@@ -236,6 +236,32 @@ function getEmbeddableLinkTypes() {
iframe.onload = () => makeResizableToRatio(iframe, 9.0 / 16.0);
return setContent(div, iframe);
}
+ },
+ {
+ name: 'Twitter',
+ id: 'embed_twitter_status',
+ className: 'twi compact',
+ ctsDefault: false,
+ re: /^(?:https?:)?\/\/(?:www\.)?(?:mobile\.)?twitter\.com\/([\w-]+)\/status(?:es)?\/([\d]+)/i,
+ makeNode: function(aNode, reResult, div) {
+ let [url, userId, postId] = reResult;
+ url = url.replace('mobile.','');
+
+ div.innerHTML = `<blockquote class="twitter-tweet" data-lang="en"><a href="${url}"></a></blockquote>`;
+
+ if (window.twttr) {
+ // https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/guides/scripting-loading-and-initialization
+ window.twttr.widgets.load(div);
+ } else {
+ // innerHTML cannot insert scripts, so...
+ let script = document.createElement('script');
+ script.src = 'https://platform.twitter.com/widgets.js';
+ script.charset = 'utf-8';
+ div.appendChild(script);
+ }
+
+ return div;
+ }
}
];
}