webfontloader 1.0.31 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/README.md +20 -3
- data/lib/webfontloader/demo/public/ascender-iframe.html +46 -0
- data/lib/webfontloader/demo/public/blank.html +9 -0
- data/lib/webfontloader/demo/public/custom-iframe.html +41 -0
- data/lib/webfontloader/demo/public/custom.html +10 -10
- data/lib/webfontloader/demo/public/google-iframe.html +40 -0
- data/lib/webfontloader/demo/public/index.html +15 -2
- data/lib/webfontloader/demo/public/monotype-iframe.html +46 -0
- data/lib/webfontloader/demo/public/typekit-iframe.html +41 -0
- data/lib/webfontloader/demo/public/typekit.html +7 -9
- data/lib/webfontloader.rb +1 -1
- data/src/ascender/ascender_script.js +2 -3
- data/src/core/domhelper.js +36 -4
- data/src/core/font.js +12 -6
- data/src/core/fontmoduleloader.js +2 -2
- data/src/core/initialize.js +2 -3
- data/src/custom/customcss.js +1 -2
- data/src/fontdeck/fontdeck_script.js +12 -10
- data/src/google/fontapiurlbuilder.js +1 -3
- data/src/google/googlefontapi.js +3 -4
- data/src/monotype/monotype_script.js +8 -25
- data/src/typekit/typekit_script.js +9 -10
- data/src-test/ascender/ascender_script_test.js +3 -0
- data/src-test/core/domhelpertest.js +44 -1
- data/src-test/core/eventdispatchertest.js +1 -1
- data/src-test/core/fonttest.js +53 -28
- data/src-test/fontdeck/fontdeck_script_test.js +26 -16
- data/src-test/google/fontapiurlbuildertest.js +5 -5
- data/src-test/google/googlefontapitest.js +12 -0
- data/src-test/monotype/monotype_script_test.js +36 -62
- data/src-test/typekit/typekit_script_test.js +30 -6
- data/webfontloader.gemspec +8 -2
- metadata +10 -4
data/src/core/domhelper.js
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
/**
|
2
2
|
* Handles common DOM manipulation tasks. The aim of this library is to cover
|
3
3
|
* the needs of typical font loading. Not more, not less.
|
4
|
-
* @param {
|
4
|
+
* @param {Window} mainWindow The main window webfontloader.js is loaded in.
|
5
|
+
* @param {Window=} opt_loadWindow The window we'll load the font into. By
|
6
|
+
* default, the main window is used.
|
5
7
|
* @constructor
|
6
8
|
*/
|
7
|
-
webfont.DomHelper = function(
|
8
|
-
this.
|
9
|
+
webfont.DomHelper = function(mainWindow, opt_loadWindow) {
|
10
|
+
this.mainWindow_ = mainWindow;
|
11
|
+
this.loadWindow_ = opt_loadWindow || mainWindow;
|
12
|
+
|
13
|
+
/** @type {Document} */
|
14
|
+
this.document_ = this.loadWindow_.document;
|
9
15
|
|
10
16
|
/** @type {boolean|undefined} */
|
11
17
|
this.supportForStyle_ = undefined;
|
@@ -28,7 +34,7 @@ webfont.DomHelper.prototype.createElement = function(elem, opt_attr,
|
|
28
34
|
if (opt_attr.hasOwnProperty(attr)) {
|
29
35
|
if (attr == "style") {
|
30
36
|
this.setStyle(domElement, opt_attr[attr]);
|
31
|
-
|
37
|
+
} else {
|
32
38
|
domElement.setAttribute(attr, opt_attr[attr]);
|
33
39
|
}
|
34
40
|
}
|
@@ -194,3 +200,29 @@ webfont.DomHelper.prototype.hasSupportForStyle_ = function() {
|
|
194
200
|
}
|
195
201
|
return this.supportForStyle_
|
196
202
|
};
|
203
|
+
|
204
|
+
/**
|
205
|
+
* @return {Window} The main window webfontloader.js is loaded in (for config).
|
206
|
+
*/
|
207
|
+
webfont.DomHelper.prototype.getMainWindow = function() {
|
208
|
+
return this.mainWindow_;
|
209
|
+
};
|
210
|
+
|
211
|
+
/**
|
212
|
+
* @return {Window} The window that we're loading the font(s) into.
|
213
|
+
*/
|
214
|
+
webfont.DomHelper.prototype.getLoadWindow = function() {
|
215
|
+
return this.loadWindow_;
|
216
|
+
};
|
217
|
+
|
218
|
+
/**
|
219
|
+
* @return {string} The protocol (http: or https:) to request resources in.
|
220
|
+
*/
|
221
|
+
webfont.DomHelper.prototype.getProtocol = function() {
|
222
|
+
var protocol = this.loadWindow_.location.protocol;
|
223
|
+
// For empty iframes, fallback to main window's protocol.
|
224
|
+
if (protocol == 'about:') {
|
225
|
+
protocol = this.mainWindow_.location.protocol;
|
226
|
+
}
|
227
|
+
return protocol == 'https:' ? 'https:' : 'http:';
|
228
|
+
};
|
data/src/core/font.js
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
/**
|
2
|
+
* @param {Window} mainWindow The main application window containing
|
3
|
+
* webfontloader.js.
|
4
|
+
* @param {webfont.FontModuleLoader} fontModuleLoader A loader instance to use.
|
5
|
+
* @param {function(function(), number=)} asyncCall An async function to use.
|
6
|
+
* @param {webfont.UserAgent} userAgent The detected user agent to load for.
|
2
7
|
* @constructor
|
3
8
|
*/
|
4
|
-
webfont.WebFont = function(
|
5
|
-
|
6
|
-
this.domHelper_ = domHelper;
|
9
|
+
webfont.WebFont = function(mainWindow, fontModuleLoader, asyncCall, userAgent) {
|
10
|
+
this.mainWindow_ = mainWindow;
|
7
11
|
this.fontModuleLoader_ = fontModuleLoader;
|
8
|
-
this.htmlElement_ = htmlElement;
|
9
12
|
this.asyncCall_ = asyncCall;
|
10
13
|
this.userAgent_ = userAgent;
|
11
14
|
this.moduleLoading_ = 0;
|
@@ -17,8 +20,11 @@ webfont.WebFont.prototype.addModule = function(name, factory) {
|
|
17
20
|
};
|
18
21
|
|
19
22
|
webfont.WebFont.prototype.load = function(configuration) {
|
23
|
+
var context = configuration['context'] || this.mainWindow_;
|
24
|
+
this.domHelper_ = new webfont.DomHelper(this.mainWindow_, context);
|
25
|
+
|
20
26
|
var eventDispatcher = new webfont.EventDispatcher(
|
21
|
-
this.domHelper_,
|
27
|
+
this.domHelper_, context.document.documentElement, configuration);
|
22
28
|
|
23
29
|
if (this.userAgent_.isSupportingWebFont()) {
|
24
30
|
this.load_(eventDispatcher, configuration);
|
@@ -66,7 +72,7 @@ webfont.WebFont.prototype.onModuleReady_ = function(eventDispatcher, fontWatcher
|
|
66
72
|
};
|
67
73
|
|
68
74
|
webfont.WebFont.prototype.load_ = function(eventDispatcher, configuration) {
|
69
|
-
var modules = this.fontModuleLoader_.getModules(configuration),
|
75
|
+
var modules = this.fontModuleLoader_.getModules(configuration, this.domHelper_),
|
70
76
|
self = this;
|
71
77
|
|
72
78
|
this.moduleFailedLoading_ = this.moduleLoading_ = modules.length;
|
@@ -9,7 +9,7 @@ webfont.FontModuleLoader.prototype.addModuleFactory = function(name, factory) {
|
|
9
9
|
this.modules_[name] = factory;
|
10
10
|
};
|
11
11
|
|
12
|
-
webfont.FontModuleLoader.prototype.getModules = function(configuration) {
|
12
|
+
webfont.FontModuleLoader.prototype.getModules = function(configuration, domHelper) {
|
13
13
|
var modules = [];
|
14
14
|
|
15
15
|
for (var key in configuration) {
|
@@ -17,7 +17,7 @@ webfont.FontModuleLoader.prototype.getModules = function(configuration) {
|
|
17
17
|
var moduleFactory = this.modules_[key];
|
18
18
|
|
19
19
|
if (moduleFactory) {
|
20
|
-
modules.push(moduleFactory(configuration[key]));
|
20
|
+
modules.push(moduleFactory(configuration[key], domHelper));
|
21
21
|
}
|
22
22
|
}
|
23
23
|
}
|
data/src/core/initialize.js
CHANGED
@@ -5,11 +5,10 @@ var globalName = 'WebFont';
|
|
5
5
|
var globalNamespaceObject = window[globalName] = (function() {
|
6
6
|
var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
|
7
7
|
var userAgent = userAgentParser.parse();
|
8
|
-
var
|
8
|
+
var fontModuleLoader = new webfont.FontModuleLoader();
|
9
9
|
var asyncCall = function(func, timeout) { setTimeout(func, timeout); };
|
10
10
|
|
11
|
-
return new webfont.WebFont(
|
12
|
-
document.documentElement, asyncCall, userAgent);
|
11
|
+
return new webfont.WebFont(window, fontModuleLoader, asyncCall, userAgent);
|
13
12
|
})();
|
14
13
|
|
15
14
|
// Export the public API.
|
data/src/custom/customcss.js
CHANGED
@@ -31,7 +31,6 @@ webfont.CustomCss.prototype.supportUserAgent = function(userAgent, support) {
|
|
31
31
|
return support(userAgent.isSupportingWebFont());
|
32
32
|
};
|
33
33
|
|
34
|
-
globalNamespaceObject.addModule(webfont.CustomCss.NAME, function(configuration) {
|
35
|
-
var domHelper = new webfont.DomHelper(document);
|
34
|
+
globalNamespaceObject.addModule(webfont.CustomCss.NAME, function(configuration, domHelper) {
|
36
35
|
return new webfont.CustomCss(domHelper, configuration);
|
37
36
|
});
|
@@ -1,8 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @constructor
|
3
3
|
*/
|
4
|
-
webfont.FontdeckScript = function(
|
5
|
-
this.global_ = global;
|
4
|
+
webfont.FontdeckScript = function(domHelper, configuration) {
|
6
5
|
this.domHelper_ = domHelper;
|
7
6
|
this.configuration_ = configuration;
|
8
7
|
this.fontFamilies_ = [];
|
@@ -15,24 +14,28 @@ webfont.FontdeckScript.HOOK = '__webfontfontdeckmodule__';
|
|
15
14
|
webfont.FontdeckScript.API = '//f.fontdeck.com/s/css/js/';
|
16
15
|
|
17
16
|
webfont.FontdeckScript.prototype.getScriptSrc = function(projectId) {
|
18
|
-
var protocol =
|
17
|
+
var protocol = this.domHelper_.getProtocol();
|
18
|
+
// For empty iframes, fall back to main window's hostname.
|
19
|
+
var hostname = this.domHelper_.getLoadWindow().location.hostname ||
|
20
|
+
this.domHelper_.getMainWindow().location.hostname;
|
19
21
|
var api = this.configuration_['api'] || webfont.FontdeckScript.API;
|
20
|
-
return protocol + api +
|
22
|
+
return protocol + api + hostname + '/' + projectId + '.js';
|
21
23
|
};
|
22
24
|
|
23
25
|
webfont.FontdeckScript.prototype.supportUserAgent = function(userAgent, support) {
|
24
26
|
var projectId = this.configuration_['id'];
|
27
|
+
var loadWindow = this.domHelper_.getLoadWindow();
|
25
28
|
var self = this;
|
26
29
|
|
27
30
|
if (projectId) {
|
28
31
|
// Provide data to Fontdeck for processing.
|
29
|
-
if (!
|
30
|
-
|
32
|
+
if (!loadWindow[webfont.FontdeckScript.HOOK]) {
|
33
|
+
loadWindow[webfont.FontdeckScript.HOOK] = {};
|
31
34
|
}
|
32
35
|
|
33
36
|
// Fontdeck will call this function to indicate support status
|
34
37
|
// and what fonts are provided.
|
35
|
-
|
38
|
+
loadWindow[webfont.FontdeckScript.HOOK][projectId] = function(fontdeckSupports, data) {
|
36
39
|
for (var i = 0, j = data['fonts'].length; i<j; ++i) {
|
37
40
|
var font = data['fonts'][i];
|
38
41
|
// Add the FVDs
|
@@ -55,7 +58,6 @@ webfont.FontdeckScript.prototype.load = function(onReady) {
|
|
55
58
|
onReady(this.fontFamilies_, this.fontVariations_);
|
56
59
|
};
|
57
60
|
|
58
|
-
globalNamespaceObject.addModule(webfont.FontdeckScript.NAME, function(configuration) {
|
59
|
-
|
60
|
-
return new webfont.FontdeckScript(window, domHelper, configuration);
|
61
|
+
globalNamespaceObject.addModule(webfont.FontdeckScript.NAME, function(configuration, domHelper) {
|
62
|
+
return new webfont.FontdeckScript(domHelper, configuration);
|
61
63
|
});
|
@@ -1,12 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* @constructor
|
3
3
|
*/
|
4
|
-
webfont.FontApiUrlBuilder = function(apiUrl) {
|
4
|
+
webfont.FontApiUrlBuilder = function(apiUrl, protocol) {
|
5
5
|
if (apiUrl) {
|
6
6
|
this.apiUrl_ = apiUrl;
|
7
7
|
} else {
|
8
|
-
var protocol = 'https:' == window.location.protocol ? 'https:' : 'http:';
|
9
|
-
|
10
8
|
this.apiUrl_ = protocol + webfont.FontApiUrlBuilder.DEFAULT_API_URL;
|
11
9
|
}
|
12
10
|
this.fontFamilies_ = [];
|
data/src/google/googlefontapi.js
CHANGED
@@ -35,7 +35,7 @@ webfont.GoogleFontApi.prototype.load = function(onReady) {
|
|
35
35
|
webfont.GoogleFontApi.prototype.insertLink_ = function(onReady) {
|
36
36
|
var domHelper = this.domHelper_;
|
37
37
|
var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(
|
38
|
-
this.configuration_['api']);
|
38
|
+
this.configuration_['api'], domHelper.getProtocol());
|
39
39
|
var fontFamilies = this.configuration_['families'];
|
40
40
|
fontApiUrlBuilder.setFontFamilies(fontFamilies);
|
41
41
|
|
@@ -48,9 +48,8 @@ webfont.GoogleFontApi.prototype.insertLink_ = function(onReady) {
|
|
48
48
|
fontApiParser.getFontTestStrings());
|
49
49
|
};
|
50
50
|
|
51
|
-
globalNamespaceObject.addModule(webfont.GoogleFontApi.NAME, function(configuration) {
|
51
|
+
globalNamespaceObject.addModule(webfont.GoogleFontApi.NAME, function(configuration, domHelper) {
|
52
52
|
var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
|
53
53
|
var userAgent = userAgentParser.parse();
|
54
|
-
return new webfont.GoogleFontApi(userAgent,
|
55
|
-
configuration);
|
54
|
+
return new webfont.GoogleFontApi(userAgent, domHelper, configuration);
|
56
55
|
});
|
@@ -9,11 +9,9 @@ projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'//this is your Fonts.com Web fo
|
|
9
9
|
/**
|
10
10
|
* @constructor
|
11
11
|
*/
|
12
|
-
webfont.MonotypeScript = function (
|
13
|
-
this.global_ = global;
|
12
|
+
webfont.MonotypeScript = function (userAgent, domHelper, configuration) {
|
14
13
|
this.userAgent_ = userAgent;
|
15
14
|
this.domHelper_ = domHelper;
|
16
|
-
this.doc_ = doc;
|
17
15
|
this.configuration_ = configuration;
|
18
16
|
this.fontFamilies_ = [];
|
19
17
|
this.fontVariations_ = {};
|
@@ -32,7 +30,7 @@ webfont.MonotypeScript.NAME = 'monotype';
|
|
32
30
|
webfont.MonotypeScript.HOOK = '__mti_fntLst';
|
33
31
|
|
34
32
|
/**
|
35
|
-
* __MonotypeAPIScript__ is the id of script added by google API. Currently 'webfonts.fonts.com' supports only one script in a page.
|
33
|
+
* __MonotypeAPIScript__ is the id of script added by google API. Currently 'webfonts.fonts.com' supports only one script in a page.
|
36
34
|
* This may require change in future if 'webfonts.fonts.com' begins supporting multiple scripts per page.
|
37
35
|
* @const
|
38
36
|
*/
|
@@ -52,9 +50,10 @@ webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support
|
|
52
50
|
}
|
53
51
|
};
|
54
52
|
|
53
|
+
var loadWindow = this.domHelper_.getLoadWindow();
|
55
54
|
sc["onload"] = function (e) {
|
56
|
-
if (
|
57
|
-
var mti_fnts =
|
55
|
+
if (loadWindow[webfont.MonotypeScript.HOOK + projectId]) {
|
56
|
+
var mti_fnts = loadWindow[webfont.MonotypeScript.HOOK + projectId]();
|
58
57
|
if (mti_fnts && mti_fnts.length) {
|
59
58
|
var i;
|
60
59
|
for (i = 0; i < mti_fnts.length; i++) {
|
@@ -73,7 +72,7 @@ webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support
|
|
73
72
|
};
|
74
73
|
|
75
74
|
webfont.MonotypeScript.prototype.getScriptSrc = function (projectId) {
|
76
|
-
var p = this.
|
75
|
+
var p = this.domHelper_.getProtocol();
|
77
76
|
var api = (this.configuration_['api'] || 'fast.fonts.com/jsapi').replace(/^.*http(s?):(\/\/)?/, "");
|
78
77
|
return p + "//" + api + '/' + projectId + '.js';
|
79
78
|
};
|
@@ -82,24 +81,8 @@ webfont.MonotypeScript.prototype.load = function (onReady) {
|
|
82
81
|
onReady(this.fontFamilies_, this.fontVariations_);
|
83
82
|
};
|
84
83
|
|
85
|
-
webfont.MonotypeScript.
|
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
|
-
globalNamespaceObject.addModule(webfont.MonotypeScript.NAME, function (configuration) {
|
84
|
+
globalNamespaceObject.addModule(webfont.MonotypeScript.NAME, function (configuration, domHelper) {
|
101
85
|
var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
|
102
86
|
var userAgent = userAgentParser.parse();
|
103
|
-
|
104
|
-
return new webfont.MonotypeScript(window, userAgent, domHelper, document, configuration);
|
87
|
+
return new webfont.MonotypeScript(userAgent, domHelper, configuration);
|
105
88
|
});
|
@@ -1,8 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @constructor
|
3
3
|
*/
|
4
|
-
webfont.TypekitScript = function(
|
5
|
-
this.global_ = global;
|
4
|
+
webfont.TypekitScript = function(domHelper, configuration) {
|
6
5
|
this.domHelper_ = domHelper;
|
7
6
|
this.configuration_ = configuration;
|
8
7
|
this.fontFamilies_ = [];
|
@@ -13,7 +12,7 @@ webfont.TypekitScript.NAME = 'typekit';
|
|
13
12
|
webfont.TypekitScript.HOOK = '__webfonttypekitmodule__';
|
14
13
|
|
15
14
|
webfont.TypekitScript.prototype.getScriptSrc = function(kitId) {
|
16
|
-
var protocol =
|
15
|
+
var protocol = this.domHelper_.getProtocol();
|
17
16
|
var api = this.configuration_['api'] || protocol + '//use.typekit.com';
|
18
17
|
return api + '/' + kitId + '.js';
|
19
18
|
};
|
@@ -21,17 +20,18 @@ webfont.TypekitScript.prototype.getScriptSrc = function(kitId) {
|
|
21
20
|
webfont.TypekitScript.prototype.supportUserAgent = function(userAgent, support) {
|
22
21
|
var kitId = this.configuration_['id'];
|
23
22
|
var configuration = this.configuration_;
|
23
|
+
var loadWindow = this.domHelper_.getLoadWindow();
|
24
24
|
var self = this;
|
25
25
|
|
26
26
|
if (kitId) {
|
27
|
-
// Provide data to Typekit for processing.
|
28
|
-
if (!
|
29
|
-
|
27
|
+
// Provide data to Typekit for processing.main
|
28
|
+
if (!loadWindow[webfont.TypekitScript.HOOK]) {
|
29
|
+
loadWindow[webfont.TypekitScript.HOOK] = {};
|
30
30
|
}
|
31
31
|
|
32
32
|
// Typekit will call 'init' to indicate whether it supports fonts
|
33
33
|
// and what fonts will be provided.
|
34
|
-
|
34
|
+
loadWindow[webfont.TypekitScript.HOOK][kitId] = function(callback) {
|
35
35
|
var init = function(typekitSupports, fontFamilies, fontVariations) {
|
36
36
|
self.fontFamilies_ = fontFamilies;
|
37
37
|
self.fontVariations_ = fontVariations;
|
@@ -53,8 +53,7 @@ webfont.TypekitScript.prototype.load = function(onReady) {
|
|
53
53
|
onReady(this.fontFamilies_, this.fontVariations_);
|
54
54
|
};
|
55
55
|
|
56
|
-
globalNamespaceObject.addModule(webfont.TypekitScript.NAME, function(configuration) {
|
57
|
-
|
58
|
-
return new webfont.TypekitScript(window, domHelper, configuration);
|
56
|
+
globalNamespaceObject.addModule(webfont.TypekitScript.NAME, function(configuration, domHelper) {
|
57
|
+
return new webfont.TypekitScript(domHelper, configuration);
|
59
58
|
});
|
60
59
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
var DomHelperTest = TestCase('DomHelperTest');
|
2
2
|
|
3
3
|
DomHelperTest.prototype.setUp = function() {
|
4
|
-
this.domHelper_ = new webfont.DomHelper(
|
4
|
+
this.domHelper_ = new webfont.DomHelper(window);
|
5
5
|
};
|
6
6
|
|
7
7
|
DomHelperTest.prototype.testCreateElementNoAttr = function() {
|
@@ -106,3 +106,46 @@ DomHelperTest.prototype.testHasSupportForStyle = function() {
|
|
106
106
|
this.domHelper_.supportForStyle_ = true;
|
107
107
|
assertTrue(this.domHelper_.hasSupportForStyle_());
|
108
108
|
};
|
109
|
+
|
110
|
+
DomHelperTest.prototype.testGetWindows = function() {
|
111
|
+
var fakeMainWindow = 'main window';
|
112
|
+
var fakeLoadWindow = 'load window';
|
113
|
+
var domHelper = new webfont.DomHelper(fakeMainWindow, fakeLoadWindow);
|
114
|
+
assertEquals('main window', domHelper.getMainWindow());
|
115
|
+
assertEquals('load window', domHelper.getLoadWindow());
|
116
|
+
};
|
117
|
+
|
118
|
+
DomHelperTest.prototype.testGetProtocol = function() {
|
119
|
+
var fakeWindow = {
|
120
|
+
location: {
|
121
|
+
protocol: 'https:'
|
122
|
+
}
|
123
|
+
};
|
124
|
+
var domHelper = new webfont.DomHelper(fakeWindow);
|
125
|
+
assertEquals('https:', domHelper.getProtocol());
|
126
|
+
};
|
127
|
+
|
128
|
+
DomHelperTest.prototype.testGetProtocolHttpDefault = function() {
|
129
|
+
var fakeWindow = {
|
130
|
+
location: {
|
131
|
+
protocol: 'file:'
|
132
|
+
}
|
133
|
+
};
|
134
|
+
var domHelper = new webfont.DomHelper(fakeWindow);
|
135
|
+
assertEquals('http:', domHelper.getProtocol());
|
136
|
+
};
|
137
|
+
|
138
|
+
DomHelperTest.prototype.testGetProtocolIframeFallback = function() {
|
139
|
+
var fakeMainWindow = {
|
140
|
+
location: {
|
141
|
+
protocol: 'https:'
|
142
|
+
}
|
143
|
+
};
|
144
|
+
var fakeLoadWindow = {
|
145
|
+
location: {
|
146
|
+
protocol: 'about:'
|
147
|
+
}
|
148
|
+
};
|
149
|
+
var domHelper = new webfont.DomHelper(fakeMainWindow, fakeLoadWindow);
|
150
|
+
assertEquals('https:', domHelper.getProtocol());
|
151
|
+
};
|
@@ -15,7 +15,7 @@ EventDispatcherTest.prototype.setUp = function() {
|
|
15
15
|
var self = this;
|
16
16
|
|
17
17
|
this.eventDispatcher_ = new webfont.EventDispatcher(new webfont.DomHelper(
|
18
|
-
|
18
|
+
window), this.fakeHtmlElement_, {
|
19
19
|
loading: function() {
|
20
20
|
self.loadingEventCalled_ = true;
|
21
21
|
},
|
data/src-test/core/fonttest.js
CHANGED
@@ -1,49 +1,38 @@
|
|
1
1
|
var FontTest = TestCase('FontTest');
|
2
2
|
|
3
3
|
FontTest.prototype.setUp = function() {
|
4
|
-
this.fakeHtmlElement_ = { className: '' };
|
5
|
-
this.fakeDomHelper_ = {
|
6
|
-
appendClassName: function() {},
|
7
|
-
removeClassName: function() {},
|
8
|
-
hasClassName: function() {},
|
9
|
-
createElement: function(name) {
|
10
|
-
return document.createElement(name);
|
11
|
-
},
|
12
|
-
insertInto: function() {},
|
13
|
-
removeElement: function() {}
|
14
|
-
};
|
15
4
|
this.fontModuleLoader_ = new webfont.FontModuleLoader();
|
16
5
|
};
|
17
6
|
|
18
7
|
FontTest.prototype.testFontLoad = function() {
|
19
8
|
var userAgent = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2',
|
20
9
|
'Macintosh', '10.6', undefined, true);
|
21
|
-
var font = new webfont.WebFont(
|
22
|
-
|
23
|
-
var self = this;
|
10
|
+
var font = new webfont.WebFont(window, this.fontModuleLoader_,
|
11
|
+
function(func, timeout) { func(); }, userAgent);
|
24
12
|
var testModule = null;
|
25
13
|
|
26
|
-
font.addModule('test', function(conf) {
|
14
|
+
font.addModule('test', function(conf, domHelper) {
|
27
15
|
testModule = new function() {
|
28
16
|
this.conf = conf;
|
17
|
+
this.domHelper = domHelper;
|
29
18
|
this.loadCalled = false;
|
30
19
|
this.supportUserAgentCalled = false;
|
31
|
-
};
|
32
|
-
testModule.load = function(onReady) {
|
33
|
-
this.loadCalled = true;
|
34
|
-
onReady([]);
|
35
20
|
};
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
21
|
+
testModule.load = function(onReady) {
|
22
|
+
this.loadCalled = true;
|
23
|
+
onReady([]);
|
24
|
+
};
|
25
|
+
testModule.supportUserAgent = function(ua, support) {
|
26
|
+
this.supportUserAgentCalled = true;
|
27
|
+
support(true);
|
28
|
+
};
|
29
|
+
return testModule;
|
41
30
|
});
|
42
|
-
var loadingEventCalled = false;
|
43
31
|
|
44
32
|
assertEquals(0, font.moduleFailedLoading_);
|
45
33
|
assertEquals(0, font.moduleLoading_);
|
46
34
|
|
35
|
+
var loadingEventCalled = false;
|
47
36
|
font.load({
|
48
37
|
test: {
|
49
38
|
somedata: 'in french a cow says meuh'
|
@@ -58,17 +47,53 @@ FontTest.prototype.testFontLoad = function() {
|
|
58
47
|
assertNotNull(testModule);
|
59
48
|
assertNotUndefined(testModule.conf);
|
60
49
|
assertNotNull(testModule.conf);
|
50
|
+
assertNotUndefined(testModule.domHelper);
|
51
|
+
assertNotNull(testModule.domHelper);
|
52
|
+
assertSame(window, testModule.domHelper.getMainWindow());
|
53
|
+
assertSame(window, testModule.domHelper.getLoadWindow());
|
61
54
|
assertEquals('in french a cow says meuh', testModule.conf.somedata);
|
62
55
|
assertTrue(testModule.loadCalled);
|
63
56
|
assertTrue(testModule.supportUserAgentCalled);
|
64
57
|
assertTrue(loadingEventCalled);
|
65
58
|
};
|
66
59
|
|
60
|
+
FontTest.prototype.testFontLoadWithContext = function() {
|
61
|
+
var fakeMainWindow = {};
|
62
|
+
|
63
|
+
var userAgent = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2',
|
64
|
+
'Macintosh', '10.6', undefined, true);
|
65
|
+
var font = new webfont.WebFont(fakeMainWindow, this.fontModuleLoader_,
|
66
|
+
function(func, timeout) { func(); }, userAgent);
|
67
|
+
var testModule = null;
|
68
|
+
|
69
|
+
font.addModule('test', function(conf, domHelper) {
|
70
|
+
testModule = new function() {
|
71
|
+
this.domHelper = domHelper;
|
72
|
+
};
|
73
|
+
testModule.load = function() {};
|
74
|
+
testModule.supportUserAgent = function(ua, support) {
|
75
|
+
support(true);
|
76
|
+
};
|
77
|
+
return testModule;
|
78
|
+
});
|
79
|
+
|
80
|
+
font.load({
|
81
|
+
test: {
|
82
|
+
somedata: 'in french a cow says meuh'
|
83
|
+
},
|
84
|
+
context: window
|
85
|
+
});
|
86
|
+
|
87
|
+
assertNotUndefined(testModule.domHelper);
|
88
|
+
assertNotNull(testModule.domHelper);
|
89
|
+
assertSame(fakeMainWindow, testModule.domHelper.getMainWindow());
|
90
|
+
assertSame(window, testModule.domHelper.getLoadWindow());
|
91
|
+
};
|
92
|
+
|
67
93
|
FontTest.prototype.testFontInactive = function() {
|
68
94
|
var userAgent = new webfont.UserAgent('Firefox', '3.0', false);
|
69
|
-
var font = new webfont.WebFont(
|
70
|
-
|
71
|
-
var self = this;
|
95
|
+
var font = new webfont.WebFont(window, this.fontModuleLoader_,
|
96
|
+
function(func, timeout) { func(); }, userAgent);
|
72
97
|
var testModule;
|
73
98
|
|
74
99
|
font.addModule('test', function(conf) {
|