webfontloader 1.6.7 → 1.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/lib/webfontloader.rb +1 -1
- data/package.json +1 -1
- data/spec/core/fontwatcher_spec.js +9 -4
- data/spec/deps.js +3 -2
- data/spec/modules/custom_spec.js +23 -3
- data/spec/modules/google/googlefontapi_spec.js +24 -2
- data/src/core/domhelper.js +34 -13
- data/src/core/fontwatcher.js +26 -31
- data/src/core/stylesheetwaiter.js +48 -0
- data/src/modules/custom.js +8 -4
- data/src/modules/google/googlefontapi.js +7 -2
- data/src/modules.yml +1 -0
- data/webfontloader.gemspec +3 -2
- data/webfontloader.js +16 -16
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4164b541b5770878b3fd7fbb3c79f7450649891c
|
4
|
+
data.tar.gz: c716c510446e57990b3c0c07f4741b1e170ca892
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a93f51b5e24eab7f7cf44a43ff1bb6047c36189c2d7e13591b0b8b59aa4134138b2d449cb4ea9524f3e04555e7722dba72fa947115715d94b7bfd6503ba6607b
|
7
|
+
data.tar.gz: 4f346002717ddb89d7e3ce98208b459ee5133fa5d408c643f66c7d10524ea1f1a5584aaeb4bdd27efeb16d9201782a1f17f2ccc0d71efab7a76b97aaace4e605
|
data/CHANGELOG
CHANGED
data/lib/webfontloader.rb
CHANGED
data/package.json
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
describe('FontWatcher', function () {
|
2
2
|
var FontWatcher = webfont.FontWatcher,
|
3
3
|
FontWatchRunner = webfont.FontWatchRunner,
|
4
|
+
NativeFontWatchRunner = webfont.NativeFontWatchRunner,
|
4
5
|
Font = webfont.Font,
|
5
6
|
DomHelper = webfont.DomHelper,
|
6
7
|
Version = webfont.Version,
|
@@ -29,7 +30,7 @@ describe('FontWatcher', function () {
|
|
29
30
|
eventDispatcher.dispatchActive = jasmine.createSpy('dispatchActive');
|
30
31
|
eventDispatcher.dispatchInactive = jasmine.createSpy('dispatchInactive');
|
31
32
|
|
32
|
-
|
33
|
+
var fakeStart = function (font, fontTestString) {
|
33
34
|
var found = false;
|
34
35
|
|
35
36
|
testStrings(this.fontTestString_);
|
@@ -47,7 +48,10 @@ describe('FontWatcher', function () {
|
|
47
48
|
} else {
|
48
49
|
this.inactiveCallback_(this.font_);
|
49
50
|
}
|
50
|
-
}
|
51
|
+
};
|
52
|
+
|
53
|
+
spyOn(FontWatchRunner.prototype, 'start').andCallFake(fakeStart);
|
54
|
+
spyOn(NativeFontWatchRunner.prototype, 'start').andCallFake(fakeStart);
|
51
55
|
});
|
52
56
|
|
53
57
|
describe('watch zero fonts', function () {
|
@@ -196,6 +200,7 @@ describe('FontWatcher', function () {
|
|
196
200
|
it('should use the correct tests strings', function () {
|
197
201
|
activeFonts = [font1, font2];
|
198
202
|
|
203
|
+
var defaultTestString = FontWatcher.SHOULD_USE_NATIVE_LOADER ? undefined : FontWatchRunner.DEFAULT_TEST_STRING;
|
199
204
|
var fontWatcher = new FontWatcher(domHelper, eventDispatcher);
|
200
205
|
|
201
206
|
fontWatcher.watchFonts([font1, font2, font3, font4], {
|
@@ -207,9 +212,9 @@ describe('FontWatcher', function () {
|
|
207
212
|
|
208
213
|
expect(testStrings.callCount).toEqual(4);
|
209
214
|
expect(testStrings.calls[0].args[0]).toEqual('testString1');
|
210
|
-
expect(testStrings.calls[1].args[0]).toEqual(
|
215
|
+
expect(testStrings.calls[1].args[0]).toEqual(defaultTestString);
|
211
216
|
expect(testStrings.calls[2].args[0]).toEqual('testString2');
|
212
|
-
expect(testStrings.calls[3].args[0]).toEqual(
|
217
|
+
expect(testStrings.calls[3].args[0]).toEqual(defaultTestString);
|
213
218
|
});
|
214
219
|
});
|
215
220
|
|
data/spec/deps.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
goog.addDependency("../../src/closure.js", [], []);
|
3
3
|
goog.addDependency("../../src/core/cssclassname.js", ["webfont.CssClassName"], []);
|
4
4
|
goog.addDependency("../../src/core/domhelper.js", ["webfont.DomHelper"], []);
|
5
|
+
goog.addDependency("../../src/core/stylesheetwaiter.js", ["webfont.StyleSheetWaiter"], []);
|
5
6
|
goog.addDependency("../../src/core/eventdispatcher.js", ["webfont.EventDispatcher"], ["webfont.CssClassName"]);
|
6
7
|
goog.addDependency("../../src/core/font.js", ["webfont.Font"], []);
|
7
8
|
goog.addDependency("../../src/core/fontmodule.js", ["webfont.FontModule"], []);
|
@@ -12,10 +13,10 @@ goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunne
|
|
12
13
|
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"]);
|
13
14
|
goog.addDependency("../../src/core/nativefontwatchrunner.js", ["webfont.NativeFontWatchRunner"], ["webfont.Font"]);
|
14
15
|
goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher","webfont.FontModuleLoader"]);
|
15
|
-
goog.addDependency("../../src/modules/custom.js", ["webfont.modules.Custom"], ["webfont.Font"]);
|
16
|
+
goog.addDependency("../../src/modules/custom.js", ["webfont.modules.Custom"], ["webfont.Font", "webfont.StyleSheetWaiter"]);
|
16
17
|
goog.addDependency("../../src/modules/fontdeck.js", ["webfont.modules.Fontdeck"], ["webfont.Font"]);
|
17
18
|
goog.addDependency("../../src/modules/google/fontapiparser.js", ["webfont.modules.google.FontApiParser"], ["webfont.Font"]);
|
18
19
|
goog.addDependency("../../src/modules/google/fontapiurlbuilder.js", ["webfont.modules.google.FontApiUrlBuilder"], []);
|
19
|
-
goog.addDependency("../../src/modules/google/googlefontapi.js", ["webfont.modules.google.GoogleFontApi"], ["webfont.modules.google.FontApiUrlBuilder","webfont.modules.google.FontApiParser","webfont.FontWatchRunner"]);
|
20
|
+
goog.addDependency("../../src/modules/google/googlefontapi.js", ["webfont.modules.google.GoogleFontApi"], ["webfont.modules.google.FontApiUrlBuilder","webfont.modules.google.FontApiParser","webfont.FontWatchRunner", "webfont.StyleSheetWaiter"]);
|
20
21
|
goog.addDependency("../../src/modules/monotype.js", ["webfont.modules.Monotype"], ["webfont.Font"]);
|
21
22
|
goog.addDependency("../../src/modules/typekit.js", ["webfont.modules.Typekit"], ["webfont.Font"]);
|
data/spec/modules/custom_spec.js
CHANGED
@@ -1,11 +1,20 @@
|
|
1
1
|
describe('modules.Custom', function () {
|
2
2
|
var Custom = webfont.modules.Custom,
|
3
|
-
FontFamily = webfont.FontFamily
|
3
|
+
FontFamily = webfont.FontFamily,
|
4
|
+
Any = jasmine.Matchers.Any;
|
4
5
|
|
5
6
|
describe('insert links correctly', function () {
|
6
7
|
var fakeDomHelper = null,
|
7
8
|
load = null;
|
8
9
|
|
10
|
+
function notifySheetsLoaded() {
|
11
|
+
var argsForCall = fakeDomHelper.loadStylesheet.argsForCall;
|
12
|
+
for (var i = 0; i < argsForCall.length; i++) {
|
13
|
+
var args = argsForCall[i];
|
14
|
+
args[1]();
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
9
18
|
beforeEach(function () {
|
10
19
|
fakeDomHelper = {
|
11
20
|
loadStylesheet: jasmine.createSpy('createCssLink')
|
@@ -26,11 +35,20 @@ describe('modules.Custom', function () {
|
|
26
35
|
|
27
36
|
it('should have inserted the links correctly', function () {
|
28
37
|
expect(fakeDomHelper.loadStylesheet.callCount).toEqual(2);
|
29
|
-
expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('http://moo');
|
30
|
-
expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('http://meuh');
|
38
|
+
expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('http://moo', new Any(Function));
|
39
|
+
expect(fakeDomHelper.loadStylesheet).toHaveBeenCalledWith('http://meuh', new Any(Function));
|
31
40
|
});
|
32
41
|
|
42
|
+
if (webfont.DomHelper.CAN_WAIT_STYLESHEET) {
|
43
|
+
it('should not invoke callback before all CSS are loaded', function () {
|
44
|
+
expect(load.callCount).toEqual(0);
|
45
|
+
notifySheetsLoaded();
|
46
|
+
expect(load.callCount).toEqual(1);
|
47
|
+
});
|
48
|
+
}
|
49
|
+
|
33
50
|
it('should have loaded the families correctly', function () {
|
51
|
+
notifySheetsLoaded();
|
34
52
|
expect(load.callCount).toEqual(1);
|
35
53
|
expect(load.calls[0].args[0].length).toEqual(3);
|
36
54
|
expect(load.calls[0].args[0][0].getName()).toEqual('Font1');
|
@@ -39,8 +57,10 @@ describe('modules.Custom', function () {
|
|
39
57
|
});
|
40
58
|
|
41
59
|
it('should have set a custom test string', function () {
|
60
|
+
notifySheetsLoaded();
|
42
61
|
expect(load.callCount).toEqual(1);
|
43
62
|
expect(load.calls[0].args[1]).toEqual({ Font3: 'hello world' });
|
44
63
|
});
|
45
64
|
});
|
65
|
+
|
46
66
|
});
|
@@ -1,14 +1,17 @@
|
|
1
1
|
describe('modules.google.GoogleFontApi', function () {
|
2
2
|
var GoogleFontApi = webfont.modules.google.GoogleFontApi,
|
3
|
+
Any = jasmine.Matchers.Any,
|
3
4
|
Font = webfont.Font,
|
4
5
|
link = '',
|
5
6
|
insert = '',
|
7
|
+
onload = null,
|
6
8
|
fakeDomHelper = {
|
7
9
|
whenBodyExists: function (callback) {
|
8
10
|
callback();
|
9
11
|
},
|
10
|
-
loadStylesheet: function (cssLink) {
|
12
|
+
loadStylesheet: function (cssLink, cb) {
|
11
13
|
link = cssLink;
|
14
|
+
onload = cb;
|
12
15
|
},
|
13
16
|
getProtocol: function () {
|
14
17
|
return 'http:';
|
@@ -19,8 +22,14 @@ describe('modules.google.GoogleFontApi', function () {
|
|
19
22
|
beforeEach(function () {
|
20
23
|
insert = '';
|
21
24
|
link = '';
|
25
|
+
onload = null;
|
22
26
|
});
|
23
27
|
|
28
|
+
function notifySheetsLoaded() {
|
29
|
+
if (onload)
|
30
|
+
onload();
|
31
|
+
};
|
32
|
+
|
24
33
|
describe('call onReady with font family loading', function () {
|
25
34
|
var googleFontApi = null,
|
26
35
|
fonts = null;
|
@@ -37,6 +46,7 @@ describe('modules.google.GoogleFontApi', function () {
|
|
37
46
|
});
|
38
47
|
|
39
48
|
it('has the correct families', function () {
|
49
|
+
notifySheetsLoaded();
|
40
50
|
expect(fonts).not.toBeNull();
|
41
51
|
expect(fonts.length).toEqual(2);
|
42
52
|
expect(fonts[0]).toEqual(new Font('Font1'));
|
@@ -46,18 +56,30 @@ describe('modules.google.GoogleFontApi', function () {
|
|
46
56
|
|
47
57
|
describe('call onReady with font family loading and custom API url', function () {
|
48
58
|
var googleFontApi = null;
|
59
|
+
var loaded = false;
|
49
60
|
|
50
61
|
beforeEach(function () {
|
62
|
+
loaded = false;
|
51
63
|
googleFontApi = new GoogleFontApi(fakeDomHelper, {
|
52
64
|
api: 'http://moo',
|
53
65
|
families: ['Font1', 'Font2']
|
54
66
|
});
|
55
|
-
googleFontApi.load(function () {});
|
67
|
+
googleFontApi.load(function () { loaded = true; });
|
56
68
|
});
|
57
69
|
|
58
70
|
it('has inserted the link element correctly', function () {
|
59
71
|
expect(link).toEqual('http://moo?family=Font1%7CFont2');
|
60
72
|
});
|
73
|
+
|
74
|
+
if (webfont.DomHelper.CAN_WAIT_STYLESHEET) {
|
75
|
+
it('does not call onReady until sheets are loaded', function () {
|
76
|
+
expect(onload).toMatch(new Any(Function));
|
77
|
+
expect(loaded).toBe(false);
|
78
|
+
|
79
|
+
notifySheetsLoaded();
|
80
|
+
expect(loaded).toBe(true);
|
81
|
+
});
|
82
|
+
}
|
61
83
|
});
|
62
84
|
|
63
85
|
describe('spaces replaced by plus', function () {
|
data/src/core/domhelper.js
CHANGED
@@ -22,6 +22,18 @@ webfont.DomHelper = function(mainWindow, opt_loadWindow) {
|
|
22
22
|
goog.scope(function () {
|
23
23
|
var DomHelper = webfont.DomHelper;
|
24
24
|
|
25
|
+
/**
|
26
|
+
* The NativeFontWatchRunnner depends on the correct and reliable
|
27
|
+
* |onload| event, and browsers with the native font loading API
|
28
|
+
* have reliable @onload support as far as we know. So we use the
|
29
|
+
* event for such a case and unconditionally invokes the callback
|
30
|
+
* otherwise.
|
31
|
+
*
|
32
|
+
* @const
|
33
|
+
* @type {boolean}
|
34
|
+
*/
|
35
|
+
DomHelper.CAN_WAIT_STYLESHEET = !!window['FontFace'];
|
36
|
+
|
25
37
|
/**
|
26
38
|
* Creates an element.
|
27
39
|
* @param {string} elem The element type.
|
@@ -298,25 +310,34 @@ goog.scope(function () {
|
|
298
310
|
|
299
311
|
var done = false;
|
300
312
|
|
301
|
-
|
302
|
-
|
303
|
-
done
|
313
|
+
if (DomHelper.CAN_WAIT_STYLESHEET) {
|
314
|
+
link.onload = function () {
|
315
|
+
if (!done) {
|
316
|
+
done = true;
|
304
317
|
|
305
|
-
|
306
|
-
|
318
|
+
if (opt_callback) {
|
319
|
+
opt_callback(null);
|
320
|
+
}
|
307
321
|
}
|
308
|
-
}
|
309
|
-
};
|
322
|
+
};
|
310
323
|
|
311
|
-
|
312
|
-
|
313
|
-
|
324
|
+
link.onerror = function () {
|
325
|
+
if (!done) {
|
326
|
+
done = true;
|
314
327
|
|
328
|
+
if (opt_callback) {
|
329
|
+
opt_callback(new Error('Stylesheet failed to load'));
|
330
|
+
}
|
331
|
+
}
|
332
|
+
};
|
333
|
+
} else {
|
334
|
+
// Some callers expect opt_callback being called asynchronously.
|
335
|
+
setTimeout(function () {
|
315
336
|
if (opt_callback) {
|
316
|
-
opt_callback(
|
337
|
+
opt_callback(null);
|
317
338
|
}
|
318
|
-
}
|
319
|
-
}
|
339
|
+
}, 0);
|
340
|
+
}
|
320
341
|
|
321
342
|
function onAvailable(callback) {
|
322
343
|
for (var i = 0; i < sheets.length; i++) {
|
data/src/core/fontwatcher.js
CHANGED
@@ -28,6 +28,12 @@ goog.scope(function () {
|
|
28
28
|
FontWatchRunner = webfont.FontWatchRunner,
|
29
29
|
NativeFontWatchRunner = webfont.NativeFontWatchRunner;
|
30
30
|
|
31
|
+
/**
|
32
|
+
* @const
|
33
|
+
* @type {boolean}
|
34
|
+
*/
|
35
|
+
FontWatcher.SHOULD_USE_NATIVE_LOADER = !!window['FontFace'];
|
36
|
+
|
31
37
|
/**
|
32
38
|
* Watches a set of font families.
|
33
39
|
* @param {Array.<webfont.Font>} fonts The fonts to watch.
|
@@ -61,37 +67,26 @@ goog.scope(function () {
|
|
61
67
|
|
62
68
|
var fontWatchRunner = null;
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
//} else {
|
85
|
-
//
|
86
|
-
fontWatchRunner = new FontWatchRunner(
|
87
|
-
goog.bind(this.fontActive_, this),
|
88
|
-
goog.bind(this.fontInactive_, this),
|
89
|
-
this.domHelper_,
|
90
|
-
font,
|
91
|
-
this.timeout_,
|
92
|
-
metricCompatibleFonts,
|
93
|
-
testString
|
94
|
-
);
|
70
|
+
if (FontWatcher.SHOULD_USE_NATIVE_LOADER) {
|
71
|
+
fontWatchRunner = new NativeFontWatchRunner(
|
72
|
+
goog.bind(this.fontActive_, this),
|
73
|
+
goog.bind(this.fontInactive_, this),
|
74
|
+
this.domHelper_,
|
75
|
+
font,
|
76
|
+
this.timeout_,
|
77
|
+
testString
|
78
|
+
);
|
79
|
+
} else {
|
80
|
+
fontWatchRunner = new FontWatchRunner(
|
81
|
+
goog.bind(this.fontActive_, this),
|
82
|
+
goog.bind(this.fontInactive_, this),
|
83
|
+
this.domHelper_,
|
84
|
+
font,
|
85
|
+
this.timeout_,
|
86
|
+
metricCompatibleFonts,
|
87
|
+
testString
|
88
|
+
);
|
89
|
+
}
|
95
90
|
|
96
91
|
fontWatchRunners.push(fontWatchRunner);
|
97
92
|
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
goog.provide('webfont.StyleSheetWaiter');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* A utility class for handling callback from DomHelper.loadStylesheet().
|
5
|
+
*
|
6
|
+
* @constructor
|
7
|
+
*/
|
8
|
+
webfont.StyleSheetWaiter = function() {
|
9
|
+
/** @private @type {number} */
|
10
|
+
this.waitingCount_ = 0;
|
11
|
+
/** @private @type {Function} */
|
12
|
+
this.onReady_ = null;
|
13
|
+
};
|
14
|
+
|
15
|
+
goog.scope(function () {
|
16
|
+
var StyleSheetWaiter = webfont.StyleSheetWaiter;
|
17
|
+
|
18
|
+
/**
|
19
|
+
* @return {function(Error)}
|
20
|
+
*/
|
21
|
+
StyleSheetWaiter.prototype.startWaitingLoad = function() {
|
22
|
+
var self = this;
|
23
|
+
self.waitingCount_++;
|
24
|
+
return function(error) {
|
25
|
+
self.waitingCount_--;
|
26
|
+
self.fireIfReady_();
|
27
|
+
};
|
28
|
+
};
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @param {Function} fn
|
32
|
+
*/
|
33
|
+
StyleSheetWaiter.prototype.waitWhileNeededThen = function(fn) {
|
34
|
+
this.onReady_ = fn;
|
35
|
+
this.fireIfReady_();
|
36
|
+
};
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @private
|
40
|
+
*/
|
41
|
+
StyleSheetWaiter.prototype.fireIfReady_ = function() {
|
42
|
+
var isReady = 0 == this.waitingCount_;
|
43
|
+
if (isReady && this.onReady_) {
|
44
|
+
this.onReady_();
|
45
|
+
this.onReady_ = null;
|
46
|
+
}
|
47
|
+
};
|
48
|
+
});
|
data/src/modules/custom.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
goog.provide('webfont.modules.Custom');
|
2
2
|
|
3
3
|
goog.require('webfont.Font');
|
4
|
+
goog.require('webfont.StyleSheetWaiter');
|
4
5
|
|
5
6
|
/**
|
6
7
|
*
|
@@ -26,16 +27,17 @@ webfont.modules.Custom.NAME = 'custom';
|
|
26
27
|
|
27
28
|
goog.scope(function () {
|
28
29
|
var Custom = webfont.modules.Custom,
|
29
|
-
Font = webfont.Font
|
30
|
+
Font = webfont.Font,
|
31
|
+
StyleSheetWaiter = webfont.StyleSheetWaiter;
|
30
32
|
|
31
33
|
Custom.prototype.load = function(onReady) {
|
32
34
|
var i, len;
|
33
35
|
var urls = this.configuration_['urls'] || [];
|
34
36
|
var familiesConfiguration = this.configuration_['families'] || [];
|
35
37
|
var fontTestStrings = this.configuration_['testStrings'] || {};
|
36
|
-
|
38
|
+
var waiter = new StyleSheetWaiter();
|
37
39
|
for (i = 0, len = urls.length; i < len; i++) {
|
38
|
-
this.domHelper_.loadStylesheet(urls[i]);
|
40
|
+
this.domHelper_.loadStylesheet(urls[i], waiter.startWaitingLoad());
|
39
41
|
}
|
40
42
|
|
41
43
|
var fonts = [];
|
@@ -54,6 +56,8 @@ goog.scope(function () {
|
|
54
56
|
}
|
55
57
|
}
|
56
58
|
|
57
|
-
|
59
|
+
waiter.waitWhileNeededThen(function() {
|
60
|
+
onReady(fonts, fontTestStrings);
|
61
|
+
});
|
58
62
|
};
|
59
63
|
});
|
@@ -3,6 +3,7 @@ goog.provide('webfont.modules.google.GoogleFontApi');
|
|
3
3
|
goog.require('webfont.modules.google.FontApiUrlBuilder');
|
4
4
|
goog.require('webfont.modules.google.FontApiParser');
|
5
5
|
goog.require('webfont.FontWatchRunner');
|
6
|
+
goog.require('webfont.StyleSheetWaiter');
|
6
7
|
|
7
8
|
/**
|
8
9
|
* @constructor
|
@@ -22,6 +23,7 @@ webfont.modules.google.GoogleFontApi.NAME = 'google';
|
|
22
23
|
goog.scope(function () {
|
23
24
|
var GoogleFontApi = webfont.modules.google.GoogleFontApi,
|
24
25
|
FontWatchRunner = webfont.FontWatchRunner,
|
26
|
+
StyleSheetWaiter = webfont.StyleSheetWaiter,
|
25
27
|
FontApiUrlBuilder = webfont.modules.google.FontApiUrlBuilder,
|
26
28
|
FontApiParser = webfont.modules.google.FontApiParser;
|
27
29
|
|
@@ -32,6 +34,7 @@ goog.scope(function () {
|
|
32
34
|
};
|
33
35
|
|
34
36
|
GoogleFontApi.prototype.load = function(onReady) {
|
37
|
+
var waiter = new StyleSheetWaiter();
|
35
38
|
var domHelper = this.domHelper_;
|
36
39
|
var fontApiUrlBuilder = new FontApiUrlBuilder(
|
37
40
|
this.configuration_['api'],
|
@@ -44,7 +47,9 @@ goog.scope(function () {
|
|
44
47
|
var fontApiParser = new FontApiParser(fontFamilies);
|
45
48
|
fontApiParser.parse();
|
46
49
|
|
47
|
-
domHelper.loadStylesheet(fontApiUrlBuilder.build());
|
48
|
-
|
50
|
+
domHelper.loadStylesheet(fontApiUrlBuilder.build(), waiter.startWaitingLoad());
|
51
|
+
waiter.waitWhileNeededThen(function() {
|
52
|
+
onReady(fontApiParser.getFonts(), fontApiParser.getFontTestStrings(), GoogleFontApi.METRICS_COMPATIBLE_FONTS);
|
53
|
+
});
|
49
54
|
};
|
50
55
|
});
|
data/src/modules.yml
CHANGED
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.6.
|
17
|
-
s.date = '2015-
|
16
|
+
s.version = '1.6.8'
|
17
|
+
s.date = '2015-10-01'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -158,6 +158,7 @@ DESC
|
|
158
158
|
src/core/fontwatchrunner.js
|
159
159
|
src/core/initialize.js
|
160
160
|
src/core/nativefontwatchrunner.js
|
161
|
+
src/core/stylesheetwaiter.js
|
161
162
|
src/core/webfont.js
|
162
163
|
src/modules.yml
|
163
164
|
src/modules/custom.js
|
data/webfontloader.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
/* Web Font Loader v1.6.
|
2
|
-
(function(){function aa(a,b,c){return a.call.apply(a.bind,arguments)}function ba(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function n(a,b,c){n=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?aa:ba;return n.apply(null,arguments)}var p=Date.now||function(){return+new Date};function
|
1
|
+
/* Web Font Loader v1.6.8 - (c) Adobe Systems, Google. License: Apache 2.0 */
|
2
|
+
(function(){function aa(a,b,c){return a.call.apply(a.bind,arguments)}function ba(a,b,c){if(!a)throw Error();if(2<arguments.length){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}return function(){return a.apply(b,arguments)}}function n(a,b,c){n=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?aa:ba;return n.apply(null,arguments)}var p=Date.now||function(){return+new Date};function q(a,b){this.F=a;this.k=b||a;this.H=this.k.document}var ca=!!window.FontFace;q.prototype.createElement=function(a,b,c){a=this.H.createElement(a);if(b)for(var d in b)b.hasOwnProperty(d)&&("style"==d?a.style.cssText=b[d]:a.setAttribute(d,b[d]));c&&a.appendChild(this.H.createTextNode(c));return a};function s(a,b,c){a=a.H.getElementsByTagName(b)[0];a||(a=document.documentElement);a.insertBefore(c,a.lastChild)}
|
3
3
|
function t(a,b,c){b=b||[];c=c||[];for(var d=a.className.split(/\s+/),e=0;e<b.length;e+=1){for(var f=!1,g=0;g<d.length;g+=1)if(b[e]===d[g]){f=!0;break}f||d.push(b[e])}b=[];for(e=0;e<d.length;e+=1){f=!1;for(g=0;g<c.length;g+=1)if(d[e]===c[g]){f=!0;break}f||b.push(d[e])}a.className=b.join(" ").replace(/\s+/g," ").replace(/^\s+|\s+$/,"")}function u(a,b){for(var c=a.className.split(/\s+/),d=0,e=c.length;d<e;d++)if(c[d]==b)return!0;return!1}
|
4
|
-
function v(a){if("string"===typeof a.
|
5
|
-
function
|
6
|
-
function G(a
|
7
|
-
|
8
|
-
var
|
9
|
-
function
|
10
|
-
|
11
|
-
function
|
12
|
-
|
13
|
-
var
|
14
|
-
|
15
|
-
c=c?c.split(","):f,0<c.length&&(c=
|
16
|
-
W.prototype.load=function(a){var b=this.c.id,c=this.a.
|
17
|
-
Y.prototype.load=function(a){function b(){if(e["__mti_fntLst"+c]){var d=e["__mti_fntLst"+c](),g=[],l;if(d)for(var h=0;h<d.length;h++){var k=d[h].fontfamily;void 0!=d[h].fontStyle&&void 0!=d[h].fontWeight?(l=d[h].fontStyle+d[h].fontWeight,g.push(new
|
4
|
+
function v(a){if("string"===typeof a.fa)return a.fa;var b=a.k.location.protocol;"about:"==b&&(b=a.F.location.protocol);return"https:"==b?"https:":"http:"}function x(a,b,c){b=a.createElement("link",{rel:"stylesheet",href:b,media:"all"});var d=!1;ca?(b.onload=function(){d||(d=!0,c&&c(null))},b.onerror=function(){d||(d=!0,c&&c(Error("Stylesheet failed to load")))}):setTimeout(function(){c&&c(null)},0);s(a,"head",b)}
|
5
|
+
function y(a,b,c,d){var e=a.H.getElementsByTagName("head")[0];if(e){var f=a.createElement("script",{src:b}),g=!1;f.onload=f.onreadystatechange=function(){g||this.readyState&&"loaded"!=this.readyState&&"complete"!=this.readyState||(g=!0,c&&c(null),f.onload=f.onreadystatechange=null,"HEAD"==f.parentNode.tagName&&e.removeChild(f))};e.appendChild(f);setTimeout(function(){g||(g=!0,c&&c(Error("Script load timeout")))},d||5E3);return f}return null};function z(){this.S=0;this.K=null}function A(a){a.S++;return function(){a.S--;B(a)}}function C(a,b){a.K=b;B(a)}function B(a){0==a.S&&a.K&&(a.K(),a.K=null)};function D(a){this.ea=a||"-"}D.prototype.d=function(a){for(var b=[],c=0;c<arguments.length;c++)b.push(arguments[c].replace(/[\W_]+/g,"").toLowerCase());return b.join(this.ea)};function E(a,b){this.Q=a;this.M=4;this.L="n";var c=(b||"n4").match(/^([nio])([1-9])$/i);c&&(this.L=c[1],this.M=parseInt(c[2],10))}E.prototype.getName=function(){return this.Q};function da(a){return G(a)+" "+(a.M+"00")+" 300px "+H(a.Q)}function H(a){var b=[];a=a.split(/,\s*/);for(var c=0;c<a.length;c++){var d=a[c].replace(/['"]/g,"");-1==d.indexOf(" ")?b.push(d):b.push("'"+d+"'")}return b.join(",")}function I(a){return a.L+a.M}
|
6
|
+
function G(a){var b="normal";"o"===a.L?b="oblique":"i"===a.L&&(b="italic");return b}function ea(a){var b=4,c="n",d=null;a&&((d=a.match(/(normal|oblique|italic)/i))&&d[1]&&(c=d[1].substr(0,1).toLowerCase()),(d=a.match(/([1-9]00|normal|bold)/i))&&d[1]&&(/bold/i.test(d[1])?b=7:/[1-9]00/.test(d[1])&&(b=parseInt(d[1].substr(0,1),10))));return c+b};function fa(a,b){this.a=a;this.j=a.k.document.documentElement;this.O=b;this.g="wf";this.e=new D("-");this.da=!1!==b.events;this.u=!1!==b.classes}function ga(a){a.u&&t(a.j,[a.e.d(a.g,"loading")]);J(a,"loading")}function K(a){if(a.u){var b=u(a.j,a.e.d(a.g,"active")),c=[],d=[a.e.d(a.g,"loading")];b||c.push(a.e.d(a.g,"inactive"));t(a.j,c,d)}J(a,"inactive")}function J(a,b,c){if(a.da&&a.O[b])if(c)a.O[b](c.getName(),I(c));else a.O[b]()};function ha(){this.t={}}function ia(a,b,c){var d=[],e;for(e in b)if(b.hasOwnProperty(e)){var f=a.t[e];f&&d.push(f(b[e],c))}return d};function L(a,b){this.a=a;this.h=b;this.m=this.a.createElement("span",{"aria-hidden":"true"},this.h)}function M(a,b){var c=a.m,d;d="display:block;position:absolute;top:-9999px;left:-9999px;font-size:300px;width:auto;height:auto;line-height:normal;margin:0;padding:0;font-variant:normal;white-space:nowrap;font-family:"+H(b.Q)+";"+("font-style:"+G(b)+";font-weight:"+(b.M+"00")+";");c.style.cssText=d}function N(a){s(a.a,"body",a.m)}L.prototype.remove=function(){var a=this.m;a.parentNode&&a.parentNode.removeChild(a)};function O(a,b,c,d,e,f){this.G=a;this.J=b;this.f=d;this.a=c;this.v=e||3E3;this.h=f||void 0}O.prototype.start=function(){var a=this.a.k.document,b=this;Promise.race([new Promise(function(a,d){setTimeout(function(){d(b.f)},b.v)}),a.fonts.load(da(this.f),this.h)]).then(function(a){1===a.length?b.G(b.f):b.J(b.f)},function(){b.J(b.f)})};function P(a,b,c,d,e,f,g){this.G=a;this.J=b;this.a=c;this.f=d;this.h=g||"BESbswy";this.s={};this.v=e||3E3;this.Z=f||null;this.D=this.C=this.A=this.w=null;this.w=new L(this.a,this.h);this.A=new L(this.a,this.h);this.C=new L(this.a,this.h);this.D=new L(this.a,this.h);M(this.w,new E(this.f.getName()+",serif",I(this.f)));M(this.A,new E(this.f.getName()+",sans-serif",I(this.f)));M(this.C,new E("serif",I(this.f)));M(this.D,new E("sans-serif",I(this.f)));N(this.w);N(this.A);N(this.C);N(this.D)}
|
7
|
+
var Q={ia:"serif",ha:"sans-serif"},R=null;function S(){if(null===R){var a=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent);R=!!a&&(536>parseInt(a[1],10)||536===parseInt(a[1],10)&&11>=parseInt(a[2],10))}return R}P.prototype.start=function(){this.s.serif=this.C.m.offsetWidth;this.s["sans-serif"]=this.D.m.offsetWidth;this.ga=p();T(this)};function ja(a,b,c){for(var d in Q)if(Q.hasOwnProperty(d)&&b===a.s[Q[d]]&&c===a.s[Q[d]])return!0;return!1}
|
8
|
+
function T(a){var b=a.w.m.offsetWidth,c=a.A.m.offsetWidth,d;(d=b===a.s.serif&&c===a.s["sans-serif"])||(d=S()&&ja(a,b,c));d?p()-a.ga>=a.v?S()&&ja(a,b,c)&&(null===a.Z||a.Z.hasOwnProperty(a.f.getName()))?U(a,a.G):U(a,a.J):ka(a):U(a,a.G)}function ka(a){setTimeout(n(function(){T(this)},a),50)}function U(a,b){setTimeout(n(function(){this.w.remove();this.A.remove();this.C.remove();this.D.remove();b(this.f)},a),0)};function V(a,b,c){this.a=a;this.p=b;this.P=0;this.ba=this.Y=!1;this.v=c}var la=!!window.FontFace;V.prototype.V=function(a){var b=this.p;b.u&&t(b.j,[b.e.d(b.g,a.getName(),I(a).toString(),"active")],[b.e.d(b.g,a.getName(),I(a).toString(),"loading"),b.e.d(b.g,a.getName(),I(a).toString(),"inactive")]);J(b,"fontactive",a);this.ba=!0;ma(this)};
|
9
|
+
V.prototype.W=function(a){var b=this.p;if(b.u){var c=u(b.j,b.e.d(b.g,a.getName(),I(a).toString(),"active")),d=[],e=[b.e.d(b.g,a.getName(),I(a).toString(),"loading")];c||d.push(b.e.d(b.g,a.getName(),I(a).toString(),"inactive"));t(b.j,d,e)}J(b,"fontinactive",a);ma(this)};function ma(a){0==--a.P&&a.Y&&(a.ba?(a=a.p,a.u&&t(a.j,[a.e.d(a.g,"active")],[a.e.d(a.g,"loading"),a.e.d(a.g,"inactive")]),J(a,"active")):K(a.p))};function na(a){this.F=a;this.q=new ha;this.$=0;this.T=this.U=!0}na.prototype.load=function(a){this.a=new q(this.F,a.context||this.F);this.U=!1!==a.events;this.T=!1!==a.classes;oa(this,new fa(this.a,a),a)};
|
10
|
+
function pa(a,b,c,d,e){var f=0==--a.$;(a.T||a.U)&&setTimeout(function(){var a=e||null,l=d||null||{};if(0===c.length&&f)K(b.p);else{b.P+=c.length;f&&(b.Y=f);var h,k=[];for(h=0;h<c.length;h++){var m=c[h],w=l[m.getName()],r=b.p,F=m;r.u&&t(r.j,[r.e.d(r.g,F.getName(),I(F).toString(),"loading")]);J(r,"fontloading",F);r=null;r=la?new O(n(b.V,b),n(b.W,b),b.a,m,b.v,w):new P(n(b.V,b),n(b.W,b),b.a,m,b.v,a,w);k.push(r)}for(h=0;h<k.length;h++)k[h].start()}},0)}
|
11
|
+
function oa(a,b,c){var d=[],e=c.timeout;ga(b);var d=ia(a.q,c,a.a),f=new V(a.a,b,e);a.$=d.length;b=0;for(c=d.length;b<c;b++)d[b].load(function(b,c,d){pa(a,f,b,c,d)})};function qa(a,b,c){this.N=a?a:b+ra;this.o=[];this.R=[];this.ca=c||""}var ra="//fonts.googleapis.com/css";function sa(a,b){for(var c=b.length,d=0;d<c;d++){var e=b[d].split(":");3==e.length&&a.R.push(e.pop());var f="";2==e.length&&""!=e[1]&&(f=":");a.o.push(e.join(f))}}
|
12
|
+
qa.prototype.d=function(){if(0==this.o.length)throw Error("No fonts to load!");if(-1!=this.N.indexOf("kit="))return this.N;for(var a=this.o.length,b=[],c=0;c<a;c++)b.push(this.o[c].replace(/ /g,"+"));a=this.N+"?family="+b.join("%7C");0<this.R.length&&(a+="&subset="+this.R.join(","));0<this.ca.length&&(a+="&text="+encodeURIComponent(this.ca));return a};function ta(a){this.o=a;this.aa=[];this.I={}}
|
13
|
+
var ua={latin:"BESbswy",cyrillic:"йяЖ",greek:"αβΣ",khmer:"កខគ",Hanuman:"កខគ"},va={thin:"1",extralight:"2","extra-light":"2",ultralight:"2","ultra-light":"2",light:"3",regular:"4",book:"4",medium:"5","semi-bold":"6",semibold:"6","demi-bold":"6",demibold:"6",bold:"7","extra-bold":"8",extrabold:"8","ultra-bold":"8",ultrabold:"8",black:"9",heavy:"9",l:"3",r:"4",b:"7"},wa={i:"i",italic:"i",n:"n",normal:"n"},xa=/^(thin|(?:(?:extra|ultra)-?)?light|regular|book|medium|(?:(?:semi|demi|extra|ultra)-?)?bold|black|heavy|l|r|b|[1-9]00)?(n|i|normal|italic)?$/;
|
14
|
+
ta.prototype.parse=function(){for(var a=this.o.length,b=0;b<a;b++){var c=this.o[b].split(":"),d=c[0].replace(/\+/g," "),e=["n4"];if(2<=c.length){var f;var g=c[1];f=[];if(g)for(var g=g.split(","),l=g.length,h=0;h<l;h++){var k;k=g[h];if(k.match(/^[\w-]+$/))if(k=xa.exec(k.toLowerCase()),null==k)k="";else{var m;m=k[1];if(null==m||""==m)m="4";else{var w=va[m];m=w?w:isNaN(m)?"4":m.substr(0,1)}k=k[2];k=[null==k||""==k?"n":wa[k],m].join("")}else k="";k&&f.push(k)}0<f.length&&(e=f);3==c.length&&(c=c[2],f=
|
15
|
+
[],c=c?c.split(","):f,0<c.length&&(c=ua[c[0]])&&(this.I[d]=c))}this.I[d]||(c=ua[d])&&(this.I[d]=c);for(c=0;c<e.length;c+=1)this.aa.push(new E(d,e[c]))}};function ya(a,b){this.a=a;this.c=b}var za={Arimo:!0,Cousine:!0,Tinos:!0};ya.prototype.load=function(a){var b=new z,c=this.a,d=new qa(this.c.api,v(c),this.c.text),e=this.c.families;sa(d,e);var f=new ta(e);f.parse();x(c,d.d(),A(b));C(b,function(){a(f.aa,f.I,za)})};function W(a,b){this.a=a;this.c=b;this.X=[]}W.prototype.B=function(a){var b=this.a;return v(this.a)+(this.c.api||"//f.fontdeck.com/s/css/js/")+(b.k.location.hostname||b.F.location.hostname)+"/"+a+".js"};
|
16
|
+
W.prototype.load=function(a){var b=this.c.id,c=this.a.k,d=this;b?(c.__webfontfontdeckmodule__||(c.__webfontfontdeckmodule__={}),c.__webfontfontdeckmodule__[b]=function(b,c){for(var g=0,l=c.fonts.length;g<l;++g){var h=c.fonts[g];d.X.push(new E(h.name,ea("font-weight:"+h.weight+";font-style:"+h.style)))}a(d.X)},y(this.a,this.B(b),function(b){b&&a([])})):a([])};function X(a,b){this.a=a;this.c=b}X.prototype.B=function(a){return(this.c.api||"https://use.typekit.net")+"/"+a+".js"};X.prototype.load=function(a){var b=this.c.id,c=this.a.k;b?y(this.a,this.B(b),function(b){if(b)a([]);else if(c.Typekit&&c.Typekit.config&&c.Typekit.config.fn){b=c.Typekit.config.fn;for(var e=[],f=0;f<b.length;f+=2)for(var g=b[f],l=b[f+1],h=0;h<l.length;h++)e.push(new E(g,l[h]));try{c.Typekit.load({events:!1,classes:!1,async:!0})}catch(k){}a(e)}},2E3):a([])};function Y(a,b){this.a=a;this.c=b}Y.prototype.B=function(a,b){var c=v(this.a),d=(this.c.api||"fast.fonts.net/jsapi").replace(/^.*http(s?):(\/\/)?/,"");return c+"//"+d+"/"+a+".js"+(b?"?v="+b:"")};
|
17
|
+
Y.prototype.load=function(a){function b(){if(e["__mti_fntLst"+c]){var d=e["__mti_fntLst"+c](),g=[],l;if(d)for(var h=0;h<d.length;h++){var k=d[h].fontfamily;void 0!=d[h].fontStyle&&void 0!=d[h].fontWeight?(l=d[h].fontStyle+d[h].fontWeight,g.push(new E(k,l))):g.push(new E(k))}a(g)}else setTimeout(function(){b()},50)}var c=this.c.projectId,d=this.c.version;if(c){var e=this.a.k;y(this.a,this.B(c,d),function(c){c?a([]):b()}).id="__MonotypeAPIScript__"+c}else a([])};function Aa(a,b){this.a=a;this.c=b}Aa.prototype.load=function(a){var b,c,d=this.c.urls||[],e=this.c.families||[],f=this.c.testStrings||{},g=new z;b=0;for(c=d.length;b<c;b++)x(this.a,d[b],A(g));var l=[];b=0;for(c=e.length;b<c;b++)if(d=e[b].split(":"),d[1])for(var h=d[1].split(","),k=0;k<h.length;k+=1)l.push(new E(d[0],h[k]));else l.push(new E(d[0]));C(g,function(){a(l,f)})};var Z=new na(window);Z.q.t.custom=function(a,b){return new Aa(b,a)};Z.q.t.fontdeck=function(a,b){return new W(b,a)};Z.q.t.monotype=function(a,b){return new Y(b,a)};Z.q.t.typekit=function(a,b){return new X(b,a)};Z.q.t.google=function(a,b){return new ya(b,a)};var $={load:n(Z.load,Z)};"function"===typeof define&&define.amd?define(function(){return $}):"undefined"!==typeof module&&module.exports?module.exports=$:(window.WebFont=$,window.WebFontConfig&&Z.load(window.WebFontConfig));}());
|
18
18
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Carver
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- src/core/fontwatchrunner.js
|
168
168
|
- src/core/initialize.js
|
169
169
|
- src/core/nativefontwatchrunner.js
|
170
|
+
- src/core/stylesheetwaiter.js
|
170
171
|
- src/core/webfont.js
|
171
172
|
- src/modules.yml
|
172
173
|
- src/modules/custom.js
|