webfontloader 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +4 -0
- data/CHANGELOG +3 -0
- data/README.md +246 -101
- data/lib/webfontloader.rb +1 -1
- data/lib/webfontloader/demo/public/index.html +18 -18
- data/spec/core/useragentparser_spec.js +6 -6
- data/spec/core/webfont_spec.js +29 -4
- data/spec/monotype/monotypescript_spec.js +15 -2
- data/src/core/useragent.js +53 -5
- data/src/core/useragentparser.js +121 -28
- data/webfontloader.gemspec +3 -5
- metadata +5 -10
- data/docs/EVENTS.md +0 -169
- data/docs/MODULES.md +0 -96
- data/docs/TRANSITIONS.md +0 -142
data/webfontloader.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'webfontloader'
|
16
|
-
s.version = '1.4.
|
17
|
-
s.date = '2013-05-
|
16
|
+
s.version = '1.4.4'
|
17
|
+
s.date = '2013-05-22'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -66,15 +66,13 @@ DESC
|
|
66
66
|
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
67
67
|
# = MANIFEST =
|
68
68
|
s.files = %w[
|
69
|
+
AUTHORS
|
69
70
|
CHANGELOG
|
70
71
|
Gemfile
|
71
72
|
LICENSE
|
72
73
|
README.md
|
73
74
|
Rakefile
|
74
75
|
bin/webfontloader-demos
|
75
|
-
docs/EVENTS.md
|
76
|
-
docs/MODULES.md
|
77
|
-
docs/TRANSITIONS.md
|
78
76
|
lib/webfontloader.rb
|
79
77
|
lib/webfontloader/demo/public/ascender-iframe.html
|
80
78
|
lib/webfontloader/demo/public/ascender.html
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 1.4.
|
9
|
+
- 4
|
10
|
+
version: 1.4.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Carver
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-05-
|
19
|
+
date: 2013-05-22 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: rake
|
@@ -93,19 +93,14 @@ extensions: []
|
|
93
93
|
|
94
94
|
extra_rdoc_files:
|
95
95
|
- README.md
|
96
|
-
- docs/EVENTS.md
|
97
|
-
- docs/MODULES.md
|
98
|
-
- docs/TRANSITIONS.md
|
99
96
|
files:
|
97
|
+
- AUTHORS
|
100
98
|
- CHANGELOG
|
101
99
|
- Gemfile
|
102
100
|
- LICENSE
|
103
101
|
- README.md
|
104
102
|
- Rakefile
|
105
103
|
- bin/webfontloader-demos
|
106
|
-
- docs/EVENTS.md
|
107
|
-
- docs/MODULES.md
|
108
|
-
- docs/TRANSITIONS.md
|
109
104
|
- lib/webfontloader.rb
|
110
105
|
- lib/webfontloader/demo/public/ascender-iframe.html
|
111
106
|
- lib/webfontloader/demo/public/ascender.html
|
data/docs/EVENTS.md
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
# Events
|
2
|
-
|
3
|
-
WebFont Loader provides an event system that developers can hook into. It
|
4
|
-
gives you notifications of the font loading sequence in both CSS and
|
5
|
-
JavaScript.
|
6
|
-
|
7
|
-
## The Events
|
8
|
-
|
9
|
-
* `Loading` - This event is triggered when all fonts have been requested.
|
10
|
-
* `Active` - This event is triggered when all of the fonts have rendered.
|
11
|
-
* `Inactive` - This event is triggered when the browser does not support
|
12
|
-
linked fonts *or* if none of the fonts could be loaded.
|
13
|
-
* `Font Loading` - This event is triggered once for each font that's loaded.
|
14
|
-
* `Font Active` - This event is triggered once for each font that renders.
|
15
|
-
* `Font Inactive` - This event is triggered if the font can't be loaded.
|
16
|
-
|
17
|
-
### CSS Flavored
|
18
|
-
|
19
|
-
CSS events are implemented as classes on the `html` element.
|
20
|
-
|
21
|
-
html.wf-loading
|
22
|
-
html.wf-active
|
23
|
-
html.wf-inactive
|
24
|
-
html.wf-familyname-fvd-loading
|
25
|
-
html.wf-familyname-fvd-active
|
26
|
-
html.wf-familyname-fvd-inactive
|
27
|
-
|
28
|
-
`familyname` is a sanitized version of the name of each font family. Spaces
|
29
|
-
and underscores are removed from the name, and all characters are converted to
|
30
|
-
lower case. For example, `Droid Sans` becomes `droidsans`.
|
31
|
-
|
32
|
-
`fvd` is a *Font Variation Description*. Put simply, it's a shorthand for
|
33
|
-
describing the style and weight of a particular font. Here are a few examples:
|
34
|
-
|
35
|
-
@font-face {
|
36
|
-
font-style: normal;
|
37
|
-
font-weight: normal;
|
38
|
-
}
|
39
|
-
=> n4
|
40
|
-
|
41
|
-
@font-face {
|
42
|
-
font-style: italic;
|
43
|
-
font-weight: bold;
|
44
|
-
}
|
45
|
-
=> i7
|
46
|
-
|
47
|
-
If no style/weight is specified, the default "n4" (font-style: normal;
|
48
|
-
font-weight: normal;) will be used.
|
49
|
-
|
50
|
-
If fonts are loaded multiple times on a single page, the CSS classes continue
|
51
|
-
to update to reflect the current state of the page. The global `wf-loading`
|
52
|
-
class is applied whenever fonts are being requested (even if other fonts are
|
53
|
-
already active or inactive). The `wf-inactive` class is applied only if none of
|
54
|
-
the fonts on the page have rendered. Otherwise, the `wf-active` class is applied
|
55
|
-
instead (even if some fonts are inactive).
|
56
|
-
|
57
|
-
Here's an example of CSS classes over multiple loads:
|
58
|
-
|
59
|
-
* Droid Sans n4 is requested
|
60
|
-
* The `html` element has `wf-loading wf-droidsans-n4-loading`
|
61
|
-
* Droid Sans n4 is detected as active
|
62
|
-
* The `html` element has `wf-active wf-droidsans-n4-active`
|
63
|
-
* Droid Sans n7 is subsequently requested
|
64
|
-
* The `html` element has `wf-active wf-loading wf-droidsans-n4-active
|
65
|
-
wf-droidsans-n7-loading`
|
66
|
-
* Droid Sans n7 is detected as active
|
67
|
-
* The `html` element has `wf-active wf-droidsans-n4-active
|
68
|
-
wf-droidsans-n7-active`
|
69
|
-
|
70
|
-
Here's another example of CSS classes over multiple loads when one of the
|
71
|
-
requested fonts is inactive:
|
72
|
-
|
73
|
-
* Droid Sans n9 is requested (which doesn't exist)
|
74
|
-
* The `html` element has `wf-loading wf-droidsans-n9-loading`
|
75
|
-
* Droid Sans n9 is detected as inactive
|
76
|
-
* The `html` element has `wf-inactive wf-droidsans-n9-inactive`
|
77
|
-
* Droid Sans n4 is subsequently requested
|
78
|
-
* The `html` element has `wf-inactive wf-loading wf-droidsans-n9-inactive
|
79
|
-
wf-droidsans-n4-loading`
|
80
|
-
* Droid Sans n4 is detected as active
|
81
|
-
* The `html` element has `wf-active wf-droidsans-n9-inactive
|
82
|
-
wf-droidsans-n4-active`
|
83
|
-
|
84
|
-
|
85
|
-
### JavaScript Flavored
|
86
|
-
|
87
|
-
JavaScript events are implemented as callback functions on the `WebFont.load`
|
88
|
-
function.
|
89
|
-
|
90
|
-
WebFont.load({
|
91
|
-
loading: function() {
|
92
|
-
},
|
93
|
-
active: function() {
|
94
|
-
},
|
95
|
-
inactive: function() {
|
96
|
-
},
|
97
|
-
fontloading: function(familyName, fvd) {
|
98
|
-
},
|
99
|
-
fontactive: function(familyName, fvd) {
|
100
|
-
},
|
101
|
-
fontinactive: function(familyName, fvd) {
|
102
|
-
}
|
103
|
-
})
|
104
|
-
|
105
|
-
|
106
|
-
## Error Handling
|
107
|
-
|
108
|
-
### Timeouts
|
109
|
-
|
110
|
-
Since the Internet is not 100% reliable, it's possible that a font fails to
|
111
|
-
load. You can use events to gracefully degrade in this situation.
|
112
|
-
|
113
|
-
> The `Font Inactive` event will be triggered after 5 seconds if the font
|
114
|
-
fails to render. If *at least* one font succesfully renders, the `Active`
|
115
|
-
event will be triggered, else the `Inactive` even will be triggered.
|
116
|
-
|
117
|
-
You can configure the timeout by using the `timeout` configuration on the
|
118
|
-
`WebFont.load` function.
|
119
|
-
|
120
|
-
WebFont.load({
|
121
|
-
timeout: 2000, // Set the timeout to two seconds
|
122
|
-
...
|
123
|
-
});
|
124
|
-
|
125
|
-
The timeout value should be in milliseconds, and defaults to 5 seconds if
|
126
|
-
not supplied.
|
127
|
-
|
128
|
-
### Browser Support
|
129
|
-
|
130
|
-
Every web browser has varying levels of support for fonts linked via
|
131
|
-
@font-face. Support for web fonts is determined using the browser user agent
|
132
|
-
string. The user agent string may claim to support a web font format
|
133
|
-
when it in fact does not. This is especially noticable on mobile browsers
|
134
|
-
with a "Desktop" mode, which usually identify as Chrome on Linux.
|
135
|
-
In this case a web font provider may decide to send WOFF fonts to the
|
136
|
-
device because the real desktop Chrome supports it, while the mobile
|
137
|
-
browser does not. The WebFont Loader is not designed to handle these
|
138
|
-
cases and it chooses to believe the user agent string. Web font providers
|
139
|
-
may or may not build on top of the basic WebFont Loader functionality
|
140
|
-
to handle these special cases individually.
|
141
|
-
|
142
|
-
> If WebFont Loader determines that the current browser does not support
|
143
|
-
`@font-face`, the `Inactive` event will be triggered.
|
144
|
-
|
145
|
-
When loading fonts from multiple providers, each provider may or may not
|
146
|
-
support a given browser.
|
147
|
-
|
148
|
-
> If WebFont Loader determines that the current browser can support
|
149
|
-
`@font-face`, and *at least* one provider is able to serve fonts,
|
150
|
-
the fonts from that provide will be loaded. When finished, the `Active` event
|
151
|
-
will be triggered.
|
152
|
-
|
153
|
-
> For fonts loaded from supported providers, the `Font Active` event will be
|
154
|
-
triggered. For fonts loaded from a provider that *does not* support the
|
155
|
-
current browser, the `Font Inactive` event will be triggered.
|
156
|
-
|
157
|
-
For example:
|
158
|
-
|
159
|
-
WebFont.load({
|
160
|
-
providerA: 'Family1',
|
161
|
-
providerB: 'Family2'
|
162
|
-
});
|
163
|
-
|
164
|
-
> If `providerA` can serve fonts to a browser, but `providerB` cannot, The
|
165
|
-
`Font Inactive` event will be triggered for `Family2`. The `Font Active`
|
166
|
-
event will be triggered for `Family1` once it loads, as will the `Active`
|
167
|
-
event.
|
168
|
-
|
169
|
-
|
data/docs/MODULES.md
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# Modules
|
2
|
-
|
3
|
-
WebFont Loader provides a generic module system so that any web font provider
|
4
|
-
may be used. The specifics of each provider are documented here.
|
5
|
-
|
6
|
-
|
7
|
-
## Google
|
8
|
-
|
9
|
-
Using Google's Font API, name the font families you'd like to load.
|
10
|
-
|
11
|
-
WebFont.load({
|
12
|
-
google: {
|
13
|
-
families: ['Droid Sans', 'Droid Serif']
|
14
|
-
}
|
15
|
-
});
|
16
|
-
|
17
|
-
Learn more about the [Google Font API][gfontapi]. You can also supply the `text` parameter to perform character subsetting:
|
18
|
-
|
19
|
-
WebFont.load({
|
20
|
-
google: {
|
21
|
-
families: ['Droid Sans', 'Droid Serif'],
|
22
|
-
text: 'abcdedfghijklmopqrstuvwxyz!'
|
23
|
-
}
|
24
|
-
});
|
25
|
-
|
26
|
-
This functionality is only available for the Google module.
|
27
|
-
|
28
|
-
## Typekit
|
29
|
-
|
30
|
-
When using Typekit, specify the Kit to retrieve by its ID. You can find this
|
31
|
-
ID within Typekit's Kit Editor interface.
|
32
|
-
|
33
|
-
WebFont.load({
|
34
|
-
typekit: {
|
35
|
-
id: 'xxxxxx'
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
Learn more about [Typekit][tk].
|
40
|
-
|
41
|
-
## Fontdeck
|
42
|
-
|
43
|
-
To use Fontdeck, specify the ID of your website. You can find this ID on the
|
44
|
-
website page within your account settings.
|
45
|
-
|
46
|
-
WebFont.load({
|
47
|
-
fontdeck: {
|
48
|
-
id: 'xxxxx'
|
49
|
-
}
|
50
|
-
});
|
51
|
-
|
52
|
-
Learn more about [Fontdeck][fd].
|
53
|
-
|
54
|
-
## Fonts.com web fonts
|
55
|
-
|
56
|
-
When using [Fonts.com web fonts][mtiwfs]
|
57
|
-
|
58
|
-
(First sign up for [Fonts.com web fonts][mtiwfs]. Create a project, choose fonts to add into the created project and retrieve your Project ID. You can find this Project ID in the "Publish" tab).
|
59
|
-
|
60
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
61
|
-
<script type="text/javascript">
|
62
|
-
WebFont.load({
|
63
|
-
monotype: {
|
64
|
-
projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
65
|
-
version: 12345 // (optional, flushes the CDN cache)
|
66
|
-
}
|
67
|
-
});
|
68
|
-
</script>
|
69
|
-
|
70
|
-
Or as pure Fonts.com Web fonts API
|
71
|
-
|
72
|
-
<script type="text/javascript" src="http://fast.fonts.com/jsapi/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.js"></script>
|
73
|
-
|
74
|
-
## Custom
|
75
|
-
|
76
|
-
To load fonts from any external stylesheet, use the `custom` module. Here you'll
|
77
|
-
need to specify both the url of the stylesheet as well as the font families it
|
78
|
-
provides.
|
79
|
-
|
80
|
-
You can specify a specific font variation or set of variations to load and watch
|
81
|
-
by appending the variations separated by commas to the family name separated by
|
82
|
-
a colon. Variations are specified using [FVD notation][fvd].
|
83
|
-
|
84
|
-
WebFont.load({
|
85
|
-
custom: {
|
86
|
-
families: ['My Font', 'My Other Font:n4,i4,n7'],
|
87
|
-
urls: ['/fonts.css']
|
88
|
-
}
|
89
|
-
});
|
90
|
-
|
91
|
-
|
92
|
-
[gfontapi]: https://code.google.com/apis/webfonts/docs/getting_started.html
|
93
|
-
[tk]: http://typekit.com/
|
94
|
-
[fd]: http://fontdeck.com/
|
95
|
-
[mtiwfs]: http://webfonts.fonts.com/
|
96
|
-
[fvd]: https://github.com/typekit/fvd
|
data/docs/TRANSITIONS.md
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
# Transitions
|
2
|
-
|
3
|
-
In order to support smooth transitions between webfont providers, WebFont
|
4
|
-
Loader provides a common interface to each provider. It also makes it trivial
|
5
|
-
to load fonts from multiple providers.
|
6
|
-
|
7
|
-
This is especially powerful when building your page against the [events][]
|
8
|
-
because the same events are triggered regardless of the provider.
|
9
|
-
|
10
|
-
Here are a few scenarios.
|
11
|
-
|
12
|
-
## From Google Fonts to Typekit
|
13
|
-
|
14
|
-
### Step 1: Use Google with WebFont Loader
|
15
|
-
|
16
|
-
You can get started with web fonts quickly and easily by just using Google.
|
17
|
-
|
18
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
19
|
-
<script type="text/javascript">
|
20
|
-
WebFont.load({
|
21
|
-
google: {
|
22
|
-
families: ['Droid Sans']
|
23
|
-
}
|
24
|
-
});
|
25
|
-
</script>
|
26
|
-
|
27
|
-
### Step 2: Add Typekit
|
28
|
-
|
29
|
-
If you discover that Google doesn't have your preferred typeface, you may wish
|
30
|
-
to add fonts from Typekit.
|
31
|
-
|
32
|
-
(first sign up for Typekit, add fonts and retrieve your Kit ID)
|
33
|
-
|
34
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
35
|
-
<script type="text/javascript">
|
36
|
-
WebFont.load({
|
37
|
-
google: {
|
38
|
-
families: ['Droid Sans']
|
39
|
-
},
|
40
|
-
typekit: {
|
41
|
-
id: 'abc1def'
|
42
|
-
}
|
43
|
-
});
|
44
|
-
</script>
|
45
|
-
|
46
|
-
### Step 3 Remove Google
|
47
|
-
|
48
|
-
You may now discover that the number of HTTP requests has increased by pulling
|
49
|
-
fonts from both Google and Typekit. Since Typekit has all of the fonts that
|
50
|
-
Google has, let's drop that dependency.
|
51
|
-
|
52
|
-
(first add 'Droid Sans' to your Kit with ID 'abc1def')
|
53
|
-
|
54
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
55
|
-
<script type="text/javascript">
|
56
|
-
WebFont.load({,
|
57
|
-
typekit: {
|
58
|
-
id: 'abc1def'
|
59
|
-
}
|
60
|
-
});
|
61
|
-
</script>
|
62
|
-
|
63
|
-
### Step 4: Remove WebFont Loader
|
64
|
-
|
65
|
-
You may wish to reduce HTTP requests further by dropping the dependency on
|
66
|
-
WebFont Loader to work directly with Typekit. Typekit's API is fully
|
67
|
-
compatible with WebFont Loader.
|
68
|
-
|
69
|
-
<script type="text/javascript" src="http://use.typekit.com/abc1def.js"></script>
|
70
|
-
<script type="text/javascript">
|
71
|
-
WebFont.load();
|
72
|
-
</script>
|
73
|
-
|
74
|
-
Or as pure Typekit
|
75
|
-
|
76
|
-
<script type="text/javascript" src="http://use.typekit.com/abc1def.js"></script>
|
77
|
-
<script type="text/javascript">
|
78
|
-
Typekit.load();
|
79
|
-
</script>
|
80
|
-
|
81
|
-
## From Google Fonts to Fonts.com Web fonts
|
82
|
-
|
83
|
-
### Step 1: Use Google with WebFont Loader
|
84
|
-
|
85
|
-
You can get started with web fonts quickly and easily by just using Google.
|
86
|
-
|
87
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
88
|
-
<script type="text/javascript">
|
89
|
-
WebFont.load({
|
90
|
-
google: {
|
91
|
-
families: ['Droid Sans']
|
92
|
-
}
|
93
|
-
});
|
94
|
-
</script>
|
95
|
-
|
96
|
-
### Step 2: Add Fonts.com Web fonts
|
97
|
-
|
98
|
-
If you discover that Google doesn't have your preferred typeface, you may wish
|
99
|
-
to add fonts from Fonts.com Web fonts.
|
100
|
-
|
101
|
-
(first sign up for Fonts.com Web fonts, add fonts and retrieve your Project ID)
|
102
|
-
|
103
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
104
|
-
<script type="text/javascript">
|
105
|
-
WebFont.load({
|
106
|
-
monotype: {
|
107
|
-
projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
108
|
-
}
|
109
|
-
});
|
110
|
-
</script>
|
111
|
-
|
112
|
-
|
113
|
-
Or as pure Fonts.com Web fonts API
|
114
|
-
|
115
|
-
<script type="text/javascript" src="http://fast.fonts.com/jsapi/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.js"></script>
|
116
|
-
|
117
|
-
## Add events to self-hosted fonts
|
118
|
-
|
119
|
-
### Step 1: Link to your own stylesheet
|
120
|
-
|
121
|
-
If you already have fonts and the `@font-face` rules written, you might
|
122
|
-
already be using them in your page.
|
123
|
-
|
124
|
-
<link type="text/css" rel="stylesheet" href="/fonts.css">
|
125
|
-
|
126
|
-
### Step 2: Use WebFont Loader
|
127
|
-
|
128
|
-
To add [events][] support, use the `custom` module to load your stylesheet,
|
129
|
-
and name the font families that the stylesheet provides.
|
130
|
-
|
131
|
-
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
132
|
-
<script type="text/javascript">
|
133
|
-
WebFont.load({
|
134
|
-
default: {
|
135
|
-
families: ['My Font'],
|
136
|
-
urls: ['/fonts.css']
|
137
|
-
}
|
138
|
-
});
|
139
|
-
</script>
|
140
|
-
|
141
|
-
|
142
|
-
[events]: EVENTS.md
|