webfontloader 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/Rakefile +2 -1
- data/lib/webfontloader.rb +1 -1
- data/spec/core/font_spec.js +9 -4
- data/spec/core/fontruler_spec.js +3 -10
- data/spec/core/fontwatcher_spec.js +22 -23
- data/spec/core/fontwatchrunner_spec.js +206 -231
- data/spec/deps.js +27 -0
- data/spec/google/lastresortwebkitfontwatchrunner_spec.js +47 -58
- data/spec/index.html +14 -25
- data/src/ascender/ascender_script.js +52 -45
- data/src/core/browserinfo.js +54 -47
- data/src/core/cssclassname.js +27 -22
- data/src/core/cssfontfamilyname.js +23 -17
- data/src/core/domhelper.js +209 -203
- data/src/core/eventdispatcher.js +111 -103
- data/src/core/font.js +110 -68
- data/src/core/fontmoduleloader.js +56 -13
- data/src/core/fontruler.js +52 -43
- data/src/core/fontvariationdescription.js +82 -76
- data/src/core/fontwatcher.js +93 -88
- data/src/core/fontwatchrunner.js +161 -161
- data/src/core/initialize.js +22 -15
- data/src/core/namespace.js +0 -29
- data/src/core/size.js +31 -25
- data/src/core/useragent.js +63 -48
- data/src/core/useragentparser.js +317 -306
- data/src/custom/customcss.js +31 -24
- data/src/fontdeck/fontdeck_script.js +46 -37
- data/src/google/fontapiparser.js +105 -97
- data/src/google/fontapiurlbuilder.js +46 -41
- data/src/google/googlefontapi.js +48 -32
- data/src/google/lastresortwebkitfontwatchrunner.js +80 -67
- data/src/modules.yml +6 -6
- data/src/monotype/monotype_script.js +47 -40
- data/src/typekit/typekit_script.js +41 -35
- data/tools/compiler/base.js +1548 -0
- data/tools/compiler/compiler.jar +0 -0
- data/webfontloader.gemspec +4 -2
- metadata +18 -16
data/src/custom/customcss.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
goog.provide('webfont.CustomCss');
|
2
|
+
|
1
3
|
/**
|
2
4
|
*
|
3
5
|
* WebFont.load({
|
@@ -7,6 +9,7 @@
|
|
7
9
|
* });
|
8
10
|
*
|
9
11
|
* @constructor
|
12
|
+
* @implements {webfont.FontModule}
|
10
13
|
*/
|
11
14
|
webfont.CustomCss = function(domHelper, configuration) {
|
12
15
|
this.domHelper_ = domHelper;
|
@@ -15,38 +18,42 @@ webfont.CustomCss = function(domHelper, configuration) {
|
|
15
18
|
|
16
19
|
webfont.CustomCss.NAME = 'custom';
|
17
20
|
|
18
|
-
|
19
|
-
var
|
20
|
-
|
21
|
-
|
21
|
+
goog.scope(function () {
|
22
|
+
var CustomCss = webfont.CustomCss;
|
23
|
+
|
24
|
+
CustomCss.prototype.load = function(onReady) {
|
25
|
+
var i, len;
|
26
|
+
var urls = this.configuration_['urls'] || [];
|
27
|
+
var familiesConfiguration = this.configuration_['families'] || [];
|
22
28
|
|
23
|
-
|
24
|
-
|
29
|
+
for (i = 0, len = urls.length; i < len; i++) {
|
30
|
+
var url = urls[i];
|
25
31
|
|
26
|
-
|
27
|
-
|
32
|
+
this.domHelper_.insertInto('head', this.domHelper_.createCssLink(url));
|
33
|
+
}
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
var families = [];
|
36
|
+
var variations = {};
|
37
|
+
for (i = 0, len = familiesConfiguration.length; i < len; i++) {
|
38
|
+
var components = familiesConfiguration[i].split(":");
|
39
|
+
var family = components[0];
|
40
|
+
var familyVariations = components[1];
|
35
41
|
|
36
|
-
|
42
|
+
families.push(family);
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
if (familyVariations) {
|
45
|
+
var newVariations = familyVariations.split(",");
|
46
|
+
variations[family] = (variations[family] || []).concat(newVariations);
|
47
|
+
}
|
41
48
|
}
|
42
|
-
}
|
43
49
|
|
44
|
-
|
45
|
-
};
|
50
|
+
onReady(families, variations);
|
51
|
+
};
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
};
|
53
|
+
CustomCss.prototype.supportUserAgent = function(userAgent, support) {
|
54
|
+
return support(userAgent.getBrowserInfo().hasWebFontSupport());
|
55
|
+
};
|
56
|
+
});
|
50
57
|
|
51
58
|
globalNamespaceObject.addModule(webfont.CustomCss.NAME, function(configuration, domHelper) {
|
52
59
|
return new webfont.CustomCss(domHelper, configuration);
|
@@ -1,5 +1,10 @@
|
|
1
|
+
goog.provide('webfont.FontdeckScript');
|
2
|
+
|
3
|
+
goog.require('webfont.FontVariationDescription');
|
4
|
+
|
1
5
|
/**
|
2
6
|
* @constructor
|
7
|
+
* @implements {webfont.FontModule}
|
3
8
|
*/
|
4
9
|
webfont.FontdeckScript = function(domHelper, configuration) {
|
5
10
|
this.domHelper_ = domHelper;
|
@@ -13,50 +18,54 @@ webfont.FontdeckScript.NAME = 'fontdeck';
|
|
13
18
|
webfont.FontdeckScript.HOOK = '__webfontfontdeckmodule__';
|
14
19
|
webfont.FontdeckScript.API = '//f.fontdeck.com/s/css/js/';
|
15
20
|
|
16
|
-
|
17
|
-
var
|
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;
|
21
|
-
var api = this.configuration_['api'] || webfont.FontdeckScript.API;
|
22
|
-
return protocol + api + hostname + '/' + projectId + '.js';
|
23
|
-
};
|
21
|
+
goog.scope(function () {
|
22
|
+
var FontdeckScript = webfont.FontdeckScript;
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
FontdeckScript.prototype.getScriptSrc = function(projectId) {
|
25
|
+
var protocol = this.domHelper_.getProtocol();
|
26
|
+
// For empty iframes, fall back to main window's hostname.
|
27
|
+
var hostname = this.domHelper_.getLoadWindow().location.hostname ||
|
28
|
+
this.domHelper_.getMainWindow().location.hostname;
|
29
|
+
var api = this.configuration_['api'] || webfont.FontdeckScript.API;
|
30
|
+
return protocol + api + hostname + '/' + projectId + '.js';
|
31
|
+
};
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}
|
33
|
+
FontdeckScript.prototype.supportUserAgent = function(userAgent, support) {
|
34
|
+
var projectId = this.configuration_['id'];
|
35
|
+
var loadWindow = this.domHelper_.getLoadWindow();
|
36
|
+
var self = this;
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
var font = data['fonts'][i];
|
41
|
-
// Add the FVDs
|
42
|
-
self.fontFamilies_.push(font['name']);
|
43
|
-
self.fontVariations_[font['name']] = [self.fvd_.compact("font-weight:" + font['weight'] + ";font-style:" + font['style'])];
|
38
|
+
if (projectId) {
|
39
|
+
// Provide data to Fontdeck for processing.
|
40
|
+
if (!loadWindow[webfont.FontdeckScript.HOOK]) {
|
41
|
+
loadWindow[webfont.FontdeckScript.HOOK] = {};
|
44
42
|
}
|
45
|
-
support(fontdeckSupports);
|
46
|
-
};
|
47
43
|
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
// Fontdeck will call this function to indicate support status
|
45
|
+
// and what fonts are provided.
|
46
|
+
loadWindow[webfont.FontdeckScript.HOOK][projectId] = function(fontdeckSupports, data) {
|
47
|
+
for (var i = 0, j = data['fonts'].length; i<j; ++i) {
|
48
|
+
var font = data['fonts'][i];
|
49
|
+
// Add the FVDs
|
50
|
+
self.fontFamilies_.push(font['name']);
|
51
|
+
self.fontVariations_[font['name']] = [self.fvd_.compact("font-weight:" + font['weight'] + ";font-style:" + font['style'])];
|
52
|
+
}
|
53
|
+
support(fontdeckSupports);
|
54
|
+
};
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
};
|
56
|
+
// Call the Fontdeck API.
|
57
|
+
var script = this.domHelper_.createScriptSrc(this.getScriptSrc(projectId));
|
58
|
+
this.domHelper_.insertInto('head', script);
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
}
|
60
|
+
} else {
|
61
|
+
support(true);
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
FontdeckScript.prototype.load = function(onReady) {
|
66
|
+
onReady(this.fontFamilies_, this.fontVariations_);
|
67
|
+
};
|
68
|
+
});
|
60
69
|
|
61
70
|
globalNamespaceObject.addModule(webfont.FontdeckScript.NAME, function(configuration, domHelper) {
|
62
71
|
return new webfont.FontdeckScript(domHelper, configuration);
|
data/src/google/fontapiparser.js
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
goog.provide('webfont.FontApiParser');
|
2
|
+
|
3
|
+
goog.require('webfont.FontVariationDescription');
|
4
|
+
|
1
5
|
/**
|
2
6
|
* @constructor
|
3
7
|
*/
|
@@ -56,122 +60,126 @@ webfont.FontApiParser.VARIATION_MATCH =
|
|
56
60
|
"(?:(?:semi|demi|extra|ultra)-?)?bold|black|heavy|l|r|b|[1-9]00)?(n|i" +
|
57
61
|
"|normal|italic)?$");
|
58
62
|
|
59
|
-
|
60
|
-
var
|
61
|
-
|
62
|
-
|
63
|
-
var
|
64
|
-
|
65
|
-
var
|
66
|
-
|
67
|
-
|
68
|
-
var
|
69
|
-
|
70
|
-
if (
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
if (
|
79
|
-
|
80
|
-
|
81
|
-
|
63
|
+
goog.scope(function () {
|
64
|
+
var FontApiParser = webfont.FontApiParser;
|
65
|
+
|
66
|
+
FontApiParser.prototype.parse = function() {
|
67
|
+
var length = this.fontFamilies_.length;
|
68
|
+
|
69
|
+
for (var i = 0; i < length; i++) {
|
70
|
+
var elements = this.fontFamilies_[i].split(":");
|
71
|
+
var fontFamily = elements[0].replace(/\+/g, " ");
|
72
|
+
var variations = ['n4'];
|
73
|
+
|
74
|
+
if (elements.length >= 2) {
|
75
|
+
var fvds = this.parseVariations_(elements[1]);
|
76
|
+
|
77
|
+
if (fvds.length > 0) {
|
78
|
+
variations = fvds;
|
79
|
+
}
|
80
|
+
if (elements.length == 3) {
|
81
|
+
var subsets = this.parseSubsets_(elements[2]);
|
82
|
+
if (subsets.length > 0) {
|
83
|
+
var fontTestString = FontApiParser.INT_FONTS[subsets[0]];
|
84
|
+
|
85
|
+
if (fontTestString) {
|
86
|
+
this.fontTestStrings_[fontFamily] = fontTestString;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
82
90
|
}
|
83
|
-
}
|
84
91
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
92
|
+
// For backward compatibility
|
93
|
+
if (!this.fontTestStrings_[fontFamily]) {
|
94
|
+
var hanumanTestString = FontApiParser.INT_FONTS[fontFamily];
|
95
|
+
if (hanumanTestString) {
|
96
|
+
this.fontTestStrings_[fontFamily] = hanumanTestString;
|
97
|
+
}
|
90
98
|
}
|
99
|
+
this.parsedFontFamilies_.push(fontFamily);
|
100
|
+
this.variations_[fontFamily] = variations;
|
91
101
|
}
|
92
|
-
|
93
|
-
this.variations_[fontFamily] = variations;
|
94
|
-
}
|
95
|
-
};
|
102
|
+
};
|
96
103
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
};
|
104
|
+
FontApiParser.prototype.generateFontVariationDescription_ = function(variation) {
|
105
|
+
if (!variation.match(/^[\w]+$/)) {
|
106
|
+
return '';
|
107
|
+
}
|
108
|
+
var normalizedVariation = variation.toLowerCase();
|
109
|
+
var groups = FontApiParser.VARIATION_MATCH.exec(normalizedVariation);
|
110
|
+
if (groups == null) {
|
111
|
+
return '';
|
112
|
+
}
|
113
|
+
var styleMatch = this.normalizeStyle_(groups[2]);
|
114
|
+
var weightMatch = this.normalizeWeight_(groups[1]);
|
115
|
+
var css = this.fvd_.expand([styleMatch, weightMatch].join(''));
|
116
|
+
return css ? this.fvd_.compact(css) : null;
|
117
|
+
};
|
111
118
|
|
112
119
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
};
|
120
|
+
FontApiParser.prototype.normalizeStyle_ = function(parsedStyle) {
|
121
|
+
if (parsedStyle == null || parsedStyle == '') {
|
122
|
+
return 'n';
|
123
|
+
}
|
124
|
+
return FontApiParser.STYLES[parsedStyle];
|
125
|
+
};
|
119
126
|
|
120
127
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
};
|
128
|
+
FontApiParser.prototype.normalizeWeight_ = function(parsedWeight) {
|
129
|
+
if (parsedWeight == null || parsedWeight == '') {
|
130
|
+
return '4';
|
131
|
+
}
|
132
|
+
var weight = FontApiParser.WEIGHTS[parsedWeight];
|
133
|
+
if (weight) {
|
134
|
+
return weight;
|
135
|
+
}
|
136
|
+
if (isNaN(parsedWeight)) {
|
137
|
+
return '4';
|
138
|
+
}
|
139
|
+
return parsedWeight.substr(0, 1);
|
140
|
+
};
|
134
141
|
|
135
142
|
|
136
|
-
|
137
|
-
|
143
|
+
FontApiParser.prototype.parseVariations_ = function(variations) {
|
144
|
+
var finalVariations = [];
|
138
145
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
146
|
+
if (!variations) {
|
147
|
+
return finalVariations;
|
148
|
+
}
|
149
|
+
var providedVariations = variations.split(",");
|
150
|
+
var length = providedVariations.length;
|
144
151
|
|
145
|
-
|
146
|
-
|
147
|
-
|
152
|
+
for (var i = 0; i < length; i++) {
|
153
|
+
var variation = providedVariations[i];
|
154
|
+
var fvd = this.generateFontVariationDescription_(variation);
|
148
155
|
|
149
|
-
|
150
|
-
|
156
|
+
if (fvd) {
|
157
|
+
finalVariations.push(fvd);
|
158
|
+
}
|
151
159
|
}
|
152
|
-
|
153
|
-
|
154
|
-
};
|
160
|
+
return finalVariations;
|
161
|
+
};
|
155
162
|
|
156
163
|
|
157
|
-
|
158
|
-
|
164
|
+
FontApiParser.prototype.parseSubsets_ = function(subsets) {
|
165
|
+
var finalSubsets = [];
|
159
166
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
};
|
167
|
+
if (!subsets) {
|
168
|
+
return finalSubsets;
|
169
|
+
}
|
170
|
+
return subsets.split(",");
|
171
|
+
};
|
165
172
|
|
166
173
|
|
167
|
-
|
168
|
-
|
169
|
-
};
|
174
|
+
FontApiParser.prototype.getFontFamilies = function() {
|
175
|
+
return this.parsedFontFamilies_;
|
176
|
+
};
|
170
177
|
|
171
|
-
|
172
|
-
|
173
|
-
};
|
178
|
+
FontApiParser.prototype.getVariations = function() {
|
179
|
+
return this.variations_;
|
180
|
+
};
|
174
181
|
|
175
|
-
|
176
|
-
|
177
|
-
};
|
182
|
+
FontApiParser.prototype.getFontTestStrings = function() {
|
183
|
+
return this.fontTestStrings_;
|
184
|
+
};
|
185
|
+
});
|
@@ -1,3 +1,5 @@
|
|
1
|
+
goog.provide('webfont.FontApiUrlBuilder');
|
2
|
+
|
1
3
|
/**
|
2
4
|
* @constructor
|
3
5
|
*/
|
@@ -15,58 +17,61 @@ webfont.FontApiUrlBuilder = function(apiUrl, protocol, text) {
|
|
15
17
|
|
16
18
|
webfont.FontApiUrlBuilder.DEFAULT_API_URL = '//fonts.googleapis.com/css';
|
17
19
|
|
20
|
+
goog.scope(function () {
|
21
|
+
var FontApiUrlBuilder = webfont.FontApiUrlBuilder;
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
};
|
23
|
+
FontApiUrlBuilder.prototype.setFontFamilies = function(fontFamilies) {
|
24
|
+
this.parseFontFamilies_(fontFamilies);
|
25
|
+
};
|
22
26
|
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
FontApiUrlBuilder.prototype.parseFontFamilies_ =
|
29
|
+
function(fontFamilies) {
|
30
|
+
var length = fontFamilies.length;
|
27
31
|
|
28
|
-
|
29
|
-
|
32
|
+
for (var i = 0; i < length; i++) {
|
33
|
+
var elements = fontFamilies[i].split(':');
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
if (elements.length == 3) {
|
36
|
+
this.subsets_.push(elements.pop());
|
37
|
+
}
|
38
|
+
var joinCharacter = '';
|
39
|
+
if (elements.length == 2 && elements[1] != ''){
|
40
|
+
joinCharacter = ':';
|
41
|
+
}
|
42
|
+
this.fontFamilies_.push(elements.join(joinCharacter));
|
37
43
|
}
|
38
|
-
|
39
|
-
}
|
40
|
-
};
|
44
|
+
};
|
41
45
|
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
};
|
47
|
+
FontApiUrlBuilder.prototype.webSafe = function(string) {
|
48
|
+
return string.replace(/ /g, '+');
|
49
|
+
};
|
46
50
|
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
FontApiUrlBuilder.prototype.build = function() {
|
53
|
+
if (this.fontFamilies_.length == 0) {
|
54
|
+
throw new Error('No fonts to load !');
|
55
|
+
}
|
56
|
+
if (this.apiUrl_.indexOf("kit=") != -1) {
|
57
|
+
return this.apiUrl_;
|
58
|
+
}
|
59
|
+
var length = this.fontFamilies_.length;
|
60
|
+
var sb = [];
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
for (var i = 0; i < length; i++) {
|
63
|
+
sb.push(this.webSafe(this.fontFamilies_[i]));
|
64
|
+
}
|
65
|
+
var url = this.apiUrl_ + '?family=' + sb.join('%7C'); // '|' escaped.
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
if (this.subsets_.length > 0) {
|
68
|
+
url += '&subset=' + this.subsets_.join(',');
|
69
|
+
}
|
66
70
|
|
67
|
-
|
68
|
-
|
69
|
-
|
71
|
+
if (this.text_.length > 0) {
|
72
|
+
url += '&text=' + encodeURIComponent(this.text_);
|
73
|
+
}
|
70
74
|
|
71
|
-
|
72
|
-
};
|
75
|
+
return url;
|
76
|
+
};
|
77
|
+
});
|