webfontloader 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +5 -0
  2. data/Rakefile +2 -1
  3. data/lib/webfontloader.rb +1 -1
  4. data/spec/core/font_spec.js +9 -4
  5. data/spec/core/fontruler_spec.js +3 -10
  6. data/spec/core/fontwatcher_spec.js +22 -23
  7. data/spec/core/fontwatchrunner_spec.js +206 -231
  8. data/spec/deps.js +27 -0
  9. data/spec/google/lastresortwebkitfontwatchrunner_spec.js +47 -58
  10. data/spec/index.html +14 -25
  11. data/src/ascender/ascender_script.js +52 -45
  12. data/src/core/browserinfo.js +54 -47
  13. data/src/core/cssclassname.js +27 -22
  14. data/src/core/cssfontfamilyname.js +23 -17
  15. data/src/core/domhelper.js +209 -203
  16. data/src/core/eventdispatcher.js +111 -103
  17. data/src/core/font.js +110 -68
  18. data/src/core/fontmoduleloader.js +56 -13
  19. data/src/core/fontruler.js +52 -43
  20. data/src/core/fontvariationdescription.js +82 -76
  21. data/src/core/fontwatcher.js +93 -88
  22. data/src/core/fontwatchrunner.js +161 -161
  23. data/src/core/initialize.js +22 -15
  24. data/src/core/namespace.js +0 -29
  25. data/src/core/size.js +31 -25
  26. data/src/core/useragent.js +63 -48
  27. data/src/core/useragentparser.js +317 -306
  28. data/src/custom/customcss.js +31 -24
  29. data/src/fontdeck/fontdeck_script.js +46 -37
  30. data/src/google/fontapiparser.js +105 -97
  31. data/src/google/fontapiurlbuilder.js +46 -41
  32. data/src/google/googlefontapi.js +48 -32
  33. data/src/google/lastresortwebkitfontwatchrunner.js +80 -67
  34. data/src/modules.yml +6 -6
  35. data/src/monotype/monotype_script.js +47 -40
  36. data/src/typekit/typekit_script.js +41 -35
  37. data/tools/compiler/base.js +1548 -0
  38. data/tools/compiler/compiler.jar +0 -0
  39. data/webfontloader.gemspec +4 -2
  40. metadata +18 -16
@@ -1,5 +1,13 @@
1
+ goog.provide('webfont.GoogleFontApi');
2
+
3
+ goog.require('webfont.FontApiUrlBuilder');
4
+ goog.require('webfont.FontApiParser');
5
+ goog.require('webfont.FontWatchRunner');
6
+ goog.require('webfont.LastResortWebKitFontWatchRunner');
7
+
1
8
  /**
2
9
  * @constructor
10
+ * @implements {webfont.FontModule}
3
11
  */
