webfontjsonloader

0.0.4 • Public • Published

WebFontJSONLoader Dependency Status devDependency Status Build Status Code Climate Test Coverage

A simple WebfontJSON loader for webfontjson or grunt-webfontjson.

Install

With npm, use the familiar syntax e.g.:

npm install webfontjsonloader --save

once the WebfontJSON package is installed, just require it in the main application file.

var WebFontJSONLoader = require("webfontjsonloader");

This package also supports AMD/RequireJS, it is defined as webfontjsonloader. Aren't using AMD/CommonJS? Just grab a release, include the Dist/WebFontJSONLoader.min.js and access the loader via the following global:

var WebFontJSONLoader = window.WebFontJSONLoader;

Configuration

In the main application file, create a new instance of the Constructor e.g.:

// Initialize a new instance of the WebFontJSONLoader.
var loader = new WebFontJSONLoader({
  url: "fonts/webfont.json",
  timeStamp: "?t=01072015",
  JSONPCallbackName: "callbackName"
});
 
// Load the fonts.
loader.getWebFontStyles();

Options

options.url

Type: String

The URL to the generated JSONP file.

options.timeStamp

Type: String || Number

A timestamp which will be saved on each device visiting the site, if the users cached version doesn't match value, the JSONP will be re-fetched and applied to the page, thus, getting the newest version of the font. It's recommended to renew the timeStamp on each re-compilation of the JSONP file.

If this option wasn't set, a new Date object will be used as the timeStamp, thus, the cache will be disabled.

options.JSONPCallbackName

Type: String

The JSONP callback name, filed as callback in the WebfontJSON configuration.

options.fontLoadedCallback (optional)

Type: Function

An optional callback which get's executed once the styles are attached to the document.

options.namespace (optional)

Type: String

The namespace for the font, usefull if multiple instances of the loader are executed on a page.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.

Package Sidebar

Install

npm i webfontjsonloader

Weekly Downloads

0

Version

0.0.4

License

ISC

Last publish

Collaborators

  • inkdpixels