Skip to content

Commit cbeb689

Browse files
authored
Merge pull request #352 from typekit/pz-disable-native-font-loading-safari10
Disable native font loading in Safari 10
2 parents 33bec9d + bdea6ee commit cbeb689

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

spec/core/fontwatcher_spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ describe('FontWatcher', function () {
7474
spyOn(FontWatcher, 'getUserAgent').andReturn('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:43.0) Gecko/20100101 Firefox/43.0');
7575
expect(FontWatcher.shouldUseNativeLoader()).toEqual(true);
7676
});
77+
78+
it('is disabled on Safari > 10', function () {
79+
spyOn(FontWatcher, 'getUserAgent').andReturn('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0.1 Safari/602.2.14');
80+
spyOn(FontWatcher, 'getVendor').andReturn('Apple');
81+
expect(FontWatcher.shouldUseNativeLoader()).toEqual(false);
82+
});
7783
});
7884
}
7985

src/core/fontwatcher.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ goog.scope(function () {
4040
return window.navigator.userAgent;
4141
};
4242

43+
/**
44+
* @return {string}
45+
*/
46+
FontWatcher.getVendor = function () {
47+
return window.navigator.vendor;
48+
};
49+
4350
/**
4451
* Returns true if this browser has support for
4552
* the CSS font loading API.
@@ -50,9 +57,12 @@ goog.scope(function () {
5057
if (FontWatcher.SHOULD_USE_NATIVE_LOADER === null) {
5158
if (!!window.FontFace) {
5259
var match = /Gecko.*Firefox\/(\d+)/.exec(FontWatcher.getUserAgent());
60+
var safari10Match = /OS X.*Version\/10\..*Safari/.exec(FontWatcher.getUserAgent()) && /Apple/.exec(FontWatcher.getVendor());
5361

5462
if (match) {
5563
FontWatcher.SHOULD_USE_NATIVE_LOADER = parseInt(match[1], 10) > 42;
64+
} else if (safari10Match) {
65+
FontWatcher.SHOULD_USE_NATIVE_LOADER = false;
5666
} else {
5767
FontWatcher.SHOULD_USE_NATIVE_LOADER = true;
5868
}

0 commit comments

Comments
 (0)