webfontloader 1.0.21 → 1.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -2
- data/lib/webfontloader.rb +1 -1
- data/src/core/fontwatchrunner.js +22 -5
- data/src-test/core/fontwatchrunnertest.js +40 -8
- data/webfontloader.gemspec +2 -2
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
v1.0.22 (July 1, 2011)
|
2
|
+
* Fixed a bug in Webkit-based browsers with font detection where active would trigger without the font actually being active yet.
|
3
|
+
* Increased the frequency of checking the widths of the font watcher spans.
|
4
|
+
|
1
5
|
v1.0.21 (June 17, 2011)
|
2
|
-
* Added a protocol detect for the Typekit module so JS is loaded securely on
|
3
|
-
secure pages. Thanks to bee525 for the pull request.
|
6
|
+
* Added a protocol detect for the Typekit module so JS is loaded securely on secure pages. Thanks to bee525 for the pull request.
|
4
7
|
|
5
8
|
v1.0.20 (March 30, 2011)
|
6
9
|
* Changed CSS style for hidden span so it's not affected by inline or floated elements at the end of the body
|
data/lib/webfontloader.rb
CHANGED
data/src/core/fontwatchrunner.js
CHANGED
@@ -27,6 +27,8 @@ webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
|
|
27
27
|
webfont.FontWatchRunner.DEFAULT_FONTS_A);
|
28
28
|
this.originalSizeB_ = this.getDefaultFontSize_(
|
29
29
|
webfont.FontWatchRunner.DEFAULT_FONTS_B);
|
30
|
+
this.lastObservedSizeA_ = this.originalSizeA_;
|
31
|
+
this.lastObservedSizeB_ = this.originalSizeB_;
|
30
32
|
this.requestedFontA_ = this.createHiddenElementWithFont_(
|
31
33
|
webfont.FontWatchRunner.DEFAULT_FONTS_A);
|
32
34
|
this.requestedFontB_ = this.createHiddenElementWithFont_(
|
@@ -69,18 +71,33 @@ webfont.FontWatchRunner.DEFAULT_FONTS_B = "Georgia,'Century Schoolbook L',serif"
|
|
69
71
|
webfont.FontWatchRunner.DEFAULT_TEST_STRING = 'BESs';
|
70
72
|
|
71
73
|
/**
|
74
|
+
* Checks the size of the two spans against their original sizes during each
|
75
|
+
* async loop. If the size of one of the spans is different than the original
|
76
|
+
* size, then we know that the font is rendering and finish with the active
|
77
|
+
* callback. If we wait more than 5 seconds and nothing has changed, we finish
|
78
|
+
* with the inactive callback.
|
79
|
+
*
|
80
|
+
* Because of an odd Webkit quirk, we wait to observe the new width twice
|
81
|
+
* in a row before finishing with the active callback. Sometimes, Webkit will
|
82
|
+
* render the spans with a changed width for one iteration even though the font
|
83
|
+
* is broken. This only happens for one async loop, so waiting for 2 consistent
|
84
|
+
* measurements allows us to work around the quirk.
|
85
|
+
*
|
72
86
|
* @private
|
73
87
|
*/
|
74
88
|
webfont.FontWatchRunner.prototype.check_ = function() {
|
75
89
|
var sizeA = this.fontSizer_.getWidth(this.requestedFontA_);
|
76
90
|
var sizeB = this.fontSizer_.getWidth(this.requestedFontB_);
|
77
91
|
|
78
|
-
if (this.originalSizeA_ != sizeA || this.originalSizeB_ != sizeB)
|
92
|
+
if ((this.originalSizeA_ != sizeA || this.originalSizeB_ != sizeB) &&
|
93
|
+
this.lastObservedSizeA_ == sizeA && this.lastObservedSizeB_ == sizeB) {
|
79
94
|
this.finish_(this.activeCallback_);
|
80
|
-
} else if (this.getTime_() - this.started_
|
81
|
-
this.asyncCheck_();
|
82
|
-
} else {
|
95
|
+
} else if (this.getTime_() - this.started_ >= 5000) {
|
83
96
|
this.finish_(this.inactiveCallback_);
|
97
|
+
} else {
|
98
|
+
this.lastObservedSizeA_ = sizeA;
|
99
|
+
this.lastObservedSizeB_ = sizeB;
|
100
|
+
this.asyncCheck_();
|
84
101
|
}
|
85
102
|
};
|
86
103
|
|
@@ -92,7 +109,7 @@ webfont.FontWatchRunner.prototype.asyncCheck_ = function() {
|
|
92
109
|
return function() {
|
93
110
|
func.call(context);
|
94
111
|
}
|
95
|
-
}(this, this.check_),
|
112
|
+
}(this, this.check_), 25);
|
96
113
|
};
|
97
114
|
|
98
115
|
/**
|
@@ -49,14 +49,17 @@ FontWatchRunnerTest.prototype.setUp = function() {
|
|
49
49
|
};
|
50
50
|
|
51
51
|
this.timesToCheckWidthsBeforeChange_ = 0;
|
52
|
+
this.timesToReportChangedWidth_ = 2;
|
52
53
|
this.fakeFontSizer_ = {
|
53
54
|
getWidth: function(el) {
|
54
55
|
if (el.style.fontFamily.indexOf(self.fontFamily_) != -1) {
|
55
56
|
// This is a font stack with fontFamily included (not just fallbacks)
|
56
|
-
if (self.timesToCheckWidthsBeforeChange_ <= 0) {
|
57
|
+
if (self.timesToCheckWidthsBeforeChange_ <= 0 && self.timesToReportChangedWidth_ > 0) {
|
58
|
+
// Decrement by 0.5 because we're checking two separate font stacks each iteration
|
59
|
+
self.timesToReportChangedWidth_ -= 0.5;
|
57
60
|
return 2;
|
58
61
|
} else {
|
59
|
-
//
|
62
|
+
// Decrement by 0.5 because we're checking two separate font stacks each iteration
|
60
63
|
self.timesToCheckWidthsBeforeChange_ -= 0.5;
|
61
64
|
return 1;
|
62
65
|
}
|
@@ -76,9 +79,9 @@ FontWatchRunnerTest.prototype.setUp = function() {
|
|
76
79
|
}
|
77
80
|
};
|
78
81
|
|
79
|
-
this.
|
82
|
+
this.asyncCount_ = 0;
|
80
83
|
this.fakeAsyncCall_ = function(func, timeout) {
|
81
|
-
self.
|
84
|
+
self.asyncCount_++;
|
82
85
|
func();
|
83
86
|
};
|
84
87
|
|
@@ -86,13 +89,14 @@ FontWatchRunnerTest.prototype.setUp = function() {
|
|
86
89
|
|
87
90
|
FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
|
88
91
|
this.timesToCheckWidthsBeforeChange_ = 0;
|
92
|
+
this.timesToReportChangedWidth_ = 2;
|
89
93
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
90
94
|
|
91
95
|
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
92
96
|
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
93
97
|
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
94
98
|
|
95
|
-
|
99
|
+
assertEquals(1, this.asyncCount_);
|
96
100
|
|
97
101
|
assertEquals(1, this.fontActiveCalled_);
|
98
102
|
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
@@ -101,13 +105,14 @@ FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
|
|
101
105
|
|
102
106
|
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActive = function() {
|
103
107
|
this.timesToCheckWidthsBeforeChange_ = 3;
|
108
|
+
this.timesToReportChangedWidth_ = 2;
|
104
109
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
105
110
|
|
106
111
|
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
107
112
|
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
108
113
|
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
109
114
|
|
110
|
-
|
115
|
+
assertEquals(4, this.asyncCount_);
|
111
116
|
|
112
117
|
assertEquals(1, this.fontActiveCalled_);
|
113
118
|
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
@@ -116,13 +121,38 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActive = function() {
|
|
116
121
|
|
117
122
|
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
|
118
123
|
this.timesToCheckWidthsBeforeChange_ = 10;
|
119
|
-
this.
|
124
|
+
this.timesToReportChangedWidth_ = 2;
|
125
|
+
this.timesToGetTimeBeforeTimeout_ = 5;
|
120
126
|
|
121
127
|
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
122
128
|
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
123
129
|
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
124
130
|
|
125
|
-
|
131
|
+
assertEquals(4, this.asyncCount_);
|
132
|
+
|
133
|
+
assertEquals(0, this.fontActiveCalled_);
|
134
|
+
assertEquals(1, this.fontInactiveCalled_);
|
135
|
+
assertEquals(true, this.fontInactive_['fontFamily1 n4']);
|
136
|
+
};
|
137
|
+
|
138
|
+
/**
|
139
|
+
* This test ensures that even if the fonts change width for one cycle and
|
140
|
+
* then change back, active won't be fired. This works around an issue in Webkit
|
141
|
+
* browsers, where an inactive webfont will briefly change widths for one cycle
|
142
|
+
* and then change back to fallback widths on the next cycle. This is apparently
|
143
|
+
* due to some quirk in the way that web fonts are rendered.
|
144
|
+
*/
|
145
|
+
FontWatchRunnerTest.prototype.testWatchFontWithInconsistentWidthIsStillInactive = function() {
|
146
|
+
this.timesToCheckWidthsBeforeChange_ = 3;
|
147
|
+
// Only report a new width for one cycle, then switch back to original fallback width
|
148
|
+
this.timesToReportChangedWidth_ = 1;
|
149
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
150
|
+
|
151
|
+
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
152
|
+
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
153
|
+
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
154
|
+
|
155
|
+
assertEquals(9, this.asyncCount_);
|
126
156
|
|
127
157
|
assertEquals(0, this.fontActiveCalled_);
|
128
158
|
assertEquals(1, this.fontInactiveCalled_);
|
@@ -131,6 +161,7 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
|
|
131
161
|
|
132
162
|
FontWatchRunnerTest.prototype.testDomWithDefaultTestString = function() {
|
133
163
|
this.timesToCheckWidthsBeforeChange_ = 3;
|
164
|
+
this.timesToReportChangedWidth_ = 2;
|
134
165
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
135
166
|
|
136
167
|
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
@@ -161,6 +192,7 @@ FontWatchRunnerTest.prototype.testDomWithDefaultTestString = function() {
|
|
161
192
|
|
162
193
|
FontWatchRunnerTest.prototype.testDomWithNotDefaultTestString = function() {
|
163
194
|
this.timesToCheckWidthsBeforeChange_ = 3;
|
195
|
+
this.timesToReportChangedWidth_ = 2;
|
164
196
|
this.timesToGetTimeBeforeTimeout_ = 10;
|
165
197
|
|
166
198
|
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
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.0.
|
17
|
-
s.date = '2011-
|
16
|
+
s.version = '1.0.22'
|
17
|
+
s.date = '2011-07-01'
|
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: 59
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 22
|
10
|
+
version: 1.0.22
|
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: 2011-
|
19
|
+
date: 2011-07-01 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|