webfontloader 1.0.5

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.
Files changed (71) hide show
  1. data/Gemfile +9 -0
  2. data/LICENSE +201 -0
  3. data/README.md +148 -0
  4. data/Rakefile +243 -0
  5. data/bin/webfontloader-demos +28 -0
  6. data/docs/EVENTS.md +115 -0
  7. data/docs/MODULES.md +49 -0
  8. data/docs/TRANSITIONS.md +107 -0
  9. data/lib/webfontloader.rb +10 -0
  10. data/lib/webfontloader/demo/public/ascender.html +99 -0
  11. data/lib/webfontloader/demo/public/basic.css +9 -0
  12. data/lib/webfontloader/demo/public/custom.html +88 -0
  13. data/lib/webfontloader/demo/public/event-css-active-multiple.html +44 -0
  14. data/lib/webfontloader/demo/public/event-css-active.html +38 -0
  15. data/lib/webfontloader/demo/public/event-css-inactive.html +38 -0
  16. data/lib/webfontloader/demo/public/event-css-loading.html +55 -0
  17. data/lib/webfontloader/demo/public/event-js-active.html +39 -0
  18. data/lib/webfontloader/demo/public/event-js-font-active.html +40 -0
  19. data/lib/webfontloader/demo/public/event-js-loading.html +60 -0
  20. data/lib/webfontloader/demo/public/events-variations.html +130 -0
  21. data/lib/webfontloader/demo/public/events.html +103 -0
  22. data/lib/webfontloader/demo/public/google-css.html +27 -0
  23. data/lib/webfontloader/demo/public/google.html +33 -0
  24. data/lib/webfontloader/demo/public/ie-fast-js.html +47 -0
  25. data/lib/webfontloader/demo/public/ie-slow-js.html +48 -0
  26. data/lib/webfontloader/demo/public/ie-slow-link.html +38 -0
  27. data/lib/webfontloader/demo/public/index.html +70 -0
  28. data/lib/webfontloader/demo/public/typekit-variations.html +50 -0
  29. data/lib/webfontloader/demo/public/typekit.html +41 -0
  30. data/lib/webfontloader/demo/server.rb +92 -0
  31. data/lib/webfontloader/modules.rb +44 -0
  32. data/src-test/ascender/ascender_script_test.js +48 -0
  33. data/src-test/core/cssclassnametest.js +42 -0
  34. data/src-test/core/cssfontfamilynametest.js +54 -0
  35. data/src-test/core/domhelpertest.js +81 -0
  36. data/src-test/core/eventdispatchertest.js +99 -0
  37. data/src-test/core/fontmoduleloadertest.js +30 -0
  38. data/src-test/core/fonttest.js +92 -0
  39. data/src-test/core/fontvariationdescriptiontest.js +76 -0
  40. data/src-test/core/fontwatchertest.js +510 -0
  41. data/src-test/core/useragenttest.js +395 -0
  42. data/src-test/custom/customcsstest.js +30 -0
  43. data/src-test/google/fontapiparsertest.js +92 -0
  44. data/src-test/google/fontapiurlbuildertest.js +28 -0
  45. data/src-test/google/googlefontapitest.js +173 -0
  46. data/src-test/typekit/typekit_script_test.js +171 -0
  47. data/src/ascender/ascender_script.js +84 -0
  48. data/src/async_load.js +3 -0
  49. data/src/closure.js +3 -0
  50. data/src/core/cssclassname.js +21 -0
  51. data/src/core/cssfontfamilyname.js +20 -0
  52. data/src/core/domhelper.js +103 -0
  53. data/src/core/eventdispatcher.js +78 -0
  54. data/src/core/font.js +84 -0
  55. data/src/core/fontmoduleloader.js +25 -0
  56. data/src/core/fontvariationdescription.js +112 -0
  57. data/src/core/fontwatcher.js +121 -0
  58. data/src/core/initialize.js +26 -0
  59. data/src/core/namespace.js +11 -0
  60. data/src/core/useragent.js +41 -0
  61. data/src/core/useragentparser.js +234 -0
  62. data/src/custom/customcss.js +37 -0
  63. data/src/google/fontapiparser.js +94 -0
  64. data/src/google/fontapiurlbuilder.js +39 -0
  65. data/src/google/googlefontapi.js +49 -0
  66. data/src/modules.yml +27 -0
  67. data/src/typekit/typekit_script.js +58 -0
  68. data/tools/compiler/compiler.jar +0 -0
  69. data/tools/jstestdriver/JsTestDriver-1.2.1.jar +0 -0
  70. data/webfontloader.gemspec +144 -0
  71. metadata +191 -0
