webfontloader 1.3.0 → 1.3.1
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 +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/core/useragent.js
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
goog.provide('webfont.UserAgent');
|
2
|
+
|
1
3
|
/**
|
4
|
+
* @export
|
2
5
|
* @param {string} name
|
3
6
|
* @param {string} version
|
4
7
|
* @param {string} engine
|
@@ -21,58 +24,70 @@ webfont.UserAgent = function(name, version, engine, engineVersion, platform,
|
|
21
24
|
this.browserInfo_ = browserInfo;
|
22
25
|
};
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
*/
|
27
|
-
webfont.UserAgent.prototype.getName = function() {
|
28
|
-
return this.name_;
|
29
|
-
};
|
27
|
+
goog.scope(function () {
|
28
|
+
var UserAgent = webfont.UserAgent;
|
30
29
|
|
31
|
-
/**
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
/**
|
31
|
+
* @export
|
32
|
+
* @return {string}
|
33
|
+
*/
|
34
|
+
UserAgent.prototype.getName = function() {
|
35
|
+
return this.name_;
|
36
|
+
};
|
37
37
|
|
38
|
-
/**
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
/**
|
39
|
+
* @export
|
40
|
+
* @return {string}
|
41
|
+
*/
|
42
|
+
UserAgent.prototype.getVersion = function() {
|
43
|
+
return this.version_;
|
44
|
+
};
|
44
45
|
|
45
|
-
/**
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
/**
|
47
|
+
* @export
|
48
|
+
* @return {string}
|
49
|
+
*/
|
50
|
+
UserAgent.prototype.getEngine = function() {
|
51
|
+
return this.engine_;
|
52
|
+
};
|
51
53
|
|
52
|
-
/**
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
/**
|
55
|
+
* @export
|
56
|
+
* @return {string}
|
57
|
+
*/
|
58
|
+
UserAgent.prototype.getEngineVersion = function() {
|
59
|
+
return this.engineVersion_;
|
60
|
+
};
|
58
61
|
|
59
|
-
/**
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
/**
|
63
|
+
* @export
|
64
|
+
* @return {string}
|
65
|
+
*/
|
66
|
+
UserAgent.prototype.getPlatform = function() {
|
67
|
+
return this.platform_;
|
68
|
+
};
|
65
69
|
|
66
|
-
/**
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
/**
|
71
|
+
* @export
|
72
|
+
* @return {string}
|
73
|
+
*/
|
74
|
+
UserAgent.prototype.getPlatformVersion = function() {
|
75
|
+
return this.platformVersion_;
|
76
|
+
};
|
72
77
|
|
73
|
-
/**
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
78
|
+
/**
|
79
|
+
* @export
|
80
|
+
* @return {number|undefined}
|
81
|
+
*/
|
82
|
+
UserAgent.prototype.getDocumentMode = function() {
|
83
|
+
return this.documentMode_;
|
84
|
+
};
|
85
|
+
|
86
|
+
/**
|
87
|
+
* @export
|
88
|
+
* @return {webfont.BrowserInfo}
|
89
|
+
*/
|
90
|
+
UserAgent.prototype.getBrowserInfo = function() {
|
91
|
+
return this.browserInfo_;
|
92
|
+
};
|
93
|
+
});
|
data/src/core/useragentparser.js
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
goog.provide('webfont.UserAgentParser');
|
2
|
+
|
3
|
+
goog.require('webfont.BrowserInfo');
|
4
|
+
goog.require('webfont.UserAgent');
|
5
|
+
|
1
6
|
/**
|
2
7
|
* @param {string} userAgent The browser userAgent string to parse.
|
3
8
|
* @constructor
|
@@ -37,336 +42,342 @@ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
|
|
37
42
|
undefined,
|
38
43
|
new webfont.BrowserInfo(false, false, false));
|
39
44
|
|
40
|
-
/**
|
41
|
-
* Parses the user agent string and returns an object.
|
42
|
-
* @return {webfont.UserAgent}
|
43
|
-
*/
|
44
|
-
webfont.UserAgentParser.prototype.parse = function() {
|
45
|
-
if (this.isIe_()) {
|
46
|
-
return this.parseIeUserAgentString_();
|
47
|
-
} else if (this.isOpera_()) {
|
48
|
-
return this.parseOperaUserAgentString_();
|
49
|
-
} else if (this.isWebKit_()) {
|
50
|
-
return this.parseWebKitUserAgentString_();
|
51
|
-
} else if (this.isGecko_()) {
|
52
|
-
return this.parseGeckoUserAgentString_();
|
53
|
-
} else {
|
54
|
-
return webfont.UserAgentParser.UNKNOWN_USER_AGENT;
|
55
|
-
}
|
56
|
-
};
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
goog.scope(function () {
|
47
|
+
var UserAgentParser = webfont.UserAgentParser,
|
48
|
+
BrowserInfo = webfont.BrowserInfo,
|
49
|
+
UserAgent = webfont.UserAgent;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Parses the user agent string and returns an object.
|
53
|
+
* @return {webfont.UserAgent}
|
54
|
+
*/
|
55
|
+
UserAgentParser.prototype.parse = function() {
|
56
|
+
if (this.isIe_()) {
|
57
|
+
return this.parseIeUserAgentString_();
|
58
|
+
} else if (this.isOpera_()) {
|
59
|
+
return this.parseOperaUserAgentString_();
|
60
|
+
} else if (this.isWebKit_()) {
|
61
|
+
return this.parseWebKitUserAgentString_();
|
62
|
+
} else if (this.isGecko_()) {
|
63
|
+
return this.parseGeckoUserAgentString_();
|
64
|
+
} else {
|
65
|
+
return webfont.UserAgentParser.UNKNOWN_USER_AGENT;
|
68
66
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
};
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @private
|
71
|
+
*/
|
72
|
+
UserAgentParser.prototype.getPlatform_ = function() {
|
73
|
+
var mobileOs = this.getMatchingGroup_(this.userAgent_,
|
74
|
+
/(iPod|iPad|iPhone|Android|Windows Phone|BB\d{2}|BlackBerry)/, 1);
|
75
|
+
|
76
|
+
if (mobileOs != "") {
|
77
|
+
if (/BB\d{2}/.test(mobileOs)) {
|
78
|
+
mobileOs = "BlackBerry";
|
79
|
+
}
|
80
|
+
return mobileOs;
|
81
|
+
}
|
82
|
+
var os = this.getMatchingGroup_(this.userAgent_,
|
83
|
+
/(Linux|Mac_PowerPC|Macintosh|Windows|CrOS)/, 1);
|
84
|
+
|
85
|
+
if (os != "") {
|
86
|
+
if (os == "Mac_PowerPC") {
|
87
|
+
os = "Macintosh";
|
88
|
+
}
|
89
|
+
return os;
|
90
|
+
}
|
91
|
+
return webfont.UserAgentParser.UNKNOWN;
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @private
|
96
|
+
*/
|
97
|
+
UserAgentParser.prototype.getPlatformVersion_ = function() {
|
98
|
+
var genericVersion = this.getMatchingGroup_(this.userAgent_,
|
99
|
+
/(OS X|Windows NT|Android|CrOS) ([^;)]+)/, 2);
|
100
|
+
if (genericVersion) {
|
101
|
+
return genericVersion;
|
102
|
+
}
|
103
|
+
var winPhoneVersion = this.getMatchingGroup_(this.userAgent_,
|
104
|
+
/Windows Phone( OS)? ([^;)]+)/, 2);
|
105
|
+
if (winPhoneVersion) {
|
106
|
+
return winPhoneVersion;
|
107
|
+
}
|
108
|
+
var iVersion = this.getMatchingGroup_(this.userAgent_,
|
109
|
+
/(iPhone )?OS ([\d_]+)/, 2);
|
110
|
+
if (iVersion) {
|
111
|
+
return iVersion;
|
112
|
+
}
|
113
|
+
var linuxVersion = this.getMatchingGroup_(this.userAgent_,
|
114
|
+
/Linux ([i\d]+)/, 1);
|
115
|
+
if (linuxVersion) {
|
116
|
+
return linuxVersion;
|
117
|
+
}
|
118
|
+
var blackBerryVersion = this.getMatchingGroup_(this.userAgent_,
|
119
|
+
/(BB\d{2}|BlackBerry).*?Version\/([^\s]*)/, 2);
|
120
|
+
if (blackBerryVersion) {
|
121
|
+
return blackBerryVersion;
|
77
122
|
}
|
78
|
-
return os;
|
79
|
-
}
|
80
|
-
return webfont.UserAgentParser.UNKNOWN;
|
81
|
-
};
|
82
|
-
|
83
|
-
/**
|
84
|
-
* @private
|
85
|
-
*/
|
86
|
-
webfont.UserAgentParser.prototype.getPlatformVersion_ = function() {
|
87
|
-
var genericVersion = this.getMatchingGroup_(this.userAgent_,
|
88
|
-
/(OS X|Windows NT|Android|CrOS) ([^;)]+)/, 2);
|
89
|
-
if (genericVersion) {
|
90
|
-
return genericVersion;
|
91
|
-
}
|
92
|
-
var winPhoneVersion = this.getMatchingGroup_(this.userAgent_,
|
93
|
-
/Windows Phone( OS)? ([^;)]+)/, 2);
|
94
|
-
if (winPhoneVersion) {
|
95
|
-
return winPhoneVersion;
|
96
|
-
}
|
97
|
-
var iVersion = this.getMatchingGroup_(this.userAgent_,
|
98
|
-
/(iPhone )?OS ([\d_]+)/, 2);
|
99
|
-
if (iVersion) {
|
100
|
-
return iVersion;
|
101
|
-
}
|
102
|
-
var linuxVersion = this.getMatchingGroup_(this.userAgent_,
|
103
|
-
/Linux ([i\d]+)/, 1);
|
104
|
-
if (linuxVersion) {
|
105
|
-
return linuxVersion;
|
106
|
-
}
|
107
|
-
var blackBerryVersion = this.getMatchingGroup_(this.userAgent_,
|
108
|
-
/(BB\d{2}|BlackBerry).*?Version\/([^\s]*)/, 2);
|
109
|
-
if (blackBerryVersion) {
|
110
|
-
return blackBerryVersion;
|
111
|
-
}
|
112
|
-
|
113
|
-
return webfont.UserAgentParser.UNKNOWN;
|
114
|
-
};
|
115
|
-
|
116
|
-
/**
|
117
|
-
* @private
|
118
|
-
*/
|
119
|
-
webfont.UserAgentParser.prototype.isIe_ = function() {
|
120
|
-
return this.userAgent_.indexOf("MSIE") != -1;
|
121
|
-
};
|
122
123
|
|
123
|
-
|
124
|
-
|
125
|
-
*/
|
126
|
-
webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
|
127
|
-
// For IE we give MSIE as the engine name and the version of IE
|
128
|
-
// instead of the specific Trident engine name and version
|
124
|
+
return UserAgentParser.UNKNOWN;
|
125
|
+
};
|
129
126
|
|
130
|
-
|
131
|
-
|
127
|
+
/**
|
128
|
+
* @private
|
129
|
+
*/
|
130
|
+
UserAgentParser.prototype.isIe_ = function() {
|
131
|
+
return this.userAgent_.indexOf("MSIE") != -1;
|
132
|
+
};
|
132
133
|
|
133
|
-
|
134
|
+
/**
|
135
|
+
* @private
|
136
|
+
*/
|
137
|
+
UserAgentParser.prototype.parseIeUserAgentString_ = function() {
|
138
|
+
// For IE we give MSIE as the engine name and the version of IE
|
139
|
+
// instead of the specific Trident engine name and version
|
134
140
|
|
135
|
-
|
136
|
-
var
|
137
|
-
var name = pair[0];
|
138
|
-
var version = pair[1];
|
139
|
-
var browserVersion = this.parseVersion_(version);
|
140
|
-
var platformVersion = this.parseVersion_(platformVersionString);
|
141
|
-
var supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
|
142
|
-
(platform == "Windows Phone" && platformVersion.major >= 8);
|
141
|
+
var platform = this.getPlatform_();
|
142
|
+
var platformVersionString = this.getPlatformVersion_();
|
143
143
|
|
144
|
-
|
145
|
-
platform, platformVersionString, this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(supportWebFont, false, false));
|
146
|
-
}
|
144
|
+
var browser = this.getMatchingGroup_(this.userAgent_, /(MSIE [\d\w\.]+)/, 1);
|
147
145
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
146
|
+
if (browser != "") {
|
147
|
+
var pair = browser.split(' ');
|
148
|
+
var name = pair[0];
|
149
|
+
var version = pair[1];
|
150
|
+
var browserVersion = this.parseVersion_(version);
|
151
|
+
var platformVersion = this.parseVersion_(platformVersionString);
|
152
|
+
var supportWebFont = (platform == "Windows" && browserVersion.major >= 6) ||
|
153
|
+
(platform == "Windows Phone" && platformVersion.major >= 8);
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
-
*/
|
156
|
-
webfont.UserAgentParser.prototype.isOpera_ = function() {
|
157
|
-
return this.userAgent_.indexOf("Opera") != -1;
|
158
|
-
};
|
155
|
+
return new UserAgent(name, version, name, version,
|
156
|
+
platform, platformVersionString, this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, false, false));
|
159
157
|
|
160
|
-
/**
|
161
|
-
* @private
|
162
|
-
*/
|
163
|
-
webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
|
164
|
-
var engineName = webfont.UserAgentParser.UNKNOWN;
|
165
|
-
var engineVersion = webfont.UserAgentParser.UNKNOWN;
|
166
|
-
var enginePair = this.getMatchingGroup_(this.userAgent_,
|
167
|
-
/(Presto\/[\d\w\.]+)/, 1);
|
168
|
-
|
169
|
-
if (enginePair != "") {
|
170
|
-
var splittedEnginePair = enginePair.split('/');
|
171
|
-
|
172
|
-
engineName = splittedEnginePair[0];
|
173
|
-
engineVersion = splittedEnginePair[1];
|
174
|
-
} else {
|
175
|
-
if (this.userAgent_.indexOf("Gecko") != -1) {
|
176
|
-
engineName = "Gecko";
|
177
158
|
}
|
178
|
-
var geckoVersion = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
|
179
159
|
|
180
|
-
|
181
|
-
|
160
|
+
return new UserAgent("MSIE", webfont.UserAgentParser.UNKNOWN,
|
161
|
+
"MSIE", webfont.UserAgentParser.UNKNOWN,
|
162
|
+
platform, platformVersionString, this.getDocumentMode_(this.doc_), new BrowserInfo(false, false, false));
|
163
|
+
};
|
164
|
+
|
165
|
+
/**
|
166
|
+
* @private
|
167
|
+
*/
|
168
|
+
UserAgentParser.prototype.isOpera_ = function() {
|
169
|
+
return this.userAgent_.indexOf("Opera") != -1;
|
170
|
+
};
|
171
|
+
|
172
|
+
/**
|
173
|
+
* @private
|
174
|
+
*/
|
175
|
+
UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
|
176
|
+
var engineName = UserAgentParser.UNKNOWN;
|
177
|
+
var engineVersion = UserAgentParser.UNKNOWN;
|
178
|
+
var enginePair = this.getMatchingGroup_(this.userAgent_,
|
179
|
+
/(Presto\/[\d\w\.]+)/, 1);
|
180
|
+
|
181
|
+
if (enginePair != "") {
|
182
|
+
var splittedEnginePair = enginePair.split('/');
|
183
|
+
|
184
|
+
engineName = splittedEnginePair[0];
|
185
|
+
engineVersion = splittedEnginePair[1];
|
186
|
+
} else {
|
187
|
+
if (this.userAgent_.indexOf("Gecko") != -1) {
|
188
|
+
engineName = "Gecko";
|
189
|
+
}
|
190
|
+
var geckoVersion = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
|
191
|
+
|
192
|
+
if (geckoVersion != "") {
|
193
|
+
engineVersion = geckoVersion;
|
194
|
+
}
|
182
195
|
}
|
183
|
-
}
|
184
196
|
|
185
|
-
|
186
|
-
|
187
|
-
|
197
|
+
// Check for Opera Mini first, since it looks like normal Opera
|
198
|
+
if (this.userAgent_.indexOf("Opera Mini/") != -1) {
|
199
|
+
var version = this.getMatchingGroup_(this.userAgent_, /Opera Mini\/([\d\.]+)/, 1);
|
200
|
+
|
201
|
+
if (version == "") {
|
202
|
+
version = UserAgentParser.UNKNOWN;
|
203
|
+
}
|
188
204
|
|
189
|
-
|
190
|
-
|
205
|
+
return new UserAgent("OperaMini", version, engineName,
|
206
|
+
engineVersion, this.getPlatform_(), this.getPlatformVersion_(),
|
207
|
+
this.getDocumentMode_(this.doc_), new BrowserInfo(false, false, false));
|
191
208
|
}
|
192
209
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
}
|
210
|
+
// Otherwise, find version information for normal Opera or Opera Mobile
|
211
|
+
if (this.userAgent_.indexOf("Version/") != -1) {
|
212
|
+
var versionString = this.getMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/, 1);
|
197
213
|
|
198
|
-
|
199
|
-
|
200
|
-
|
214
|
+
if (versionString != "") {
|
215
|
+
var version = this.parseVersion_(versionString);
|
216
|
+
return new UserAgent("Opera", versionString, engineName, engineVersion,
|
217
|
+
this.getPlatform_(), this.getPlatformVersion_(),
|
218
|
+
this.getDocumentMode_(this.doc_), new BrowserInfo(version.major >= 10, false, false));
|
219
|
+
}
|
220
|
+
}
|
221
|
+
var versionString = this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1);
|
201
222
|
|
202
223
|
if (versionString != "") {
|
203
224
|
var version = this.parseVersion_(versionString);
|
204
|
-
return new
|
225
|
+
return new UserAgent("Opera", versionString, engineName, engineVersion,
|
205
226
|
this.getPlatform_(), this.getPlatformVersion_(),
|
206
|
-
this.getDocumentMode_(this.doc_), new
|
227
|
+
this.getDocumentMode_(this.doc_), new BrowserInfo(version.major >= 10, false, false));
|
228
|
+
}
|
229
|
+
return new UserAgent("Opera", UserAgentParser.UNKNOWN,
|
230
|
+
engineName, engineVersion, this.getPlatform_(),
|
231
|
+
this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new BrowserInfo(false, false, false));
|
232
|
+
};
|
233
|
+
|
234
|
+
/**
|
235
|
+
* @private
|
236
|
+
*/
|
237
|
+
UserAgentParser.prototype.isWebKit_ = function() {
|
238
|
+
return /AppleWeb(K|k)it/.test(this.userAgent_);
|
239
|
+
};
|
240
|
+
|
241
|
+
/**
|
242
|
+
* @private
|
243
|
+
*/
|
244
|
+
UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
245
|
+
var platform = this.getPlatform_();
|
246
|
+
var platformVersionString = this.getPlatformVersion_();
|
247
|
+
var webKitVersionString = this.getMatchingGroup_(this.userAgent_,
|
248
|
+
/AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1);
|
249
|
+
var supportWebFont = false;
|
250
|
+
|
251
|
+
if (webKitVersionString == "") {
|
252
|
+
webKitVersionString = UserAgentParser.UNKNOWN;
|
207
253
|
}
|
208
|
-
}
|
209
|
-
var versionString = this.getMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/, 1);
|
210
|
-
|
211
|
-
if (versionString != "") {
|
212
|
-
var version = this.parseVersion_(versionString);
|
213
|
-
return new webfont.UserAgent("Opera", versionString, engineName, engineVersion,
|
214
|
-
this.getPlatform_(), this.getPlatformVersion_(),
|
215
|
-
this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(version.major >= 10, false, false));
|
216
|
-
}
|
217
|
-
return new webfont.UserAgent("Opera", webfont.UserAgentParser.UNKNOWN,
|
218
|
-
engineName, engineVersion, this.getPlatform_(),
|
219
|
-
this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(false, false, false));
|
220
|
-
};
|
221
|
-
|
222
|
-
/**
|
223
|
-
* @private
|
224
|
-
*/
|
225
|
-
webfont.UserAgentParser.prototype.isWebKit_ = function() {
|
226
|
-
return /AppleWeb(K|k)it/.test(this.userAgent_);
|
227
|
-
};
|
228
|
-
|
229
|
-
/**
|
230
|
-
* @private
|
231
|
-
*/
|
232
|
-
webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
233
|
-
var platform = this.getPlatform_();
|
234
|
-
var platformVersionString = this.getPlatformVersion_();
|
235
|
-
var webKitVersionString = this.getMatchingGroup_(this.userAgent_,
|
236
|
-
/AppleWeb(?:K|k)it\/([\d\.\+]+)/, 1);
|
237
|
-
var supportWebFont = false;
|
238
|
-
|
239
|
-
if (webKitVersionString == "") {
|
240
|
-
webKitVersionString = webfont.UserAgentParser.UNKNOWN;
|
241
|
-
}
|
242
|
-
|
243
|
-
var webKitVersion = this.parseVersion_(webKitVersionString);
|
244
|
-
var platformVersion = this.parseVersion_(platformVersionString);
|
245
|
-
|
246
|
-
var name = webfont.UserAgentParser.UNKNOWN;
|
247
|
-
|
248
|
-
if (this.userAgent_.indexOf("Chrome") != -1 || this.userAgent_.indexOf("CrMo") != -1 || this.userAgent_.indexOf("CriOS") != -1) {
|
249
|
-
name = "Chrome";
|
250
|
-
} else if (platform == "BlackBerry" || platform == "Android") {
|
251
|
-
name = webfont.UserAgentParser.BUILTIN_BROWSER;
|
252
|
-
} else if (this.userAgent_.indexOf("Safari") != -1) {
|
253
|
-
name = "Safari";
|
254
|
-
} else if (this.userAgent_.indexOf("AdobeAIR") != -1) {
|
255
|
-
name = "AdobeAIR";
|
256
|
-
}
|
257
|
-
var version = webfont.UserAgentParser.UNKNOWN;
|
258
|
-
|
259
|
-
if (name == webfont.UserAgentParser.BUILTIN_BROWSER) {
|
260
|
-
version = webfont.UserAgentParser.UNKNOWN;
|
261
|
-
} else if (this.userAgent_.indexOf("Version/") != -1) {
|
262
|
-
version = this.getMatchingGroup_(this.userAgent_,
|
263
|
-
/Version\/([\d\.\w]+)/, 1);
|
264
|
-
} else if (name == "Chrome") {
|
265
|
-
version = this.getMatchingGroup_(this.userAgent_,
|
266
|
-
/(Chrome|CrMo|CriOS)\/([\d\.]+)/, 2);
|
267
|
-
} else if (name == "AdobeAIR") {
|
268
|
-
version = this.getMatchingGroup_(this.userAgent_,
|
269
|
-
/AdobeAIR\/([\d\.]+)/, 1);
|
270
|
-
}
|
271
|
-
if (name == "AdobeAIR") {
|
272
|
-
var browserVersion = this.parseVersion_(version);
|
273
|
-
supportWebFont = browserVersion.major > 2 || browserVersion.major == 2 && browserVersion.minor >= 5;
|
274
|
-
} else if (platform == "BlackBerry") {
|
275
|
-
supportWebFont = platformVersion.major >= 10;
|
276
|
-
} else if (platform == "Android") {
|
277
|
-
supportWebFont = platformVersion.major > 2 || (platformVersion.major == 2 && platformVersion.minor > 1);
|
278
|
-
} else {
|
279
|
-
supportWebFont = webKitVersion.major >= 526 || webKitVersion.major >= 525 && webKitVersion.minor >= 13;
|
280
|
-
}
|
281
|
-
|
282
|
-
var hasWebKitFallbackBug = webKitVersion.major < 536 || (webKitVersion.major == 536 && webKitVersion.minor < 11),
|
283
|
-
hasWebKitMetricsBug = platform == 'iPhone' || platform == 'iPad' || platform == 'iPod' || platform == 'Macintosh';
|
284
|
-
|
285
|
-
return new webfont.UserAgent(name, version, "AppleWebKit", webKitVersionString,
|
286
|
-
platform, platformVersionString, this.getDocumentMode_(this.doc_), new webfont.BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug));
|
287
|
-
};
|
288
|
-
|
289
|
-
/**
|
290
|
-
* @private
|
291
|
-
*/
|
292
|
-
webfont.UserAgentParser.prototype.isGecko_ = function() {
|
293
|
-
return this.userAgent_.indexOf("Gecko") != -1;
|
294
|
-
};
|
295
254
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
if (versionNum != "") {
|
310
|
-
var firefoxVersion = this.parseVersion_(versionNum);
|
311
|
-
|
312
|
-
version = versionNum;
|
313
|
-
supportWebFont = firefoxVersion.major >= 3 &&
|
314
|
-
firefoxVersion.minor >= 5;
|
255
|
+
var webKitVersion = this.parseVersion_(webKitVersionString);
|
256
|
+
var platformVersion = this.parseVersion_(platformVersionString);
|
257
|
+
var name = UserAgentParser.UNKNOWN;
|
258
|
+
|
259
|
+
if (this.userAgent_.indexOf("Chrome") != -1 || this.userAgent_.indexOf("CrMo") != -1 || this.userAgent_.indexOf("CriOS") != -1) {
|
260
|
+
name = "Chrome";
|
261
|
+
} else if (platform == "BlackBerry" || platform == "Android") {
|
262
|
+
name = UserAgentParser.BUILTIN_BROWSER;
|
263
|
+
} else if (this.userAgent_.indexOf("Safari") != -1) {
|
264
|
+
name = "Safari";
|
265
|
+
} else if (this.userAgent_.indexOf("AdobeAIR") != -1) {
|
266
|
+
name = "AdobeAIR";
|
315
267
|
}
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
geckoVersion.major == 1 && geckoVersion.minor == 9 && geckoVersion.patch >= 2 ||
|
330
|
-
geckoVersionString.match(/1\.9\.1b[123]/) != null ||
|
331
|
-
geckoVersionString.match(/1\.9\.1\.[\d\.]+/) != null;
|
268
|
+
var version = UserAgentParser.UNKNOWN;
|
269
|
+
|
270
|
+
if (name == UserAgentParser.BUILTIN_BROWSER) {
|
271
|
+
version = UserAgentParser.UNKNOWN;
|
272
|
+
} else if (this.userAgent_.indexOf("Version/") != -1) {
|
273
|
+
version = this.getMatchingGroup_(this.userAgent_,
|
274
|
+
/Version\/([\d\.\w]+)/, 1);
|
275
|
+
} else if (name == "Chrome") {
|
276
|
+
version = this.getMatchingGroup_(this.userAgent_,
|
277
|
+
/(Chrome|CrMo|CriOS)\/([\d\.]+)/, 2);
|
278
|
+
} else if (name == "AdobeAIR") {
|
279
|
+
version = this.getMatchingGroup_(this.userAgent_,
|
280
|
+
/AdobeAIR\/([\d\.]+)/, 1);
|
332
281
|
}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
}
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
282
|
+
if (name == "AdobeAIR") {
|
283
|
+
var browserVersion = this.parseVersion_(version);
|
284
|
+
supportWebFont = browserVersion.major > 2 || browserVersion.major == 2 && browserVersion.minor >= 5;
|
285
|
+
} else if (platform == "BlackBerry") {
|
286
|
+
supportWebFont = platformVersion.major >= 10;
|
287
|
+
} else if (platform == "Android") {
|
288
|
+
supportWebFont = platformVersion.major > 2 || (platformVersion.major == 2 && platformVersion.minor > 1);
|
289
|
+
} else {
|
290
|
+
supportWebFont = webKitVersion.major >= 526 || webKitVersion.major >= 525 && webKitVersion.minor >= 13;
|
291
|
+
}
|
292
|
+
var hasWebKitFallbackBug = webKitVersion.major < 536 || (webKitVersion.major == 536 && webKitVersion.minor < 11),
|
293
|
+
hasWebKitMetricsBug = platform == 'iPhone' || platform == 'iPad' || platform == 'iPod' || platform == 'Macintosh';
|
294
|
+
|
295
|
+
return new UserAgent(name, version, "AppleWebKit", webKitVersionString,
|
296
|
+
platform, platformVersionString, this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, hasWebKitFallbackBug, hasWebKitMetricsBug));
|
297
|
+
};
|
298
|
+
|
299
|
+
/**
|
300
|
+
* @private
|
301
|
+
*/
|
302
|
+
UserAgentParser.prototype.isGecko_ = function() {
|
303
|
+
return this.userAgent_.indexOf("Gecko") != -1;
|
304
|
+
};
|
305
|
+
|
306
|
+
/**
|
307
|
+
* @private
|
308
|
+
*/
|
309
|
+
UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
|
310
|
+
var name = UserAgentParser.UNKNOWN;
|
311
|
+
var version = UserAgentParser.UNKNOWN;
|
312
|
+
var supportWebFont = false;
|
313
|
+
|
314
|
+
if (this.userAgent_.indexOf("Firefox") != -1) {
|
315
|
+
name = "Firefox";
|
316
|
+
var versionNum = this.getMatchingGroup_(this.userAgent_,
|
317
|
+
/Firefox\/([\d\w\.]+)/, 1);
|
318
|
+
|
319
|
+
if (versionNum != "") {
|
320
|
+
var firefoxVersion = this.parseVersion_(versionNum);
|
321
|
+
|
322
|
+
version = versionNum;
|
323
|
+
supportWebFont = firefoxVersion.major >= 3 &&
|
324
|
+
firefoxVersion.minor >= 5;
|
325
|
+
}
|
326
|
+
} else if (this.userAgent_.indexOf("Mozilla") != -1) {
|
327
|
+
name = "Mozilla";
|
328
|
+
}
|
329
|
+
var geckoVersionString = this.getMatchingGroup_(this.userAgent_, /rv:([^\)]+)/, 1);
|
330
|
+
|
331
|
+
if (geckoVersionString == "") {
|
332
|
+
geckoVersionString = UserAgentParser.UNKNOWN;
|
333
|
+
} else {
|
334
|
+
if (!supportWebFont) {
|
335
|
+
var geckoVersion = this.parseVersion_(geckoVersionString);
|
336
|
+
|
337
|
+
supportWebFont = geckoVersion.major > 1 ||
|
338
|
+
geckoVersion.major == 1 && geckoVersion.minor > 9 ||
|
339
|
+
geckoVersion.major == 1 && geckoVersion.minor == 9 && geckoVersion.patch >= 2 ||
|
340
|
+
geckoVersionString.match(/1\.9\.1b[123]/) != null ||
|
341
|
+
geckoVersionString.match(/1\.9\.1\.[\d\.]+/) != null;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
return new UserAgent(name, version, "Gecko", geckoVersionString,
|
345
|
+
this.getPlatform_(), this.getPlatformVersion_(), this.getDocumentMode_(this.doc_), new BrowserInfo(supportWebFont, false, false));
|
346
|
+
};
|
347
|
+
|
348
|
+
/**
|
349
|
+
* @private
|
350
|
+
*/
|
351
|
+
UserAgentParser.prototype.parseVersion_ = function(version) {
|
352
|
+
var m = /([0-9]+)(?:\.([0-9]+)(?:\.([0-9]+)?)?)?/.exec(version),
|
353
|
+
result = {};
|
354
|
+
|
355
|
+
if (m) {
|
356
|
+
result.major = parseInt(m[1] || -1, 10);
|
357
|
+
result.minor = parseInt(m[2] || -1, 10);
|
358
|
+
result.patch = parseInt(m[3] || -1, 10);
|
359
|
+
}
|
360
|
+
return result;
|
361
|
+
};
|
362
|
+
|
363
|
+
/**
|
364
|
+
* @private
|
365
|
+
*/
|
366
|
+
UserAgentParser.prototype.getMatchingGroup_ = function(str,
|
367
|
+
regexp, index) {
|
368
|
+
var groups = str.match(regexp);
|
369
|
+
|
370
|
+
if (groups && groups[index]) {
|
371
|
+
return groups[index];
|
372
|
+
}
|
373
|
+
return "";
|
374
|
+
};
|
375
|
+
|
376
|
+
/**
|
377
|
+
* @private
|
378
|
+
*/
|
379
|
+
UserAgentParser.prototype.getDocumentMode_ = function(doc) {
|
380
|
+
if (doc.documentMode) return doc.documentMode;
|
381
|
+
return undefined;
|
382
|
+
};
|
383
|
+
});
|