mirror of
https://github.com/arfct/itty-bitty.git
synced 2026-03-11 08:54:33 +00:00
Update recipes style
This commit is contained in:
parent
0844d64d1a
commit
2be4b74d4e
3 changed files with 27 additions and 14 deletions
|
|
@ -26,8 +26,9 @@
|
|||
}
|
||||
|
||||
const renderers = {
|
||||
"application/ld+json": "recipe",
|
||||
"javascript": "bookmarklet",
|
||||
"application/ld+json": {script:"recipe"},
|
||||
"javascript": {script:"bookmarklet"},
|
||||
"web3": {script:"web3", mode:"frame"},
|
||||
}
|
||||
|
||||
window.addEventListener("message", function(e) {
|
||||
|
|
@ -95,7 +96,7 @@
|
|||
renderMode = "download";
|
||||
}
|
||||
|
||||
const renderer = info.params?.render || renderers[info.mediatype];
|
||||
const renderer = info.params?.render || renderers[info.mediatype].script;
|
||||
if (renderer) {
|
||||
var script = renderer;
|
||||
if (script.indexOf("/") == -1) script = location.origin + '/render/' + script + '.js'
|
||||
|
|
@ -116,7 +117,7 @@
|
|||
let scheme = fragment.substring(0,colon);
|
||||
let renderer = renderers[scheme];
|
||||
if (renderer) {
|
||||
return renderContentWithScript(renderer, title, fragment, fragment);
|
||||
return renderContentWithScript(renderer.script, title, fragment, fragment);
|
||||
}
|
||||
return window.location.replace(fragment);
|
||||
}
|
||||
|
|
@ -177,14 +178,16 @@
|
|||
|
||||
};
|
||||
|
||||
const SCRIPT_LOADER = `data:text/html,<!doctype html><meta charset=utf-8><script src="${location.origin}/render.js"></script>`
|
||||
const SCRIPT_LOADER = `<!doctype html><meta charset=utf-8><script src="${location.origin}/render.js"></script>`
|
||||
function renderContentWithScript(script, title, body, url) {
|
||||
if (script.indexOf("/") == -1) script = location.origin + '/render/' + script + '.js'
|
||||
iframe.onload = (() => {
|
||||
iframe.contentWindow.postMessage({script, url, title, body}, "*");
|
||||
delete iframe.onload
|
||||
});
|
||||
iframe.src = SCRIPT_LOADER;
|
||||
// writeDocContent(iframe.contentWindow.document, SCRIPT_LOADER)
|
||||
// iframe.srcdoc = SCRIPT_LOADER;
|
||||
iframe.src = "data:text/html," + SCRIPT_LOADER;
|
||||
}
|
||||
|
||||
function writeDocContent(doc, content) {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,26 @@
|
|||
window.el = function (tagName, attrs, ...children) {
|
||||
let l = document.createElement(tagName);
|
||||
Object.entries(attrs).forEach(([k,v]) => l[k] = v);
|
||||
children.forEach((c) => l.appendChild(c));
|
||||
children.forEach((c) => l.appendChild(typeof c == "string" ? document.createTextNode(c) : c));
|
||||
return l;
|
||||
}
|
||||
|
||||
function loadScript(src) {
|
||||
document.head.appendChild(el("script", { src }));
|
||||
document.onload = () => {
|
||||
document.write("hi");
|
||||
function loadScript(src, callback) {
|
||||
let script = el("script", { src });
|
||||
script.addEventListener('load', function(e) {
|
||||
console.log("Loaded", src);
|
||||
if (callback) callback(e);
|
||||
});
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
}
|
||||
function async(u, c) {
|
||||
var d = document, t = 'script',
|
||||
o = d.createElement(t),
|
||||
s = d.getElementsByTagName(t)[0];
|
||||
o.src = '//' + u;
|
||||
if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
|
||||
s.parentNode.insertBefore(o, s);
|
||||
}
|
||||
|
||||
function loadSyle(href) {
|
||||
|
|
@ -21,7 +31,6 @@ window.addEventListener("message", function(e) {
|
|||
var base = el('base', {href: e.data.script});
|
||||
document.head.appendChild(base);
|
||||
|
||||
|
||||
window.params = e.data;
|
||||
window.params.origin = e.origin;
|
||||
console.log("Rendering with", e.data.script, e.data)
|
||||
|
|
|
|||
|
|
@ -91,7 +91,8 @@ span.number {
|
|||
text-align: center;
|
||||
font-size: 10px;
|
||||
line-height: 16px;
|
||||
opacity:0.7
|
||||
opacity:0.7;
|
||||
display:none;
|
||||
}
|
||||
.number.big {
|
||||
font-size:8px;
|
||||
|
|
|
|||
Loading…
Reference in a new issue