@@ -0,0 +1,121 @@
1
+ /**
2
+ * @constructor
3
+ */
4
+ webfont.FontWatcher = function(domHelper, eventDispatcher, fontSizer,
5
+ asyncCall, getTime) {
6
+ this.domHelper_ = domHelper;
7
+ this.eventDispatcher_ = eventDispatcher;
8
+ this.fontSizer_ = fontSizer;
9
+ this.asyncCall_ = asyncCall;
10
+ this.getTime_ = getTime;
11
+ this.currentlyWatched_ = 0;
12
+ this.last_ = false;
13
+ this.success_ = false;
14
+ this.nameHelper_ = new webfont.CssFontFamilyName();
15
+ this.fvd_ = new webfont.FontVariationDescription();
16
+ };
17
+
18
+ webfont.FontWatcher.DEFAULT_FONT = '_,arial,helvetica';
19
+ webfont.FontWatcher.DEFAULT_VARIATION = 'n4';
20
+
21
+ webfont.FontWatcher.prototype.watch = function(fontFamilies, fontDescriptions, last) {
22
+ var length = fontFamilies.length;
23
+
24
+ for (var i = 0; i < length; i++) {
25
+ var fontFamily = fontFamilies[i];
26
+ if (!fontDescriptions[fontFamily]) {
27
+ fontDescriptions[fontFamily] = [webfont.FontWatcher.DEFAULT_VARIATION];
28
+ }
29
+ this.currentlyWatched_ += fontDescriptions[fontFamily].length;
30
+ }
31
+
32
+ if (last) {
33
+ this.last_ = last;
34
+ }
35
+
36
+ for (var i = 0; i < length; i++) {
37
+ var fontFamily = fontFamilies[i];
38
+ var descriptions = fontDescriptions[fontFamily];
39
+
40
+ for (var j = 0, len = descriptions.length; j < len; j++) {
41
+ var fontDescription = descriptions[j];
42
+ var originalSize = this.getDefaultFontSize_(fontDescription);
43
+
44
+ this.watch_(fontFamily, fontDescription, originalSize);
45
+ }
46
+ }
47
+ };
48
+
49
+ webfont.FontWatcher.prototype.watch_ = function(fontFamily, fontDescription, originalSize) {
50
+ this.eventDispatcher_.dispatchFontLoading(fontFamily, fontDescription);
51
+ var requestedFont = this.createHiddenElementWithFont_(this.nameHelper_.quote(fontFamily),
52
+ fontDescription);
53
+ var size = this.fontSizer_.getWidth(requestedFont);
54
+
55
+ if (originalSize != size) {
56
+ this.domHelper_.removeElement(requestedFont);
57
+ this.eventDispatcher_.dispatchFontActive(fontFamily, fontDescription);
58
+ this.success_ = true;
59
+ this.decreaseCurrentlyWatched_();
60
+ } else {
61
+ this.asyncCheck_(this.getTime_(), originalSize, requestedFont,
62
+ fontFamily, fontDescription);
63
+ }
64
+ };
65
+
66
+ webfont.FontWatcher.prototype.decreaseCurrentlyWatched_ = function() {
67
+ if (--this.currentlyWatched_ == 0 && this.last_) {
68
+ if (this.success_) {
69
+ this.eventDispatcher_.dispatchActive();
70
+ } else {
71
+ this.eventDispatcher_.dispatchInactive();
72
+ }
73
+ }
74
+ };
75
+
76
+ webfont.FontWatcher.prototype.check_ = function(started, originalSize,
77
+ requestedFont, fontFamily, fontDescription) {
78
+ var size = this.fontSizer_.getWidth(requestedFont);
79
+
80
+ if (originalSize != size) {
81
+ this.domHelper_.removeElement(requestedFont);
82
+ this.eventDispatcher_.dispatchFontActive(fontFamily, fontDescription);
83
+ this.success_ = true;
84
+ this.decreaseCurrentlyWatched_();
85
+ } else if ((this.getTime_() - started) < 5000) {
86
+ this.asyncCheck_(started, originalSize, requestedFont, fontFamily, fontDescription);
87
+ } else {
88
+ this.domHelper_.removeElement(requestedFont);
89
+ this.eventDispatcher_.dispatchFontInactive(fontFamily, fontDescription);
90
+ this.decreaseCurrentlyWatched_();
91
+ }
92
+ };
93
+
94
+ webfont.FontWatcher.prototype.asyncCheck_ = function(started, originalSize,
95
+ requestedFont, fontFamily, fontDescription) {
96
+ this.asyncCall_(function(context, func) {
97
+ return function() {
98
+ func.call(context, started, originalSize, requestedFont, fontFamily, fontDescription);
99
+ }
100
+ }(this, this.check_), 50);
101
+ };
102
+
103
+ webfont.FontWatcher.prototype.getDefaultFontSize_ = function(fontDescription) {
104
+ var defaultFont = this.createHiddenElementWithFont_(
105
+ webfont.FontWatcher.DEFAULT_FONT, fontDescription);
106
+ var size = this.fontSizer_.getWidth(defaultFont);
107
+
108
+ this.domHelper_.removeElement(defaultFont);
109
+ return size;
110
+ };
111
+
112
+ webfont.FontWatcher.prototype.createHiddenElementWithFont_ = function(
113
+ fontFamily, fontDescription) {
114
+ var variationCss = this.fvd_.expand(fontDescription);
115
+ var styleString = "position:absolute;top:-999px;font-size:300px;font-family:" +
116
+ fontFamily + "," + webfont.FontWatcher.DEFAULT_FONT + ";" + variationCss;
117
+ var span = this.domHelper_.createElement('span', { 'style': styleString }, 'Mm');
118
+
119
+ this.domHelper_.insertInto('body', span);
120
+ return span;
121
+ };
@@ -0,0 +1,26 @@
1
+ // Name of the global object.
2
+ var globalName = 'WebFont';
3
+
4
+ // Provide an instance of WebFont in the global namespace.
5
+ window[globalName] = (function() {
6
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
7
+ var userAgent = userAgentParser.parse();
8
+ var domHelper = new webfont.DomHelper(document, userAgent);
9
+ var asyncCall = function(func, timeout) { setTimeout(func, timeout); };
10
+
11
+ return new webfont.WebFont(domHelper, new webfont.FontModuleLoader(),
12
+ document.documentElement, asyncCall, userAgent);
13
+ })();
14
+
15
+ // Export the public API.
16
+ window[globalName]['load'] = window[globalName].load;
17
+ window[globalName]['addModule'] = window[globalName].addModule;
18
+
19
+ // Export the UserAgent API because we pass this object to external modules.
20
+ webfont.UserAgent.prototype['getName'] = webfont.UserAgent.prototype.getName;
21
+ webfont.UserAgent.prototype['getVersion'] = webfont.UserAgent.prototype.getVersion;
22
+ webfont.UserAgent.prototype['getEngine'] = webfont.UserAgent.prototype.getEngine;
23
+ webfont.UserAgent.prototype['getEngineVersion'] = webfont.UserAgent.prototype.getEngineVersion;
24
+ webfont.UserAgent.prototype['getPlatform'] = webfont.UserAgent.prototype.getPlatform;
25
+ webfont.UserAgent.prototype['getPlatformVersion'] = webfont.UserAgent.prototype.getPlatformVersion;
26
+ webfont.UserAgent.prototype['isSupportingWebFont'] = webfont.UserAgent.prototype.isSupportingWebFont;
@@ -0,0 +1,11 @@
1
+ var webfont = {};
2
+
3
+ webfont.bind = function(context, func, opt_args) {
4
+ var args = arguments.length > 2 ?
5
+ Array.prototype.slice.call(arguments, 2) : [];
6
+
7
+ return function() {
8
+ args.push.apply(args, arguments);
9
+ return func.apply(context, args);
10
+ };
11
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @constructor
3
+ */
4
+ webfont.UserAgent = function(name, version, engine, engineVersion, platform,
5
+ platformVersion, webFontSupport) {
6
+ this.name_ = name;
7
+ this.version_ = version;
8
+ this.engine_ = engine;
9
+ this.engineVersion_ = engineVersion;
10
+ this.platform_ = platform;
11
+ this.platformVersion_ = platformVersion;
12
+ this.webFontSupport_ = webFontSupport;
13
+ };
14
+
15
+ webfont.UserAgent.prototype.getName = function() {
16
+ return this.name_;
17
+ };
18
+
19
+ webfont.UserAgent.prototype.getVersion = function() {
20
+ return this.version_;
21
+ };
22
+
23
+ webfont.UserAgent.prototype.getEngine = function() {
24
+ return this.engine_;
25
+ };
26
+
27
+ webfont.UserAgent.prototype.getEngineVersion = function() {
28
+ return this.engineVersion_;
29
+ };
30
+
31
+ webfont.UserAgent.prototype.getPlatform = function() {
32
+ return this.platform_;
33
+ };
34
+
35
+ webfont.UserAgent.prototype.getPlatformVersion = function() {
36
+ return this.platformVersion_;
37
+ };
38
+
39
+ webfont.UserAgent.prototype.isSupportingWebFont = function() {
40
+ return this.webFontSupport_;
41
+ };
@@ -0,0 +1,234 @@
1
+ /**
2
+ * @constructor
3
+ */
4
+ webfont.UserAgentParser = function(userAgent) {
5
+ this.userAgent_ = userAgent;
6
+ };
7
+
8
+ webfont.UserAgentParser.UNKNOWN = "Unknown";
9
+
10
+ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(webfont.UserAgentParser.UNKNOWN,
11
+ webfont.UserAgentParser.UNKNOWN, webfont.UserAgentParser.UNKNOWN, webfont.UserAgentParser.UNKNOWN, false);
12
+
13
+ webfont.UserAgentParser.prototype.parse = function() {
14
+ if (this.isIe_()) {
15
+ return this.parseIeUserAgentString_();
16
+ } else if (this.isOpera_()) {
17
+ return this.parseOperaUserAgentString_();
18
+ } else if (this.isWebKit_()) {
19
+ return this.parseWebKitUserAgentString_();
20
+ } else if (this.isGecko_()) {
21
+ return this.parseGeckoUserAgentString_();
22
+ } else {
23
+ return webfont.UserAgentParser.UNKNOWN_USER_AGENT;
24
+ }
25
+ };
26
+
27
+ webfont.UserAgentParser.prototype.getPlatform_ = function() {
28
+ var mobileOs = this.getMatchingGroup_(this.userAgent_,
29
+ /(iPod|iPad|iPhone|Android)/, 1);
30
+
31
+ if (mobileOs != "") {
32
+ return mobileOs;
33
+ }
34
+ var os = this.getMatchingGroup_(this.userAgent_,
35
+ /(Linux|Mac_PowerPC|Macintosh|Windows)/, 1);
36
+
37
+ if (os != "") {
38
+ if (os == "Mac_PowerPC") {
39
+ os = "Macintosh";
40
+ }
41
+ return os;
42
+ }
43
+ return webfont.UserAgentParser.UNKNOWN;
44
+ };
45
+
46
+ webfont.UserAgentParser.prototype.getPlatformVersion_ = function() {
47
+ var macVersion = this.getMatchingGroup_(this.userAgent_,
48
+ /(OS X|Windows NT|Android) ([^;]+)/, 2);
49
+ if (macVersion) {
50
+ return macVersion;
51
+ }
52
+ var iVersion = this.getMatchingGroup_(this.userAgent_,
53
+ /(iPhone )?OS ([\d_]+)/, 2);
54
+ if (iVersion) {
55
+ return iVersion;
56
+ }
57
+ var linuxVersion = this.getMatchingGroup_(this.userAgent_,
58
+ /Linux ([i\d]+)/, 1);
59
+ if (linuxVersion) {
60
+ return linuxVersion;
61
+ }
62
+
63
+ return webfont.UserAgentParser.UNKNOWN;
64
+ };
65
+
66
+ webfont.UserAgentParser.prototype.isIe_ = function() {
67
+ return this.userAgent_.indexOf("MSIE") != -1;
68
+ };
69
+
70
+ webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
71
+ var browser = this.getMatchingGroup_(this.userAgent_, /(MSIE [\d\w\.]+)/, 1);
72
+ var engineName = webfont.UserAgentParser.UNKNOWN;
73
+ var engineVersion = webfont.UserAgentParser.UNKNOWN;
74
+
75
+ if (browser != "") {
76
+ var pair = browser.split(' ');
77
+ var name = pair[0];
78
+ var version = pair[1];
79
+
80
+ // For IE we give MSIE as the engine name and the version of IE
81
+ // instead of the specific Trident engine name and version
82
+ return new webfont.UserAgent(name, version, name, version,
83
+ this.getPlatform_(), this.getPlatformVersion_(), this.getMajorVersion_(version) >= 6);
84
+ }
85
+ return new webfont.UserAgent("MSIE", webfont.UserAgentParser.UNKNOWN,
86
+ "MSIE", webfont.UserAgentParser.UNKNOWN,
87
+ this.getPlatform_(), this.getPlatformVersion_(), false);
88
+ };
89
+
90
+ webfont.UserAgentParser.prototype.isOpera_ = function() {
91
+ return this.userAgent_.indexOf("Opera") != -1;
92
+ };
93
+
94
+ webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
95
+ var engineName = webfont.UserAgentParser.UNKNOWN;
96
+ var engineVersion = webfont.UserAgentParser.UNKNOWN;
97
+ var enginePair = this.getMatchingGroup_(this.userAgent_,
98
+ /(Presto\/[\d\w\.]+)/, 1);
99
+
100
+ if (enginePair != "") {
101
+ var splittedEnginePair = enginePair.split('/');
102
+
103
+ engineName = splittedEnginePair[0];
104
+ engineVersion = splittedEnginePair[1];
105
+ } else {
106
+ if (this.userAgent_.indexOf("Gecko") != -1) {
107
+ engineName = "Gecko";
108
+ }
109
+ var geckoVersion = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
110
+
111
+ if (geckoVersion != "") {
112
+ engineVersion = geckoVersion;
113
+ }
114
+ }
115
+ if (this.userAgent_.indexOf("Version/") != -1) {
116
+ var version = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1);
117
+
118
+ if (version != "") {
119
+ return new webfont.UserAgent("Opera", version, engineName, engineVersion,
120
+ this.getPlatform_(), this.getPlatformVersion_(),
121
+ this.getMajorVersion_(version) >= 10);
122
+ }
123
+ }
124
+ var version = this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1);
125
+
126
+ if (version != "") {
127
+ return new webfont.UserAgent("Opera", version, engineName, engineVersion,
128
+ this.getPlatform_(), this.getPlatformVersion_(),
129
+ this.getMajorVersion_(version) >= 10);
130
+ }
131
+ return new webfont.UserAgent("Opera", webfont.UserAgentParser.UNKNOWN,
132
+ engineName, engineVersion,
133
+ this.getPlatform_(), this.getPlatformVersion_(), false);
134
+ };
135
+
136
+ webfont.UserAgentParser.prototype.isWebKit_ = function() {
137
+ return this.userAgent_.indexOf("AppleWebKit") != -1;
138
+ };
139
+
140
+ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
141
+ var platform = this.getPlatform_();
142
+ var platformVersion = this.getPlatformVersion_();
143
+ var webKitVersion = this.getMatchingGroup_(this.userAgent_,
144
+ /AppleWebKit\/([\d\.\+]+)/, 1);
145
+
146
+ if (webKitVersion == "") {
147
+ webKitVersion = webfont.UserAgentParser.UNKNOWN;
148
+ }
149
+ var name = webfont.UserAgentParser.UNKNOWN;
150
+
151
+ if (this.userAgent_.indexOf("Chrome") != -1) {
152
+ name = "Chrome";
153
+ } else if (this.userAgent_.indexOf("Safari") != -1) {
154
+ name = "Safari";
155
+ }
156
+ var version = webfont.UserAgentParser.UNKNOWN;
157
+
158
+ if (this.userAgent_.indexOf("Version/") != -1) {
159
+ version = this.getMatchingGroup_(this.userAgent_,
160
+ /Version\/([\d\.\w]+)/, 1);
161
+ } else if (name == "Chrome") {
162
+ version = this.getMatchingGroup_(this.userAgent_,
163
+ /Chrome\/([\d\.]+)/, 1);
164
+ }
165
+ var minor = this.getMatchingGroup_(webKitVersion, /\d+\.(\d+)/, 1);
166
+
167
+ return new webfont.UserAgent(name, version, "AppleWebKit", webKitVersion,
168
+ platform, platformVersion, this.getMajorVersion_(webKitVersion) >= 526 ||
169
+ this.getMajorVersion_(webKitVersion) >= 525 && parseInt(minor) >= 13);
170
+ };
171
+
172
+ webfont.UserAgentParser.prototype.isGecko_ = function() {
173
+ return this.userAgent_.indexOf("Gecko") != -1;
174
+ };
175
+
176
+ webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
177
+ var name = webfont.UserAgentParser.UNKNOWN;
178
+ var version = webfont.UserAgentParser.UNKNOWN;
179
+ var supportWebFont = false;
180
+
181
+ if (this.userAgent_.indexOf("Firefox") != -1) {
182
+ name = "Firefox";
183
+ var versionNum = this.getMatchingGroup_(this.userAgent_,
184
+ /Firefox\/([\d\w\.]+)/, 1);
185
+
186
+ if (versionNum != "") {
187
+ var minor = this.getMatchingGroup_(versionNum, /\d+\.(\d+)/, 1);
188
+
189
+ version = versionNum;
190
+ supportWebFont = versionNum != "" && this.getMajorVersion_(versionNum) >= 3 &&
191
+ parseInt(minor) >= 5;
192
+ }
193
+ } else if (this.userAgent_.indexOf("Mozilla") != -1) {
194
+ name = "Mozilla";
195
+ }
196
+ var geckoVersion = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
197
+
198
+ if (geckoVersion == "") {
199
+ geckoVersion = webfont.UserAgentParser.UNKNOWN;
200
+ } else {
201
+ if (!supportWebFont) {
202
+ var majorVersion = this.getMajorVersion_(geckoVersion);
203
+ var intMinorVersion = parseInt(this.getMatchingGroup_(geckoVersion, /\d+\.(\d+)/, 1));
204
+ var subVersion = parseInt(this.getMatchingGroup_(geckoVersion, /\d+\.\d+\.(\d+)/, 1));
205
+
206
+ supportWebFont = majorVersion > 1 ||
207
+ majorVersion == 1 && intMinorVersion > 9 ||
208
+ majorVersion == 1 && intMinorVersion == 9 && subVersion >= 2 ||
209
+ geckoVersion.match(/1\.9\.1b[123]/) != null ||
210
+ geckoVersion.match(/1\.9\.1\.[\d\.]+/) != null;
211
+ }
212
+ }
213
+ return new webfont.UserAgent(name, version, "Gecko", geckoVersion,
214
+ this.getPlatform_(), this.getPlatformVersion_(), supportWebFont);
215
+ };
216
+
217
+ webfont.UserAgentParser.prototype.getMajorVersion_ = function(version) {
218
+ var majorVersion = this.getMatchingGroup_(version, /(\d+)/, 1);
219
+
220
+ if (majorVersion != "") {
221
+ return parseInt(majorVersion);
222
+ }
223
+ return -1;
224
+ };
225
+
226
+ webfont.UserAgentParser.prototype.getMatchingGroup_ = function(str,
227
+ regexp, index) {
228
+ var groups = str.match(regexp);
229
+
230
+ if (groups && groups[index]) {
231
+ return groups[index];
232
+ }
233
+ return "";
234
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ *
3
+ * WebFont.load({
4
+ * custom: {
5
+ * families: ['Font1', 'Font2'],
6
+ * urls: [ 'http://moo', 'http://meuh' ] }
7
+ * });
8
+ *
9
+ * @constructor
10
+ */
11
+ webfont.CustomCss = function(domHelper, configuration) {
12
+ this.domHelper_ = domHelper;
13
+ this.configuration_ = configuration;
14
+ };
15
+
16
+ webfont.CustomCss.NAME = 'custom';
17
+
18
+ webfont.CustomCss.prototype.load = function(onReady) {
19
+ var urls = this.configuration_['urls'] || [];
20
+ var families = this.configuration_['families'] || [];
21
+
22
+ for (var i = 0, len = urls.length; i < len; i++) {
23
+ var url = urls[i];
24
+
25
+ this.domHelper_.insertInto('head', this.domHelper_.createCssLink(url));
26
+ }
27
+ onReady(families);
28
+ };
29
+
30
+ webfont.CustomCss.prototype.supportUserAgent = function(userAgent, support) {
31
+ return support(userAgent.isSupportingWebFont());
32
+ };
33
+
34
+ WebFont.addModule(webfont.CustomCss.NAME, function(configuration) {
35
+ return new webfont.CustomCss(new webfont.DomHelper(document),
36
+ configuration);
37
+ });