Auto-scroll containing terminal if an iframe resizes. Other oEmbed tweaks.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3336 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
a5def62efa
commit
475da6dbf2
@ -527,6 +527,13 @@ function onMessage(event) {
|
|||||||
var iframe = document.getElementById("iframe_" + event.data.name);
|
var iframe = document.getElementById("iframe_" + event.data.name);
|
||||||
iframe.setAttribute("width", event.data.width);
|
iframe.setAttribute("width", event.data.width);
|
||||||
iframe.setAttribute("height", event.data.height);
|
iframe.setAttribute("height", event.data.height);
|
||||||
|
var node = iframe.parentElement;
|
||||||
|
while (node && !node.classList.contains("terminal")) {
|
||||||
|
node = node.parentElement;
|
||||||
|
}
|
||||||
|
if (node) {
|
||||||
|
autoScroll(node);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
send({event: "onWindowMessage", message: event.data});
|
send({event: "onWindowMessage", message: event.data});
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ let libxml = require("libxml");
|
|||||||
let libhttp = require("libhttp");
|
let libhttp = require("libhttp");
|
||||||
|
|
||||||
let gEmbedIndex = 0;
|
let gEmbedIndex = 0;
|
||||||
|
let gCache = {};
|
||||||
|
|
||||||
async function unfurl(url) {
|
async function unfurl(url) {
|
||||||
let result = {href: url};
|
let result = {href: url};
|
||||||
@ -26,10 +27,8 @@ async function unfurl(url) {
|
|||||||
result = [{href: url}, "\n", {
|
result = [{href: url}, "\n", {
|
||||||
name: "oEmbed" + gEmbedIndex,
|
name: "oEmbed" + gEmbedIndex,
|
||||||
iframe: `
|
iframe: `
|
||||||
<span style="border: 0; padding: 0; margin: 0; overflow: hidden">
|
<style type="text/css">border: 0; padding: 0; margin: 0; overflow: hidden</style>
|
||||||
${oEmbed.html}
|
${oEmbed.html}<script language="javascript">
|
||||||
</span>
|
|
||||||
<script language="javascript">
|
|
||||||
let gResizeMeMessage = {
|
let gResizeMeMessage = {
|
||||||
event: "resizeMe",
|
event: "resizeMe",
|
||||||
name: "oEmbed${gEmbedIndex}",
|
name: "oEmbed${gEmbedIndex}",
|
||||||
@ -44,8 +43,7 @@ async function unfurl(url) {
|
|||||||
parent.postMessage(gResizeMeMessage, "*");
|
parent.postMessage(gResizeMeMessage, "*");
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
</script>
|
</script>`,
|
||||||
`,
|
|
||||||
width: oEmbed.width || 320,
|
width: oEmbed.width || 320,
|
||||||
height: oEmbed.height || 120,
|
height: oEmbed.height || 120,
|
||||||
style: "margin: 0; padding: 0; border: 0; overflow: hidden",
|
style: "margin: 0; padding: 0; border: 0; overflow: hidden",
|
||||||
@ -62,6 +60,23 @@ async function test() {
|
|||||||
|
|
||||||
//test().catch(terminal.print);
|
//test().catch(terminal.print);
|
||||||
|
|
||||||
core.register("onMessage", function(sender, message) {
|
core.register("onMessage", async function(sender, message) {
|
||||||
return unfurl(message).catch(error => [message, "(error retrieving: ", error, ")"]);
|
let result = message;
|
||||||
|
if (gCache[message] && new Date().valueOf() < gCache[message].expires) {
|
||||||
|
result = gCache[message].result;
|
||||||
|
} else {
|
||||||
|
if (gCache[message]) {
|
||||||
|
print("Didn't use", gCache[message]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
result = await unfurl(message);
|
||||||
|
} catch (error) {
|
||||||
|
result = [message, "(error retrieving: ", error, ")"];
|
||||||
|
}
|
||||||
|
gCache[message] = {
|
||||||
|
expires: new Date().valueOf() + 7 * 24 * 60 * 60 * 1000,
|
||||||
|
result: result,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return result;
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user