Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ WebFontConfig = {

The `text` subsetting functionality is only available for the Google module.

Additional option you can pass to google option is display, it enables use of [font-display(https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display)] property.

```javascript
WebFontConfig = {
google: {
families: ['Droid Sans', 'Droid Serif'],
display: 'swap'
}
};
```

### Typekit

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.
Expand Down
8 changes: 8 additions & 0 deletions spec/modules/google/fontapiurlbuilder_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ describe('modules.google.FontApiUrlBuilder', function () {
'?family=Font1:bold,italic%7CFont2:italic%7CFont3' +
'&subset=greek,cyrillic,latin');
});
it('should build a proper url - display param', function () {
var builder = new FontApiUrlBuilder(undefined, undefined, 'swap');
builder.setFontFamilies(['Font1:bold,italic:greek,cyrillic', 'Font2:italic', 'Font3::latin']);
expect(builder.build()).toEqual(
FontApiUrlBuilder.DEFAULT_API_URL +
'?family=Font1:bold,italic%7CFont2:italic%7CFont3' +
'&subset=greek,cyrillic,latin&display=swap');
});
});
5 changes: 3 additions & 2 deletions spec/modules/google/googlefontapi_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ describe('modules.google.GoogleFontApi', function () {
loaded = false;
googleFontApi = new GoogleFontApi(fakeDomHelper, {
api: 'https://moo',
families: ['Font1', 'Font2']
families: ['Font1', 'Font2'],
display: 'swap'
});
googleFontApi.load(function () { loaded = true; });
});

it('has inserted the link element correctly', function () {
expect(link).toEqual('https://moo?family=Font1%7CFont2');
expect(link).toEqual('https://moo?family=Font1%7CFont2&display=swap');
});

if (webfont.DomHelper.CAN_WAIT_STYLESHEET) {
Expand Down
7 changes: 6 additions & 1 deletion src/modules/google/fontapiurlbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ goog.provide('webfont.modules.google.FontApiUrlBuilder');
/**
* @constructor
*/
webfont.modules.google.FontApiUrlBuilder = function(apiUrl, text) {
webfont.modules.google.FontApiUrlBuilder = function(apiUrl, text, display) {
if (apiUrl) {
this.apiUrl_ = apiUrl;
} else {
Expand All @@ -12,6 +12,7 @@ webfont.modules.google.FontApiUrlBuilder = function(apiUrl, text) {
this.fontFamilies_ = [];
this.subsets_ = [];
this.text_ = text || '';
this.display_ = display || '';
};


Expand Down Expand Up @@ -72,6 +73,10 @@ goog.scope(function () {
url += '&text=' + encodeURIComponent(this.text_);
}

if (this.display_.length > 0) {
url += '&display=' + this.display_;
}

return url;
};
});
3 changes: 2 additions & 1 deletion src/modules/google/googlefontapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ goog.scope(function () {
var domHelper = this.domHelper_;
var fontApiUrlBuilder = new FontApiUrlBuilder(
this.configuration_['api'],
this.configuration_['text']
this.configuration_['text'],
this.configuration_['display']
);
var fontFamilies = this.configuration_['families'];
fontApiUrlBuilder.setFontFamilies(fontFamilies);
Expand Down