webfontloader 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/README.md +1 -0
- data/lib/webfontloader.rb +1 -1
- data/lib/webfontloader/demo/public/event-js-font-active.html +2 -2
- data/src-test/core/useragenttest.js +51 -4
- data/src-test/monotype/monotype_script_test.js +20 -10
- data/src/core/useragentparser.js +28 -2
- data/src/monotype/monotype_script.js +14 -9
- data/webfontloader.gemspec +2 -2
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
v1.1.1 (December 12, 2012)
|
2
|
+
* Added the ability to recognize BlackBerry devices, which have web font support (WOFF) in platform version 10+
|
3
|
+
* Added a new browser name "BuiltinBrowser" to recognize built-in browsers on mobile platforms which we previously called "Safari" (applies to Android's "Browser" app and BlackBerry's built-in browser)
|
4
|
+
* Fixed a bug in the Monotype module which caused a double active event in IE9 and no active event in IE8 (reported in issue #64)
|
5
|
+
* Fixed some typos in the demo pages
|
6
|
+
|
1
7
|
v1.1.0 (December 5, 2012)
|
2
8
|
* Adds the ability to load fonts into a same-origin child window or iframe using the new optional `context` configuration option (thanks to @ryanwolf of Google).
|
3
9
|
* Updates the demos to fix broken stuff and demonstrate the new context option in action.
|
data/README.md
CHANGED
data/lib/webfontloader.rb
CHANGED
@@ -10,9 +10,9 @@
|
|
10
10
|
api: '/fonts/api'
|
11
11
|
},
|
12
12
|
fontactive: function(familyName, fontDescription) {
|
13
|
-
if (
|
13
|
+
if (familyName == 'Droid Sans') {
|
14
14
|
var h1 = document.getElementsByTagName('h1')[0];
|
15
|
-
h1.innerHTML = 'Hello World. I am ' +
|
15
|
+
h1.innerHTML = 'Hello World. I am ' + familyName + ' (' + fontDescription + ')';
|
16
16
|
}
|
17
17
|
}
|
18
18
|
});
|
@@ -196,21 +196,36 @@ UserAgentTest.prototype.testBrowserIsIPhone = function() {
|
|
196
196
|
assertTrue(userAgent.isSupportingWebFont());
|
197
197
|
};
|
198
198
|
|
199
|
-
|
200
199
|
UserAgentTest.prototype.testBrowserIsAndroid = function() {
|
200
|
+
var userAgentParser = new webfont.UserAgentParser(
|
201
|
+
"Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
|
202
|
+
this.defaultDocument_);
|
203
|
+
var userAgent = userAgentParser.parse();
|
204
|
+
|
205
|
+
assertEquals("BuiltinBrowser", userAgent.getName());
|
206
|
+
assertEquals("Unknown", userAgent.getVersion());
|
207
|
+
assertEquals("Android", userAgent.getPlatform());
|
208
|
+
assertEquals("2.2.1", userAgent.getPlatformVersion());
|
209
|
+
assertEquals("AppleWebKit", userAgent.getEngine());
|
210
|
+
assertEquals("533.1", userAgent.getEngineVersion());
|
211
|
+
assertEquals(undefined, userAgent.getDocumentMode());
|
212
|
+
assertTrue(userAgent.isSupportingWebFont());
|
213
|
+
};
|
214
|
+
|
215
|
+
UserAgentTest.prototype.testBrowserIsOldUnsupportedAndroid = function() {
|
201
216
|
var userAgentParser = new webfont.UserAgentParser(
|
202
217
|
"Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17",
|
203
218
|
this.defaultDocument_);
|
204
219
|
var userAgent = userAgentParser.parse();
|
205
220
|
|
206
|
-
assertEquals("
|
207
|
-
assertEquals("
|
221
|
+
assertEquals("BuiltinBrowser", userAgent.getName());
|
222
|
+
assertEquals("Unknown", userAgent.getVersion());
|
208
223
|
assertEquals("Android", userAgent.getPlatform());
|
209
224
|
assertEquals("2.1-update1", userAgent.getPlatformVersion());
|
210
225
|
assertEquals("AppleWebKit", userAgent.getEngine());
|
211
226
|
assertEquals("530.17", userAgent.getEngineVersion());
|
212
227
|
assertEquals(undefined, userAgent.getDocumentMode());
|
213
|
-
|
228
|
+
assertFalse(userAgent.isSupportingWebFont());
|
214
229
|
};
|
215
230
|
|
216
231
|
UserAgentTest.prototype.testBrowserIsAndroidChromeMobile = function() {
|
@@ -670,3 +685,35 @@ UserAgentTest.prototype.testBrowserGeckoHighSubVerShouldNotSupportWebFont = func
|
|
670
685
|
assertEquals(undefined, userAgent.getDocumentMode());
|
671
686
|
assertFalse(userAgent.isSupportingWebFont());
|
672
687
|
};
|
688
|
+
|
689
|
+
UserAgentTest.prototype.testBrowserBBSupportWebfont = function() {
|
690
|
+
var userAgentParser = new webfont.UserAgentParser(
|
691
|
+
"Mozilla/5.0 (BB10; Touch) AppleWebKit/537.3+ (KHTML, like Gecko) Version/10.0.9.388 Mobile Safari/537.3+",
|
692
|
+
this.defaultDocument_);
|
693
|
+
var userAgent = userAgentParser.parse();
|
694
|
+
|
695
|
+
assertEquals("BuiltinBrowser", userAgent.getName());
|
696
|
+
assertEquals("Unknown", userAgent.getVersion());
|
697
|
+
assertEquals("BlackBerry", userAgent.getPlatform());
|
698
|
+
assertEquals("10.0.9.388", userAgent.getPlatformVersion());
|
699
|
+
assertEquals("AppleWebKit", userAgent.getEngine());
|
700
|
+
assertEquals("537.3+", userAgent.getEngineVersion());
|
701
|
+
assertEquals(undefined, userAgent.getDocumentMode());
|
702
|
+
assertTrue(userAgent.isSupportingWebFont());
|
703
|
+
};
|
704
|
+
|
705
|
+
UserAgentTest.prototype.testBrowserBBNotSupportWebfont = function() {
|
706
|
+
var userAgentParser = new webfont.UserAgentParser(
|
707
|
+
"Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.1.0.346 Mobile Safari/534.11+",
|
708
|
+
this.defaultDocument_);
|
709
|
+
var userAgent = userAgentParser.parse();
|
710
|
+
|
711
|
+
assertEquals("BuiltinBrowser", userAgent.getName());
|
712
|
+
assertEquals("Unknown", userAgent.getVersion());
|
713
|
+
assertEquals("BlackBerry", userAgent.getPlatform());
|
714
|
+
assertEquals("7.1.0.346", userAgent.getPlatformVersion());
|
715
|
+
assertEquals("AppleWebKit", userAgent.getEngine());
|
716
|
+
assertEquals("534.11+", userAgent.getEngineVersion());
|
717
|
+
assertEquals(undefined, userAgent.getDocumentMode());
|
718
|
+
assertFalse(userAgent.isSupportingWebFont());
|
719
|
+
};
|
@@ -8,8 +8,10 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
|
|
8
8
|
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
|
9
9
|
|
10
10
|
var fakeDomHelper = {
|
11
|
-
|
12
|
-
script = {
|
11
|
+
createElement: function () {
|
12
|
+
script = {
|
13
|
+
addEventListener: function () {}
|
14
|
+
};
|
13
15
|
return script;
|
14
16
|
},
|
15
17
|
insertInto: function (tag, elem) {
|
@@ -67,8 +69,10 @@ MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
|
|
67
69
|
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
|
68
70
|
|
69
71
|
var fakeDomHelper = {
|
70
|
-
|
71
|
-
script = {
|
72
|
+
createElement: function () {
|
73
|
+
script = {
|
74
|
+
addEventListener: function () {}
|
75
|
+
};
|
72
76
|
return script;
|
73
77
|
},
|
74
78
|
insertInto: function (tag, elem) {
|
@@ -139,8 +143,10 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
|
|
139
143
|
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
140
144
|
|
141
145
|
var fakeDomHelper = {
|
142
|
-
|
143
|
-
script = {
|
146
|
+
createElement: function () {
|
147
|
+
script = {
|
148
|
+
addEventListener: function () {}
|
149
|
+
};
|
144
150
|
return script;
|
145
151
|
},
|
146
152
|
insertInto: function (tag, elem) {
|
@@ -199,8 +205,10 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlH
|
|
199
205
|
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
|
200
206
|
|
201
207
|
var fakeDomHelper = {
|
202
|
-
|
203
|
-
script = {
|
208
|
+
createElement: function () {
|
209
|
+
script = {
|
210
|
+
addEventListener: function () {}
|
211
|
+
};
|
204
212
|
return script;
|
205
213
|
},
|
206
214
|
insertInto: function (tag, elem) {
|
@@ -259,8 +267,10 @@ MonotypeScriptTest.prototype.testWithoutProjectId = function () {
|
|
259
267
|
var config = {};
|
260
268
|
|
261
269
|
var fakeDomHelper = {
|
262
|
-
|
263
|
-
script = {
|
270
|
+
createElement: function () {
|
271
|
+
script = {
|
272
|
+
addEventListener: function () {}
|
273
|
+
};
|
264
274
|
return script;
|
265
275
|
},
|
266
276
|
insertInto: function (tag, elem) {
|
data/src/core/useragentparser.js
CHANGED
@@ -13,6 +13,16 @@ webfont.UserAgentParser = function(userAgent, doc) {
|
|
13
13
|
*/
|
14
14
|
webfont.UserAgentParser.UNKNOWN = "Unknown";
|
15
15
|
|
16
|
+
/**
|
17
|
+
* A constant for identifying a generic browser on a mobile platform that
|
18
|
+
* doesn't really have a name, but just came with the platform. Usually these
|
19
|
+
* are WebKit based, and examples are the default browser app on Android and
|
20
|
+
* the default browser app on BlackBerry 10.
|
21
|
+
* @const
|
22
|
+
* @type {string}
|
23
|
+
*/
|
24
|
+
webfont.UserAgentParser.BUILTIN_BROWSER = "BuiltinBrowser";
|
25
|
+
|
16
26
|
/**
|
17
27
|
* @const
|
18
28
|
* @type {webfont.UserAgent}
|
@@ -50,9 +60,12 @@ webfont.UserAgentParser.prototype.parse = function() {
|
|
50
60
|
*/
|
51
61
|
webfont.UserAgentParser.prototype.getPlatform_ = function() {
|
52
62
|
var mobileOs = this.getMatchingGroup_(this.userAgent_,
|
53
|
-
/(iPod|iPad|iPhone|Android|Windows Phone)/, 1);
|
63
|
+
/(iPod|iPad|iPhone|Android|Windows Phone|BB\d{2}|BlackBerry)/, 1);
|
54
64
|
|
55
65
|
if (mobileOs != "") {
|
66
|
+
if (/BB\d{2}/.test(mobileOs)) {
|
67
|
+
mobileOs = "BlackBerry";
|
68
|
+
}
|
56
69
|
return mobileOs;
|
57
70
|
}
|
58
71
|
var os = this.getMatchingGroup_(this.userAgent_,
|
@@ -91,6 +104,11 @@ webfont.UserAgentParser.prototype.getPlatformVersion_ = function() {
|
|
91
104
|
if (linuxVersion) {
|
92
105
|
return linuxVersion;
|
93
106
|
}
|
107
|
+
var blackBerryVersion = this.getMatchingGroup_(this.userAgent_,
|
108
|
+
/(BB\d{2}|BlackBerry).*?Version\/([^\s]*)/, 2);
|
109
|
+
if (blackBerryVersion) {
|
110
|
+
return blackBerryVersion;
|
111
|
+
}
|
94
112
|
|
95
113
|
return webfont.UserAgentParser.UNKNOWN;
|
96
114
|
};
|
@@ -224,6 +242,8 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
|
224
242
|
|
225
243
|
if (this.userAgent_.indexOf("Chrome") != -1 || this.userAgent_.indexOf("CrMo") != -1 || this.userAgent_.indexOf("CriOS") != -1) {
|
226
244
|
name = "Chrome";
|
245
|
+
} else if (platform == "BlackBerry" || platform == "Android") {
|
246
|
+
name = webfont.UserAgentParser.BUILTIN_BROWSER;
|
227
247
|
} else if (this.userAgent_.indexOf("Safari") != -1) {
|
228
248
|
name = "Safari";
|
229
249
|
} else if (this.userAgent_.indexOf("AdobeAIR") != -1) {
|
@@ -231,7 +251,9 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
|
231
251
|
}
|
232
252
|
var version = webfont.UserAgentParser.UNKNOWN;
|
233
253
|
|
234
|
-
if (
|
254
|
+
if (name == webfont.UserAgentParser.BUILTIN_BROWSER) {
|
255
|
+
version = webfont.UserAgentParser.UNKNOWN;
|
256
|
+
} else if (this.userAgent_.indexOf("Version/") != -1) {
|
235
257
|
version = this.getMatchingGroup_(this.userAgent_,
|
236
258
|
/Version\/([\d\.\w]+)/, 1);
|
237
259
|
} else if (name == "Chrome") {
|
@@ -246,6 +268,10 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
|
|
246
268
|
var minor = this.getMatchingGroup_(version, /\d+\.(\d+)/, 1);
|
247
269
|
supportWebFont = this.getMajorVersion_(version) > 2 ||
|
248
270
|
this.getMajorVersion_(version) == 2 && parseInt(minor, 10) >= 5;
|
271
|
+
} else if (platform == "BlackBerry") {
|
272
|
+
supportWebFont = parseInt(platformVersion, 10) >= 10;
|
273
|
+
} else if (platform == "Android") {
|
274
|
+
supportWebFont = parseFloat(platformVersion) > 2.1;
|
249
275
|
} else {
|
250
276
|
var minor = this.getMatchingGroup_(webKitVersion, /\d+\.(\d+)/, 1);
|
251
277
|
supportWebFont = this.getMajorVersion_(webKitVersion) >= 526 ||
|
@@ -40,18 +40,12 @@ webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support
|
|
40
40
|
var self = this;
|
41
41
|
var projectId = self.configuration_['projectId'];
|
42
42
|
if (projectId) {
|
43
|
-
var sc = self.domHelper_.
|
43
|
+
var sc = self.domHelper_.createElement("script");
|
44
44
|
sc["id"] = webfont.MonotypeScript.SCRIPTID + projectId;
|
45
45
|
|
46
|
-
sc["onreadystatechange"] = function (e) {
|
47
|
-
if (sc["readyState"] === "loaded" || sc["readyState"] === "complete") {
|
48
|
-
sc["onreadystatechange"] = null;
|
49
|
-
sc["onload"](e);
|
50
|
-
}
|
51
|
-
};
|
52
|
-
|
53
46
|
var loadWindow = this.domHelper_.getLoadWindow();
|
54
|
-
|
47
|
+
|
48
|
+
function onload() {
|
55
49
|
if (loadWindow[webfont.MonotypeScript.HOOK + projectId]) {
|
56
50
|
var mti_fnts = loadWindow[webfont.MonotypeScript.HOOK + projectId]();
|
57
51
|
if (mti_fnts && mti_fnts.length) {
|
@@ -62,8 +56,19 @@ webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support
|
|
62
56
|
}
|
63
57
|
}
|
64
58
|
support(userAgent.isSupportingWebFont());
|
59
|
+
}
|
60
|
+
|
61
|
+
var done = false;
|
62
|
+
|
63
|
+
sc["onload"] = sc["onreadystatechange"] = function () {
|
64
|
+
if (!done && (!this["readyState"] || this["readyState"] === "loaded" || this["readyState"] === "complete")) {
|
65
|
+
done = true;
|
66
|
+
onload();
|
67
|
+
sc["onload"] = sc["onreadystatechange"] = null;
|
68
|
+
}
|
65
69
|
};
|
66
70
|
|
71
|
+
sc["src"] = self.getScriptSrc(projectId);
|
67
72
|
this.domHelper_.insertInto('head', sc);
|
68
73
|
}
|
69
74
|
else {
|
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.1.
|
17
|
-
s.date = '2012-12-
|
16
|
+
s.version = '1.1.1'
|
17
|
+
s.date = '2012-12-12'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Carver
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-12-
|
19
|
+
date: 2012-12-12 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
prerelease: false
|