4
12
  webfont.GoogleFontApi = function(userAgent, domHelper, configuration) {
5
13
  this.userAgent_ = userAgent;
@@ -9,44 +17,52 @@ webfont.GoogleFontApi = function(userAgent, domHelper, configuration) {
9
17
 
10
18
  webfont.GoogleFontApi.NAME = 'google';
11
19
 
12
- webfont.GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
13
- support(userAgent.getBrowserInfo().hasWebFontSupport());
14
- };
20
+ goog.scope(function () {
21
+ var GoogleFontApi = webfont.GoogleFontApi,
22
+ FontWatchRunner = webfont.FontWatchRunner,
23
+ LastResortWebKitFontWatchRunner = webfont.LastResortWebKitFontWatchRunner,
24
+ FontApiUrlBuilder = webfont.FontApiUrlBuilder,
25
+ FontApiParser = webfont.FontApiParser;
15
26
 
16
- webfont.GoogleFontApi.prototype.getFontWatchRunnerCtor = function() {
17
- if (this.userAgent_.getEngine() == "AppleWebKit") {
18
- return webfont.LastResortWebKitFontWatchRunner;
19
- }
20
- return webfont.FontWatchRunner;
21
- };
27
+ GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
28
+ support(userAgent.getBrowserInfo().hasWebFontSupport());
29
+ };
22
30
 
23
- webfont.GoogleFontApi.prototype.load = function(onReady) {
24
- var domHelper = this.domHelper_;
25
- var nonBlockingIe = this.userAgent_.getName() == 'MSIE' &&
26
- this.configuration_['blocking'] != true;
31
+ GoogleFontApi.prototype.getFontWatchRunnerCtor = function() {
32
+ if (this.userAgent_.getEngine() == "AppleWebKit") {
33
+ return LastResortWebKitFontWatchRunner;
34
+ }
35
+ return FontWatchRunner;
36
+ };
27
37
 
28
- if (nonBlockingIe) {
29
- domHelper.whenBodyExists(webfont.bind(this, this.insertLink_, onReady));
30
- } else {
31
- this.insertLink_(onReady);
32
- }
33
- };
38
+ GoogleFontApi.prototype.load = function(onReady) {
39
+ var domHelper = this.domHelper_;
40
+ var nonBlockingIe = this.userAgent_.getName() == 'MSIE' &&
41
+ this.configuration_['blocking'] != true;
34
42
 
35
- webfont.GoogleFontApi.prototype.insertLink_ = function(onReady) {
36
- var domHelper = this.domHelper_;
37
- var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(
38
- this.configuration_['api'], domHelper.getProtocol(), this.configuration_['text']);
39
- var fontFamilies = this.configuration_['families'];
40
- fontApiUrlBuilder.setFontFamilies(fontFamilies);
43
+ if (nonBlockingIe) {
44
+ domHelper.whenBodyExists(goog.bind(this.insertLink_, this, onReady));
45
+ } else {
46
+ this.insertLink_(onReady);
47
+ }
48
+ };
41
49
 
42
- var fontApiParser = new webfont.FontApiParser(fontFamilies);
43
- fontApiParser.parse();
50
+ GoogleFontApi.prototype.insertLink_ = function(onReady) {
51
+ var domHelper = this.domHelper_;
52
+ var fontApiUrlBuilder = new FontApiUrlBuilder(
53
+ this.configuration_['api'], domHelper.getProtocol(), this.configuration_['text']);
54
+ var fontFamilies = this.configuration_['families'];
55
+ fontApiUrlBuilder.setFontFamilies(fontFamilies);
44
56
 
45
- domHelper.insertInto('head', domHelper.createCssLink(
46
- fontApiUrlBuilder.build()));
47
- onReady(fontApiParser.getFontFamilies(), fontApiParser.getVariations(),
48
- fontApiParser.getFontTestStrings());
49
- };
57
+ var fontApiParser = new FontApiParser(fontFamilies);
58
+ fontApiParser.parse();
59
+
60
+ domHelper.insertInto('head', domHelper.createCssLink(
61
+ fontApiUrlBuilder.build()));
62
+ onReady(fontApiParser.getFontFamilies(), fontApiParser.getVariations(),
63
+ fontApiParser.getFontTestStrings());
64
+ };
65
+ });
50
66
 
