webfontloader 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +4 -0
- data/README.md +163 -131
- data/lib/webfontloader.rb +1 -1
- data/spec/core/domhelper_spec.js +100 -0
- data/src/core/domhelper.js +50 -12
- data/src/core/eventdispatcher.js +57 -44
- data/src/core/fontruler.js +1 -1
- data/webfontloader.gemspec +2 -2
- metadata +65 -90
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f2d29daa39ef38194d69ef325ccd687a3b906fa
|
4
|
+
data.tar.gz: 7dd1853c96e114304e74a2305c3585e03693cc20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd13cb3191c2608c60d65e8872f6945599161335ca299ca842f377298a8b53cdd2b8f8af8d5ba2f592fc50a01ad2bdbdce492adc05e7f6452ac8b029b3ccc8df
|
7
|
+
data.tar.gz: cc7e4b91fe6b7c53e76de4c0baa39b09ec17f54d793d03b96ba185edd638c081376a9e7e470d8249f354be0df84bf7a83b9e91b1114ccac7be79ba45aea0e44c
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
v1.5.3 (April 8, 2014)
|
2
|
+
* Prevent a potential FOUT when setting the font event classes.
|
3
|
+
* Add "display:block" to test rulers so "* { display: none; }" doesn't override it
|
4
|
+
|
1
5
|
v1.5.2 (January 3, 2014)
|
2
6
|
* Add Copyright, License and Version to the compiled output file(s)
|
3
7
|
* Fix small bug in Google Font module that rejected font variations with dashes
|
data/README.md
CHANGED
@@ -24,34 +24,38 @@ Web Font Loader gives you added control when using linked fonts via `@font-face`
|
|
24
24
|
|
25
25
|
To use the Web Font Loader library, just include it in your page and tell it which fonts to load. For example, you could load fonts from [Google Fonts](http://www.google.com/fonts/) using the Web Font Loader hosted on [Google Hosted Libraries](https://developers.google.com/speed/libraries/) using the following code.
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
```html
|
28
|
+
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js"></script>
|
29
|
+
<script>
|
30
|
+
WebFont.load({
|
31
|
+
google: {
|
32
|
+
families: ['Droid Sans', 'Droid Serif']
|
33
|
+
}
|
34
|
+
});
|
35
|
+
</script>
|
36
|
+
```
|
35
37
|
|
36
38
|
Alternatively, you can link to the latest `1.x` version of the Web Font Loader by using `//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js` as the `script` source. Note that the version in this url is less specific. It will always load the latest `1.x` version, but it also has a shorter cache time to ensure that your page gets updates in a timely manner. For performance reasons, we recommend using an explicit version number (such as `1.4.7`) in urls when using the Web Font Loader in production. You can manually update the Web Font Loader version number in the url when you want to adopt a new version.
|
37
39
|
|
38
40
|
It is also possible to use the Web Font Loader asynchronously. For example, to load [Typekit](http://www.typekit.com) fonts asynchronously, you could use the following code.
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
42
|
+
```html
|
43
|
+
<script>
|
44
|
+
WebFontConfig = {
|
45
|
+
typekit: { id: 'xxxxxx' }
|
46
|
+
};
|
47
|
+
|
48
|
+
(function() {
|
49
|
+
var wf = document.createElement('script');
|
50
|
+
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
|
51
|
+
'://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js';
|
52
|
+
wf.type = 'text/javascript';
|
53
|
+
wf.async = 'true';
|
54
|
+
var s = document.getElementsByTagName('script')[0];
|
55
|
+
s.parentNode.insertBefore(wf, s);
|
56
|
+
})();
|
57
|
+
</script>
|
58
|
+
```
|
55
59
|
|
56
60
|
Using the Web Font Loader asynchronously avoids blocking your page while loading the JavaScript. Be aware that if the script is used asynchronously, the rest of the page might render before the Web Font Loader is loaded and executed, which can cause a [Flash of Unstyled Text (FOUT)](http://help.typekit.com/customer/portal/articles/6852).
|
57
61
|
|
@@ -74,20 +78,24 @@ Web Font Loader provides an event system that developers can hook into. It gives
|
|
74
78
|
|
75
79
|
CSS events are implemented as classes on the `html` element. The following classes are set on the `html` element:
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
```css
|
82
|
+
.wf-loading
|
83
|
+
.wf-active
|
84
|
+
.wf-inactive
|
85
|
+
.wf-<familyname>-<fvd>-loading
|
86
|
+
.wf-<familyname>-<fvd>-active
|
87
|
+
.wf-<familyname>-<fvd>-inactive
|
88
|
+
```
|
83
89
|
|
84
90
|
The `<familyname>` placeholder will be replaced by a sanitized version of the name of each font family. Spaces and underscores are removed from the name, and all characters are converted to lower case. For example, `Droid Sans` becomes `droidsans`. The `<fvd>` placeholder is a [Font Variation Description](https://github.com/typekit/fvd). Put simply, it's a shorthand for describing the style and weight of a particular font. Here are a few examples:
|
85
91
|
|
86
|
-
|
87
|
-
|
92
|
+
```css
|
93
|
+
/* n4 */
|
94
|
+
@font-face { font-style: normal; font-weight: normal; }
|
88
95
|
|
89
|
-
|
90
|
-
|
96
|
+
/* i7 */
|
97
|
+
@font-face { font-style: italic; font-weight: bold; }
|
98
|
+
```
|
91
99
|
|
92
100
|
Keep in mind that `font-weight: normal` maps to `font-weight: 400` and `font-weight: bold` maps to `font-weight: 700`. If no style/weight is specified, the default `n4` (`font-style: normal; font-weight: normal;`) will be used.
|
93
101
|
|
@@ -95,29 +103,33 @@ If fonts are loaded multiple times on a single page, the CSS classes continue to
|
|
95
103
|
|
96
104
|
JavaScript events are implemented as callback functions on the `WebFontConfig` configuration object.
|
97
105
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
+
```javascript
|
107
|
+
WebFontConfig = {
|
108
|
+
loading: function() {},
|
109
|
+
active: function() {},
|
110
|
+
inactive: function() {},
|
111
|
+
fontloading: function(familyName, fvd) {},
|
112
|
+
fontactive: function(familyName, fvd) {},
|
113
|
+
fontinactive: function(familyName, fvd) {}
|
114
|
+
};
|
115
|
+
```
|
106
116
|
|
107
117
|
The `fontloading`, `fontactive` and `fontinactive` callbacks are passed the family name and font variation description of the font that concerns the event.
|
108
118
|
|
109
119
|
### Timeouts
|
110
120
|
|
111
|
-
Since the Internet is not 100% reliable, it's possible that a font will fail to load. The `fontinactive` event will be triggered after 5 seconds if the font fails to render. If *at least* one font succesfully renders, the `active` event will be triggered, else the `inactive`
|
121
|
+
Since the Internet is not 100% reliable, it's possible that a font will fail to load. The `fontinactive` event will be triggered after 5 seconds if the font fails to render. If *at least* one font succesfully renders, the `active` event will be triggered, else the `inactive` event will be triggered.
|
112
122
|
|
113
123
|
You can change the default timeout by using the `timeout` option on the `WebFontConfig` object.
|
114
124
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
125
|
+
```javascript
|
126
|
+
WebFontConfig = {
|
127
|
+
google: {
|
128
|
+
families: ['Droid Sans']
|
129
|
+
},
|
130
|
+
timeout: 2000 // Set the timeout to two seconds
|
131
|
+
};
|
132
|
+
```
|
121
133
|
|
122
134
|
The timeout value should be in milliseconds, and defaults to 5000 milliseconds (5 seconds) if not supplied.
|
123
135
|
|
@@ -125,12 +137,14 @@ The timeout value should be in milliseconds, and defaults to 5000 milliseconds (
|
|
125
137
|
|
126
138
|
Usually, it's easiest to include a copy of Web Font Loader 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, Web Font Loader supports that as well. Just use the optional `context` configuration option and give it a reference to the target window for loading:
|
127
139
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
140
|
+
```javascript
|
141
|
+
WebFontConfig = {
|
142
|
+
google: {
|
143
|
+
families: ['Droid Sans']
|
144
|
+
},
|
145
|
+
context: frames['my-child']
|
146
|
+
};
|
147
|
+
```
|
134
148
|
|
135
149
|
This is an advanced configuration option that isn't needed for most use cases.
|
136
150
|
|
@@ -148,68 +162,74 @@ You can specify a specific font variation or set of variations to load and watch
|
|
148
162
|
by appending the variations separated by commas to the family name separated by
|
149
163
|
a colon. Variations are specified using [FVD notation](https://github.com/typekit/fvd).
|
150
164
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
165
|
+
```javascript
|
166
|
+
WebFontConfig = {
|
167
|
+
custom: {
|
168
|
+
families: ['My Font', 'My Other Font:n4,i4,n7'],
|
169
|
+
urls: ['/fonts.css']
|
170
|
+
}
|
171
|
+
};
|
172
|
+
```
|
157
173
|
|
158
174
|
In this example, the `fonts.css` file might look something like this:
|
159
175
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
176
|
+
```css
|
177
|
+
@font-face {
|
178
|
+
font-family: 'My Font';
|
179
|
+
src: ...;
|
180
|
+
}
|
181
|
+
@font-face {
|
182
|
+
font-family: 'My Other Font';
|
183
|
+
font-style: normal;
|
184
|
+
font-weight: normal; /* or 400 */
|
185
|
+
src: ...;
|
186
|
+
}
|
187
|
+
@font-face {
|
188
|
+
font-family: 'My Other Font';
|
189
|
+
font-style: italic;
|
190
|
+
font-weight: normal; /* or 400 */
|
191
|
+
src: ...;
|
192
|
+
}
|
193
|
+
@font-face {
|
194
|
+
font-family: 'My Other Font';
|
195
|
+
font-style: normal;
|
196
|
+
font-weight: bold; /* or 700 */
|
197
|
+
src: ...;
|
198
|
+
}
|
199
|
+
```
|
182
200
|
|
183
201
|
Alternatively, you can load your fonts from a stylesheet not specified in WebFontConfig. As long as the names match those that are declared in the `families` array, the proper loading classes will be applied to the html element.
|
184
202
|
|
185
|
-
```
|
203
|
+
```html
|
186
204
|
<script src="//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js"></script>
|
187
205
|
<script>
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
206
|
+
WebFont.load({
|
207
|
+
custom: {
|
208
|
+
families: ['My Font']
|
209
|
+
}
|
210
|
+
});
|
193
211
|
</script>
|
194
212
|
|
195
213
|
<style type="text/css">
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
214
|
+
@font-face {
|
215
|
+
font-family:"My Font";
|
216
|
+
src:url("assets/fonts/my_font.woff") format("woff");
|
217
|
+
}
|
200
218
|
</style>
|
201
219
|
```
|
202
220
|
|
203
221
|
The custom module also supports customizing the test strings that are used to determine whether or not a font has loaded. This can be used to load fonts with custom subsets or glyphs in the private use unicode area.
|
204
222
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
223
|
+
```javascript
|
224
|
+
WebFontConfig = {
|
225
|
+
custom: {
|
226
|
+
families: ['My Font'],
|
227
|
+
testStrings: {
|
228
|
+
'My Font': '\uE003\uE005'
|
229
|
+
}
|
230
|
+
}
|
231
|
+
};
|
232
|
+
```
|
213
233
|
|
214
234
|
Tests strings should be specified on a per font basis and contain at least one character. If not specified the default test string (`BESbswy`) is used.
|
215
235
|
|
@@ -217,22 +237,26 @@ Tests strings should be specified on a per font basis and contain at least one c
|
|
217
237
|
|
218
238
|
To use the [Fontdeck](http://fontdeck.com/) module, specify the ID of your website. You can find this ID on the website page within your account settings.
|
219
239
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
240
|
+
```javascript
|
241
|
+
WebFontConfig = {
|
242
|
+
fontdeck: {
|
243
|
+
id: 'xxxxx'
|
244
|
+
}
|
245
|
+
};
|
246
|
+
```
|
225
247
|
|
226
248
|
### Fonts.com
|
227
249
|
|
228
250
|
When using [Fonts.com web fonts](http://webfonts.fonts.com/) specify your Project ID.
|
229
251
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
252
|
+
```javascript
|
253
|
+
WebFontConfig = {
|
254
|
+
monotype: {
|
255
|
+
projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
|
256
|
+
version: 12345 // (optional, flushes the CDN cache)
|
257
|
+
}
|
258
|
+
};
|
259
|
+
```
|
236
260
|
|
237
261
|
The Fonts.com module has an optional `version` option which acts as a cache-buster.
|
238
262
|
|
@@ -240,20 +264,24 @@ The Fonts.com module has an optional `version` option which acts as a cache-bust
|
|
240
264
|
|
241
265
|
Using [Google's Font API](https://code.google.com/apis/webfonts/docs/getting_started.html), name the font families you'd like to load. You can use the same [syntax](https://developers.google.com/fonts/docs/getting_started#Syntax) as in the Font API to specify styles:
|
242
266
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
267
|
+
```javascript
|
268
|
+
WebFontConfig = {
|
269
|
+
google: {
|
270
|
+
families: ['Droid Sans', 'Droid Serif:bold']
|
271
|
+
}
|
272
|
+
};
|
273
|
+
```
|
248
274
|
|
249
275
|
You can also supply the `text` parameter to perform character subsetting:
|
250
276
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
277
|
+
```javascript
|
278
|
+
WebFontConfig = {
|
279
|
+
google: {
|
280
|
+
families: ['Droid Sans', 'Droid Serif'],
|
281
|
+
text: 'abcdedfghijklmopqrstuvwxyz!'
|
282
|
+
}
|
283
|
+
};
|
284
|
+
```
|
257
285
|
|
258
286
|
The `text` subsetting functionality is only available for the Google module.
|
259
287
|
|
@@ -261,11 +289,13 @@ The `text` subsetting functionality is only available for the Google module.
|
|
261
289
|
|
262
290
|
When using [Typekit](http://www.typekit.com), specify the Kit to retrieve by its ID. You can find the Kit ID within Typekit's Kit Editor interface.
|
263
291
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
292
|
+
```javascript
|
293
|
+
WebFontConfig = {
|
294
|
+
typekit: {
|
295
|
+
id: 'xxxxxx'
|
296
|
+
}
|
297
|
+
};
|
298
|
+
```
|
269
299
|
|
270
300
|
**FYI:** Typekit's own JavaScript is built using the Web Font Loader library and already provides all of the same font event functionality. If you're using Typekit, you should use their embed codes directly unless you also need to load web fonts from other providers on the same page.
|
271
301
|
|
@@ -281,10 +311,12 @@ For fonts loaded from supported providers, the `fontactive` event will be trigge
|
|
281
311
|
|
282
312
|
For example:
|
283
313
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
314
|
+
```javascript
|
315
|
+
WebFontConfig = {
|
316
|
+
providerA: 'Family1',
|
317
|
+
providerB: 'Family2'
|
318
|
+
};
|
319
|
+
```
|
288
320
|
|
289
321
|
If `providerA` can serve fonts to a browser, but `providerB` cannot, The `fontinactive` event will be triggered for `Family2`. The `fontactive` event will be triggered for `Family1` once it loads, as will the `active` event.
|
290
322
|
|
data/lib/webfontloader.rb
CHANGED
data/spec/core/domhelper_spec.js
CHANGED
@@ -99,6 +99,106 @@ describe('DomHelper', function () {
|
|
99
99
|
});
|
100
100
|
});
|
101
101
|
|
102
|
+
describe('#updateClassName', function () {
|
103
|
+
it('should handle optional arguments correctly', function () {
|
104
|
+
var div = domHelper.createElement('div');
|
105
|
+
|
106
|
+
domHelper.appendClassName(div, 'moo');
|
107
|
+
|
108
|
+
domHelper.updateClassName(div);
|
109
|
+
expect(div.className).toEqual('moo');
|
110
|
+
|
111
|
+
domHelper.updateClassName(div, [], []);
|
112
|
+
expect(div.className).toEqual('moo');
|
113
|
+
|
114
|
+
domHelper.updateClassName(div, null, null);
|
115
|
+
expect(div.className).toEqual('moo');
|
116
|
+
});
|
117
|
+
|
118
|
+
it('should have added a class name', function () {
|
119
|
+
var div = domHelper.createElement('div');
|
120
|
+
domHelper.updateClassName(div, ['moo']);
|
121
|
+
|
122
|
+
expect(div.className).toEqual('moo');
|
123
|
+
});
|
124
|
+
|
125
|
+
it('should not add duplicate class names', function () {
|
126
|
+
var div = domHelper.createElement('div');
|
127
|
+
|
128
|
+
domHelper.appendClassName(div, 'moo');
|
129
|
+
domHelper.updateClassName(div, ['moo']);
|
130
|
+
|
131
|
+
expect(div.className).toEqual('moo');
|
132
|
+
});
|
133
|
+
|
134
|
+
it('should add multiple class names', function () {
|
135
|
+
var div = domHelper.createElement('div');
|
136
|
+
|
137
|
+
domHelper.updateClassName(div, ['moo', 'meu', 'moo']);
|
138
|
+
expect(div.className).toEqual('moo meu');
|
139
|
+
});
|
140
|
+
|
141
|
+
it('should normalize spaces and tabs', function () {
|
142
|
+
var div = domHelper.createElement('div');
|
143
|
+
|
144
|
+
domHelper.updateClassName(div, ['meu', ' foo']);
|
145
|
+
expect(div.className).toEqual('meu foo');
|
146
|
+
});
|
147
|
+
|
148
|
+
it('should remove class names', function () {
|
149
|
+
var div = domHelper.createElement('div');
|
150
|
+
|
151
|
+
domHelper.appendClassName(div, 'meu moo');
|
152
|
+
expect(div.className).toEqual('meu moo');
|
153
|
+
|
154
|
+
domHelper.updateClassName(div, null, ['meu']);
|
155
|
+
expect(div.className).toEqual('moo');
|
156
|
+
});
|
157
|
+
|
158
|
+
it('should remove multiple class names', function () {
|
159
|
+
var div = domHelper.createElement('div');
|
160
|
+
|
161
|
+
domHelper.appendClassName(div, 'meu');
|
162
|
+
domHelper.appendClassName(div, 'moo');
|
163
|
+
expect(div.className).toEqual('meu moo');
|
164
|
+
|
165
|
+
domHelper.updateClassName(div, null, ['meu', 'moo']);
|
166
|
+
expect(div.className).toEqual('');
|
167
|
+
});
|
168
|
+
|
169
|
+
it('should not remove non-existing classes', function () {
|
170
|
+
var div = domHelper.createElement('div');
|
171
|
+
|
172
|
+
domHelper.appendClassName(div, 'moo');
|
173
|
+
expect(div.className).toEqual('moo');
|
174
|
+
|
175
|
+
domHelper.updateClassName(div, null, 'boo');
|
176
|
+
expect(div.className).toEqual('moo');
|
177
|
+
});
|
178
|
+
|
179
|
+
it('should add and remove class names', function () {
|
180
|
+
var div = domHelper.createElement('div');
|
181
|
+
|
182
|
+
domHelper.appendClassName(div, 'moo');
|
183
|
+
domHelper.appendClassName(div, 'meh');
|
184
|
+
expect(div.className).toEqual('moo meh');
|
185
|
+
|
186
|
+
domHelper.updateClassName(div, ['meu'], ['moo', 'meh']);
|
187
|
+
expect(div.className).toEqual('meu');
|
188
|
+
});
|
189
|
+
|
190
|
+
it('should update one of many class names', function () {
|
191
|
+
var div = domHelper.createElement('div');
|
192
|
+
|
193
|
+
domHelper.appendClassName(div, 'moo');
|
194
|
+
domHelper.appendClassName(div, 'meh');
|
195
|
+
expect(div.className).toEqual('moo meh');
|
196
|
+
|
197
|
+
domHelper.updateClassName(div, ['meu'], ['moo']);
|
198
|
+
expect(div.className).toEqual('meh meu');
|
199
|
+
});
|
200
|
+
});
|
201
|
+
|
102
202
|
describe('#hasClassName', function () {
|
103
203
|
var div = null;
|
104
204
|
|
data/src/core/domhelper.js
CHANGED
@@ -104,36 +104,74 @@ goog.scope(function () {
|
|
104
104
|
};
|
105
105
|
|
106
106
|
/**
|
107
|
+
* @deprecated Use updateClassName().
|
108
|
+
*
|
107
109
|
* Appends a name to an element's class attribute.
|
108
110
|
* @param {Element} e The element.
|
109
111
|
* @param {string} name The class name to add.
|
110
112
|
*/
|
111
113
|
DomHelper.prototype.appendClassName = function(e, name) {
|
112
|
-
|
113
|
-
for (var i = 0, len = classes.length; i < len; i++) {
|
114
|
-
if (classes[i] == name) {
|
115
|
-
return;
|
116
|
-
}
|
117
|
-
}
|
118
|
-
classes.push(name);
|
119
|
-
e.className = classes.join(' ')
|
120
|
-
.replace(/\s+/g, ' ')
|
121
|
-
.replace(/^\s+|\s+$/, '');
|
114
|
+
this.updateClassName(e, [name]);
|
122
115
|
};
|
123
116
|
|
124
117
|
/**
|
118
|
+
* @deprecated Use updateClassName().
|
119
|
+
*
|
125
120
|
* Removes a name to an element's class attribute.
|
126
121
|
* @param {Element} e The element.
|
127
122
|
* @param {string} name The class name to remove.
|
128
123
|
*/
|
129
124
|
DomHelper.prototype.removeClassName = function(e, name) {
|
125
|
+
this.updateClassName(e, null, [name]);
|
126
|
+
};
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Updates an element's class attribute in a single change. This
|
130
|
+
* allows multiple updates in a single class name change so there
|
131
|
+
* is no chance for a browser to relayout in between changes.
|
132
|
+
*
|
133
|
+
* @param {Element} e The element.
|
134
|
+
* @param {Array.<string>=} opt_add List of class names to add.
|
135
|
+
* @param {Array.<string>=} opt_remove List of class names to remove.
|
136
|
+
*/
|
137
|
+
DomHelper.prototype.updateClassName = function (e, opt_add, opt_remove) {
|
138
|
+
var add = opt_add || [],
|
139
|
+
remove = opt_remove || [];
|
140
|
+
|
130
141
|
var classes = e.className.split(/\s+/);
|
142
|
+
|
143
|
+
for (var i = 0; i < add.length; i += 1) {
|
144
|
+
var found = false;
|
145
|
+
|
146
|
+
for (var j = 0; j < classes.length; j += 1) {
|
147
|
+
if (add[i] === classes[j]) {
|
148
|
+
found = true;
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
if (!found) {
|
154
|
+
classes.push(add[i]);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
131
158
|
var remainingClasses = [];
|
132
|
-
|
133
|
-
|
159
|
+
|
160
|
+
for (var i = 0; i < classes.length; i += 1) {
|
161
|
+
var found = false;
|
162
|
+
|
163
|
+
for (var j = 0; j < remove.length; j += 1) {
|
164
|
+
if (classes[i] === remove[j]) {
|
165
|
+
found = true;
|
166
|
+
break;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
|
170
|
+
if (!found) {
|
134
171
|
remainingClasses.push(classes[i]);
|
135
172
|
}
|
136
173
|
}
|
174
|
+
|
137
175
|
e.className = remainingClasses.join(' ')
|
138
176
|
.replace(/\s+/g, ' ')
|
139
177
|
.replace(/^\s+|\s+$/, '');
|
data/src/core/eventdispatcher.js
CHANGED
@@ -60,9 +60,12 @@ goog.scope(function () {
|
|
60
60
|
* Dispatch the loading event and append the loading class name.
|
61
61
|
*/
|
62
62
|
EventDispatcher.prototype.dispatchLoading = function() {
|
63
|
-
this.domHelper_.
|
64
|
-
|
65
|
-
|
63
|
+
this.domHelper_.updateClassName(this.htmlElement_,
|
64
|
+
[
|
65
|
+
this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.LOADING)
|
66
|
+
]
|
67
|
+
);
|
68
|
+
|
66
69
|
this.dispatch_(webfont.EventDispatcher.LOADING);
|
67
70
|
};
|
68
71
|
|
@@ -71,9 +74,12 @@ goog.scope(function () {
|
|
71
74
|
* @param {webfont.Font} font
|
72
75
|
*/
|
73
76
|
EventDispatcher.prototype.dispatchFontLoading = function(font) {
|
74
|
-
this.domHelper_.
|
75
|
-
|
76
|
-
|
77
|
+
this.domHelper_.updateClassName(this.htmlElement_,
|
78
|
+
[
|
79
|
+
this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.LOADING)
|
80
|
+
]
|
81
|
+
);
|
82
|
+
|
77
83
|
this.dispatch_(
|
78
84
|
webfont.EventDispatcher.FONT + webfont.EventDispatcher.LOADING, font);
|
79
85
|
};
|
@@ -84,17 +90,18 @@ goog.scope(function () {
|
|
84
90
|
* @param {webfont.Font} font
|
85
91
|
*/
|
86
92
|
EventDispatcher.prototype.dispatchFontActive = function(font) {
|
87
|
-
this.domHelper_.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
this.cssClassName_.build(
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
this.domHelper_.updateClassName(
|
94
|
+
this.htmlElement_,
|
95
|
+
[
|
96
|
+
this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.ACTIVE)
|
97
|
+
],
|
98
|
+
[
|
99
|
+
this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.LOADING),
|
100
|
+
this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.INACTIVE)
|
101
|
+
]
|
102
|
+
);
|
103
|
+
|
104
|
+
this.dispatch_(webfont.EventDispatcher.FONT + webfont.EventDispatcher.ACTIVE, font);
|
98
105
|
};
|
99
106
|
|
100
107
|
/**
|
@@ -104,19 +111,21 @@ goog.scope(function () {
|
|
104
111
|
* @param {webfont.Font} font
|
105
112
|
*/
|
106
113
|
EventDispatcher.prototype.dispatchFontInactive = function(font) {
|
107
|
-
this.domHelper_.removeClassName(this.htmlElement_,
|
108
|
-
this.cssClassName_.build(
|
109
|
-
this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.LOADING));
|
110
114
|
var hasFontActive = this.domHelper_.hasClassName(this.htmlElement_,
|
111
|
-
|
112
|
-
|
115
|
+
this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.ACTIVE)
|
116
|
+
),
|
117
|
+
add = [],
|
118
|
+
remove = [
|
119
|
+
this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.LOADING)
|
120
|
+
];
|
121
|
+
|
113
122
|
if (!hasFontActive) {
|
114
|
-
this.
|
115
|
-
this.cssClassName_.build(
|
116
|
-
this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.INACTIVE));
|
123
|
+
add.push(this.cssClassName_.build(this.namespace_, font.getName(), font.getVariation().toString(), webfont.EventDispatcher.INACTIVE));
|
117
124
|
}
|
118
|
-
|
119
|
-
|
125
|
+
|
126
|
+
this.domHelper_.updateClassName(this.htmlElement_, add, remove);
|
127
|
+
|
128
|
+
this.dispatch_(webfont.EventDispatcher.FONT + webfont.EventDispatcher.INACTIVE, font);
|
120
129
|
};
|
121
130
|
|
122
131
|
/**
|
@@ -124,17 +133,20 @@ goog.scope(function () {
|
|
124
133
|
* inactive class name (unless the active class name is already present).
|
125
134
|
*/
|
126
135
|
EventDispatcher.prototype.dispatchInactive = function() {
|
127
|
-
this.domHelper_.removeClassName(this.htmlElement_,
|
128
|
-
this.cssClassName_.build(
|
129
|
-
this.namespace_, webfont.EventDispatcher.LOADING));
|
130
136
|
var hasActive = this.domHelper_.hasClassName(this.htmlElement_,
|
131
|
-
|
132
|
-
|
137
|
+
this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.ACTIVE)
|
138
|
+
),
|
139
|
+
add = [],
|
140
|
+
remove = [
|
141
|
+
this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.LOADING)
|
142
|
+
];
|
143
|
+
|
133
144
|
if (!hasActive) {
|
134
|
-
this.
|
135
|
-
this.cssClassName_.build(
|
136
|
-
this.namespace_, webfont.EventDispatcher.INACTIVE));
|
145
|
+
add.push(this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.INACTIVE));
|
137
146
|
}
|
147
|
+
|
148
|
+
this.domHelper_.updateClassName(this.htmlElement_, add, remove);
|
149
|
+
|
138
150
|
this.dispatch_(webfont.EventDispatcher.INACTIVE);
|
139
151
|
};
|
140
152
|
|
@@ -143,15 +155,16 @@ goog.scope(function () {
|
|
143
155
|
* class name, and append the active class name.
|
144
156
|
*/
|
145
157
|
EventDispatcher.prototype.dispatchActive = function() {
|
146
|
-
this.domHelper_.
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
158
|
+
this.domHelper_.updateClassName(this.htmlElement_,
|
159
|
+
[
|
160
|
+
this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.ACTIVE)
|
161
|
+
],
|
162
|
+
[
|
163
|
+
this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.LOADING),
|
164
|
+
this.cssClassName_.build(this.namespace_, webfont.EventDispatcher.INACTIVE)
|
165
|
+
]
|
166
|
+
);
|
167
|
+
|
155
168
|
this.dispatch_(webfont.EventDispatcher.ACTIVE);
|
156
169
|
};
|
157
170
|
|
data/src/core/fontruler.js
CHANGED
@@ -38,7 +38,7 @@ goog.scope(function () {
|
|
38
38
|
* @return {string}
|
39
39
|
*/
|
40
40
|
FontRuler.prototype.computeStyleString_ = function(font) {
|
41
|
-
return "position:absolute;top:-999px;left:-999px;" +
|
41
|
+
return "display:block;position:absolute;top:-999px;left:-999px;" +
|
42
42
|
"font-size:300px;width:auto;height:auto;line-height:normal;margin:0;" +
|
43
43
|
"padding:0;font-variant:normal;white-space:nowrap;font-family:" +
|
44
44
|
font.getCssName() + ";" + font.getCssVariation();
|
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.5.
|
17
|
-
s.date = '2014-
|
16
|
+
s.version = '1.5.3'
|
17
|
+
s.date = '2014-04-08'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
metadata
CHANGED
@@ -1,99 +1,83 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 5
|
9
|
-
- 2
|
10
|
-
version: 1.5.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Ryan Carver
|
14
8
|
- Jeremie Lenfant-engelmann
|
15
9
|
autorequire:
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rake
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
33
21
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rack
|
37
22
|
prerelease: false
|
38
|
-
|
39
|
-
|
40
|
-
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rack
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
41
32
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 1
|
44
|
-
segments:
|
45
|
-
- 1
|
46
|
-
- 5
|
47
|
-
- 1
|
33
|
+
- !ruby/object:Gem::Version
|
48
34
|
version: 1.5.1
|
49
35
|
type: :development
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: sinatra
|
53
36
|
prerelease: false
|
54
|
-
|
55
|
-
|
56
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.5.1
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: sinatra
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
57
46
|
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 19
|
60
|
-
segments:
|
61
|
-
- 1
|
62
|
-
- 3
|
63
|
-
- 4
|
47
|
+
- !ruby/object:Gem::Version
|
64
48
|
version: 1.3.4
|
65
49
|
type: :development
|
66
|
-
version_requirements: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: vegas
|
69
50
|
prerelease: false
|
70
|
-
|
71
|
-
|
72
|
-
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.3.4
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: vegas
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
73
60
|
- - ~>
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
hash: 13
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
- 1
|
79
|
-
- 11
|
61
|
+
- !ruby/object:Gem::Version
|
80
62
|
version: 0.1.11
|
81
63
|
type: :development
|
82
|
-
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.1.11
|
83
70
|
description: |
|
84
71
|
WebFont Loader gives you added control when using linked fonts via
|
85
72
|
`@font-face`. It provides a common interface to loading fonts regardless of
|
86
73
|
the source, then adds a standard set of events you may use to control the
|
87
74
|
loading experience.
|
88
|
-
|
89
75
|
email: ryan@typekit.com
|
90
76
|
executables: []
|
91
|
-
|
92
77
|
extensions: []
|
93
|
-
|
94
|
-
extra_rdoc_files:
|
78
|
+
extra_rdoc_files:
|
95
79
|
- README.md
|
96
|
-
files:
|
80
|
+
files:
|
97
81
|
- AUTHORS
|
98
82
|
- CHANGELOG
|
99
83
|
- CONTRIBUTING.md
|
@@ -204,37 +188,28 @@ files:
|
|
204
188
|
- tools/jasmine/jasmine.js
|
205
189
|
- webfontloader.gemspec
|
206
190
|
homepage: http://github.com/typekit/webfontloader
|
207
|
-
licenses:
|
191
|
+
licenses:
|
208
192
|
- Apache 2.0
|
193
|
+
metadata: {}
|
209
194
|
post_install_message:
|
210
|
-
rdoc_options:
|
195
|
+
rdoc_options:
|
211
196
|
- --charset=UTF-8
|
212
|
-
require_paths:
|
197
|
+
require_paths:
|
213
198
|
- lib
|
214
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
none: false
|
225
|
-
requirements:
|
226
|
-
- - ">="
|
227
|
-
- !ruby/object:Gem::Version
|
228
|
-
hash: 3
|
229
|
-
segments:
|
230
|
-
- 0
|
231
|
-
version: "0"
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - '>='
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
232
209
|
requirements: []
|
233
|
-
|
234
210
|
rubyforge_project:
|
235
|
-
rubygems_version:
|
211
|
+
rubygems_version: 2.0.3
|
236
212
|
signing_key:
|
237
213
|
specification_version: 2
|
238
214
|
summary: WebFont Loader gives you added control when using linked fonts via @font-face.
|
239
215
|
test_files: []
|
240
|
-
|