webfontloader 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -19,8 +19,8 @@ describe('UserAgentParser', function () {
|
|
19
19
|
return false;
|
20
20
|
}
|
21
21
|
|
22
|
-
if (actual.
|
23
|
-
this.message = msg('version', actual.
|
22
|
+
if (actual.getParsedVersion().ne(expected.version)) {
|
23
|
+
this.message = msg('version', actual.getParsedVersion(), expected.version);
|
24
24
|
return false;
|
25
25
|
}
|
26
26
|
|
@@ -29,8 +29,8 @@ describe('UserAgentParser', function () {
|
|
29
29
|
return false;
|
30
30
|
}
|
31
31
|
|
32
|
-
if (actual.
|
33
|
-
this.message = msg('platform version', actual.
|
32
|
+
if (actual.getParsedPlatformVersion().ne(expected.platformVersion)) {
|
33
|
+
this.message = msg('platform version', actual.getParsedPlatformVersion(), expected.platformVersion);
|
34
34
|
return false;
|
35
35
|
}
|
36
36
|
|
@@ -39,8 +39,8 @@ describe('UserAgentParser', function () {
|
|
39
39
|
return false;
|
40
40
|
}
|
41
41
|
|
42
|
-
if (actual.
|
43
|
-
this.message = msg('engine version', actual.
|
42
|
+
if (actual.getParsedEngineVersion().ne(expected.engineVersion)) {
|
43
|
+
this.message = msg('engine version', actual.getParsedEngineVersion(), expected.engineVersion);
|
44
44
|
return false;
|
45
45
|
}
|
46
46
|
|
data/spec/core/webfont_spec.js
CHANGED
@@ -2,13 +2,26 @@ describe('WebFont', function () {
|
|
2
2
|
var WebFont = webfont.WebFont,
|
3
3
|
UserAgent = webfont.UserAgent,
|
4
4
|
BrowserInfo = webfont.BrowserInfo,
|
5
|
+
Version = webfont.Version,
|
5
6
|
Font = webfont.Font,
|
6
7
|
FontModuleLoader = webfont.FontModuleLoader,
|
7
8
|
fontModuleLoader = null,
|
8
9
|
userAgent = null;
|
9
10
|
|
10
11
|
beforeEach(function () {
|
11
|
-
userAgent = new UserAgent(
|
12
|
+
userAgent = new UserAgent(
|
13
|
+
'Firefox',
|
14
|
+
new Version(3, 6),
|
15
|
+
'3.6',
|
16
|
+
'Gecko',
|
17
|
+
new Version(1, 9, 2),
|
18
|
+
'1.9.2',
|
19
|
+
'Macintosh',
|
20
|
+
new Version(10, 6),
|
21
|
+
'10.6',
|
22
|
+
undefined,
|
23
|
+
new BrowserInfo(true, false, false)
|
24
|
+
);
|
12
25
|
fontModuleLoader = new FontModuleLoader();
|
13
26
|
});
|
14
27
|
|
@@ -121,7 +134,7 @@ describe('WebFont', function () {
|
|
121
134
|
beforeEach(function () {
|
122
135
|
font = new Font('Font1');
|
123
136
|
jasmine.Clock.useMock();
|
124
|
-
webfont = new WebFont(window, fontModuleLoader,
|
137
|
+
webfont = new WebFont(window, fontModuleLoader, userAgent);
|
125
138
|
webfont.addModule('test', function (conf, domHelper) {
|
126
139
|
testModule = new function () {
|
127
140
|
this.conf = conf;
|
@@ -197,7 +210,7 @@ describe('WebFont', function () {
|
|
197
210
|
testModule = null;
|
198
211
|
|
199
212
|
beforeEach(function () {
|
200
|
-
font = new WebFont(window, fontModuleLoader,
|
213
|
+
font = new WebFont(window, fontModuleLoader, userAgent);
|
201
214
|
|
202
215
|
font.addModule('test', function (conf, domHelper) {
|
203
216
|
testModule = new function () {};
|
@@ -228,7 +241,19 @@ describe('WebFont', function () {
|
|
228
241
|
testModule = null;
|
229
242
|
|
230
243
|
beforeEach(function () {
|
231
|
-
font = new WebFont(window, fontModuleLoader, new UserAgent(
|
244
|
+
font = new WebFont(window, fontModuleLoader, new UserAgent(
|
245
|
+
'Firefox',
|
246
|
+
new Version(3, 6),
|
247
|
+
'3.6',
|
248
|
+
'Gecko',
|
249
|
+
new Version(1, 9, 2),
|
250
|
+
'1.9.2',
|
251
|
+
'Macintosh',
|
252
|
+
new Version(10, 6),
|
253
|
+
'10.6',
|
254
|
+
undefined,
|
255
|
+
new BrowserInfo(false, false, false)
|
256
|
+
));
|
232
257
|
font.addModule('test', function (conf, domHelper) {
|
233
258
|
testModule = new function () {
|
234
259
|
this.conf = conf;
|
@@ -2,7 +2,8 @@ describe('MonotypeScript', function () {
|
|
2
2
|
var MonotypeScript = webfont.MonotypeScript,
|
3
3
|
Font = webfont.Font,
|
4
4
|
BrowserInfo = webfont.BrowserInfo,
|
5
|
-
UserAgent = webfont.UserAgent
|
5
|
+
UserAgent = webfont.UserAgent,
|
6
|
+
Version = webfont.Version;
|
6
7
|
|
7
8
|
var configuration = {
|
8
9
|
projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc',
|
@@ -28,7 +29,19 @@ describe('MonotypeScript', function () {
|
|
28
29
|
};
|
29
30
|
support = jasmine.createSpy('support');
|
30
31
|
load = jasmine.createSpy('load');
|
31
|
-
useragent = new UserAgent(
|
32
|
+
useragent = new UserAgent(
|
33
|
+
'Firefox',
|
34
|
+
new Version(3, 6),
|
35
|
+
'3.6',
|
36
|
+
'Gecko',
|
37
|
+
new Version(1, 9, 3),
|
38
|
+
'1.9.3',
|
39
|
+
'Macintosh',
|
40
|
+
new Version(10, 6),
|
41
|
+
'10.6',
|
42
|
+
undefined,
|
43
|
+
new BrowserInfo(true, false, false)
|
44
|
+
);
|
32
45
|
|
33
46
|
monotype = new MonotypeScript(useragent, fakeDomHelper, configuration);
|
34
47
|
monotype.supportUserAgent(useragent, support);
|
data/src/core/useragent.js
CHANGED
@@ -1,25 +1,49 @@
|
|
1
1
|
goog.provide('webfont.UserAgent');
|
2
2
|
|
3
3
|
/**
|
4
|
+
* A user agent string representation.
|
5
|
+
*
|
6
|
+
* This currently keeps a string and parsed `Version` representation
|
7
|
+
* of version strings. This is done for backwards compatibility with
|
8
|
+
* older versions of Typekit's KitJS when loaded through the Web Font
|
9
|
+
* Loader. The old string based API is deprecated and will eventually
|
10
|
+
* be removed.
|
11
|
+
*
|
4
12
|
* @export
|
5
13
|
* @param {string} name
|
6
14
|
* @param {webfont.Version} version
|
15
|
+
* @param {string} versionString
|
7
16
|
* @param {string} engine
|
8
17
|
* @param {webfont.Version} engineVersion
|
18
|
+
* @param {string} engineVersionString
|
9
19
|
* @param {string} platform
|
10
20
|
* @param {webfont.Version} platformVersion
|
21
|
+
* @param {string} platformVersionString
|
11
22
|
* @param {number|undefined} documentMode
|
12
23
|
* @param {!webfont.BrowserInfo} browserInfo
|
13
24
|
* @constructor
|
14
25
|
*/
|
15
|
-
webfont.UserAgent = function(
|
16
|
-
|
26
|
+
webfont.UserAgent = function(
|
27
|
+
name,
|
28
|
+
version,
|
29
|
+
versionString,
|
30
|
+
engine,
|
31
|
+
engineVersion,
|
32
|
+
engineVersionString,
|
33
|
+
platform,
|
34
|
+
platformVersion,
|
35
|
+
platformVersionString,
|
36
|
+
documentMode,
|
37
|
+
browserInfo) {
|
17
38
|
this.name_ = name;
|
18
39
|
this.version_ = version;
|
40
|
+
this.versionString_ = versionString;
|
19
41
|
this.engine_ = engine;
|
20
42
|
this.engineVersion_ = engineVersion;
|
43
|
+
this.engineVersionString_ = engineVersionString;
|
21
44
|
this.platform_ = platform;
|
22
45
|
this.platformVersion_ = platformVersion;
|
46
|
+
this.platformVersionString_ = platformVersionString;
|
23
47
|
this.documentMode_ = documentMode;
|
24
48
|
this.browserInfo_ = browserInfo;
|
25
49
|
};
|
@@ -37,9 +61,17 @@ goog.scope(function () {
|
|
37
61
|
|
38
62
|
/**
|
39
63
|
* @export
|
40
|
-
* @
|
64
|
+
* @deprecated
|
65
|
+
* @return {string}
|
41
66
|
*/
|
42
67
|
UserAgent.prototype.getVersion = function() {
|
68
|
+
return this.versionString_;
|
69
|
+
};
|
70
|
+
|
71
|
+
/**
|
72
|
+
* @return {webfont.Version}
|
73
|
+
*/
|
74
|
+
UserAgent.prototype.getParsedVersion = function() {
|
43
75
|
return this.version_;
|
44
76
|
};
|
45
77
|
|
@@ -53,9 +85,17 @@ goog.scope(function () {
|
|
53
85
|
|
54
86
|
/**
|
55
87
|
* @export
|
56
|
-
* @
|
88
|
+
* @deprecated
|
89
|
+
* @return {string}
|
57
90
|
*/
|
58
91
|
UserAgent.prototype.getEngineVersion = function() {
|
92
|
+
return this.engineVersionString_;
|
93
|
+
};
|
94
|
+
|
95
|
+
/**
|
96
|
+
* @return {webfont.Version}
|
97
|
+
*/
|
98
|
+
UserAgent.prototype.getParsedEngineVersion = function() {
|
59
99
|
return this.engineVersion_;
|
60
100
|
};
|
61
101
|
|
@@ -69,9 +109,17 @@ goog.scope(function () {
|
|
69
109
|
|
70
110
|
/**
|
71
111
|
* @export
|
72
|
-
* @
|
112
|
+
* @deprecated
|
113
|
+
* @return {string}
|
73
114
|
*/
|
74
115
|
UserAgent.prototype.getPlatformVersion = function() {
|
116
|
+
return this.platformVersionString_;
|
117
|
+
};
|
118
|
+
|
119
|
+
/**
|
120
|
+
* @return {webfont.Version}
|
121
|
+
*/
|
122
|
+
UserAgent.prototype.getParsedPlatformVersion = function() {
|
75
123
|
return this.platformVersion_;
|
76
124
|
};
|
77
125
|
|
data/src/core/useragentparser.js
CHANGED
@@ -37,9 +37,12 @@ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
|
|
37
37
|
webfont.UserAgentParser.UNKNOWN,
|
38
38
|
new webfont.Version(),
|
39
39
|
webfont.UserAgentParser.UNKNOWN,
|
40
|
+
webfont.UserAgentParser.UNKNOWN,
|
40
41
|
new webfont.Version(),
|
41
42
|
webfont.UserAgentParser.UNKNOWN,
|
43
|
+
webfont.UserAgentParser.UNKNOWN,
|
42
44
|
new webfont.Version(),
|
45
|
+
webfont.UserAgentParser.UNKNOWN,
|
43
46
|
undefined,
|
44
47
|
new webfont.BrowserInfo(false, false, false));
|
45
48
|
|
@@ -144,16 +147,29 @@ goog.scope(function () {
|
|
144
147
|
*/
|
145
148
|
UserAgentParser.prototype.parseIeUserAgentString_ = function() {
|
146
149
|
var platform = this.getPlatform_(),
|
147
|
-
|
148
|
-
|
150
|
+
platformVersionString = this.getPlatformVersionString_(),
|
151
|
+
platformVersion = Version.parse(platformVersionString),
|
152
|
+
browserVersionString = this.getMatchingGroup_(this.userAgent_, /MSIE ([\d\w\.]+)/, 1),
|
153
|
+
browserVersion = Version.parse(browserVersionString),
|
149
154
|
documentMode = this.getDocumentMode_(this.doc_),
|
150
155
|
supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
|
151
156
|
(platform == "Windows Phone" && platformVersion.major >= 8);
|
152
157
|
|
153
158
|
// For IE we give MSIE as the engine name and the version of IE
|
154
159
|
// instead of the specific Trident engine name and version
|
155
|
-
return new UserAgent(
|
156
|
-
|
160
|
+
return new UserAgent(
|
161
|
+
"MSIE",
|
162
|
+
browserVersion,
|
163
|
+
browserVersionString,
|
164
|
+
"MSIE",
|
165
|
+
browserVersion,
|
166
|
+
browserVersionString,
|
167
|
+
platform,
|
168
|
+
platformVersion,
|
169
|
+
platformVersionString,
|
170
|
+
documentMode,
|
171
|
+
new BrowserInfo(supportWebFont, false, false)
|
172
|
+
);
|
157
173
|
};
|
158
174
|
|
159
175
|
/**
|
@@ -168,8 +184,10 @@ goog.scope(function () {
|
|
168
184
|
*/
|
169
185
|
UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
|
170
186
|
var engineName = UserAgentParser.UNKNOWN,
|
171
|
-
|
172
|
-
|
187
|
+
engineVersionString = this.getMatchingGroup_(this.userAgent_, /Presto\/([\d\w\.]+)/, 1),
|
188
|
+
engineVersion = Version.parse(engineVersionString),
|
189
|
+
platformVersionString = this.getPlatformVersionString_(),
|
190
|
+
platformVersion = Version.parse(platformVersionString),
|
173
191
|
documentMode = this.getDocumentMode_(this.doc_);
|
174
192
|
|
175
193
|
if (engineVersion.isValid()) {
|
@@ -178,35 +196,82 @@ goog.scope(function () {
|
|
178
196
|
if (this.userAgent_.indexOf("Gecko") != -1) {
|
179
197
|
engineName = "Gecko";
|
180
198
|
}
|
181
|
-
|
199
|
+
engineVersionString = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
|
200
|
+
engineVersion = Version.parse(engineVersionString);
|
182
201
|
}
|
183
202
|
|
184
203
|
// Check for Opera Mini first, since it looks like normal Opera
|
185
204
|
if (this.userAgent_.indexOf("Opera Mini/") != -1) {
|
186
|
-
var
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
205
|
+
var browserVersionString = this.getMatchingGroup_(this.userAgent_, /Opera Mini\/([\d\.]+)/, 1);
|
206
|
+
var browserVersion = Version.parse(browserVersionString);
|
207
|
+
|
208
|
+
return new UserAgent(
|
209
|
+
"OperaMini",
|
210
|
+
browserVersion,
|
211
|
+
browserVersionString,
|
212
|
+
engineName,
|
213
|
+
engineVersion,
|
214
|
+
engineVersionString,
|
215
|
+
this.getPlatform_(),
|
216
|
+
platformVersion,
|
217
|
+
platformVersionString,
|
218
|
+
documentMode,
|
219
|
+
new BrowserInfo(false, false, false)
|
220
|
+
);
|
191
221
|
}
|
192
222
|
|
193
223
|
// Otherwise, find version information for normal Opera or Opera Mobile
|
194
224
|
if (this.userAgent_.indexOf("Version/") != -1) {
|
195
|
-
var
|
225
|
+
var browserVersionString = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1);
|
226
|
+
var browserVersion = Version.parse(browserVersionString);
|
196
227
|
|
197
228
|
if (browserVersion.isValid()) {
|
198
|
-
return new UserAgent(
|
199
|
-
|
229
|
+
return new UserAgent(
|
230
|
+
"Opera",
|
231
|
+
browserVersion,
|
232
|
+
browserVersionString,
|
233
|
+
engineName,
|
234
|
+
engineVersion,
|
235
|
+
engineVersionString,
|
236
|
+
this.getPlatform_(),
|
237
|
+
platformVersion,
|
238
|
+
platformVersionString,
|
239
|
+
documentMode,
|
240
|
+
new BrowserInfo(browserVersion.major >= 10, false, false)
|
241
|
+
);
|
200
242
|
}
|
201
243
|
}
|
202
|
-
var
|
244
|
+
var browserVersionString = this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1);
|
245
|
+
var browserVersion = Version.parse(browserVersionString);
|
203
246
|
|
204
247
|
if (browserVersion.isValid()) {
|
205
|
-
return new UserAgent(
|
206
|
-
|
248
|
+
return new UserAgent(
|
249
|
+
"Opera",
|
250
|
+
browserVersion,
|
251
|
+
browserVersionString,
|
252
|
+
engineName,
|
253
|
+
engineVersion,
|
254
|
+
engineVersionString,
|
255
|
+
this.getPlatform_(),
|
256
|
+
platformVersion,
|
257
|
+
platformVersionString,
|
258
|
+
documentMode,
|
259
|
+
new BrowserInfo(browserVersion.major >= 10, false, false)
|
260
|
+
);
|
207
261
|
}
|
208
|
-
return new UserAgent(
|
209
|
-
|
262
|
+
return new UserAgent(
|
263
|
+
"Opera",
|
264
|
+
new Version(),
|
265
|
+
UserAgentParser.UNKNOWN,
|
266
|
+
engineName,
|
267
|
+
engineVersion,
|
268
|
+
engineVersionString,
|
269
|
+
this.getPlatform_(),
|
270
|
+
platformVersion,
|
271
|
+
platformVersionString,
|
272
|
+
documentMode,
|
273
|
+
new BrowserInfo(false, false, false)
|
274
|
+
);
|
210
275
|
};
|
211
276
|
|
212
277
|
/**
|
@@ -221,10 +286,13 @@ goog.scope(function () {
|
|
221
286
|
*/
|
222
287
|
UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
223
288
|
var platform = this.getPlatform_(),
|
224
|
-
|
225
|
-
|
289
|
+
platformVersionString = this.getPlatformVersionString_(),
|
290
|
+
platformVersion = Version.parse(platformVersionString),
|
291
|
+
webKitVersionString = this.getMatchingGroup_(this.userAgent_, /AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1),
|
292
|
+
webKitVersion = Version.parse(webKitVersionString),
|
226
293
|
browserName = UserAgentParser.UNKNOWN,
|
227
294
|
browserVersion = new Version(),
|
295
|
+
browserVersionString = UserAgentParser.UNKNOWN,
|
228
296
|
supportWebFont = false;
|
229
297
|
|
230
298
|
if (this.userAgent_.indexOf("Chrome") != -1 ||
|
@@ -266,8 +334,19 @@ goog.scope(function () {
|
|
266
334
|
var hasWebKitFallbackBug = webKitVersion.major < 536 || (webKitVersion.major == 536 && webKitVersion.minor < 11),
|
267
335
|
hasWebKitMetricsBug = platform == 'iPhone' || platform == 'iPad' || platform == 'iPod' || platform == 'Macintosh';
|
268
336
|
|
269
|
-
return new UserAgent(
|
270
|
-
|
337
|
+
return new UserAgent(
|
338
|
+
browserName,
|
339
|
+
browserVersion,
|
340
|
+
browserVersionString,
|
341
|
+
"AppleWebKit",
|
342
|
+
webKitVersion,
|
343
|
+
webKitVersionString,
|
344
|
+
platform,
|
345
|
+
platformVersion,
|
346
|
+
platformVersionString,
|
347
|
+
this.getDocumentMode_(this.doc_),
|
348
|
+
new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug)
|
349
|
+
);
|
271
350
|
};
|
272
351
|
|
273
352
|
/**
|
@@ -283,12 +362,15 @@ goog.scope(function () {
|
|
283
362
|
UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
|
284
363
|
var name = UserAgentParser.UNKNOWN,
|
285
364
|
version = new Version(),
|
286
|
-
|
365
|
+
versionString = UserAgentParser.UNKNOWN,
|
366
|
+
platformVersionString = this.getPlatformVersionString_(),
|
367
|
+
platformVersion = Version.parse(platformVersionString),
|
287
368
|
supportWebFont = false;
|
288
369
|
|
289
370
|
if (this.userAgent_.indexOf("Firefox") != -1) {
|
290
371
|
name = "Firefox";
|
291
|
-
|
372
|
+
versionString = this.getMatchingGroup_(this.userAgent_, /Firefox\/([\d\w\.]+)/, 1);
|
373
|
+
version = Version.parse(versionString);
|
292
374
|
supportWebFont = version.major >= 3 && version.minor >= 5;
|
293
375
|
} else if (this.userAgent_.indexOf("Mozilla") != -1) {
|
294
376
|
name = "Mozilla";
|
@@ -304,8 +386,19 @@ goog.scope(function () {
|
|
304
386
|
engineVersionString.match(/1\.9\.1b[123]/) != null ||
|
305
387
|
engineVersionString.match(/1\.9\.1\.[\d\.]+/) != null;
|
306
388
|
}
|
307
|
-
return new UserAgent(
|
308
|
-
|
389
|
+
return new UserAgent(
|
390
|
+
name,
|
391
|
+
version,
|
392
|
+
versionString,
|
393
|
+
"Gecko",
|
394
|
+
engineVersion,
|
395
|
+
engineVersionString,
|
396
|
+
this.getPlatform_(),
|
397
|
+
platformVersion,
|
398
|
+
platformVersionString,
|
399
|
+
this.getDocumentMode_(this.doc_),
|
400
|
+
new BrowserInfo(supportWebFont, false, false)
|
401
|
+
);
|
309
402
|
};
|
310
403
|
|
311
404
|
/**
|