51
67
  globalNamespaceObject.addModule(webfont.GoogleFontApi.NAME, function(configuration, domHelper) {
52
68
  var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
@@ -1,29 +1,34 @@
1
+ goog.provide('webfont.LastResortWebKitFontWatchRunner');
2
+
3
+ goog.require('webfont.FontRuler');
4
+
1
5
  /**
2
6
  * @constructor
3
7
  * @param {function(string, string)} activeCallback
4
8
  * @param {function(string, string)} inactiveCallback
5
9
  * @param {webfont.DomHelper} domHelper
6
- * @param {Object.<string, function(Object): webfont.Size>} fontSizer
7
- * @param {function(function(), number=)} asyncCall
8
- * @param {function(): number} getTime
9
10
  * @param {string} fontFamily
10
11
  * @param {string} fontDescription
11
- * @param {boolean} hasWebkitFallbackBug
12
+ * @param {webfont.BrowserInfo} browserInfo
13
+ * @param {number=} opt_timeout
14
+ * @param {Object.<string, boolean>=} opt_metricCompatibleFonts
12
15
  * @param {string=} opt_fontTestString
13
16
  * @extends webfont.FontWatchRunner
14
17
  */
15
18
  webfont.LastResortWebKitFontWatchRunner = function(activeCallback,
16
- inactiveCallback, domHelper, fontSizer, asyncCall, getTime, fontFamily,
17
- fontDescription, hasWebkitFallbackBug, opt_fontTestString) {
18
- webfont.LastResortWebKitFontWatchRunner.superCtor_.call(this,
19
- activeCallback, inactiveCallback, domHelper, fontSizer, asyncCall,
20
- getTime, fontFamily, fontDescription, hasWebkitFallbackBug, opt_fontTestString);
19
+ inactiveCallback, domHelper, fontFamily,
20
+ fontDescription, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString) {
21
+
22
+ goog.base(this, activeCallback, inactiveCallback, domHelper,
23
+ fontFamily, fontDescription, browserInfo, opt_timeout, opt_metricCompatibleFonts, opt_fontTestString);
24
+
21
25
  this.webKitLastResortFontSizes_ = this.setUpWebKitLastResortFontSizes_();
22
26
  this.webKitLastResortSizeChange_ = false;
23
27
  this.lastObservedSizeA_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SERIF];
24
28
  this.lastObservedSizeB_ = this.lastResortSizes_[webfont.FontWatchRunner.LastResortFonts.SANS_SERIF];;
25
29
  };
26
- webfont.extendsClass(webfont.FontWatchRunner, webfont.LastResortWebKitFontWatchRunner);
30
+
31
+ goog.inherits(webfont.LastResortWebKitFontWatchRunner, webfont.FontWatchRunner)
27
32
 
28
33
  webfont.LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS = {
29
34
  "Arimo": true,
@@ -31,70 +36,78 @@ webfont.LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS = {
31
36
  "Tinos": true
32
37
  };
33
38
 
34
- /**
35
- * While loading a web font webkit applies a last resort fallback font to the
36
- * element on which the web font is applied.
37
- * See file: WebKit/Source/WebCore/css/CSSFontFaceSource.cpp.
38
- * Looking at the different implementation for the different platforms,
39
- * the last resort fallback font is different. This code uses the default
40
- * OS/browsers values.
41
- */
42
- webfont.LastResortWebKitFontWatchRunner.prototype
43
- .setUpWebKitLastResortFontSizes_ = function() {
44
- var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
45
- var lastResortFontSizes = lastResortFonts.length;
46
- var webKitLastResortFontSizes = {};
47
- var fontRuler = new webfont.FontRuler(this.domHelper_, this.fontSizer_, this.fontTestString_);
39
+ goog.scope(function () {
40
+ var LastResortWebKitFontWatchRunner = webfont.LastResortWebKitFontWatchRunner,
41
+ FontRuler = webfont.FontRuler;
48
42
 
49
- fontRuler.insert();
50
- fontRuler.setFont(lastResortFonts[0], this.fontDescription_);
43
+ /**
44
+ * While loading a web font webkit applies a last resort fallback font to the
45
+ * element on which the web font is applied.
46
+ * See file: WebKit/Source/WebCore/css/CSSFontFaceSource.cpp.
47
+ * Looking at the different implementation for the different platforms,
48
+ * the last resort fallback font is different. This code uses the default
49
+ * OS/browsers values.
50
+ */
51
+ LastResortWebKitFontWatchRunner.prototype
52
+ .setUpWebKitLastResortFontSizes_ = function() {
53
+ var lastResortFonts = ['Times New Roman', 'Arial', 'Times', 'Sans', 'Serif'];
54
+ var lastResortFontSizes = lastResortFonts.length;
55
+ var webKitLastResortFontSizes = {};
56
+ var fontRuler = new FontRuler(this.domHelper_, this.fontTestString_);
51
57
 
52
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
53
- for (var i = 1; i < lastResortFontSizes; i++) {
54
- var font = lastResortFonts[i];
55
- fontRuler.setFont(font, this.fontDescription_);
56
- webKitLastResortFontSizes[fontRuler.getSize().width] = true;
58
+ fontRuler.insert();
59
+ fontRuler.setFont(lastResortFonts[0], this.fontDescription_);
57
60
 
58
- // Another WebKit quirk if the normal weight/style is loaded first,
59
- // the size of the normal weight is returned when loading another weight.
60
- if (this.fontDescription_[1] != '4') {
61
- fontRuler.setFont(font, this.fontDescription_[0] + '4');
61
+ webKitLastResortFontSizes[fontRuler.getSize().width] = true;
62
+ for (var i = 1; i < lastResortFontSizes; i++) {
63
+ var font = lastResortFonts[i];
64
+ fontRuler.setFont(font, this.fontDescription_);
62
65
  webKitLastResortFontSizes[fontRuler.getSize().width] = true;
63
- }
64
- }
65
- fontRuler.remove();
66
- return webKitLastResortFontSizes;
67
- };
68
66
 
69
- webfont.LastResortWebKitFontWatchRunner.prototype.check_ = function() {
70
- var sizeA = this.fontRulerA_.getSize();
71
- var sizeB = this.fontRulerB_.getSize();
67
+ // Another WebKit quirk if the normal weight/style is loaded first,
68
+ // the size of the normal weight is returned when loading another weight.
69
+ if (this.fontDescription_[1] != '4') {
70
+ fontRuler.setFont(font, this.fontDescription_[0] + '4');
71
+ webKitLastResortFontSizes[fontRuler.getSize().width] = true;
72
+ }
73
+ }
74
+ fontRuler.remove();
75
+ return webKitLastResortFontSizes;
76
+ };
72
77
 
73
- if (!this.webKitLastResortSizeChange_ && sizeA.width == sizeB.width &&
74
- this.webKitLastResortFontSizes_[sizeA.width]) {
75
- this.webKitLastResortFontSizes_ = {};
76
- this.webKitLastResortFontSizes_[sizeA.width] = true;
77
- this.webKitLastResortSizeChange_ = true;
78
- }
79
- if ((this.lastObservedSizeA_.width != sizeA.width || this.lastObservedSizeB_.width != sizeB.width) &&
80
- (!this.webKitLastResortFontSizes_[sizeA.width] &&
81
- !this.webKitLastResortFontSizes_[sizeB.width])) {
82
- this.finish_(this.activeCallback_);
83
- } else if (this.getTime_() - this.started_ >= 5000) {
78
+ /**
79
+ * @override
80
+ */
81
+ LastResortWebKitFontWatchRunner.prototype.check_ = function() {
82
+ var sizeA = this.fontRulerA_.getSize();
83
+ var sizeB = this.fontRulerB_.getSize();
84
84
 
85
- // In order to handle the fact that a font could be the same size as the
86
- // default browser font on a webkit browser, mark the font as active
87
- // after 5 seconds if the latest 2 sizes are in webKitLastResortFontSizes_
88
- // and the font name is known to be metrics compatible.
89
- if (this.webKitLastResortFontSizes_[sizeA.width]
90
- && this.webKitLastResortFontSizes_[sizeB.width] &&
91
- webfont.LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS[
92
- this.fontFamily_]) {
85
+ if (!this.webKitLastResortSizeChange_ && sizeA.width == sizeB.width &&
86
+ this.webKitLastResortFontSizes_[sizeA.width]) {
87
+ this.webKitLastResortFontSizes_ = {};
88
+ this.webKitLastResortFontSizes_[sizeA.width] = true;
89
+ this.webKitLastResortSizeChange_ = true;
90
+ }
91
+ if ((this.lastObservedSizeA_.width != sizeA.width || this.lastObservedSizeB_.width != sizeB.width) &&
92
+ (!this.webKitLastResortFontSizes_[sizeA.width] &&
93
+ !this.webKitLastResortFontSizes_[sizeB.width])) {
93
94
  this.finish_(this.activeCallback_);
95
+ } else if (goog.now() - this.started_ >= 5000) {
96
+
97
+ // In order to handle the fact that a font could be the same size as the
98
+ // default browser font on a webkit browser, mark the font as active
99
+ // after 5 seconds if the latest 2 sizes are in webKitLastResortFontSizes_
100
+ // and the font name is known to be metrics compatible.
101
+ if (this.webKitLastResortFontSizes_[sizeA.width]
102
+ && this.webKitLastResortFontSizes_[sizeB.width] &&
103
+ LastResortWebKitFontWatchRunner.METRICS_COMPATIBLE_FONTS[
104
+ this.fontFamily_]) {
105
+ this.finish_(this.activeCallback_);
106
+ } else {
107
+ this.finish_(this.inactiveCallback_);
108
+ }
94
109
  } else {
95
- this.finish_(this.inactiveCallback_);
110
+ this.asyncCheck_();
96
111
  }
97
- } else {
98
- this.asyncCheck_();
99
- }
100
- };
112
+ };
113
+ });
data/src/modules.yml CHANGED
@@ -1,19 +1,19 @@
1
1
  core:
2
- - core/namespace.js
2
+ - ../tools/compiler/base.js
3
3
  - core/domhelper.js
4
4
  - core/browserinfo.js
5
5
  - core/useragent.js
6
6
  - core/useragentparser.js
7
+ - core/cssclassname.js
8
+ - core/cssfontfamilyname.js
9
+ - core/fontvariationdescription.js
7
10
  - core/eventdispatcher.js
8
11
  - core/fontmoduleloader.js
9
12
  - core/size.js
10
- - core/fontwatcher.js
11
- - core/fontwatchrunner.js
12
13
  - core/fontruler.js
14
+ - core/fontwatchrunner.js
15
+ - core/fontwatcher.js
13
16
  - core/font.js
14
- - core/cssclassname.js
15
- - core/cssfontfamilyname.js
16
- - core/fontvariationdescription.js
17
17
  - core/initialize.js
18
18
 
19
19
  ascender:
@@ -1,3 +1,5 @@
1
+ goog.provide('webfont.MonotypeScript');
2
+
1
3
  /**
2
4
  webfont.load({
3
5
  monotype: {
@@ -8,6 +10,7 @@ projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'//this is your Fonts.com Web fo
8
10
 
9
11
  /**
10
12
  * @constructor
13
+ * @implements {webfont.FontModule}
11
14
  */
12
15
  webfont.MonotypeScript = function (userAgent, domHelper, configuration) {
13
16
  this.userAgent_ = userAgent;
@@ -36,56 +39,60 @@ webfont.MonotypeScript.HOOK = '__mti_fntLst';
36
39
  */
37
40
  webfont.MonotypeScript.SCRIPTID = '__MonotypeAPIScript__';
38
41
 
39
- webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support) {
40
- var self = this;
41
- var projectId = self.configuration_['projectId'];
42
- var version = self.configuration_['version'];
43
- if (projectId) {
44
- var sc = self.domHelper_.createElement("script");
45
- sc["id"] = webfont.MonotypeScript.SCRIPTID + projectId;
42
+ goog.scope(function () {
43
+ var MonotypeScript = webfont.MonotypeScript;
44
+
45
+ MonotypeScript.prototype.supportUserAgent = function (userAgent, support) {
46
+ var self = this;
47
+ var projectId = self.configuration_['projectId'];
48
+ var version = self.configuration_['version'];
49
+ if (projectId) {
50
+ var sc = self.domHelper_.createElement("script");
51
+ sc["id"] = MonotypeScript.SCRIPTID + projectId;
46
52
 
47
- var loadWindow = this.domHelper_.getLoadWindow();
53
+ var loadWindow = this.domHelper_.getLoadWindow();
48
54
 
49
- function onload() {
50
- if (loadWindow[webfont.MonotypeScript.HOOK + projectId]) {
51
- var mti_fnts = loadWindow[webfont.MonotypeScript.HOOK + projectId]();
52
- if (mti_fnts && mti_fnts.length) {
53
- var i;
54
- for (i = 0; i < mti_fnts.length; i++) {
55
- self.fontFamilies_.push(mti_fnts[i]["fontfamily"]);
55
+ function onload() {
56
+ if (loadWindow[MonotypeScript.HOOK + projectId]) {
57
+ var mti_fnts = loadWindow[webfont.MonotypeScript.HOOK + projectId]();
58
+ if (mti_fnts && mti_fnts.length) {
59
+ var i;
60
+ for (i = 0; i < mti_fnts.length; i++) {
61
+ self.fontFamilies_.push(mti_fnts[i]["fontfamily"]);
62
+ }
56
63
  }
57
64
  }
65
+ support(userAgent.getBrowserInfo().hasWebFontSupport());
58
66
  }
59
- support(userAgent.getBrowserInfo().hasWebFontSupport());
60
- }
61
67
 
62
- var done = false;
68
+ var done = false;
63
69
 
64
- sc["onload"] = sc["onreadystatechange"] = function () {
65
- if (!done && (!this["readyState"] || this["readyState"] === "loaded" || this["readyState"] === "complete")) {
66
- done = true;
67
- onload();
68
- sc["onload"] = sc["onreadystatechange"] = null;
69
- }
70
- };
70
+ sc["onload"] = sc["onreadystatechange"] = function () {
71
+ if (!done && (!this["readyState"] || this["readyState"] === "loaded" || this["readyState"] === "complete")) {
72
+ done = true;
73
+ onload();
74
+ sc["onload"] = sc["onreadystatechange"] = null;
75
+ }
76
+ };
71
77
 
72
- sc["src"] = self.getScriptSrc(projectId, version);
73
- this.domHelper_.insertInto('head', sc);
74
- }
75
- else {
76
- support(true);
77
- }
78
- };
78
+ sc["src"] = self.getScriptSrc(projectId, version);
79
+ this.domHelper_.insertInto('head', sc);
80
+ }
81
+ else {
82
+ support(true);
83
+ }
84
+ };
79
85
 
80
- webfont.MonotypeScript.prototype.getScriptSrc = function (projectId, version) {
81
- var p = this.domHelper_.getProtocol();
82
- var api = (this.configuration_['api'] || 'fast.fonts.com/jsapi').replace(/^.*http(s?):(\/\/)?/, "");
83
- return p + "//" + api + '/' + projectId + '.js' + ( version ? '?v='+ version : '' );
84
- };
86
+ MonotypeScript.prototype.getScriptSrc = function (projectId, version) {
87
+ var p = this.domHelper_.getProtocol();
88
+ var api = (this.configuration_['api'] || 'fast.fonts.com/jsapi').replace(/^.*http(s?):(\/\/)?/, "");
89
+ return p + "//" + api + '/' + projectId + '.js' + ( version ? '?v='+ version : '' );
90
+ };
85
91
 
86
- webfont.MonotypeScript.prototype.load = function (onReady) {
87
- onReady(this.fontFamilies_, this.fontVariations_);
88
- };
92
+ MonotypeScript.prototype.load = function (onReady) {
93
+ onReady(this.fontFamilies_, this.fontVariations_);
94
+ };
95
+ });
89
96
 
90
97
  globalNamespaceObject.addModule(webfont.MonotypeScript.NAME, function (configuration, domHelper) {
91
98
  var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
@@ -1,5 +1,8 @@
1
+ goog.provide('webfont.TypekitScript');
2
+
1
3
  /**
2
4
  * @constructor
5
+ * @implements {webfont.FontModule}
3
6
  */
4
7
  webfont.TypekitScript = function(domHelper, configuration) {
5
8
  this.domHelper_ = domHelper;
@@ -11,49 +14,52 @@ webfont.TypekitScript = function(domHelper, configuration) {
11
14
  webfont.TypekitScript.NAME = 'typekit';
12
15
  webfont.TypekitScript.HOOK = '__webfonttypekitmodule__';
13
16
 
14
- webfont.TypekitScript.prototype.getScriptSrc = function(kitId) {
15
- var protocol = this.domHelper_.getProtocol();
16
- var api = this.configuration_['api'] || protocol + '//use.typekit.net';
17
- return api + '/' + kitId + '.js';
18
- };
17
+ goog.scope(function () {
18
+ var TypekitScript = webfont.TypekitScript;
19
19
 
20
- webfont.TypekitScript.prototype.supportUserAgent = function(userAgent, support) {
21
- var kitId = this.configuration_['id'];
22
- var configuration = this.configuration_;
23
- var loadWindow = this.domHelper_.getLoadWindow();
24
- var self = this;
20
+ TypekitScript.prototype.getScriptSrc = function(kitId) {
21
+ var protocol = this.domHelper_.getProtocol();
22
+ var api = this.configuration_['api'] || protocol + '//use.typekit.net';
23
+ return api + '/' + kitId + '.js';
24
+ };
25
25
 
26
- if (kitId) {
27
- // Provide data to Typekit for processing.main
28
- if (!loadWindow[webfont.TypekitScript.HOOK]) {
29
- loadWindow[webfont.TypekitScript.HOOK] = {};
30
- }
26
+ TypekitScript.prototype.supportUserAgent = function(userAgent, support) {
27
+ var kitId = this.configuration_['id'];
28
+ var configuration = this.configuration_;
29
+ var loadWindow = this.domHelper_.getLoadWindow();
30
+ var self = this;
31
31
 
32
- // Typekit will call 'init' to indicate whether it supports fonts
33
- // and what fonts will be provided.
34
- loadWindow[webfont.TypekitScript.HOOK][kitId] = function(callback) {
35
- var init = function(typekitSupports, fontFamilies, fontVariations) {
36
- self.fontFamilies_ = fontFamilies;
37
- self.fontVariations_ = fontVariations;
38
- support(typekitSupports);
32
+ if (kitId) {
33
+ // Provide data to Typekit for processing.main
34
+ if (!loadWindow[webfont.TypekitScript.HOOK]) {
35
+ loadWindow[webfont.TypekitScript.HOOK] = {};
36
+ }
37
+
38
+ // Typekit will call 'init' to indicate whether it supports fonts
39
+ // and what fonts will be provided.
40
+ loadWindow[webfont.TypekitScript.HOOK][kitId] = function(callback) {
41
+ var init = function(typekitSupports, fontFamilies, fontVariations) {
42
+ self.fontFamilies_ = fontFamilies;
43
+ self.fontVariations_ = fontVariations;
44
+ support(typekitSupports);
45
+ };
46
+ callback(userAgent, configuration, init);
39
47
  };
40
- callback(userAgent, configuration, init);
41
- };
42
48
 
43
- // Load the Typekit script.
44
- var script = this.domHelper_.createScriptSrc(this.getScriptSrc(kitId))
45
- this.domHelper_.insertInto('head', script);
49
+ // Load the Typekit script.
50
+ var script = this.domHelper_.createScriptSrc(this.getScriptSrc(kitId))
51
+ this.domHelper_.insertInto('head', script);
46
52
 
47
- } else {
48
- support(true);
49
- }
50
- };
53
+ } else {
54
+ support(true);
55
+ }
56
+ };
51
57
 
52
- webfont.TypekitScript.prototype.load = function(onReady) {
53
- onReady(this.fontFamilies_, this.fontVariations_);
54
- };
58
+ TypekitScript.prototype.load = function(onReady) {
59
+ onReady(this.fontFamilies_, this.fontVariations_);
60
+ };
61
+ });
55
62
 
56
63
  globalNamespaceObject.addModule(webfont.TypekitScript.NAME, function(configuration, domHelper) {
57
64
  return new webfont.TypekitScript(domHelper, configuration);
58
65
  });
59
-