webfontloader 1.5.21 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/deps.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // This file was autogenerated by calcdeps.js
2
2
  goog.addDependency("../../src/closure.js", [], []);
3
- goog.addDependency("../../src/core/browserinfo.js", ["webfont.BrowserInfo"], []);
4
3
  goog.addDependency("../../src/core/cssclassname.js", ["webfont.CssClassName"], []);
5
4
  goog.addDependency("../../src/core/domhelper.js", ["webfont.DomHelper"], []);
6
5
  goog.addDependency("../../src/core/eventdispatcher.js", ["webfont.EventDispatcher"], ["webfont.CssClassName"]);
@@ -12,10 +11,7 @@ goog.addDependency("../../src/core/fontwatcher.js", ["webfont.FontWatcher"], ["w
12
11
  goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunner"], ["webfont.Font","webfont.FontRuler"]);
13
12
  goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.WebFont","webfont.modules.Typekit","webfont.modules.Fontdeck","webfont.modules.Monotype","webfont.modules.Custom","webfont.modules.google.GoogleFontApi"]);
14
13
  goog.addDependency("../../src/core/nativefontwatchrunner.js", ["webfont.NativeFontWatchRunner"], ["webfont.Font"]);
15
- goog.addDependency("../../src/core/useragent.js", ["webfont.UserAgent"], []);
16
- goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent","webfont.Version"]);
17
- goog.addDependency("../../src/core/version.js", ["webfont.Version"], []);
18
- goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher","webfont.FontModuleLoader","webfont.UserAgentParser"]);
14
+ goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher","webfont.FontModuleLoader"]);
19
15
  goog.addDependency("../../src/modules/custom.js", ["webfont.modules.Custom"], ["webfont.Font"]);
20
16
  goog.addDependency("../../src/modules/fontdeck.js", ["webfont.modules.Fontdeck"], ["webfont.Font"]);
21
17
  goog.addDependency("../../src/modules/google/fontapiparser.js", ["webfont.modules.google.FontApiParser"], ["webfont.Font"]);
data/spec/index.html CHANGED
@@ -29,7 +29,6 @@
29
29
 
30
30
  <script src="../spec/core/domhelper_spec.js"></script>
31
31
  <script src="../spec/core/cssclassname_spec.js"></script>
32
- <script src="../spec/core/useragentparser_spec.js"></script>
33
32
  <script src="../spec/core/fontmoduleloader_spec.js"></script>
34
33
  <script src="../spec/core/eventdispatcher_spec.js"></script>
35
34
  <script src="../spec/core/font_spec.js"></script>
@@ -38,7 +37,6 @@
38
37
  <script src="../spec/core/nativefontwatchrunner_spec.js"></script>
39
38
  <script src="../spec/core/fontwatcher_spec.js"></script>
40
39
  <script src="../spec/core/webfont_spec.js"></script>
41
- <script src="../spec/core/version_spec.js"></script>
42
40
  <script src="../spec/modules/google/fontapiparser_spec.js"></script>
43
41
  <script src="../spec/modules/google/fontapiurlbuilder_spec.js"></script>
44
42
  <script src="../spec/modules/google/googlefontapi_spec.js"></script>
@@ -61,13 +61,11 @@ describe('modules.Fontdeck', function () {
61
61
 
62
62
  describe('support and load life cycle', function () {
63
63
  var fontdeck = null,
64
- support = null;
64
+ onReady = jasmine.createSpy('onReady');
65
65
 
66
66
  beforeEach(function () {
67
67
  fontdeck = new Fontdeck(fakeDomHelper, configuration);
68
- support = jasmine.createSpy('support');
69
-
70
- fontdeck.supportUserAgent('user agent', support);
68
+ fontdeck.load(onReady);
71
69
  });
72
70
 
73
71
  it('should create the script correctly', function () {
@@ -84,8 +82,6 @@ describe('modules.Fontdeck', function () {
84
82
  global.__webfontfontdeckmodule__['2282'](true, apiResponse);
85
83
 
86
84
  expect(fontdeck.fonts_).toEqual([new Font(apiResponse.fonts[0].name), new Font(apiResponse.fonts[1].name, 'i7')]);
87
-
88
- expect(support).toHaveBeenCalled();
89
85
  });
90
86
  });
91
87
 
@@ -95,14 +91,10 @@ describe('modules.Fontdeck', function () {
95
91
 
96
92
  beforeEach(function () {
97
93
  fontdeck = new Fontdeck(fakeDomHelper, { id: null });
98
- support = jasmine.createSpy('support');
99
-
100
- fontdeck.supportUserAgent('user agent', support);
101
94
  });
102
95
 
103
96
  it('should not have loaded any fonts', function () {
104
97
  expect(fontdeck.fonts_).toEqual([]);
105
- expect(support).toHaveBeenCalled();
106
98
  });
107
99
  });
108
100
  });
@@ -15,7 +15,6 @@ describe('modules.Monotype', function () {
15
15
  script = {},
16
16
  monotype = null,
17
17
  load = null,
18
- useragent = null,
19
18
  support = null;
20
19
 
21
20
  beforeEach(function () {
@@ -31,19 +30,8 @@ describe('modules.Monotype', function () {
31
30
  };
32
31
  support = jasmine.createSpy('support');
33
32
  load = jasmine.createSpy('load');
34
- useragent = new UserAgent(
35
- 'Firefox',
36
- new Version(3, 6),
37
- 'Gecko',
38
- new Version(1, 9, 3),
39
- 'Macintosh',
40
- new Version(10, 6),
41
- undefined,
42
- new BrowserInfo(true, false, false, false)
43
- );
44
33
 
45
34
  monotype = new Monotype(fakeDomHelper, configuration);
46
- monotype.supportUserAgent(useragent, support);
47
35
  monotype.load(load);
48
36
 
49
37
  global[Monotype.HOOK + configuration.projectId] = function () {
@@ -55,7 +43,6 @@ describe('modules.Monotype', function () {
55
43
 
56
44
 
57
45
  it('should create a script element', function () {
58
- expect(support).toHaveBeenCalled();
59
46
  expect(fakeDomHelper.loadScript).toHaveBeenCalled();
60
47
  expect(fakeDomHelper.loadScript.calls[0].args[0]).toEqual('http://fast.fonts.net/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js');
61
48
  expect(load).toHaveBeenCalledWith([new Font('aachen bold'), new Font('kid print regular')]);
@@ -9,7 +9,7 @@ describe('modules.Typekit', function () {
9
9
  var fakeDomHelper = null,
10
10
  global = {},
11
11
  load = null,
12
- support = null;
12
+ onReady = null;
13
13
 
14
14
  beforeEach(function () {
15
15
  global = {
@@ -21,7 +21,7 @@ describe('modules.Typekit', function () {
21
21
  }
22
22
  };
23
23
 
24
- support = jasmine.createSpy('support');
24
+ onReady = jasmine.createSpy('onReady');
25
25
 
26
26
  load = jasmine.createSpy('load');
27
27
 
@@ -37,11 +37,10 @@ describe('modules.Typekit', function () {
37
37
  it('should load with variations', function () {
38
38
  var typekit = new Typekit(fakeDomHelper, configuration);
39
39
 
40
- typekit.supportUserAgent('useragent', support);
40
+ typekit.load(onReady);
41
41
 
42
42
  expect(fakeDomHelper.loadScript).toHaveBeenCalled();
43
- expect(fakeDomHelper.loadScript.calls[0].args[0]).toEqual('http://use.typekit.net/abc.js');
44
- expect(support).toHaveBeenCalled();
43
+ expect(fakeDomHelper.loadScript.calls[0].args[0]).toEqual('https://use.typekit.net/abc.js');
45
44
 
46
45
  expect(global.Typekit.load).toHaveBeenCalled();
47
46
  typekit.load(load);
@@ -52,7 +51,8 @@ describe('modules.Typekit', function () {
52
51
  it('should load through the alternative API', function () {
53
52
  var typekit = new Typekit(fakeDomHelper, { id: 'abc', api: '/test' });
54
53
 
55
- typekit.supportUserAgent('useragent', support);
54
+ typekit.load(onReady);
55
+
56
56
  expect(fakeDomHelper.loadScript).toHaveBeenCalled();
57
57
  expect(fakeDomHelper.loadScript.calls[0].args[0]).toEqual('/test/abc.js');
58
58
  });
@@ -60,10 +60,9 @@ describe('modules.Typekit', function () {
60
60
  it('should not load without a kit id', function () {
61
61
  var typekit = new Typekit(fakeDomHelper, { id: null });
62
62
 
63
- typekit.supportUserAgent('useragent', support);
63
+ typekit.load(onReady);
64
64
 
65
65
  expect(fakeDomHelper.loadScript).not.toHaveBeenCalled();
66
- expect(support).toHaveBeenCalled();
67
66
 
68
67
  typekit.load(load);
69
68
 
@@ -8,12 +8,6 @@ webfont.FontModule = function () {};
8
8
  goog.scope(function () {
9
9
  var FontModule = webfont.FontModule;
10
10
 
11
- /**
12
- * @param {webfont.UserAgent} userAgent
13
- * @param {function(boolean)} support
14
- */
15
- FontModule.prototype.supportUserAgent = function (userAgent, support) {};
16
-
17
11
  /**
18
12
  * @param {function(Array.<webfont.Font>, webfont.FontTestStrings=, Object.<string, boolean>=)} onReady
19
13
  */
@@ -10,20 +10,17 @@ webfont.FontTestStrings;
10
10
 
11
11
  /**
12
12
  * @constructor
13
- * @param {webfont.UserAgent} userAgent
14
13
  * @param {webfont.DomHelper} domHelper
15
14
  * @param {webfont.EventDispatcher} eventDispatcher
16
15
  * @param {number=} opt_timeout
17
16
  */
18
- webfont.FontWatcher = function(userAgent, domHelper, eventDispatcher, opt_timeout) {
17
+ webfont.FontWatcher = function(domHelper, eventDispatcher, opt_timeout) {
19
18
  this.domHelper_ = domHelper;
20
19
  this.eventDispatcher_ = eventDispatcher;
21
20
  this.currentlyWatched_ = 0;
22
21
  this.last_ = false;
23
22
  this.success_ = false;
24
23
  this.timeout_ = opt_timeout;
25
-
26
- this.browserInfo_ = userAgent.getBrowserInfo();
27
24
  };
28
25
 
29
26
  goog.scope(function () {
@@ -74,7 +71,7 @@ goog.scope(function () {
74
71
  // stylesheet has loaded reliably). Until that issue is
75
72
  // resolved we'll keep the native font disabled.
76
73
  //
77
- //if (this.browserInfo_.hasNativeFontLoading()) {
74
+ //if (window['FontFace']) {
78
75
  // fontWatchRunner = new NativeFontWatchRunner(
79
76
  // goog.bind(this.fontActive_, this),
80
77
  // goog.bind(this.fontInactive_, this),
@@ -90,7 +87,6 @@ goog.scope(function () {
90
87
  goog.bind(this.fontInactive_, this),
91
88
  this.domHelper_,
92
89
  font,
93
- this.browserInfo_,
94
90
  this.timeout_,
95
91
  metricCompatibleFonts,
96
92
  testString
@@ -9,18 +9,16 @@ goog.require('webfont.FontRuler');
9
9
  * @param {function(webfont.Font)} inactiveCallback
10
10
  * @param {webfont.DomHelper} domHelper
11
11
  * @param {webfont.Font} font
12
- * @param {webfont.BrowserInfo} browserInfo
13
12
  * @param {number=} opt_timeout
14
13
  * @param {Object.<string, boolean>=} opt_metricCompatibleFonts
15
14
  * @param {string=} opt_fontTestString
16
15
  */
17
16
  webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
18
- font, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString) {
17
+ font, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString) {
19
18
  this.activeCallback_ = activeCallback;
20
19
  this.inactiveCallback_ = inactiveCallback;
21
20
  this.domHelper_ = domHelper;
22
21
  this.font_ = font;
23
- this.browserInfo_ = browserInfo;
24
22
  this.fontTestString_ = opt_fontTestString || webfont.FontWatchRunner.DEFAULT_TEST_STRING;
25
23
  this.lastResortWidths_ = {};
26
24
  this.timeout_ = opt_timeout || 3000;
@@ -58,6 +56,36 @@ goog.scope(function () {
58
56
  Font = webfont.Font,
59
57
  FontRuler = webfont.FontRuler;
60
58
 
59
+ /**
60
+ * @type {null|boolean}
61
+ */
62
+ FontWatchRunner.HAS_WEBKIT_FALLBACK_BUG = null;
63
+
64
+ /**
65
+ * @return {string}
66
+ */
67
+ FontWatchRunner.getUserAgent = function () {
68
+ return window.navigator.userAgent;
69
+ };
70
+
71
+ /**
72
+ * Returns true if this browser is WebKit and it has the fallback bug
73
+ * which is present in WebKit 536.11 and earlier.
74
+ *
75
+ * @return {boolean}
76
+ */
77
+ FontWatchRunner.hasWebKitFallbackBug = function () {
78
+ if (FontWatchRunner.HAS_WEBKIT_FALLBACK_BUG === null) {
79
+ var match = /AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(FontWatchRunner.getUserAgent());
80
+
81
+ FontWatchRunner.HAS_WEBKIT_FALLBACK_BUG = !!match &&
82
+ (parseInt(match[1], 10) < 536 ||
83
+ (parseInt(match[1], 10) === 536 &&
84
+ parseInt(match[2], 10) <= 11));
85
+ }
86
+ return FontWatchRunner.HAS_WEBKIT_FALLBACK_BUG;
87
+ };
88
+
61
89
  /**
62
90
  * @private
63
91
  */
@@ -152,7 +180,7 @@ goog.scope(function () {
152
180
  * @return {boolean}
153
181
  */
154
182
  FontWatchRunner.prototype.isLastResortFont_ = function (a, b) {
155
- return this.browserInfo_.hasWebKitFallbackBug() && this.widthsMatchLastResortWidths_(a, b);
183
+ return FontWatchRunner.hasWebKitFallbackBug() && this.widthsMatchLastResortWidths_(a, b);
156
184
  };
157
185
 
158
186
  /**
data/src/core/webfont.js CHANGED
@@ -4,7 +4,6 @@ goog.require('webfont.DomHelper');
4
4
  goog.require('webfont.EventDispatcher');
5
5
  goog.require('webfont.FontWatcher');
6
6
  goog.require('webfont.FontModuleLoader');
7
- goog.require('webfont.UserAgentParser');
8
7
 
9
8
  /**
10
9
  * @param {Window} mainWindow The main application window containing
@@ -14,10 +13,7 @@ goog.require('webfont.UserAgentParser');
14
13
  webfont.WebFont = function(mainWindow) {
15
14
  this.mainWindow_ = mainWindow;
16
15
  this.fontModuleLoader_ = new webfont.FontModuleLoader();
17
- this.userAgentParser_ = new webfont.UserAgentParser(mainWindow.navigator.userAgent, mainWindow.document);
18
- this.userAgent_ = this.userAgentParser_.parse();
19
16
  this.moduleLoading_ = 0;
20
- this.moduleFailedLoading_ = 0;
21
17
  this.events_ = true;
22
18
  this.classes_ = true;
23
19
  };
@@ -54,35 +50,6 @@ goog.scope(function () {
54
50
  this.load_(eventDispatcher, configuration);
55
51
  };
56
52
 
57
- /**
58
- * @param {webfont.FontModule} module
59
- * @param {webfont.EventDispatcher} eventDispatcher
60
- * @param {webfont.FontWatcher} fontWatcher
61
- * @param {boolean} support
62
- */
63
- WebFont.prototype.isModuleSupportingUserAgent_ = function(module, eventDispatcher,
64
- fontWatcher, support) {
65
- var that = this;
66
-
67
- if (support) {
68
- module.load(function (fonts, opt_fontTestStrings, opt_metricCompatibleFonts) {
69
- that.onModuleReady_(eventDispatcher, fontWatcher, fonts, opt_fontTestStrings, opt_metricCompatibleFonts);
70
- });
71
- } else {
72
- var allModulesLoaded = --this.moduleLoading_ == 0;
73
-
74
- this.moduleFailedLoading_--;
75
-
76
- if (allModulesLoaded && this.moduleFailedLoading_ == 0) {
77
- eventDispatcher.dispatchInactive();
78
- } else {
79
- if (this.classes_ || this.events_) {
80
- fontWatcher.watchFonts([], {}, null, allModulesLoaded);
81
- }
82
- }
83
- }
84
- };
85
-
86
53
  /**
87
54
  * @param {webfont.EventDispatcher} eventDispatcher
88
55
  * @param {webfont.FontWatcher} fontWatcher
@@ -115,16 +82,16 @@ goog.scope(function () {
115
82
 
116
83
  modules = this.fontModuleLoader_.getModules(configuration, this.domHelper_);
117
84
 
118
- this.moduleFailedLoading_ = this.moduleLoading_ = modules.length;
85
+ var fontWatcher = new webfont.FontWatcher(this.domHelper_, eventDispatcher, timeout);
119
86
 
120
- var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.domHelper_, eventDispatcher, timeout);
87
+ this.moduleLoading_ = modules.length;
121
88
 
122
89
  for (var i = 0, len = modules.length; i < len; i++) {
123
90
  var module = modules[i];
124
91
 
125
- module.supportUserAgent(this.userAgent_,
126
- goog.bind(this.isModuleSupportingUserAgent_, this, module,
127
- eventDispatcher, fontWatcher));
92
+ module.load(function (fonts, opt_fontTestStrings, opt_metricCompatibleFonts) {
93
+ self.onModuleReady_(eventDispatcher, fontWatcher, fonts, opt_fontTestStrings, opt_metricCompatibleFonts);
94
+ });
128
95
  }
129
96
  };
130
97
  });
data/src/modules.yml CHANGED
@@ -1,10 +1,6 @@
1
1
  core:
2
2
  - ../tools/compiler/base.js
3
3
  - core/domhelper.js
4
- - core/browserinfo.js
5
- - core/version.js
6
- - core/useragent.js
7
- - core/useragentparser.js
8
4
  - core/cssclassname.js
9
5
  - core/font.js
10
6
  - core/eventdispatcher.js
@@ -56,8 +56,4 @@ goog.scope(function () {
56
56
 
57
57
  onReady(fonts, fontTestStrings);
58
58
  };
59
-
60
- Custom.prototype.supportUserAgent = function(userAgent, support) {
61
- return support(userAgent.getBrowserInfo().hasWebFontSupport());
62
- };
63
59
  });
@@ -33,7 +33,7 @@ goog.scope(function () {
33
33
  return protocol + api + hostname + '/' + projectId + '.js';
34
34
  };
35
35
 
36
- Fontdeck.prototype.supportUserAgent = function(userAgent, support) {
36
+ Fontdeck.prototype.load = function(onReady) {
37
37
  var projectId = this.configuration_['id'];
38
38
  var loadWindow = this.domHelper_.getLoadWindow();
39
39
  var self = this;
@@ -51,21 +51,17 @@ goog.scope(function () {
51
51
  var font = data['fonts'][i];
52
52
  self.fonts_.push(new Font(font['name'], Font.parseCssVariation('font-weight:' + font['weight'] + ';font-style:' + font['style'])));
53
53
  }
54
- support(fontdeckSupports);
54
+ onReady(self.fonts_);
55
55
  };
56
56
 
57
57
  // Call the Fontdeck API.
58
58
  this.domHelper_.loadScript(this.getScriptSrc(projectId), function (err) {
59
59
  if (err) {
60
- support(false);
60
+ onReady([]);
61
61
  }
62
62
  });
63
63
  } else {
64
- support(false);
64
+ onReady([]);
65
65
  }
66
66
  };
67
-
68
- Fontdeck.prototype.load = function(onReady) {
69
- onReady(this.fonts_);
70
- };
71
67
  });
@@ -9,10 +9,6 @@ goog.require('webfont.FontWatchRunner');
9
9
  * @implements {webfont.FontModule}
10
10
  */
11
11
  webfont.modules.google.GoogleFontApi = function(domHelper, configuration) {
12
- var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
13
-
14
- this.userAgent_ = userAgentParser.parse();
15
-
16
12
  this.domHelper_ = domHelper;
17
13
  this.configuration_ = configuration;
18
14
  };
@@ -35,20 +31,8 @@ goog.scope(function () {
35
31
  "Tinos": true
36
32
  };
37
33
 
38
- GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
39
- support(userAgent.getBrowserInfo().hasWebFontSupport());
40
- };
41
-
42
34
  GoogleFontApi.prototype.load = function(onReady) {
43
- var domHelper = this.domHelper_;
44
- var nonBlockingIe = this.userAgent_.getName() == 'MSIE' &&
45
- this.configuration_['blocking'] != true;
46
-
47
- if (nonBlockingIe) {
48
- domHelper.whenBodyExists(goog.bind(this.insertLink_, this, onReady));
49
- } else {
50
- this.insertLink_(onReady);
51
- }
35
+ this.insertLink_(onReady);
52
36
  };
53
37
 
54
38
  GoogleFontApi.prototype.insertLink_ = function(onReady) {