Skip to content

Commit

Permalink
Merge pull request #352 from typekit/pz-disable-native-font-loading-s…
Browse files Browse the repository at this point in the history
…afari10

Disable native font loading in Safari 10
  • Loading branch information
pzula committed Nov 29, 2016
2 parents 33bec9d + bdea6ee commit cbeb689
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/core/fontwatcher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ describe('FontWatcher', function () {
spyOn(FontWatcher, 'getUserAgent').andReturn('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:43.0) Gecko/20100101 Firefox/43.0');
expect(FontWatcher.shouldUseNativeLoader()).toEqual(true);
});

it('is disabled on Safari > 10', function () {
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');
spyOn(FontWatcher, 'getVendor').andReturn('Apple');
expect(FontWatcher.shouldUseNativeLoader()).toEqual(false);
});
});
}

Expand Down
10 changes: 10 additions & 0 deletions src/core/fontwatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ goog.scope(function () {
return window.navigator.userAgent;
};

/**
* @return {string}
*/
FontWatcher.getVendor = function () {
return window.navigator.vendor;
};

/**
* Returns true if this browser has support for
* the CSS font loading API.
Expand All @@ -50,9 +57,12 @@ goog.scope(function () {
if (FontWatcher.SHOULD_USE_NATIVE_LOADER === null) {
if (!!window.FontFace) {
var match = /Gecko.*Firefox\/(\d+)/.exec(FontWatcher.getUserAgent());
var safari10Match = /OS X.*Version\/10\..*Safari/.exec(FontWatcher.getUserAgent()) && /Apple/.exec(FontWatcher.getVendor());

if (match) {
FontWatcher.SHOULD_USE_NATIVE_LOADER = parseInt(match[1], 10) > 42;
} else if (safari10Match) {
FontWatcher.SHOULD_USE_NATIVE_LOADER = false;
} else {
FontWatcher.SHOULD_USE_NATIVE_LOADER = true;
}
Expand Down

0 comments on commit cbeb689

Please sign in to comment.