Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/components/ScalingIframe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const ScalingIframe = ({
}) => {
const iframeRef = useRef<HTMLIFrameElement | null>(null);
const [scale, setScale] = useState(1);
const [error, setError] = useState(false);

useLayoutEffect(() => {
const fitToParent = () => {
const iframe = iframeRef.current;
Expand All @@ -24,10 +26,56 @@ export const ScalingIframe = ({
return () => window.removeEventListener("resize", fitToParent);
}, [width]);

const handleError = () => {
setError(true);
};

if (error) {
return (
<div
style={{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
backgroundColor: "#f0f0f0",
color: "#333",
fontSize: "16px",
textAlign: "center",
padding: "20px",
}}
>
<div>
<p>Unable to load embedded content</p>
<p style={{ fontSize: "14px", marginTop: "10px" }}>
Please visit{" "}
<a
href={props.src?.replace("/embed", "")}
target="_blank"
rel="noopener noreferrer"
style={{ color: "#d63384" }}
>
the original sketch
</a>
{" "}on OpenProcessing
</p>
</div>
</div>
);
}

return (
<iframe
width={width}
{...props}
sandbox="allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
allow="fullscreen; clipboard-write"
loading="lazy"
onError={handleError}
style={{
position: "absolute",
top: 0,
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/ReferenceItemLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ const { showBanner, englishUrl } = checkTranslationBanner(
Astro.url.pathname,
Astro.url.origin
);
// Normalizes malformed p5.* reference anchors (e.g. "#/p5.Element")
// to proper reference routes ("/reference/p5/p5.Element/")
// Normalizes malformed p5.* reference anchors (e.g. "#/p5.Element" or "#/p5/rectMode")
// to proper reference routes ("/reference/p5/p5.Element/" or "/reference/p5/rectMode/")
function normalizeP5ReferenceLinks(html: string | undefined): string | undefined {
if (!html) return html;
return html.replace(
/href="#\/(p5\.[^"]+)"/g,
'href="/reference/p5/$1/"'
/href="#\/p5([.\/][^"]+)"/g,
'href="/reference/p5$1/"'
);
}
---
Expand Down
3 changes: 3 additions & 0 deletions src/layouts/SketchLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const iframeTitle = `OpenProcessing Sketch: ${title} by ${authorName}`;
src={makeSketchEmbedUrl(sketchIdNumber)}
width="100%"
height="100%"
sandbox="allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
allow="fullscreen; clipboard-write"
loading="lazy"
style={{
position: "absolute",
top: 0,
Expand Down
Loading