Skip to content

Commit

Permalink
Merge pull request #71 from typekit/rw-iframe-support
Browse files Browse the repository at this point in the history
Support for loading fonts in child iframes and windows
  • Loading branch information
Sean McBride committed Dec 6, 2012
2 parents 978971b + 87e88c6 commit 6e4513e
Show file tree
Hide file tree
Showing 30 changed files with 573 additions and 215 deletions.
23 changes: 20 additions & 3 deletions README.md
Expand Up @@ -67,12 +67,29 @@ this.

Learn more about [events][evt].

## Manage loading everywhere

Usually, it's easiest to include a copy of webfontloader in every window where
fonts are needed, so that each window manages its own fonts. However, if you
need to have a single window manage fonts for multiple same-origin child windows
or iframes that are built up using JavaScript, webfontloader supports that as
well. Just use the optional `context` configuration option and give it a
reference to the target window for loading:

<script>
WebFont.load({
google: {
families: ['Droid Sans']
},
context: frames['my-child']
});
</script>

## A common ground

WebFont Loader aims to provide a common interface for font loading. Today it
works with Google, Typekit, Fonts.com Web fonts and your own CSS. Learn more in
[transitions][trn].
works with Google, Typekit, Ascender, Fontdeck, Fonts.com Web fonts and your own
CSS. Learn more in [transitions][trn].


## More to see
Expand Down Expand Up @@ -125,11 +142,11 @@ Then, run the tests.
* That's it!



## Authors

* Ryan Carver / ryan@typekit.com
* Jeremie Lenfant-engelmann / jeremiele@google.com
* Sean McBride / sean@typekit.com


