Sha256: 12c947160d4b4867312b5aa78331793d932ca5301d64c4bdd91d17c285e7617b

Contents?: true

Size: 1.5 KB

Versions: 8

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

8 entries across 8 versions & 1 rubygems

Version Path
webfontloader-1.6.10 src/core/nativefontwatchrunner.js
webfontloader-1.6.9 src/core/nativefontwatchrunner.js
webfontloader-1.6.8 src/core/nativefontwatchrunner.js
webfontloader-1.6.7 src/core/nativefontwatchrunner.js
webfontloader-1.6.6 src/core/nativefontwatchrunner.js
webfontloader-1.6.5 src/core/nativefontwatchrunner.js
webfontloader-1.6.4 src/core/nativefontwatchrunner.js
webfontloader-1.6.3 src/core/nativefontwatchrunner.js