Sha256: 6f293e442256992b568ea078fbd06cdb96141a021d9b288002fb038061aaf26c

Contents?: true

Size: 1.5 KB

Versions: 5

Compression:

Stored size: 1.5 KB

Contents

goog.provide('webfont.NativeFontWatchRunner');

goog.require('webfont.Font');

goog.scope(function () {
  /**
  * @constructor
  * @param {function(webfont.Font)} activeCallback
  * @param {function(webfont.Font)} inactiveCallback
  * @param {webfont.DomHelper} domHelper
  * @param {webfont.Font} font
  * @param {number=} opt_timeout
  * @param {string=} opt_fontTestString
  */
  webfont.NativeFontWatchRunner = function(activeCallback, inactiveCallback, domHelper, font, opt_timeout, opt_fontTestString) {
    this.activeCallback_ = activeCallback;
    this.inactiveCallback_ = inactiveCallback;
    this.font_ = font;
    this.domHelper_ = domHelper;
    this.timeout_ = opt_timeout || 3000;
    this.fontTestString_ = opt_fontTestString || undefined;
  };

  var NativeFontWatchRunner = webfont.NativeFontWatchRunner;

  NativeFontWatchRunner.prototype.start = function () {
    var doc = this.domHelper_.getLoadWindow().document,
        that = this;

    // We're using Promises here because the font load API
    // uses them, so we can be sure they're available.
    Promise.race([new Promise(function (resolve, reject) {
      setTimeout(function () {
        reject(that.font_);
      }, that.timeout_);
    }), doc.fonts.load(this.font_.toCssString(), this.fontTestString_)]).then(function (fonts) {
      if (fonts.length >= 1) {
        that.activeCallback_(that.font_);
      } else {
        that.inactiveCallback_(that.font_);
      }
    }, function () {
      that.inactiveCallback_(that.font_);
    });
  };
});

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webfontloader-1.6.15 src/core/nativefontwatchrunner.js
webfontloader-1.6.14 src/core/nativefontwatchrunner.js
webfontloader-1.6.13 src/core/nativefontwatchrunner.js
webfontloader-1.6.12 src/core/nativefontwatchrunner.js
webfontloader-1.6.11 src/core/nativefontwatchrunner.js