Sha256: 29a93adacccce36e0a89c9f151b3a635410200fd8b81106092be12952fbc2fac

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 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;

    var start = goog.now();

    function check() {
      var now = goog.now();

      if (now - start >= that.timeout_) {
        that.inactiveCallback_(that.font_);
      } else {
        doc.fonts.load(that.font_.toCssString(), that.fontTestString_).then(function (fonts) {
          if (fonts.length >= 1) {
            that.activeCallback_(that.font_);
          } else {
            setTimeout(check, 25);
          }
        }, function () {
          that.inactiveCallback_(that.font_);
        });
      }
    }

    check();
  };
});

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webfontloader-1.6.21 src/core/nativefontwatchrunner.js
webfontloader-1.6.20 src/core/nativefontwatchrunner.js
webfontloader-1.6.19 src/core/nativefontwatchrunner.js
webfontloader-1.6.18 src/core/nativefontwatchrunner.js
webfontloader-1.6.16 src/core/nativefontwatchrunner.js