-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
207 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<body> | ||
<script src="/website/static/child.js"></script> | ||
<style> | ||
#wrap { | ||
background-color: blue; | ||
width: 700px; | ||
height: 50px; | ||
} | ||
</style> | ||
<div id="wrap"></div> | ||
|
||
<script> | ||
const wrap = document.querySelector("#wrap"); | ||
wrap.onclick = function() { | ||
wrap.style.height = wrap.style.height === "100px" ? "200px" : "100px"; | ||
} | ||
|
||
function addElement() { | ||
// | ||
} | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<script> | ||
import { Callout, CodeBlock } from '@hyvor/design/components'; | ||
</script> | ||
|
||
<h1>Privacy Iframe</h1> | ||
|
||
<p> | ||
Adding embed codes directly to your website is a <strong>privacy concern</strong> since most of | ||
the time they include Javascript libraries that can access your page and user's data. Using an | ||
<strong>iframe to wrap the embed code</strong> is the best way to prevent this. | ||
</p> | ||
|
||
<h2 id="docker">Docker Image</h2> | ||
|
||
<p> | ||
If you are using the <a href="/docker">Docker image</a>, the iframe endpoint is already included. | ||
On your website, use iframes with `src` set to <code>/iframe?url=my-url</code> to embed content. | ||
</p> | ||
|
||
<CodeBlock | ||
code={` | ||
<iframe src="https://unfold.example.org/iframe?url=https://url-to-embed.com"></iframe> | ||
`} | ||
/> | ||
|
||
<h2 id="iframe-endpoint">PHP Library</h2> | ||
|
||
<p> | ||
If you are using the <a href="/php">PHP Library</a>, you have to set up an endpoint for the | ||
iframe. Here is an example with Laravel: | ||
</p> | ||
|
||
<CodeBlock | ||
code={` | ||
use Hyvor\\Unfold\\Unfold; | ||
use Hyvor\\Unfold\\Exceptions\\UnfoldException; | ||
use Illuminate\\Http\\Request; | ||
class IframeController | ||
{ | ||
public function getIframe(Request $request) | ||
{ | ||
$url = $request->input('url'); | ||
try { | ||
$data = Unfold::unfold($url); | ||
return PrivacyIframe::inner($data); | ||
} catch (UnfoldException) { | ||
// handle the exception | ||
} | ||
} | ||
} | ||
`} | ||
language="js" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p>This is an iframe that changes its height every time you click on it.</p> | ||
|
||
<iframe src="http://localhost:1234/.temp/iframe-inner.html" style="margin:30px;" width="700" | ||
></iframe> | ||
|
||
<svelte:head> | ||
<script src="/parent.js"></script> | ||
</svelte:head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
let items = 1; | ||
function handleClick() { | ||
items += 1; | ||
} | ||
</script> | ||
|
||
<svelte:head> | ||
<script src="/child.js"></script> | ||
</svelte:head> | ||
|
||
<body on:click={handleClick}> | ||
{#each Array(items) as _, i} | ||
<div style="height:150px" /> | ||
{/each} | ||
</body> | ||
|
||
<style> | ||
body { | ||
background-color: blue; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
(function () { | ||
function sendHeight() { | ||
const height = document.documentElement.scrollHeight; | ||
|
||
try { | ||
const iframe = window.frameElement; | ||
if (iframe) { | ||
iframe.style.height = `${height}px`; | ||
} else { | ||
throw new Error('iframe not found'); | ||
} | ||
} catch (e) { | ||
window.parent.postMessage( | ||
{ | ||
type: 'unfold-iframe-resize', | ||
height | ||
}, | ||
'*' | ||
); | ||
} | ||
} | ||
|
||
let mutationCallTimeout = null; | ||
|
||
function processMutations() { | ||
if (mutationCallTimeout) { | ||
clearTimeout(mutationCallTimeout); | ||
} | ||
mutationCallTimeout = setTimeout(sendHeight, 100); | ||
} | ||
|
||
function init() { | ||
const mutation = new window.MutationObserver(processMutations); | ||
mutation.observe(document.body, { | ||
childList: true, | ||
subtree: true | ||
}); | ||
sendHeight(); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', init); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(function () { | ||
window.addEventListener('message', function (event) { | ||
const source = event.source; | ||
const iframes = document.querySelectorAll('iframe'); | ||
|
||
for (let iframe in iframes) { | ||
if (iframes[iframe].contentWindow === source) { | ||
console.log('found the source', event.data); | ||
if (event.data.type === 'unfold-iframe-resize') { | ||
iframes[iframe].style.height = `${event.data.height}px`; | ||
} | ||
} | ||
} | ||
}); | ||
})(); |