webfontloader 1.4.11 → 1.4.12

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v1.4.12 (August 21, 2013)
2
+ * Cleared up initialization code and made all modules optional and configurable at compile time
3
+
1
4
  v1.4.11 (August 8, 2013)
2
5
  * Remove Ascender module (according to Monotype the service has now been shutdown completely.)
3
6
  * Switch Monotype module to use fast.fonts.net instead of fast.fonts.com
data/CONTRIBUTING.md CHANGED
@@ -9,7 +9,7 @@ You'll need a few rubygems to run the tests, demo server, and other rake tasks,
9
9
  $ gem install bundler
10
10
  $ bundle install
11
11
 
12
- To run the tests in a headless WebKit you will also need to have [PhantomJS](http://www.phantomjs.org) installed. You can install PhantomJS by downloading a binary of using HomeBrew.
12
+ To run the tests in a headless WebKit you will also need to have [PhantomJS](http://www.phantomjs.org) installed. You can install PhantomJS by downloading a binary or using HomeBrew.
13
13
 
14
14
  $ brew install phantomjs
15
15
 
@@ -19,6 +19,12 @@ To build a JS file from source, just run rake:
19
19
 
20
20
  $ rake
21
21
 
22
+ If you want to build a JS file with only specific modules you can specify them on the command line:
23
+
24
+ $ rake compile['custom google typekit']
25
+
26
+ This will compile a JS file with only the `custom`, `google` and `typekit` modules. The available modules are: `custom`, `google`, `typekit`, `ascender`, `monotype`, `fontdeck`. By default all modules are included.
27
+
22
28
  ## Demos
23
29
 
24
30
  A full suite of demo pages is included in this source. Here you can find some
data/README.md CHANGED
@@ -205,11 +205,11 @@ The Fonts.com module has an optional `version` option which acts as a cache-bust
205
205
 
206
206
  ### Google
207
207
 
208
- Using [Google's Font API](https://code.google.com/apis/webfonts/docs/getting_started.html), name the font families you'd like to load.
208
+ Using [Google's Font API](https://code.google.com/apis/webfonts/docs/getting_started.html), name the font families you'd like to load. You can use the same [syntax](https://developers.google.com/fonts/docs/getting_started#Syntax) as in the Font API to specify styles:
209
209
 
210
210
  WebFontConfig = {
211
211
  google: {
212
- families: ['Droid Sans', 'Droid Serif']
212
+ families: ['Droid Sans', 'Droid Serif:bold']
213
213
  }
214
214
  };
215
215
 
data/Rakefile CHANGED
@@ -81,9 +81,12 @@ directory "target"
81
81
  directory "tmp"
82
82
 
83
83
  desc "Compile the JavaScript into target/webfont.js"
84
- task :compile => "target/webfont.js"
84
+ task :compile, [:modules] => "target/webfont.js"
85
85
 
86
- file "target/webfont.js" => SourceJs + ["target"] do |t|
86
+ file "target/webfont.js", [:modules] => SourceJs + ["target"] do |t, args|
87
+ args.with_defaults(:modules => 'custom google typekit monotype fontdeck')
88
+
89
+ modules = args[:modules].split ' '
87
90
 
88
91
  output_marker = "%output%"
89
92
  output_wrapper = @modules.js_output_wrapper(output_marker)
@@ -99,6 +102,8 @@ file "target/webfont.js" => SourceJs + ["target"] do |t|
99
102
  "--define goog.DEBUG=false"
100
103
  ]
101
104
 
105
+ args.concat modules.map { |m| "--define INCLUDE_" + m.upcase + "_MODULE" }
106
+
102
107
  # Extra args to add warnings.
103
108
  args.concat([
104
109
  ["--warning_level", "VERBOSE"],
@@ -113,9 +118,12 @@ file "target/webfont.js" => SourceJs + ["target"] do |t|
113
118
  end
114
119
 
115
120
  desc "Creates debug version into target/webfont.js"
116
- task :debug => "target/webfont_debug.js"
121
+ task :debug, [:modules] => "target/webfont_debug.js"
122
+
123
+ file "target/webfont_debug.js", [:modules] => SourceJs + ["target"] do |t|
124
+ args.with_defaults(:modules => 'custom google typekit monotype fontdeck')
117
125
 
118
- file "target/webfont_debug.js" => SourceJs + ["target"] do |t|
126
+ modules = args[:modules].split ' '
119
127
 
120
128
  output_marker = "%output%"
121
129
  output_wrapper = @modules.js_output_wrapper(output_marker)
@@ -133,6 +141,8 @@ file "target/webfont_debug.js" => SourceJs + ["target"] do |t|
133
141
  "--formatting=PRINT_INPUT_DELIMITER"
134
142
  ]
135
143
 
144
+ args.concat modules.map { |m| "--define INCLUDE_" + m.upcase + "_MODULE" }
145
+
136
146
  # Extra args to add warnings.
137
147
  args.concat([
138
148
  ["--warning_level", "VERBOSE"],
@@ -149,6 +159,10 @@ end
149
159
  #
150
160
  # Run
151
161
  #
162
+ desc "BrowserStack tests"
163
+ task :bstest do |t|
164
+ exec "browserstack-test -u $BROWSERSTACK_USERNAME -p $BROWSERSTACK_PASSWORD -k $BROWSERSTACK_KEY -b browsers.json http://localhost:9999/spec/index.html"
165
+ end
152
166
 
153
167
  desc "Test everything"
154
168
  task :default => [:clean, :gzipbytes, :test]
data/browsers.json ADDED
@@ -0,0 +1,122 @@
1
+ [
2
+ {
3
+ "os_version": "XP",
4
+ "os": "Windows",
5
+ "browser_version": "11.1",
6
+ "browser": "opera"
7
+ },
8
+ {
9
+ "os_version": "XP",
10
+ "os": "Windows",
11
+ "browser_version": "3.6",
12
+ "browser": "firefox"
13
+ },
14
+ {
15
+ "os_version": "XP",
16
+ "os": "Windows",
17
+ "browser_version": "20.0",
18
+ "browser": "firefox"
19
+ },
20
+ {
21
+ "os_version": "XP",
22
+ "os": "Windows",
23
+ "browser_version": "6.0",
24
+ "browser": "ie"
25
+ },
26
+ {
27
+ "os_version": "XP",
28
+ "os": "Windows",
29
+ "browser_version": "7.0",
30
+ "browser": "ie"
31
+ },
32
+ {
33
+ "os_version": "XP",
34
+ "os": "Windows",
35
+ "browser_version": "8.0",
36
+ "browser": "ie"
37
+ },
38
+ {
39
+ "os_version": "8",
40
+ "os": "Windows",
41
+ "browser_version": "10.0 Desktop",
42
+ "browser": "ie"
43
+ },
44
+ {
45
+ "os_version": "7",
46
+ "os": "Windows",
47
+ "browser_version": "9.0",
48
+ "browser": "ie"
49
+ },
50
+ {
51
+ "os_version": "Mountain Lion",
52
+ "os": "OS X",
53
+ "browser_version": "6.0",
54
+ "browser": "safari"
55
+ },
56
+ {
57
+ "os_version": "Mountain Lion",
58
+ "os": "OS X",
59
+ "browser_version": "25.0",
60
+ "browser": "chrome"
61
+ },
62
+ {
63
+ "os_version": "Snow Leopard",
64
+ "os": "OS X",
65
+ "browser_version": "5.0",
66
+ "browser": "safari"
67
+ },
68
+ {
69
+ "os_version": "5.0",
70
+ "device": "iPad 2 (5.0)",
71
+ "os": "ios",
72
+ "browser": "Mobile Safari"
73
+ },
74
+ {
75
+ "os_version": "5.1",
76
+ "device": "iPad 3rd",
77
+ "os": "ios",
78
+ "browser": "Mobile Safari"
79
+ },
80
+ {
81
+ "os_version": "6.0",
82
+ "device": "iPhone 5",
83
+ "os": "ios",
84
+ "browser": "Mobile Safari"
85
+ },
86
+ {
87
+ "os_version": "4.3.2",
88
+ "device": "iPad 2",
89
+ "os": "ios",
90
+ "browser": "Mobile Safari"
91
+ },
92
+ {
93
+ "os_version": "2.3",
94
+ "device": "Samsung Galaxy S II",
95
+ "os": "android",
96
+ "browser": "Android Browser"
97
+ },
98
+ {
99
+ "os_version": "2.2",
100
+ "device": "Samsung Galaxy S",
101
+ "os": "android",
102
+ "browser": "Android Browser"
103
+ },
104
+ {
105
+ "os_version": "4.2",
106
+ "device": "LG Nexus 4",
107
+ "os": "android",
108
+ "browser": "Android Browser"
109
+ },
110
+ {
111
+ "os_version": "4.0",
112
+ "device": "Samsung Galaxy Nexus",
113
+ "os": "android",
114
+ "browser": "Android Browser"
115
+ },
116
+ {
117
+ "os_version": "4.1",
118
+ "device": "Samsung Galaxy S III",
119
+ "os": "android",
120
+ "browser": "Android Browser"
121
+ }
122
+ ]
@@ -16,7 +16,7 @@ module WebFontLoader
16
16
 
17
17
  def all_source_files
18
18
  @all_source_files ||= begin
19
- modules.map { |mod| config[mod] }.compact.flatten.map { |f| File.join(js_src, f) }.push File.join(js_src, "async_load.js")
19
+ modules.map { |mod| config[mod] }.compact.flatten.map { |f| File.join(js_src, f) }
20
20
  end
21
21
  end
22
22
 
data/lib/webfontloader.rb CHANGED
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  require 'webfontloader/modules'
4
4
 
5
5
  module WebFontLoader
6
- VERSION = '1.4.11'
6
+ VERSION = '1.4.12'
7
7
 
8
8
  ProjectRoot = File.expand_path(File.dirname(__FILE__) + "/..")
9
9
 
@@ -1,5 +1,6 @@
1
1
  describe('WebFont', function () {
2
2
  var WebFont = webfont.WebFont,
3
+ Font = webfont.Font;
3
4
  UserAgent = webfont.UserAgent,
4
5
  FontWatchRunner = webfont.FontWatchRunner,
5
6
  BrowserInfo = webfont.BrowserInfo,
@@ -31,7 +32,7 @@ describe('WebFont', function () {
31
32
  testModule = null;
32
33
 
33
34
  beforeEach(function () {
34
- font = new WebFont(window, fontModuleLoader, userAgent);
35
+ font = new WebFont(window);
35
36
  font.addModule('test', function (conf, domHelper) {
36
37
  testModule = new function () {
37
38
  this.conf = conf;
@@ -92,10 +93,15 @@ describe('WebFont', function () {
92
93
  describe('font load with context', function () {
93
94
  var font = null,
94
95
  testModule = null,
95
- fakeMainWindow = {};
96
+ fakeMainWindow = {
97
+ navigator: {
98
+ userAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.9 Safari/533.2'
99
+ },
100
+ document: {}
101
+ };
96
102
 
97
103
  beforeEach(function () {
98
- font = new WebFont(fakeMainWindow, fontModuleLoader, userAgent);
104
+ font = new WebFont(fakeMainWindow);
99
105
  font.addModule('test', function (conf, domHelper) {
100
106
  testModule = new function () {
101
107
  this.domHelper = domHelper;
@@ -135,7 +141,7 @@ describe('WebFont', function () {
135
141
  beforeEach(function () {
136
142
  font = new Font('Font1');
137
143
  jasmine.Clock.useMock();
138
- webfont = new WebFont(window, fontModuleLoader, userAgent);
144
+ webfont = new WebFont(window);
139
145
  webfont.addModule('test', function (conf, domHelper) {
140
146
  testModule = new function () {
141
147
  this.conf = conf;
@@ -202,7 +208,7 @@ describe('WebFont', function () {
202
208
  testModule = null;
203
209
 
204
210
  beforeEach(function () {
205
- font = new WebFont(window, fontModuleLoader, userAgent);
211
+ font = new WebFont(window);
206
212
 
207
213
  font.addModule('test', function (conf, domHelper) {
208
214
  testModule = new function () {};
@@ -233,24 +239,15 @@ describe('WebFont', function () {
233
239
  testModule = null;
234
240
 
235
241
  beforeEach(function () {
236
- font = new WebFont(window, fontModuleLoader, new UserAgent(
237
- 'Firefox',
238
- new Version(3, 6),
239
- '3.6',
240
- 'Gecko',
241
- new Version(1, 9, 2),
242
- '1.9.2',
243
- 'Macintosh',
244
- new Version(10, 6),
245
- '10.6',
246
- undefined,
247
- new BrowserInfo(false, false, false)
248
- ));
242
+ font = new WebFont(window);
249
243
  font.addModule('test', function (conf, domHelper) {
250
244
  testModule = new function () {
251
245
  this.conf = conf;
252
246
  this.loadCalled = false;
253
247
  };
248
+ testModule.supportUserAgent = function (ua, support) {
249
+ support(false);
250
+ };
254
251
  testModule.load = function () {};
255
252
  return testModule;
256
253
  });
@@ -266,7 +263,6 @@ describe('WebFont', function () {
266
263
  inactive: inactive
267
264
  });
268
265
 
269
- expect(testModule).toBeNull()
270
266
  expect(inactive).toHaveBeenCalled();
271
267
  });
272
268
  });
data/spec/deps.js CHANGED
@@ -1,21 +1,20 @@
1
1
  // This file was autogenerated by calcdeps.js
2
- goog.addDependency("../../src/async_load.js", [], []);
3
2
  goog.addDependency("../../src/closure.js", [], []);
4
3
  goog.addDependency("../../src/core/browserinfo.js", ["webfont.BrowserInfo"], []);
5
4
  goog.addDependency("../../src/core/cssclassname.js", ["webfont.CssClassName"], []);
6
5
  goog.addDependency("../../src/core/domhelper.js", ["webfont.DomHelper"], []);
7
6
  goog.addDependency("../../src/core/eventdispatcher.js", ["webfont.EventDispatcher"], ["webfont.CssClassName"]);
8
7
  goog.addDependency("../../src/core/font.js", ["webfont.Font"], []);
9
- goog.addDependency("../../src/core/fontmoduleloader.js", ["webfont.FontModuleLoader","webfont.FontModule","webfont.FontModuleFactory"], []);
8
+ goog.addDependency("../../src/core/fontmodule.js", ["webfont.FontModule"], []);
9
+ goog.addDependency("../../src/core/fontmoduleloader.js", ["webfont.FontModuleLoader","webfont.FontModuleFactory"], []);
10
10
  goog.addDependency("../../src/core/fontruler.js", ["webfont.FontRuler"], []);
11
11
  goog.addDependency("../../src/core/fontwatcher.js", ["webfont.FontWatcher"], ["webfont.FontWatchRunner"]);
12
12
  goog.addDependency("../../src/core/fontwatchrunner.js", ["webfont.FontWatchRunner"], ["webfont.Font","webfont.FontRuler"]);
13
- goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.UserAgentParser","webfont.FontModuleLoader","webfont.WebFont"]);
14
- goog.addDependency("../../src/core/namespace.js", [], []);
13
+ goog.addDependency("../../src/core/initialize.js", ["webfont"], ["webfont.WebFont","webfont.modules.Typekit","webfont.modules.Fontdeck","webfont.modules.Monotype","webfont.modules.Custom","webfont.modules.google.GoogleFontApi"]);
15
14
  goog.addDependency("../../src/core/useragent.js", ["webfont.UserAgent"], []);
16
15
  goog.addDependency("../../src/core/useragentparser.js", ["webfont.UserAgentParser"], ["webfont.BrowserInfo","webfont.UserAgent","webfont.Version"]);
17
16
  goog.addDependency("../../src/core/version.js", ["webfont.Version"], []);
18
- goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher"]);
17
+ goog.addDependency("../../src/core/webfont.js", ["webfont.WebFont"], ["webfont.DomHelper","webfont.EventDispatcher","webfont.FontWatcher","webfont.FontModuleLoader","webfont.UserAgentParser"]);
19
18
  goog.addDependency("../../src/modules/custom.js", ["webfont.modules.Custom"], ["webfont.Font"]);
20
19
  goog.addDependency("../../src/modules/fontdeck.js", ["webfont.modules.Fontdeck"], ["webfont.Font"]);
21
20
  goog.addDependency("../../src/modules/google/fontapiparser.js", ["webfont.modules.google.FontApiParser"], ["webfont.Font"]);
data/spec/index.html CHANGED
@@ -20,6 +20,7 @@
20
20
  <script src="../tools/jasmine/jasmine.js"></script>
21
21
  <script src="../tools/jasmine/jasmine-html.js"></script>
22
22
  <script src="../tools/jasmine-phantomjs/terminal-reporter.js"></script>
23
+ <script src="../tools/jasmine-browserstack/jasmine-browserstack.js"></script>
23
24
  <script src="../tools/compiler/base.js"></script>
24
25
  <script src="../spec/deps.js"></script>
25
26
 
@@ -64,12 +65,14 @@
64
65
  terminalReporter = new jasmine.TerminalReporter({
65
66
  verbosity: 3,
66
67
  color: true
67
- });
68
+ }),
69
+ browserStackReporter = new jasmine.BrowserStackReporter();
68
70
 
69
71
  if (/PhantomJS/.test(navigator.userAgent)) {
70
72
  env.addReporter(terminalReporter);
71
73
  }
72
74
  env.addReporter(htmlReporter);
75
+ env.addReporter(browserStackReporter);
73
76
  env.specFilter = function (spec) {
74
77
  return htmlReporter.specFilter(spec);
75
78
  };
@@ -1,8 +1,6 @@
1
1
  describe('modules.google.GoogleFontApi', function () {
2
2
  var GoogleFontApi = webfont.modules.google.GoogleFontApi,
3
3
  Font = webfont.Font,
4
- UserAgent = webfont.UserAgent,
5
- userAgent = null,
6
4
  link = '',
7
5
  insert = '',
8
6
  fakeDomHelper = {
@@ -18,7 +16,6 @@ describe('modules.google.GoogleFontApi', function () {
18
16
  beforeEach(function () {
19
17
  insert = '';
20
18
  link = '';
21
- userAgent = new UserAgent('Test', '1.0', true);
22
19
  });
23
20
 
24
21
  describe('call onReady with font family loading', function () {
@@ -26,7 +23,7 @@ describe('modules.google.GoogleFontApi', function () {
26
23
  fonts = null;
27
24
 
28
25
  beforeEach(function () {
29
- googleFontApi = new GoogleFontApi(userAgent, fakeDomHelper, { families: ['Font1', 'Font2'] });
26
+ googleFontApi = new GoogleFontApi(fakeDomHelper, { families: ['Font1', 'Font2'] });
30
27
  googleFontApi.load(function (f) {
31
28
  fonts = f;
32
29
  });
@@ -48,7 +45,7 @@ describe('modules.google.GoogleFontApi', function () {
48
45
  var googleFontApi = null;
49
46
 
50
47
  beforeEach(function () {
51
- googleFontApi = new GoogleFontApi(userAgent, fakeDomHelper, {
48
+ googleFontApi = new GoogleFontApi(fakeDomHelper, {
52
49
  api: 'http://moo',
53
50
  families: ['Font1', 'Font2']
54
51
  });
@@ -64,7 +61,7 @@ describe('modules.google.GoogleFontApi', function () {
64
61
  var googleFontApi = null;
65
62
 
66
63
  beforeEach(function () {
67
- googleFontApi = new GoogleFontApi(userAgent, fakeDomHelper, { families: ['Font1 WithSpace', 'Font2 WithSpaceToo'] });
64
+ googleFontApi = new GoogleFontApi(fakeDomHelper, { families: ['Font1 WithSpace', 'Font2 WithSpaceToo'] });
68
65
  googleFontApi.load(function () {});
69
66
  });
70
67
 
@@ -77,7 +74,7 @@ describe('modules.google.GoogleFontApi', function () {
77
74
  var googleFontApi = null;
78
75
 
79
76
  beforeEach(function () {
80
- googleFontApi = new GoogleFontApi(userAgent, fakeDomHelper, { families: ['Font1 WithSpace:bi', 'Font2 WithSpaceToo:b,r'] });
77
+ googleFontApi = new GoogleFontApi(fakeDomHelper, { families: ['Font1 WithSpace:bi', 'Font2 WithSpaceToo:b,r'] });
81
78
  googleFontApi.load(function () {});
82
79
  });
83
80
 
@@ -45,7 +45,7 @@ describe('modules.Monotype', function () {
45
45
  new BrowserInfo(true, false, false)
46
46
  );
47
47
 
48
- monotype = new Monotype(useragent, fakeDomHelper, configuration);
48
+ monotype = new Monotype(fakeDomHelper, configuration);
49
49
  monotype.supportUserAgent(useragent, support);
50
50
  monotype.load(load);
51
51
 
@@ -1,28 +1,93 @@
1
1
  goog.provide('webfont');
2
2
 
3
- goog.require('webfont.UserAgentParser');
4
- goog.require('webfont.FontModuleLoader');
5
3
  goog.require('webfont.WebFont');
6
4
 
5
+ goog.require('webfont.modules.Typekit');
6
+ goog.require('webfont.modules.Fontdeck');
7
+ goog.require('webfont.modules.Monotype');
8
+ goog.require('webfont.modules.Custom');
9
+ goog.require('webfont.modules.google.GoogleFontApi');
10
+
7
11
  /**
8
12
  * @typedef {Object.<string, Array.<string>>}
9
13
  */
10
14
  webfont.FontTestStrings;
11
15
 
12
16
  /**
13
- * Name of the global object
14
- *
17
+ * @define {boolean}
18
+ */
19
+ var INCLUDE_CUSTOM_MODULE = false;
20
+
21
+ /**
22
+ * @define {boolean}
23
+ */
24
+ var INCLUDE_FONTDECK_MODULE = false;
25
+
26
+ /**
27
+ * @define {boolean}
28
+ */
29
+ var INCLUDE_MONOTYPE_MODULE = false;
30
+
31
+ /**
32
+ * @define {boolean}
33
+ */
34
+ var INCLUDE_TYPEKIT_MODULE = false;
35
+
36
+ /**
37
+ * @define {boolean}
38
+ */
39
+ var INCLUDE_GOOGLE_MODULE = false;
40
+
41
+ /**
15
42
  * @define {string}
16
43
  */
17
- var GLOBAL_NAME = 'WebFont';
44
+ var WEBFONT = 'WebFont';
45
+
46
+ /**
47
+ * @define {string}
48
+ */
49
+ var WEBFONT_CONFIG = 'WebFontConfig';
50
+
51
+ /**
52
+ * @type {webfont.WebFont}
53
+ */
54
+ var webFontLoader = new webfont.WebFont(goog.global);
55
+
56
+ if (INCLUDE_CUSTOM_MODULE) {
57
+ webFontLoader.addModule(webfont.modules.Custom.NAME, function (configuration, domHelper) {
58
+ return new webfont.modules.Custom(domHelper, configuration);
59
+ });
60
+ }
61
+
62
+ if (INCLUDE_FONTDECK_MODULE) {
63
+ webFontLoader.addModule(webfont.modules.Fontdeck.NAME, function (configuration, domHelper) {
64
+ return new webfont.modules.Fontdeck(domHelper, configuration);
65
+ });
66
+ }
67
+
68
+ if (INCLUDE_MONOTYPE_MODULE) {
69
+ webFontLoader.addModule(webfont.modules.Monotype.NAME, function (configuration, domHelper) {
70
+ return new webfont.modules.Monotype(domHelper, configuration);
71
+ });
72
+ }
73
+
74
+ if (INCLUDE_TYPEKIT_MODULE) {
75
+ webFontLoader.addModule(webfont.modules.Typekit.NAME, function (configuration, domHelper) {
76
+ return new webfont.modules.Typekit(domHelper, configuration);
77
+ });
78
+ }
79
+
80
+ if (INCLUDE_GOOGLE_MODULE) {
81
+ webFontLoader.addModule(webfont.modules.google.GoogleFontApi.NAME, function (configuration, domHelper) {
82
+ return new webfont.modules.google.GoogleFontApi(domHelper, configuration);
83
+ });
84
+ }
18
85
 
19
- // Provide an instance of WebFont in the global namespace.
20
- var globalNamespaceObject = window[GLOBAL_NAME] = (function() {
21
- var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
22
- var userAgent = userAgentParser.parse();
23
- var fontModuleLoader = new webfont.FontModuleLoader();
24
- return new webfont.WebFont(window, fontModuleLoader, userAgent);
25
- })();
86
+ if (!goog.global[WEBFONT]) {
87
+ goog.global[WEBFONT] = {};
88
+ goog.global[WEBFONT]['load'] = goog.bind(webFontLoader.load, webFontLoader);
26
89
 
27
- // Export the public API.
28
- globalNamespaceObject['load'] = globalNamespaceObject.load;
90
+ if (goog.global[WEBFONT_CONFIG]) {
91
+ webFontLoader.load(goog.global[WEBFONT_CONFIG]);
92
+ }
93
+ }
data/src/core/webfont.js CHANGED
@@ -3,18 +3,19 @@ goog.provide('webfont.WebFont');
3
3
  goog.require('webfont.DomHelper');
4
4
  goog.require('webfont.EventDispatcher');
5
5
  goog.require('webfont.FontWatcher');
6
+ goog.require('webfont.FontModuleLoader');
7
+ goog.require('webfont.UserAgentParser');
6
8
 
7
9
  /**
8
10
  * @param {Window} mainWindow The main application window containing
9
11
  * webfontloader.js.
10
- * @param {webfont.FontModuleLoader} fontModuleLoader A loader instance to use.
11
- * @param {webfont.UserAgent} userAgent The detected user agent to load for.
12
12
  * @constructor
13
13
  */
14
- webfont.WebFont = function(mainWindow, fontModuleLoader, userAgent) {
14
+ webfont.WebFont = function(mainWindow) {
15
15
  this.mainWindow_ = mainWindow;
16
- this.fontModuleLoader_ = fontModuleLoader;
17
- this.userAgent_ = userAgent;
16
+ this.fontModuleLoader_ = new webfont.FontModuleLoader();
17
+ this.userAgentParser_ = new webfont.UserAgentParser(mainWindow.navigator.userAgent, mainWindow.document);
18
+ this.userAgent_ = this.userAgentParser_.parse();
18
19
  this.moduleLoading_ = 0;
19
20
  this.moduleFailedLoading_ = 0;
20
21
  };
@@ -43,11 +44,7 @@ goog.scope(function () {
43
44
  var eventDispatcher = new EventDispatcher(
44
45
  this.domHelper_, context.document.documentElement, configuration);
45
46
 
46
- if (this.userAgent_.getBrowserInfo().hasWebFontSupport()) {
47
- this.load_(eventDispatcher, configuration);
48
- } else {
49
- eventDispatcher.dispatchInactive();
50
- }
47
+ this.load_(eventDispatcher, configuration);
51
48
  };
52
49
 
53
50
  /**
@@ -18,6 +18,10 @@ webfont.modules.Custom = function(domHelper, configuration) {
18
18
  this.configuration_ = configuration;
19
19
  };
20
20
 
21
+ /**
22
+ * @const
23
+ * @type {string}
24
+ */
21
25
  webfont.modules.Custom.NAME = 'custom';
22
26
 
23
27
  goog.scope(function () {
@@ -56,7 +60,3 @@ goog.scope(function () {
56
60
  return support(userAgent.getBrowserInfo().hasWebFontSupport());
57
61
  };
58
62
  });
59
-
60
- globalNamespaceObject.addModule(webfont.modules.Custom.NAME, function(configuration, domHelper) {
61
- return new webfont.modules.Custom(domHelper, configuration);
62
- });
@@ -12,6 +12,10 @@ webfont.modules.Fontdeck = function(domHelper, configuration) {
12
12
  this.fonts_ = [];
13
13
  };
14
14
 
15
+ /**
16
+ * @const
17
+ * @type {string}
18
+ */
15
19
  webfont.modules.Fontdeck.NAME = 'fontdeck';
16
20
  webfont.modules.Fontdeck.HOOK = '__webfontfontdeckmodule__';
17
21
  webfont.modules.Fontdeck.API = '//f.fontdeck.com/s/css/js/';
@@ -65,7 +69,3 @@ goog.scope(function () {
65
69
  onReady(this.fonts_);
66
70
  };
67
71
  });
68
-
69
- globalNamespaceObject.addModule(webfont.modules.Fontdeck.NAME, function(configuration, domHelper) {
70
- return new webfont.modules.Fontdeck(domHelper, configuration);
71
- });
@@ -8,12 +8,19 @@ goog.require('webfont.FontWatchRunner');
8
8
  * @constructor
9
9
  * @implements {webfont.FontModule}
10
10
  */
11
- webfont.modules.google.GoogleFontApi = function(userAgent, domHelper, configuration) {
12
- this.userAgent_ = userAgent;
11
+ webfont.modules.google.GoogleFontApi = function(domHelper, configuration) {
12
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
13
+
14
+ this.userAgent_ = userAgentParser.parse();
15
+
13
16
  this.domHelper_ = domHelper;
14
17
  this.configuration_ = configuration;
15
18
  };
16
19
 
20
+ /**
21
+ * @const
22
+ * @type {string}
23
+ */
17
24
  webfont.modules.google.GoogleFontApi.NAME = 'google';
18
25
 
19
26
  goog.scope(function () {
@@ -58,9 +65,3 @@ goog.scope(function () {
58
65
  onReady(fontApiParser.getFonts(), fontApiParser.getFontTestStrings(), GoogleFontApi.METRICS_COMPATIBLE_FONTS);
59
66
  };
60
67
  });
61
-
62
- globalNamespaceObject.addModule(webfont.modules.google.GoogleFontApi.NAME, function(configuration, domHelper) {
63
- var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
64
- var userAgent = userAgentParser.parse();
65
- return new webfont.modules.google.GoogleFontApi(userAgent, domHelper, configuration);
66
- });
@@ -14,8 +14,7 @@ projectId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'//this is your Fonts.com Web fo
14
14
  * @constructor
15
15
  * @implements {webfont.FontModule}
16
16
  */
17
- webfont.modules.Monotype = function (userAgent, domHelper, configuration) {
18
- this.userAgent_ = userAgent;
17
+ webfont.modules.Monotype = function (domHelper, configuration) {
19
18
  this.domHelper_ = domHelper;
20
19
  this.configuration_ = configuration;
21
20
  this.fonts_ = [];
@@ -23,7 +22,9 @@ webfont.modules.Monotype = function (userAgent, domHelper, configuration) {
23
22
 
24
23
  /**
25
24
  * name of the module through which external API is supposed to call the MonotypeFontAPI.
25
+ *
26
26
  * @const
27
+ * @type {string}
27
28
  */
28
29
  webfont.modules.Monotype.NAME = 'monotype';
29
30
 
@@ -87,9 +88,3 @@ goog.scope(function () {
87
88
  onReady(this.fonts_);
88
89
  };
89
90
  });
90
-
91
- globalNamespaceObject.addModule(webfont.modules.Monotype.NAME, function (configuration, domHelper) {
92
- var userAgentParser = new webfont.UserAgentParser(navigator.userAgent, document);
93
- var userAgent = userAgentParser.parse();
94
- return new webfont.modules.Monotype(userAgent, domHelper, configuration);
95
- });
@@ -12,7 +12,12 @@ webfont.modules.Typekit = function(domHelper, configuration) {
12
12
  this.fonts_ = [];
13
13
  };
14
14
 
15
+ /**
16
+ * @const
17
+ * @type {string}
18
+ */
15
19
  webfont.modules.Typekit.NAME = 'typekit';
20
+
16
21
  webfont.modules.Typekit.HOOK = '__webfonttypekitmodule__';
17
22
 
18
23
  goog.scope(function () {
@@ -72,7 +77,3 @@ goog.scope(function () {
72
77
  onReady(this.fonts_);
73
78
  };
74
79
  });
75
-
76
- globalNamespaceObject.addModule(webfont.modules.Typekit.NAME, function(configuration, domHelper) {
77
- return new webfont.modules.Typekit(domHelper, configuration);
78
- });
@@ -0,0 +1,128 @@
1
+ (function (root, factory) {
2
+ if (typeof define === 'function' && define.amd) {
3
+ define(['jasmine'], factory);
4
+ } else {
5
+ factory(jasmine);
6
+ }
7
+ }(this, function (jasmine) {
8
+ function stack(err) {
9
+ var str = err.stack || err.toString();
10
+
11
+ if (!~str.indexOf(err.message)) {
12
+ str = err.message + '\n' + str;
13
+ }
14
+
15
+ if ('[object Error]' == str) {
16
+ str = err.message;
17
+ }
18
+
19
+ if (!err.stack && err.sourceURL && err.line !== undefined) {
20
+ str += '\n(' + err.sourceURL + ':' + err.line + ')';
21
+ }
22
+ return str.replace(/^/gm, ' ');
23
+ }
24
+
25
+ function BrowserStackReporter() {
26
+ this.stats = {
27
+ suites: 0,
28
+ tests: 0,
29
+ passes: 0,
30
+ pending: 0,
31
+ failures: 0
32
+ };
33
+ this.tests = [];
34
+ }
35
+
36
+ BrowserStackReporter.prototype.reportRunnerStarting = function (runner) {
37
+ this.stats.start = new Date();
38
+ };
39
+
40
+ BrowserStackReporter.prototype.reportSpecStarting = function (spec) {
41
+ spec.startedAt = new Date().getTime();
42
+ };
43
+
44
+ BrowserStackReporter.prototype.reportSpecResults = function (spec) {
45
+ var currentTime = new Date().getTime();
46
+ spec.duration = currentTime - spec.startedAt;
47
+
48
+ var result = spec.results();
49
+
50
+ var test = {
51
+ status: null,
52
+ title: spec.getFullName().replace(/#/g, ''),
53
+ duration: currentTime - spec.startedAt
54
+ };
55
+
56
+ if (result.skipped) {
57
+ this.stats.pending += 1;
58
+ test.status = 'skipped';
59
+ } else if (result.failedCount === 0) {
60
+ this.stats.passes += 1;
61
+ test.status = 'passed';
62
+ } else {
63
+ var items = result.getItems(),
64
+ message = [];
65
+
66
+ for (var i = 0; i < items.length; i += 1) {
67
+ message.push(stack(items[i].trace));
68
+ }
69
+
70
+ test.err = message;
71
+ test.status = 'failed';
72
+ this.stats.failures += 1;
73
+ }
74
+
75
+ this.stats.tests += 1;
76
+ this.tests.push(test);
77
+ };
78
+
79
+ BrowserStackReporter.prototype.reportSuiteResults = function (suite) {
80
+ };
81
+
82
+ BrowserStackReporter.prototype.reportRunnerResults = function (runner) {
83
+ var suites = runner.suites();
84
+
85
+ this.stats.end = new Date();
86
+ this.stats.duration = this.stats.end - this.stats.end;
87
+
88
+ this.stats.suites = suites.length;
89
+
90
+ var result = '1..' + this.stats.tests + '\n';
91
+
92
+ for (var i = 0; i < this.tests.length; i += 1) {
93
+ var count = i + 1;
94
+
95
+ if (this.tests[i].status === 'pending') {
96
+ result += 'ok ' + count + ' ' + this.tests[i].title + ' # SKIP -\n';
97
+ } else if (this.tests[i].status === 'failed') {
98
+ result += 'not ok ' + count + ' ' + this.tests[i].title + '\n';
99
+ for (var j = 0; j < this.tests[i].err.length; j += 1) {
100
+ result += this.tests[i].err[j] + '\n';
101
+ }
102
+ } else {
103
+ result += 'ok ' + count + ' ' + this.tests[i].title + '\n';
104
+ }
105
+ }
106
+
107
+ result += '# tests ' + this.stats.tests + '\n';
108
+ result += '# pass ' + this.stats.passes + '\n';
109
+ result += '# fail ' + this.stats.failures + '\n';
110
+
111
+ if (/browser=/i.test(window.location.search)) {
112
+ var xhr = null;
113
+
114
+ if (window.XMLHttpRequest) {
115
+ xhr = new XMLHttpRequest();
116
+ } else {
117
+ xhr = new ActiveXObject('Microsoft.XMLHTTP');
118
+ }
119
+
120
+ xhr.open('POST', window.location.href);
121
+ xhr.setRequestHeader('Content-Type', 'text/plain');
122
+ xhr.send(result);
123
+ }
124
+ };
125
+
126
+ // Attach to the jasmine object like many other reporters do
127
+ jasmine.BrowserStackReporter = BrowserStackReporter;
128
+ }));
@@ -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.4.11'
17
- s.date = '2013-08-08'
16
+ s.version = '1.4.12'
17
+ s.date = '2013-08-21'
18
18
 
19
19
  ## Make sure your summary is short. The description may be as long
20
20
  ## as you like.
@@ -74,6 +74,7 @@ DESC
74
74
  README.md
75
75
  Rakefile
76
76
  bin/webfontloader-demos
77
+ browsers.json
77
78
  lib/webfontloader.rb
78
79
  lib/webfontloader/demo/public/basic.css
79
80
  lib/webfontloader/demo/public/blank.html
@@ -143,7 +144,6 @@ DESC
143
144
  spec/modules/google/googlefontapi_spec.js
144
145
  spec/modules/monotype_spec.js
145
146
  spec/modules/typekit_spec.js
146
- src/async_load.js
147
147
  src/closure.js
148
148
  src/core/browserinfo.js
149
149
  src/core/cssclassname.js
@@ -170,6 +170,7 @@ DESC
170
170
  src/modules/typekit.js
171
171
  tools/compiler/base.js
172
172
  tools/compiler/compiler.jar
173
+ tools/jasmine-browserstack/jasmine-browserstack.js
173
174
  tools/jasmine-phantomjs/jasmine-phantomjs.js
174
175
  tools/jasmine-phantomjs/terminal-reporter.js
175
176
  tools/jasmine/MIT.LICENSE
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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 11
10
- version: 1.4.11
9
+ - 12
10
+ version: 1.4.12
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: 2013-08-08 00:00:00 Z
19
+ date: 2013-08-21 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rake
@@ -102,6 +102,7 @@ files:
102
102
  - README.md
103
103
  - Rakefile
104
104
  - bin/webfontloader-demos
105
+ - browsers.json
105
106
  - lib/webfontloader.rb
106
107
  - lib/webfontloader/demo/public/basic.css
107
108
  - lib/webfontloader/demo/public/blank.html
@@ -171,7 +172,6 @@ files:
171
172
  - spec/modules/google/googlefontapi_spec.js
172
173
  - spec/modules/monotype_spec.js
173
174
  - spec/modules/typekit_spec.js
174
- - src/async_load.js
175
175
  - src/closure.js
176
176
  - src/core/browserinfo.js
177
177
  - src/core/cssclassname.js
@@ -198,6 +198,7 @@ files:
198
198
  - src/modules/typekit.js
199
199
  - tools/compiler/base.js
200
200
  - tools/compiler/compiler.jar
201
+ - tools/jasmine-browserstack/jasmine-browserstack.js
201
202
  - tools/jasmine-phantomjs/jasmine-phantomjs.js
202
203
  - tools/jasmine-phantomjs/terminal-reporter.js
203
204
  - tools/jasmine/MIT.LICENSE
data/src/async_load.js DELETED
@@ -1,3 +0,0 @@
1
- if (window['WebFontConfig']) {
2
- globalNamespaceObject['load'](window['WebFontConfig']);
3
- }