2017-01-25 11:22:19 +05:30
|
|
|
import webFont from 'webfontloader';
|
2017-03-29 10:20:38 +05:30
|
|
|
import logger from 'services/logger';
|
2017-01-25 11:22:19 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
/**
|
|
|
|
* @param {array} families
|
2017-01-25 11:48:47 +05:30
|
|
|
* @param {object} options
|
|
|
|
* @param {bool} [options.external=false] - whether the font should be loaded from external source (e.g. google)
|
2017-01-25 11:22:19 +05:30
|
|
|
*
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
2017-01-25 11:48:47 +05:30
|
|
|
load(families = [], options = {}) {
|
|
|
|
let config = {
|
|
|
|
custom: {families}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options.external) {
|
|
|
|
config = {
|
|
|
|
google: {families}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-25 11:22:19 +05:30
|
|
|
return new Promise((resolve) =>
|
|
|
|
webFont.load({
|
|
|
|
classes: false,
|
|
|
|
active: resolve,
|
2017-03-29 10:20:38 +05:30
|
|
|
inactive() {
|
|
|
|
logger.warn('Failed loading the font', {
|
|
|
|
families
|
|
|
|
});
|
|
|
|
resolve();
|
|
|
|
},
|
2017-01-25 11:22:19 +05:30
|
|
|
timeout: 2000,
|
2017-01-25 11:48:47 +05:30
|
|
|
...config
|
2017-01-25 11:22:19 +05:30
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|