webfontloader 1.0.18 → 1.0.19
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/CHANGELOG +3 -0
- data/README.md +1 -1
- data/docs/MODULES.md +21 -1
- data/docs/TRANSITIONS.md +35 -0
- data/lib/webfontloader.rb +1 -1
- data/lib/webfontloader/demo/public/index.html +1 -0
- data/lib/webfontloader/demo/public/monotype.html +32 -0
- data/src-test/monotype/monotype_script_test.js +320 -0
- data/src/modules.yml +3 -0
- data/src/monotype/monotype_script.js +105 -0
- data/webfontloader.gemspec +5 -2
- metadata +7 -4
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -71,7 +71,7 @@ Learn more about [events][evt].
|
|
71
71
|
## A common ground
|
72
72
|
|
73
73
|
WebFont Loader aims to provide a common interface for font loading. Today it
|
74
|
-
works with Google, Typekit, and your own CSS. Learn more in
|
74
|
+
works with Google, Typekit, Fonts.com Web fonts and your own CSS. Learn more in
|
75
75
|
[transitions][trn].
|
76
76
|
|
77
77
|
|
data/docs/MODULES.md
CHANGED
@@ -43,6 +43,25 @@ website page within your account settings.
|
|
43
43
|
|
44
44
|
Learn more about [Fontdeck][fd].
|
45
45
|
|
46
|
+
## Fonts.com web fonts
|
47
|
+
|
48
|
+
When using [Fonts.com web fonts][mtiwfs]
|
49
|
+
|
50
|
+
(First sign up for [Fonts.com web fonts][mtiwfs]. Create a project, choose fonts to add into the created project and retrieve your Project ID. You can find this Project ID in the "Publish" tab).
|
51
|
+
|
52
|
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
53
|
+
<script type="text/javascript">
|
54
|
+
WebFont.load({
|
55
|
+
monotype: {
|
56
|
+
projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
57
|
+
}
|
58
|
+
});
|
59
|
+
</script>
|
60
|
+
|
61
|
+
Or as pure Fonts.com Web fonts API
|
62
|
+
|
63
|
+
<script type="text/javascript" src="http://fast.fonts.com/jsapi/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.js"></script>
|
64
|
+
|
46
65
|
## Custom
|
47
66
|
|
48
67
|
To load fonts from any external stylesheet, use the `custom` module. Here you'll
|
@@ -59,4 +78,5 @@ provides.
|
|
59
78
|
|
60
79
|
[gfontapi]: https://code.google.com/apis/webfonts/docs/getting_started.html
|
61
80
|
[tk]: http://typekit.com/
|
62
|
-
[fd]: http://fontdeck.com/
|
81
|
+
[fd]: http://fontdeck.com/
|
82
|
+
[mtiwfs]: http://webfonts.fonts.com/
|
data/docs/TRANSITIONS.md
CHANGED
@@ -78,6 +78,41 @@ Or as pure Typekit
|
|
78
78
|
Typekit.load();
|
79
79
|
</script>
|
80
80
|
|
81
|
+
## From Google Fonts to Fonts.com Web fonts
|
82
|
+
|
83
|
+
### Step 1: Use Google with WebFont Loader
|
84
|
+
|
85
|
+
You can get started with web fonts quickly and easily by just using Google.
|
86
|
+
|
87
|
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
88
|
+
<script type="text/javascript">
|
89
|
+
WebFont.load({
|
90
|
+
google: {
|
91
|
+
families: ['Droid Sans']
|
92
|
+
}
|
93
|
+
});
|
94
|
+
</script>
|
95
|
+
|
96
|
+
### Step 2: Add Fonts.com Web fonts
|
97
|
+
|
98
|
+
If you discover that Google doesn't have your preferred typeface, you may wish
|
99
|
+
to add fonts from Fonts.com Web fonts.
|
100
|
+
|
101
|
+
(first sign up for Fonts.com Web fonts, add fonts and retrieve your Project ID)
|
102
|
+
|
103
|
+
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
|
104
|
+
<script type="text/javascript">
|
105
|
+
WebFont.load({
|
106
|
+
monotype: {
|
107
|
+
projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
108
|
+
}
|
109
|
+
});
|
110
|
+
</script>
|
111
|
+
|
112
|
+
|
113
|
+
Or as pure Fonts.com Web fonts API
|
114
|
+
|
115
|
+
<script type="text/javascript" src="http://fast.fonts.com/jsapi/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.js"></script>
|
81
116
|
|
82
117
|
## Add events to self-hosted fonts
|
83
118
|
|
data/lib/webfontloader.rb
CHANGED
@@ -25,6 +25,7 @@
|
|
25
25
|
<li><a href="/custom.html">Custom / WebFont Loader</a>: Load fonts from your own CSS with WebFont Loader.</li>
|
26
26
|
<li><a href="/ascender.html">Ascender / WebFont Loader</a>: Load fonts from Ascender with WebFont Loader.</li>
|
27
27
|
<li><a href="/fontdeck.html">Fontdeck / WebFont Loader</a>: Load fonts from Fontdeck with WebFont Loader.</li>
|
28
|
+
<li><a href="/monotype.html">monotype / WebFont Loader</a>: Load fonts from webfonts.fonts.com with WebFont Loader.</li>
|
28
29
|
</ol>
|
29
30
|
|
30
31
|
<h2>Events</h2>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<link href="/basic.css" rel="stylesheet" type="text/css">
|
5
|
+
<script type="text/javascript" src="/webfont.js"></script>
|
6
|
+
<script type="text/javascript">
|
7
|
+
WebFont.load({
|
8
|
+
monotype: {
|
9
|
+
projectId: 'b726c28f-a28a-45be-993f-3db719bacfab'
|
10
|
+
}
|
11
|
+
});
|
12
|
+
</script>
|
13
|
+
</head>
|
14
|
+
<body>
|
15
|
+
<h1>
|
16
|
+
Hello World. I am DIN Next Bold.
|
17
|
+
</h1>
|
18
|
+
|
19
|
+
<hr>
|
20
|
+
<p>
|
21
|
+
<a href="#" onClick="document.getElementsByTagName('body')[0].style.color = '#fff';return false;">Hide Page</a> |
|
22
|
+
<a href="/monotype.html">Reload Cached</a>
|
23
|
+
</p>
|
24
|
+
<p class="c1">
|
25
|
+
The goal of this page is to show how monotype fonts load. And I'm Albertus Regular
|
26
|
+
</p>
|
27
|
+
|
28
|
+
<p class="c2">
|
29
|
+
You must use "localhost" when testing monotype fonts. And this is Trade Gothic Condensed
|
30
|
+
</p>
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,320 @@
|
|
1
|
+
var MonotypeScriptTest = TestCase('MonotypeScriptTest');
|
2
|
+
|
3
|
+
MonotypeScriptTest.prototype.testIfProtocolMethodIsReturningProperly = function () {
|
4
|
+
var fakeDocument = {
|
5
|
+
location: { protocol: "https:" }
|
6
|
+
};
|
7
|
+
var global = {}; // should be window in actual situation.
|
8
|
+
var script = null;
|
9
|
+
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
10
|
+
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
11
|
+
var fakedom = [];
|
12
|
+
var fakeDomHelper = {
|
13
|
+
createScriptSrc: function (s) {
|
14
|
+
script = { src: s };
|
15
|
+
return script;
|
16
|
+
},
|
17
|
+
insertInto: function (tag, elem) {
|
18
|
+
fakedom[tag].push(elem);
|
19
|
+
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
20
|
+
return ["aachen bold", "kid print regualr"];
|
21
|
+
};
|
22
|
+
if (script.onload) {
|
23
|
+
script.onload();
|
24
|
+
}
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
28
|
+
var monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocument, config);
|
29
|
+
assertEquals("https:", monotypeScript.protocol());
|
30
|
+
|
31
|
+
fakeDocument = {
|
32
|
+
location: { protocol: "http:" }
|
33
|
+
};
|
34
|
+
|
35
|
+
monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocument, config);
|
36
|
+
assertEquals("http:", monotypeScript.protocol());
|
37
|
+
};
|
38
|
+
|
39
|
+
MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
|
40
|
+
var fakedom = { 'head': [], 'body': [] };
|
41
|
+
var fakeDocument = {
|
42
|
+
location: { protocol: "http:" }
|
43
|
+
};
|
44
|
+
var script = null;
|
45
|
+
var global = {}; // should be window in actual situation.
|
46
|
+
var families = null;
|
47
|
+
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
|
48
|
+
|
49
|
+
var fakeDomHelper = {
|
50
|
+
createScriptSrc: function (s) {
|
51
|
+
script = { src: s };
|
52
|
+
return script;
|
53
|
+
},
|
54
|
+
insertInto: function (tag, elem) {
|
55
|
+
fakedom[tag].push(elem);
|
56
|
+
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
57
|
+
return ["aachen bold", "kid print regualr"];
|
58
|
+
};
|
59
|
+
if (script.onload) {
|
60
|
+
script.onload();
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
function getElementById(Id) {
|
66
|
+
var p;
|
67
|
+
for (p in fakedom) {
|
68
|
+
if (fakedom[p].length > 0) {
|
69
|
+
for (i = 0; i < fakedom[p].length; i++) {
|
70
|
+
if (fakedom[p][i].id === Id) {
|
71
|
+
return fakedom[p][i];
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
return null;
|
77
|
+
}
|
78
|
+
var isSupport = null;
|
79
|
+
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
80
|
+
var monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocument, config);
|
81
|
+
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
82
|
+
monotypeScript.load(function (fontFamilies) {
|
83
|
+
families = fontFamilies;
|
84
|
+
});
|
85
|
+
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
86
|
+
|
87
|
+
assertEquals(null, isSupport);
|
88
|
+
assertNotNull(script);
|
89
|
+
assertEquals("http://fast.fonts.com/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
90
|
+
assertEquals(2, families.length);
|
91
|
+
};
|
92
|
+
|
93
|
+
//If current page is browsed using https protocol, the added script should be requested with SSL.
|
94
|
+
MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
|
95
|
+
var fakedom = { 'head': [], 'body': [] };
|
96
|
+
var fakeDocument1 = {
|
97
|
+
location: { protocol: "https:" }
|
98
|
+
};
|
99
|
+
var fakeDocument2 = {
|
100
|
+
location: { protocol: "http:" }
|
101
|
+
};
|
102
|
+
var script = null;
|
103
|
+
var global = {}; // should be window in actual situation.
|
104
|
+
var families = null;
|
105
|
+
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
|
106
|
+
|
107
|
+
var fakeDomHelper = {
|
108
|
+
createScriptSrc: function (s) {
|
109
|
+
script = { src: s };
|
110
|
+
return script;
|
111
|
+
},
|
112
|
+
insertInto: function (tag, elem) {
|
113
|
+
fakedom[tag].push(elem);
|
114
|
+
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
115
|
+
return ["aachen bold", "kid print regualr"];
|
116
|
+
};
|
117
|
+
if (script.onload) {
|
118
|
+
script.onload();
|
119
|
+
}
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
//trys to simulates exactly the getElementById behaviour, by returning the first found element.
|
124
|
+
function getElementById(Id) {
|
125
|
+
var p;
|
126
|
+
for (p in fakedom) {
|
127
|
+
if (fakedom[p].length > 0) {
|
128
|
+
for (i = 0; i < fakedom[p].length; i++) {
|
129
|
+
if (fakedom[p][i].id === Id) {
|
130
|
+
return fakedom[p][i];
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return null;
|
136
|
+
}
|
137
|
+
var isSupport = null;
|
138
|
+
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
139
|
+
var monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocument1, config);
|
140
|
+
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
141
|
+
monotypeScript.load(function (fontFamilies) {
|
142
|
+
families = fontFamilies;
|
143
|
+
});
|
144
|
+
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
145
|
+
|
146
|
+
assertEquals(null, isSupport);
|
147
|
+
assertNotNull(script);
|
148
|
+
assertEquals("https://fast.fonts.com/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
149
|
+
assertEquals(2, families.length);
|
150
|
+
|
151
|
+
//one page can have multiple projects, but not 2 projects with same projectId.
|
152
|
+
config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7c1', api: "http://fast.fonts.com/jsapidev" };
|
153
|
+
var monotypeScript2 = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocument2, config);
|
154
|
+
monotypeScript2.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
155
|
+
monotypeScript2.load(function (fontFamilies) {
|
156
|
+
families = fontFamilies;
|
157
|
+
});
|
158
|
+
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
159
|
+
assertEquals(null, isSupport);
|
160
|
+
assertNotNull(script);
|
161
|
+
assertEquals("http://fast.fonts.com/jsapidev/01e2ff27-25bf-4801-a23e-73d328e6c7c1.js", script.src);
|
162
|
+
assertEquals(2, families.length);
|
163
|
+
};
|
164
|
+
|
165
|
+
MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
|
166
|
+
var fakedom = { 'head': [], 'body': [] };
|
167
|
+
var global = {}; // should be window in actual situation.
|
168
|
+
var script = null;
|
169
|
+
var families = null;
|
170
|
+
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
171
|
+
|
172
|
+
var fakeDomHelper = {
|
173
|
+
createScriptSrc: function (s) {
|
174
|
+
script = { src: s };
|
175
|
+
return script;
|
176
|
+
},
|
177
|
+
insertInto: function (tag, elem) {
|
178
|
+
fakedom[tag].push(elem);
|
179
|
+
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
180
|
+
return ["aachen bold", "kid print regualr"];
|
181
|
+
};
|
182
|
+
if (script.onload) {
|
183
|
+
script.onload();
|
184
|
+
}
|
185
|
+
}
|
186
|
+
};
|
187
|
+
|
188
|
+
var fakeDocHelper = {
|
189
|
+
protocol: function () {
|
190
|
+
return "http:";
|
191
|
+
}
|
192
|
+
};
|
193
|
+
|
194
|
+
function getElementById(Id) {
|
195
|
+
var p;
|
196
|
+
for (p in fakedom) {
|
197
|
+
if (fakedom[p].length > 0) {
|
198
|
+
for (i = 0; i < fakedom[p].length; i++) {
|
199
|
+
if (fakedom[p][i].id === Id) {
|
200
|
+
return fakedom[p][i];
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
return null;
|
206
|
+
}
|
207
|
+
|
208
|
+
var isSupport = null;
|
209
|
+
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
210
|
+
var monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocHelper, config);
|
211
|
+
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
212
|
+
|
213
|
+
monotypeScript.load(function (fontFamilies) {
|
214
|
+
families = fontFamilies;
|
215
|
+
});
|
216
|
+
//just for testing purpose
|
217
|
+
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
218
|
+
|
219
|
+
assertNotNull(script);
|
220
|
+
assertEquals("http://fast.fonts.com/jsapi/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
221
|
+
assertEquals(2, families.length);
|
222
|
+
};
|
223
|
+
|
224
|
+
//If current page is browsed using https protocol, the added script should be requested with SSL.
|
225
|
+
MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlHasCorrectSSL = function () {
|
226
|
+
var fakedom = { 'head': [], 'body': [] };
|
227
|
+
var fakeDocument = { location: { protocol: "https:"} };
|
228
|
+
var global = {}; // should be window in actual situation.
|
229
|
+
var script = null;
|
230
|
+
var families = null;
|
231
|
+
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
232
|
+
|
233
|
+
var fakeDomHelper = {
|
234
|
+
createScriptSrc: function (s) {
|
235
|
+
script = { src: s };
|
236
|
+
return script;
|
237
|
+
},
|
238
|
+
insertInto: function (tag, elem) {
|
239
|
+
fakedom[tag].push(elem);
|
240
|
+
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
241
|
+
return ["aachen bold", "kid print regualr"];
|
242
|
+
};
|
243
|
+
if (script.onload) {
|
244
|
+
script.onload();
|
245
|
+
}
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
function getElementById(Id) {
|
250
|
+
var p;
|
251
|
+
for (p in fakedom) {
|
252
|
+
if (fakedom[p].length > 0) {
|
253
|
+
for (i = 0; i < fakedom[p].length; i++) {
|
254
|
+
if (fakedom[p][i].id === Id) {
|
255
|
+
return fakedom[p][i];
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
return null;
|
261
|
+
}
|
262
|
+
|
263
|
+
var isSupport = null;
|
264
|
+
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
265
|
+
var monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocument, config);
|
266
|
+
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
267
|
+
|
268
|
+
monotypeScript.load(function (fontFamilies) {
|
269
|
+
families = fontFamilies;
|
270
|
+
});
|
271
|
+
//just for testing purpose
|
272
|
+
script = getElementById(webfont.MonotypeScript.SCRIPTID + config.projectId);
|
273
|
+
|
274
|
+
assertNotNull(script);
|
275
|
+
assertEquals("https://fast.fonts.com/jsapi/01e2ff27-25bf-4801-a23e-73d328e6c7cc.js", script.src);
|
276
|
+
assertEquals(2, families.length);
|
277
|
+
};
|
278
|
+
|
279
|
+
//if no projectId is provided in config, the script should not be added.
|
280
|
+
MonotypeScriptTest.prototype.testWithoutProjectId = function () {
|
281
|
+
var fakedom = { 'head': [], 'body': [] };
|
282
|
+
var global = {}; // should be window in actual situation.
|
283
|
+
var script = null;
|
284
|
+
var families = null;
|
285
|
+
var config = {};
|
286
|
+
|
287
|
+
var fakeDomHelper = {
|
288
|
+
createScriptSrc: function (s) {
|
289
|
+
script = { src: s };
|
290
|
+
return script;
|
291
|
+
},
|
292
|
+
insertInto: function (tag, elem) {
|
293
|
+
fakedom[tag].push(elem);
|
294
|
+
global[webfont.MonotypeScript.HOOK + config.projectId] = function () {
|
295
|
+
return ["aachen bold", "kid print regualr"];
|
296
|
+
};
|
297
|
+
if (script.onload) {
|
298
|
+
script.onload();
|
299
|
+
}
|
300
|
+
}
|
301
|
+
};
|
302
|
+
|
303
|
+
var fakeDocHelper = {
|
304
|
+
protocol: function () {
|
305
|
+
return "http:";
|
306
|
+
}
|
307
|
+
};
|
308
|
+
|
309
|
+
var isSupport = null;
|
310
|
+
var userAgent = new webfont.UserAgent("Test", "1.0", true);
|
311
|
+
var monotypeScript = new webfont.MonotypeScript(global, userAgent, fakeDomHelper, fakeDocHelper, config);
|
312
|
+
monotypeScript.supportUserAgent(userAgent, function (support) { isSupport = support; });
|
313
|
+
|
314
|
+
monotypeScript.load(function (fontFamilies) {
|
315
|
+
families = fontFamilies;
|
316
|
+
});
|
317
|
+
assertNull(script);
|
318
|
+
assertEquals(0, families.length);
|
319
|
+
|
320
|
+
};
|
data/src/modules.yml
CHANGED
@@ -0,0 +1,105 @@
|
|
1
|
+
/**
|
2
|
+
webfont.load({
|
3
|
+
monotype: {
|
4
|
+
projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'//this is your Fonts.com Web fonts projectId
|
5
|
+
}
|
6
|
+
});
|
7
|
+
*/
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @constructor
|
11
|
+
*/
|
12
|
+
webfont.MonotypeScript = function (global, userAgent, domHelper, doc, configuration) {
|
13
|
+
this.global_ = global;
|
14
|
+
this.userAgent_ = userAgent;
|
15
|
+
this.domHelper_ = domHelper;
|
16
|
+
this.doc_ = doc;
|
17
|
+
this.configuration_ = configuration;
|
18
|
+
this.fontFamilies_ = [];
|
19
|
+
this.fontVariations_ = {};
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* name of the module through which external API is supposed to call the MonotypeFontAPI.
|
24
|
+
* @const
|
25
|
+
*/
|
26
|
+
webfont.MonotypeScript.NAME = 'monotype';
|
27
|
+
|
28
|
+
/**
|
29
|
+
* __mti_fntLst is the name of function that exposes Monotype's font list.
|
30
|
+
* @const
|
31
|
+
*/
|
32
|
+
webfont.MonotypeScript.HOOK = '__mti_fntLst';
|
33
|
+
|
34
|
+
/**
|
35
|
+
* __MonotypeAPIScript__ is the id of script added by google API. Currently 'webfonts.fonts.com' supports only one script in a page.
|
36
|
+
* This may require change in future if 'webfonts.fonts.com' begins supporting multiple scripts per page.
|
37
|
+
* @const
|
38
|
+
*/
|
39
|
+
webfont.MonotypeScript.SCRIPTID = '__MonotypeAPIScript__';
|
40
|
+
|
41
|
+
webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support) {
|
42
|
+
var self = this;
|
43
|
+
var projectId = self.configuration_['projectId'];
|
44
|
+
if (projectId) {
|
45
|
+
var sc = self.domHelper_.createScriptSrc(self.getScriptSrc(projectId));
|
46
|
+
sc["id"] = webfont.MonotypeScript.SCRIPTID + projectId;
|
47
|
+
|
48
|
+
sc["onreadystatechange"] = function (e) {
|
49
|
+
if (sc["readyState"] === "loaded" || sc["readyState"] === "complete") {
|
50
|
+
sc["onreadystatechange"] = null;
|
51
|
+
sc["onload"](e);
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
sc["onload"] = function (e) {
|
56
|
+
if (self.global_[webfont.MonotypeScript.HOOK + projectId]) {
|
57
|
+
var mti_fnts = self.global_[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
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
support(userAgent.isSupportingWebFont());
|
66
|
+
};
|
67
|
+
|
68
|
+
this.domHelper_.insertInto('head', sc);
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
support(true);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
|
75
|
+
webfont.MonotypeScript.prototype.getScriptSrc = function (projectId) {
|
76
|
+
var p = this.protocol();
|
77
|
+
var api = (this.configuration_['api'] || 'fast.fonts.com/jsapi').replace(/^.*http(s?):(\/\/)?/, "");
|
78
|
+
return p + "//" + api + '/' + projectId + '.js';
|
79
|
+
};
|
80
|
+
|
81
|
+
webfont.MonotypeScript.prototype.load = function (onReady) {
|
82
|
+
onReady(this.fontFamilies_, this.fontVariations_);
|
83
|
+
};
|
84
|
+
|
85
|
+
webfont.MonotypeScript.prototype.protocol = function () {
|
86
|
+
var supportedProtocols = ["http:", "https:"];
|
87
|
+
var defaultProtocol = supportedProtocols[0];
|
88
|
+
if (this.doc_ && this.doc_.location && this.doc_.location.protocol) {
|
89
|
+
var i = 0;
|
90
|
+
for (i = 0; i < supportedProtocols.length; i++) {
|
91
|
+
if (this.doc_.location.protocol === supportedProtocols[i]) {
|
92
|
+
return this.doc_.location.protocol;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return defaultProtocol;
|
98
|
+
};
|
99
|
+
|
100
|
+
window['WebFont'].addModule(webfont.MonotypeScript.NAME, function (configuration) {
|
101
|
+
var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
|
102
|
+
var userAgent = userAgentParser.parse();
|
103
|
+
var domHelper = new webfont.DomHelper(document, userAgent);
|
104
|
+
return new webfont.MonotypeScript(window, userAgent, domHelper, document, configuration);
|
105
|
+
});
|
data/webfontloader.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'webfontloader'
|
16
|
-
s.version = '1.0.
|
17
|
-
s.date = '2011-
|
16
|
+
s.version = '1.0.19'
|
17
|
+
s.date = '2011-03-03'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -96,6 +96,7 @@ DESC
|
|
96
96
|
lib/webfontloader/demo/public/ie-slow-link.html
|
97
97
|
lib/webfontloader/demo/public/index.html
|
98
98
|
lib/webfontloader/demo/public/jquery.min.js
|
99
|
+
lib/webfontloader/demo/public/monotype.html
|
99
100
|
lib/webfontloader/demo/public/typekit-variations.html
|
100
101
|
lib/webfontloader/demo/public/typekit.html
|
101
102
|
lib/webfontloader/demo/server.rb
|
@@ -116,6 +117,7 @@ DESC
|
|
116
117
|
src-test/google/fontapiparsertest.js
|
117
118
|
src-test/google/fontapiurlbuildertest.js
|
118
119
|
src-test/google/googlefontapitest.js
|
120
|
+
src-test/monotype/monotype_script_test.js
|
119
121
|
src-test/typekit/typekit_script_test.js
|
120
122
|
src/ascender/ascender_script.js
|
121
123
|
src/async_load.js
|
@@ -139,6 +141,7 @@ DESC
|
|
139
141
|
src/google/fontapiurlbuilder.js
|
140
142
|
src/google/googlefontapi.js
|
141
143
|
src/modules.yml
|
144
|
+
src/monotype/monotype_script.js
|
142
145
|
src/typekit/typekit_script.js
|
143
146
|
tools/compiler/compiler.jar
|
144
147
|
tools/jstestdriver/JsTestDriver-1.2.1.jar
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 49
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 19
|
10
|
+
version: 1.0.19
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Carver
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-03-03 00:00:00 -08:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/webfontloader/demo/public/ie-slow-link.html
|
115
115
|
- lib/webfontloader/demo/public/index.html
|
116
116
|
- lib/webfontloader/demo/public/jquery.min.js
|
117
|
+
- lib/webfontloader/demo/public/monotype.html
|
117
118
|
- lib/webfontloader/demo/public/typekit-variations.html
|
118
119
|
- lib/webfontloader/demo/public/typekit.html
|
119
120
|
- lib/webfontloader/demo/server.rb
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- src-test/google/fontapiparsertest.js
|
135
136
|
- src-test/google/fontapiurlbuildertest.js
|
136
137
|
- src-test/google/googlefontapitest.js
|
138
|
+
- src-test/monotype/monotype_script_test.js
|
137
139
|
- src-test/typekit/typekit_script_test.js
|
138
140
|
- src/ascender/ascender_script.js
|
139
141
|
- src/async_load.js
|
@@ -157,6 +159,7 @@ files:
|
|
157
159
|
- src/google/fontapiurlbuilder.js
|
158
160
|
- src/google/googlefontapi.js
|
159
161
|
- src/modules.yml
|
162
|
+
- src/monotype/monotype_script.js
|
160
163
|
- src/typekit/typekit_script.js
|
161
164
|
- tools/compiler/compiler.jar
|
162
165
|
- tools/jstestdriver/JsTestDriver-1.2.1.jar
|