webfontloader 1.0.15 → 1.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/webfontloader/demo/public/fontwatchrunner-default-fonts.html +86 -0
- data/lib/webfontloader/demo/public/index.html +1 -0
- data/lib/webfontloader/demo/public/jquery.min.js +166 -0
- data/lib/webfontloader/demo/server.rb +9 -0
- data/lib/webfontloader.rb +1 -1
- data/src/core/fontwatcher.js +30 -88
- data/src/core/fontwatchrunner.js +136 -0
- data/src/core/namespace.js +1 -1
- data/src/modules.yml +1 -0
- data/src-test/core/fontwatchertest.js +185 -496
- data/src-test/core/fontwatchrunnertest.js +190 -0
- data/webfontloader.gemspec +6 -2
- metadata +19 -4
@@ -0,0 +1,190 @@
|
|
1
|
+
var FontWatchRunnerTest = TestCase('FontWatchRunnerTest');
|
2
|
+
|
3
|
+
FontWatchRunnerTest.prototype.setUp = function() {
|
4
|
+
var self = this;
|
5
|
+
|
6
|
+
this.fontFamily_ = 'fontFamily1';
|
7
|
+
this.fontDescription_ = 'n4';
|
8
|
+
|
9
|
+
this.fontActiveCalled_ = 0;
|
10
|
+
this.fontActive_ = {};
|
11
|
+
this.fontInactiveCalled_ = 0;
|
12
|
+
this.fontInactive_ = {};
|
13
|
+
this.activeCallback_ = function(fontFamily, fontDescription) {
|
14
|
+
self.fontActiveCalled_++;
|
15
|
+
self.fontActive_[fontFamily + ' ' + fontDescription] = true;
|
16
|
+
};
|
17
|
+
this.inactiveCallback_ = function(fontFamily, fontDescription) {
|
18
|
+
self.fontInactiveCalled_++;
|
19
|
+
self.fontInactive_[fontFamily + ' ' + fontDescription] = true;
|
20
|
+
};
|
21
|
+
|
22
|
+
this.createElementCalled_ = 0;
|
23
|
+
this.createdElements_ = [];
|
24
|
+
this.insertIntoCalled_ = 0;
|
25
|
+
this.removeElementCalled_ = 0;
|
26
|
+
this.fakeDomHelper_ = {
|
27
|
+
createElement: function(name, attrs, innerHtml) {
|
28
|
+
self.createElementCalled_++;
|
29
|
+
self.createdElements_.push({
|
30
|
+
'name': name,
|
31
|
+
'attrs': attrs,
|
32
|
+
'innerHtml': innerHtml
|
33
|
+
});
|
34
|
+
|
35
|
+
var element = document.createElement(name);
|
36
|
+
|
37
|
+
for (var attr in attrs) {
|
38
|
+
element.setAttribute(attr, attrs[attr]);
|
39
|
+
}
|
40
|
+
element.innerHTML = innerHtml;
|
41
|
+
return element;
|
42
|
+
},
|
43
|
+
insertInto: function(name, el) {
|
44
|
+
self.insertIntoCalled_++;
|
45
|
+
},
|
46
|
+
removeElement: function(el) {
|
47
|
+
self.removeElementCalled_++;
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
this.timesToCheckWidthsBeforeChange_ = 0;
|
52
|
+
this.fakeFontSizer_ = {
|
53
|
+
getWidth: function(el) {
|
54
|
+
if (el.style.fontFamily.indexOf(self.fontFamily_) != -1) {
|
55
|
+
// This is a font stack with fontFamily included (not just fallbacks)
|
56
|
+
if (self.timesToCheckWidthsBeforeChange_ <= 0) {
|
57
|
+
return 2;
|
58
|
+
} else {
|
59
|
+
// Two fallback stacks, so we check width twice each time
|
60
|
+
self.timesToCheckWidthsBeforeChange_ -= 0.5;
|
61
|
+
return 1;
|
62
|
+
}
|
63
|
+
} else {
|
64
|
+
return 1;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
70
|
+
this.fakeGetTime_ = function() {
|
71
|
+
if (self.timesToGetTimeBeforeTimeout_ <= 0) {
|
72
|
+
return 6000;
|
73
|
+
} else {
|
74
|
+
self.timesToGetTimeBeforeTimeout_--;
|
75
|
+
return 1;
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
this.asyncCalled_ = false;
|
80
|
+
this.fakeAsyncCall_ = function(func, timeout) {
|
81
|
+
self.asyncCalled_ = true;
|
82
|
+
func();
|
83
|
+
};
|
84
|
+
|
85
|
+
};
|
86
|
+
|
87
|
+
FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
|
88
|
+
this.timesToCheckWidthsBeforeChange_ = 0;
|
89
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
90
|
+
|
91
|
+
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
92
|
+
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
93
|
+
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
94
|
+
|
95
|
+
assertFalse(this.asyncCalled_);
|
96
|
+
|
97
|
+
assertEquals(1, this.fontActiveCalled_);
|
98
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
99
|
+
assertEquals(0, this.fontInactiveCalled_);
|
100
|
+
};
|
101
|
+
|
102
|
+
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActive = function() {
|
103
|
+
this.timesToCheckWidthsBeforeChange_ = 3;
|
104
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
105
|
+
|
106
|
+
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
107
|
+
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
108
|
+
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
109
|
+
|
110
|
+
assertTrue(this.asyncCalled_);
|
111
|
+
|
112
|
+
assertEquals(1, this.fontActiveCalled_);
|
113
|
+
assertEquals(true, this.fontActive_['fontFamily1 n4']);
|
114
|
+
assertEquals(0, this.fontInactiveCalled_);
|
115
|
+
};
|
116
|
+
|
117
|
+
FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
|
118
|
+
this.timesToCheckWidthsBeforeChange_ = 10;
|
119
|
+
this.timesToGetTimeBeforeTimeout_ = 3;
|
120
|
+
|
121
|
+
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
122
|
+
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
123
|
+
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
124
|
+
|
125
|
+
assertTrue(this.asyncCalled_);
|
126
|
+
|
127
|
+
assertEquals(0, this.fontActiveCalled_);
|
128
|
+
assertEquals(1, this.fontInactiveCalled_);
|
129
|
+
assertEquals(true, this.fontInactive_['fontFamily1 n4']);
|
130
|
+
};
|
131
|
+
|
132
|
+
FontWatchRunnerTest.prototype.testDomWithDefaultTestString = function() {
|
133
|
+
this.timesToCheckWidthsBeforeChange_ = 3;
|
134
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
135
|
+
|
136
|
+
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
137
|
+
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
138
|
+
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
|
139
|
+
|
140
|
+
assertEquals(4, this.createElementCalled_);
|
141
|
+
assertEquals('span', this.createdElements_[0]['name']);
|
142
|
+
assertEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf('fontFamily1'));
|
143
|
+
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_A));
|
144
|
+
assertEquals('BESs', this.createdElements_[0]['innerHtml']);
|
145
|
+
assertEquals('span', this.createdElements_[1]['name']);
|
146
|
+
assertEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf('fontFamily1'));
|
147
|
+
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_B));
|
148
|
+
assertEquals('BESs', this.createdElements_[1]['innerHtml']);
|
149
|
+
assertEquals('span', this.createdElements_[2]['name']);
|
150
|
+
assertNotEquals(-1, this.createdElements_[2]['attrs']['style'].indexOf('fontFamily1'));
|
151
|
+
assertNotEquals(-1, this.createdElements_[2]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_A));
|
152
|
+
assertEquals('BESs', this.createdElements_[2]['innerHtml']);
|
153
|
+
assertEquals('span', this.createdElements_[3]['name']);
|
154
|
+
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf('fontFamily1'));
|
155
|
+
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_B));
|
156
|
+
assertEquals('BESs', this.createdElements_[3]['innerHtml']);
|
157
|
+
assertEquals(4, this.insertIntoCalled_);
|
158
|
+
assertEquals(4, this.removeElementCalled_);
|
159
|
+
|
160
|
+
};
|
161
|
+
|
162
|
+
FontWatchRunnerTest.prototype.testDomWithNotDefaultTestString = function() {
|
163
|
+
this.timesToCheckWidthsBeforeChange_ = 3;
|
164
|
+
this.timesToGetTimeBeforeTimeout_ = 10;
|
165
|
+
|
166
|
+
new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
|
167
|
+
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
|
168
|
+
this.fakeGetTime_, this.fontFamily_, this.fontDescription_, 'testString');
|
169
|
+
|
170
|
+
assertEquals(4, this.createElementCalled_);
|
171
|
+
assertEquals('span', this.createdElements_[0]['name']);
|
172
|
+
assertEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf('fontFamily1'));
|
173
|
+
assertNotEquals(-1, this.createdElements_[0]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_A));
|
174
|
+
assertEquals('testString', this.createdElements_[0]['innerHtml']);
|
175
|
+
assertEquals('span', this.createdElements_[1]['name']);
|
176
|
+
assertEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf('fontFamily1'));
|
177
|
+
assertNotEquals(-1, this.createdElements_[1]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_B));
|
178
|
+
assertEquals('testString', this.createdElements_[1]['innerHtml']);
|
179
|
+
assertEquals('span', this.createdElements_[2]['name']);
|
180
|
+
assertNotEquals(-1, this.createdElements_[2]['attrs']['style'].indexOf('fontFamily1'));
|
181
|
+
assertNotEquals(-1, this.createdElements_[2]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_A));
|
182
|
+
assertEquals('testString', this.createdElements_[2]['innerHtml']);
|
183
|
+
assertEquals('span', this.createdElements_[3]['name']);
|
184
|
+
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf('fontFamily1'));
|
185
|
+
assertNotEquals(-1, this.createdElements_[3]['attrs']['style'].indexOf(webfont.FontWatchRunner.DEFAULT_FONTS_B));
|
186
|
+
assertEquals('testString', this.createdElements_[3]['innerHtml']);
|
187
|
+
assertEquals(4, this.insertIntoCalled_);
|
188
|
+
assertEquals(4, this.removeElementCalled_);
|
189
|
+
|
190
|
+
};
|
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 = '2010-
|
16
|
+
s.version = '1.0.16'
|
17
|
+
s.date = '2010-11-18'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -87,12 +87,14 @@ DESC
|
|
87
87
|
lib/webfontloader/demo/public/event-js-loading.html
|
88
88
|
lib/webfontloader/demo/public/events-variations.html
|
89
89
|
lib/webfontloader/demo/public/events.html
|
90
|
+
lib/webfontloader/demo/public/fontwatchrunner-default-fonts.html
|
90
91
|
lib/webfontloader/demo/public/google-css.html
|
91
92
|
lib/webfontloader/demo/public/google.html
|
92
93
|
lib/webfontloader/demo/public/ie-fast-js.html
|
93
94
|
lib/webfontloader/demo/public/ie-slow-js.html
|
94
95
|
lib/webfontloader/demo/public/ie-slow-link.html
|
95
96
|
lib/webfontloader/demo/public/index.html
|
97
|
+
lib/webfontloader/demo/public/jquery.min.js
|
96
98
|
lib/webfontloader/demo/public/typekit-variations.html
|
97
99
|
lib/webfontloader/demo/public/typekit.html
|
98
100
|
lib/webfontloader/demo/server.rb
|
@@ -106,6 +108,7 @@ DESC
|
|
106
108
|
src-test/core/fonttest.js
|
107
109
|
src-test/core/fontvariationdescriptiontest.js
|
108
110
|
src-test/core/fontwatchertest.js
|
111
|
+
src-test/core/fontwatchrunnertest.js
|
109
112
|
src-test/core/useragenttest.js
|
110
113
|
src-test/custom/customcsstest.js
|
111
114
|
src-test/google/fontapiparsertest.js
|
@@ -123,6 +126,7 @@ DESC
|
|
123
126
|
src/core/fontmoduleloader.js
|
124
127
|
src/core/fontvariationdescription.js
|
125
128
|
src/core/fontwatcher.js
|
129
|
+
src/core/fontwatchrunner.js
|
126
130
|
src/core/initialize.js
|
127
131
|
src/core/namespace.js
|
128
132
|
src/core/useragent.js
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webfontloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 55
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 16
|
10
|
+
version: 1.0.16
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Ryan Carver
|
@@ -15,16 +16,18 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-11-18 00:00:00 -08:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
23
|
name: rack
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
25
27
|
requirements:
|
26
28
|
- - ~>
|
27
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 29
|
28
31
|
segments:
|
29
32
|
- 1
|
30
33
|
- 2
|
@@ -36,9 +39,11 @@ dependencies:
|
|
36
39
|
name: sinatra
|
37
40
|
prerelease: false
|
38
41
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
39
43
|
requirements:
|
40
44
|
- - ~>
|
41
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 15
|
42
47
|
segments:
|
43
48
|
- 1
|
44
49
|
- 0
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: vegas
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
59
|
- - ~>
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 23
|
55
62
|
segments:
|
56
63
|
- 0
|
57
64
|
- 1
|
@@ -98,12 +105,14 @@ files:
|
|
98
105
|
- lib/webfontloader/demo/public/event-js-loading.html
|
99
106
|
- lib/webfontloader/demo/public/events-variations.html
|
100
107
|
- lib/webfontloader/demo/public/events.html
|
108
|
+
- lib/webfontloader/demo/public/fontwatchrunner-default-fonts.html
|
101
109
|
- lib/webfontloader/demo/public/google-css.html
|
102
110
|
- lib/webfontloader/demo/public/google.html
|
103
111
|
- lib/webfontloader/demo/public/ie-fast-js.html
|
104
112
|
- lib/webfontloader/demo/public/ie-slow-js.html
|
105
113
|
- lib/webfontloader/demo/public/ie-slow-link.html
|
106
114
|
- lib/webfontloader/demo/public/index.html
|
115
|
+
- lib/webfontloader/demo/public/jquery.min.js
|
107
116
|
- lib/webfontloader/demo/public/typekit-variations.html
|
108
117
|
- lib/webfontloader/demo/public/typekit.html
|
109
118
|
- lib/webfontloader/demo/server.rb
|
@@ -117,6 +126,7 @@ files:
|
|
117
126
|
- src-test/core/fonttest.js
|
118
127
|
- src-test/core/fontvariationdescriptiontest.js
|
119
128
|
- src-test/core/fontwatchertest.js
|
129
|
+
- src-test/core/fontwatchrunnertest.js
|
120
130
|
- src-test/core/useragenttest.js
|
121
131
|
- src-test/custom/customcsstest.js
|
122
132
|
- src-test/google/fontapiparsertest.js
|
@@ -134,6 +144,7 @@ files:
|
|
134
144
|
- src/core/fontmoduleloader.js
|
135
145
|
- src/core/fontvariationdescription.js
|
136
146
|
- src/core/fontwatcher.js
|
147
|
+
- src/core/fontwatchrunner.js
|
137
148
|
- src/core/initialize.js
|
138
149
|
- src/core/namespace.js
|
139
150
|
- src/core/useragent.js
|
@@ -157,23 +168,27 @@ rdoc_options:
|
|
157
168
|
require_paths:
|
158
169
|
- lib
|
159
170
|
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
160
172
|
requirements:
|
161
173
|
- - ">="
|
162
174
|
- !ruby/object:Gem::Version
|
175
|
+
hash: 3
|
163
176
|
segments:
|
164
177
|
- 0
|
165
178
|
version: "0"
|
166
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
none: false
|
167
181
|
requirements:
|
168
182
|
- - ">="
|
169
183
|
- !ruby/object:Gem::Version
|
184
|
+
hash: 3
|
170
185
|
segments:
|
171
186
|
- 0
|
172
187
|
version: "0"
|
173
188
|
requirements: []
|
174
189
|
|
175
190
|
rubyforge_project:
|
176
|
-
rubygems_version: 1.3.
|
191
|
+
rubygems_version: 1.3.7
|
177
192
|
signing_key:
|
178
193
|
specification_version: 2
|
179
194
|
summary: WebFont Loader gives you added control when using linked fonts via @font-face.
|