## License
Expand Down
46 changes: 46 additions & 0 deletions lib/webfontloader/demo/public/ascender-iframe.html
@@ -0,0 +1,46 @@
<!doctype html>
<html>
<head>
<title>Ascender Module Demo</title>
<link href="/basic.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/webfont.js"></script>
<style type="text/css">
iframe {
height: 100px;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
function loaded() {
var child = frames["child"];
child.document.body.innerHTML = "<h1 style=\"font-family: 'AyitaPro'\">Hello World. I am Ayita Pro.</h1>";
WebFont.load({
ascender: {
key:'ec2de397-11ae-4c10-937f-bf94283a70c1',
families:['AyitaPro:regular,bold,bolditalic,italic']
},
context: child
});
}
</script>

<iframe name="child" src="/blank.html" onload="loaded()"></iframe>

<hr>

<p>
<a href="#" onclick="document.getElementsByTagName('body')[0].style.color = '#fff';return false;">Hide Page</a> |
<a href="/ascender.html">Reload Cached</a>
</p>
<p>
Note: use "localhost" when testing web fonts.
</p>
<p>
The goal of this page is to show how fonts load from Ascender in a child
iframe.
</p>

</body>
</html>
9 changes: 9 additions & 0 deletions lib/webfontloader/demo/public/blank.html
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Blank page</title>
</head>
<body>
</body>
</html>
41 changes: 41 additions & 0 deletions lib/webfontloader/demo/public/custom-iframe.html
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<title>Custom Module</title>
<script type="text/javascript" src="/webfont.js"></script>
<style >
iframe {
height: 100px;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
function loaded() {
var child = frames["child"];
child.document.body.innerHTML = "<h1 style=\"font-family: 'ChunkFiveRegular'\">Hello World. I am ChunkFive.</h1>";
WebFont.load({
custom: {
families: ['ChunkFiveRegular'],
urls : ['http://seanmcb.com/typekit/wfl/stylesheet.css']
},
context: child
});
}
</script>

<iframe name="child" src="/blank.html" onload="loaded()"></iframe>

<hr>
<p>
<a href="#" onclick="document.getElementsByTagName('body')[0].style.color = '#fff';return false;">Hide Page</a> |
<a href="/custom.html">Reload Cached</a>
</p>
<p>
The goal of this page is to show how fonts load from a custom module in a
child iframe.
</p>

</body>
</html>
20 changes: 10 additions & 10 deletions lib/webfontloader/demo/public/custom.html
Expand Up @@ -6,25 +6,25 @@
<style type="text/css">

h1 {
font-family: 'Tagesschrift';
font-family: 'ChunkFiveRegular';
}

/* All Class hooks */
#classes { color: #ddd; }
html.wf-loading #classes .Loading,
html.wf-active #classes .Active,
html.wf-inactive #classes .Inactive,
html.wf-tagesschrift-n4-loading #classes .TagesschriftLoading,
html.wf-tagesschrift-n4-active #classes .TagesschriftActive,
html.wf-tagesschrift-n4-inactive #classes .TagesschriftInactive {
html.wf-chunkfiveregular-n4-loading #classes .ChunkFiveLoading,
html.wf-chunkfiveregular-n4-active #classes .ChunkFiveActive,
html.wf-chunkfiveregular-n4-inactive #classes .ChunkFiveInactive {
color: #000;
}

</style>
</head>
<body>
<h1 class="tagesschrift">
Hello World. I am Tagesschrift.
Hello World. I am ChunkFive.
</h1>
<hr>
<p>
Expand All @@ -39,9 +39,9 @@ <h2>CSS Hook Status</h2>
<li class="Loading">Loading</li>
<li class="Active">Active</li>
<li class="Inactive">Inactive</li>
<li class="TagesschriftLoading">Tagesschrift Loading</li>
<li class="TagesschriftActive">Tagesschrift Active</li>
<li class="TagesschriftInactive">Tagesschrift Inactive</li>
<li class="ChunkFiveLoading">ChunkFive Loading</li>
<li class="ChunkFiveActive">ChunkFive Active</li>
<li class="ChunkFiveInactive">ChunkFive Inactive</li>
</ul>
<h2>JavaScript Event Progress</h2>
<ol id="events"></ol>
Expand All @@ -61,8 +61,8 @@ <h2>JavaScript Event Progress</h2>
}
WebFont.load({
custom: {
families: ['Tagesschrift'],
urls : ['http://paulirish.com/tagesschrift.css']
families: ['ChunkFiveRegular'],
urls : ['http://seanmcb.com/typekit/wfl/stylesheet.css']
},
loading: function() {
progress('loading');
Expand Down
40 changes: 40 additions & 0 deletions lib/webfontloader/demo/public/google-iframe.html
@@ -0,0 +1,40 @@
<!doctype html>
<html>
<head>
<link href="/basic.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/webfont.js"></script>
<style type="text/css">
iframe {
height: 100px;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
function loaded() {
var child = frames["child"];
child.document.body.innerHTML = "<h1 style=\"font-family: 'Droid Sans'\">Hello World. I am Droid Sans.</h1>";
WebFont.load({
google: {
families: ['Droid Sans'],
api: '/fonts/api'
},
context: child
});
}
</script>

<iframe name="child" src="/blank.html" onload="loaded()"></iframe>

<hr>
<p>
<a href="#" onclick="document.getElementsByTagName('body')[0].style.color = '#fff';return false;">Hide Page</a> |
<a href="/google.html">Reload Cached</a>
</p>
<p>
The goal of this page is demonstrate fonts loading from Google via
Javascript into a child iframe.
</p>
</body>
</html>
17 changes: 15 additions & 2 deletions lib/webfontloader/demo/public/index.html
Expand Up @@ -16,7 +16,7 @@ <h1>WebFont Loader Demos</h1>

<h2>Modules</h2>
<p>
WebFont Loader provides modules to load fonts from many places.
WebFont Loader provides modules to load fonts from many places.
</p>
<ol>
<li><a href="/google-css.html">Google / CSS Link</a>: Load fonts from Google with a <code>link</code> tag. Consider this a base case for font loading.</li>
Expand All @@ -25,7 +25,20 @@ <h2>Modules</h2>
<li><a href="/custom.html">Custom / WebFont Loader</a>: Load fonts from your own CSS with WebFont Loader.</li>
<li><a href="/ascender.html">Ascender / WebFont Loader</a>: Load fonts from Ascender with WebFont Loader.</li>
<li><a href="/fontdeck.html">Fontdeck / WebFont Loader</a>: Load fonts from Fontdeck with WebFont Loader.</li>
<li><a href="/monotype.html">monotype / WebFont Loader</a>: Load fonts from webfonts.fonts.com with WebFont Loader.</li>
<li><a href="/monotype.html">Monotype / WebFont Loader</a>: Load fonts from webfonts.fonts.com with WebFont Loader.</li>
</ol>

<h2>Modules in Iframes</h2>
<p>
WebFont Loader provides the ability to load fonts in child iframes using modules, instead of the main window.
</p>
<ol>
<li><a href="/google-iframe.html">Google / WebFont Loader</a>: Load fonts from Google in a child iframe with WebFont Loader.</li>
<li><a href="/typekit-iframe.html">Typekit / WebFont Loader</a>: Load fonts from Typekit in a child iframe with WebFont Loader.</li>
<li><a href="/custom-iframe.html">Custom / WebFont Loader</a>: Load fonts from your own CSS in a child iframe with WebFont Loader.</li>
<li><a href="/ascender-iframe.html">Ascender / WebFont Loader</a>: Load fonts from Ascender in a child iframe with WebFont Loader.</li>
<li>Fontdeck / WebFont Loader: Their demo fonts seem to be broken at the moment, so we don't have an iframe demo of this module.</li>
<li><a href="/monotype-iframe.html">Monotype / WebFont Loader</a>: Load fonts from webfonts.fonts.com in a child iframe with WebFont Loader.</li>
</ol>

<h2>Events</h2>
Expand Down
46 changes: 46 additions & 0 deletions lib/webfontloader/demo/public/monotype-iframe.html
@@ -0,0 +1,46 @@
<!doctype html>
<html>
<head>
<link href="/basic.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/webfont.js"></script>
<style>
iframe {
height: 100px;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
function loaded() {
frames["child"].document.body.innerHTML = "<h1>Hello World. I am DIN Next Bold.</h1>";
WebFont.load({
monotype: {
projectId: 'b726c28f-a28a-45be-993f-3db719bacfab'
},
context: frames["child"]
});
}
</script>

<iframe name="child" src="/blank.html" onload="loaded()"></iframe>

<hr>

<p>

<a href="#" onClick="document.getElementsByTagName('body')[0].style.color = '#fff';return false;">Hide Page</a> |

<a href="/monotype.html">Reload Cached</a>

</p>

<p>
The goal of this page is to show how monotype fonts load in a child iframe.
</p>

<p>
You must use "localhost" when testing monotype fonts.
</p>
</body>
</html>
41 changes: 41 additions & 0 deletions lib/webfontloader/demo/public/typekit-iframe.html
@@ -0,0 +1,41 @@
<!doctype html>
<html>
<head>
<link href="/basic.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/webfont.js"></script>
<style type="text/css">
iframe {
height: 100px;
width: 100%;
}
</style>
</head>
<body>
<script type="text/javascript">
function loaded() {
var child = frames["child"];
child.document.body.innerHTML = "<h1>Hello World. I am Futura PT.</h1>";
WebFont.load({
typekit: {
id: 'bod7grh'
},
context: child
});
}
</script>

<iframe name="child" src="/blank.html" onload="loaded()"></iframe>

<hr>
<p>
<a href="#" onclick="document.getElementsByTagName('body')[0].style.color = '#fff';return false;">Hide Page</a> |
<a href="/typekit.html">Reload Cached</a>
</p>
<p>
The goal of this page is to show how Typekit fonts load into an iframe.
</p>
<p>
You must load the fonts on "localhost" for this demo to work.
</p>
</body>
</html>

0 comments on commit 6e4513e

Please sign in to comment.