webfontloader 1.0.5 → 1.0.6

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/Rakefile CHANGED
@@ -107,13 +107,15 @@ file "target/webfont.js" => SourceJs + ["target"] do |t|
107
107
  ["--compilation_level", "ADVANCED_OPTIMIZATIONS"],
108
108
  ["--js_output_file", t.name],
109
109
  ["--output_wrapper_marker", %("#{output_marker}")],
110
- ["--output_wrapper", %("#{output_wrapper}")]
110
+ ["--output_wrapper", %("#{output_wrapper}")],
111
+ ["--warning_level", "VERBOSE"],
112
+ ["--summary_detail_level", "3"]
111
113
  ]
112
114
 
113
115
  source = @modules.all_source_files
114
116
  args.concat source.map { |f| ["--js", f] }
115
117
 
116
- system "java #{args.flatten.join(' ')}"
118
+ sh "java #{args.flatten.join(' ')}"
117
119
  end
118
120
 
119
121
  desc "Creates debug version into target/webfont.js"
@@ -166,16 +168,16 @@ task :demodev do
166
168
  end
167
169
 
168
170
  desc "Find out how many bytes the source is"
169
- task :bytes => "target/webfont.js" do |t|
170
- js = t.prerequisites.first
171
+ task :bytes => [:clean, "target/webfont.js"] do |t|
172
+ js = t.prerequisites.last
171
173
  bytes = File.read(js).size
172
174
  puts "#{bytes} bytes uncompressed"
173
175
  end
174
176
 
175
177
  desc "Find out how many bytes the source is when gzipped"
176
- task :gzipbytes => "target/webfont.js" do |t|
178
+ task :gzipbytes => [:clean, "target/webfont.js"] do |t|
177
179
  require 'zlib'
178
- js = t.prerequisites.first
180
+ js = t.prerequisites.last
179
181
  bytes = Zlib::Deflate.deflate(File.read(js)).size
180
182
  puts "#{bytes} bytes gzipped"
181
183
  end
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.0.5'
6
+ VERSION = '1.0.6'
7
7
 
8
8
  ProjectRoot = File.expand_path(File.dirname(__FILE__) + "/..")
9
9
 
@@ -78,7 +78,9 @@ webfont.AscenderScript.prototype.parseVariations = function(source){
78
78
  return variations;
79
79
  };
80
80
 
81
- WebFont.addModule(webfont.AscenderScript.NAME, function(configuration) {
82
- return new webfont.AscenderScript(new webfont.DomHelper(document),
83
- configuration);
81
+ window['WebFont'].addModule(webfont.AscenderScript.NAME, function(configuration) {
82
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
83
+ var userAgent = userAgentParser.parse();
84
+ var domHelper = new webfont.DomHelper(document, userAgent);
85
+ return new webfont.AscenderScript(domHelper, configuration);
84
86
  });
@@ -1,17 +1,37 @@
1
1
  /**
2
+ * Handles sanitization and construction of css class names.
3
+ * @param {string=} opt_joinChar The character to join parts of the name on.
4
+ * Defaults to '-'.
2
5
  * @constructor
3
6
  */
4
7
  webfont.CssClassName = function(opt_joinChar) {
8
+ /** @type {string} */
5
9
  this.joinChar_ = opt_joinChar || webfont.CssClassName.DEFAULT_JOIN_CHAR;
6
10
  };
7
11
 
12
+ /**
13
+ * @const
14
+ * @type {string}
15
+ */
8
16
  webfont.CssClassName.DEFAULT_JOIN_CHAR = '-';
9
17
 
18
+ /**
19
+ * Sanitizes a string for use as a css class name. Removes non-word and
20
+ * underscore characters.
21
+ * @param {string} name The string.
22
+ * @return {string} The sanitized string.
23
+ */
10
24
  webfont.CssClassName.prototype.sanitize = function(name) {
11
25
  return name.replace(/[\W_]+/g, '').toLowerCase();
12
26
  };
13
27
 
14
- webfont.CssClassName.prototype.build = function(__args__) {
28
+ /**
29
+ * Builds a complete css class name given a variable number of parts.
30
+ * Sanitizes, then joins the parts together.
31
+ * @param {...string} var_args The parts to join.
32
+ * @return {string} The sanitized and joined string.
33
+ */
34
+ webfont.CssClassName.prototype.build = function(var_args) {
15
35
  var parts = []
16
36
  for (var i = 0; i < arguments.length; i++) {
17
37
  parts.push(this.sanitize(arguments[i]));
@@ -1,10 +1,17 @@
1
1
  /**
2
+ * Handles quoting rules for a font family name in css.
2
3
  * @constructor
3
4
  */
4
5
  webfont.CssFontFamilyName = function() {
6
+ /** @type {string} */
5
7
  this.quote_ = '"';
6
8
  };
7
9
 
10
+ /**
11
+ * Quotes the name.
12
+ * @param {string} name The name to quote.
13
+ * @return {string} The quoted name.
14
+ */
8
15
  webfont.CssFontFamilyName.prototype.quote = function(name) {
9
16
  var quoted = [];
10
17
  var split = name.split(/,\s*/);
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * Handles common DOM manipulation tasks. The aim of this library is to cover
3
+ * the needs of typical font loading. Not more, not less.
4
+ * @param {HTMLDocument} doc The HTML document we'll manipulate.
5
+ * @param {webfont.UserAgent} userAgent The current user agent.
2
6
  * @constructor
3
7
  */
4
8
  webfont.DomHelper = function(doc, userAgent) {
@@ -6,6 +10,13 @@ webfont.DomHelper = function(doc, userAgent) {
6
10
  this.userAgent_ = userAgent;
7
11
  };
8
12
 
13
+ /**
14
+ * Creates an element.
15
+ * @param {string} elem The element type.
16
+ * @param {Object=} opt_attr A hash of attribute key/value pairs.
17
+ * @param {string=} opt_innerHtml Contents of the element.
18
+ * @return {Element} the new element.
19
+ */
9
20
  webfont.DomHelper.prototype.createElement = function(elem, opt_attr,
10
21
  opt_innerHtml) {
11
22
  var domElement = this.document_.createElement(elem);
@@ -28,6 +39,13 @@ webfont.DomHelper.prototype.createElement = function(elem, opt_attr,
28
39
  return domElement;
29
40
  };
30
41
 
42
+ /**
43
+ * Inserts an element into the document. This is intended for unambiguous
44
+ * elements such as html, body, head.
45
+ * @param {string} tagName The element name.
46
+ * @param {Element} e The element to append.
47
+ * @return {boolean} True if the element was inserted.
48
+ */
31
49
  webfont.DomHelper.prototype.insertInto = function(tagName, e) {
32
50
  var t = this.document_.getElementsByTagName(tagName)[0];
33
51
 
@@ -47,6 +65,10 @@ webfont.DomHelper.prototype.insertInto = function(tagName, e) {
47
65
  return false;
48
66
  };
49
67
 
68
+ /**
69
+ * Calls a function when the body tag exists.
70
+ * @param {function()} callback The function to call.
71
+ */
50
72
  webfont.DomHelper.prototype.whenBodyExists = function(callback) {
51
73
  var check = function() {
52
74
  if (document.body) {
@@ -58,6 +80,11 @@ webfont.DomHelper.prototype.whenBodyExists = function(callback) {
58
80
  check();
59
81
  };
60
82
 
83
+ /**
84
+ * Removes an element from the DOM.
85
+ * @param {Element} node The element to remove.
86
+ * @return {boolean} True if the element was removed.
87
+ */
61
88
  webfont.DomHelper.prototype.removeElement = function(node) {
62
89
  if (node.parentNode) {
63
90
  node.parentNode.removeChild(node);
@@ -66,6 +93,11 @@ webfont.DomHelper.prototype.removeElement = function(node) {
66
93
  return false;
67
94
  };
68
95
 
96
+ /**
97
+ * Creates a link to a CSS document.
98
+ * @param {string} src The URL of the stylesheet.
99
+ * @return {Element} a link element.
100
+ */
69
101
  webfont.DomHelper.prototype.createCssLink = function(src) {
70
102
  return this.createElement('link', {
71
103
  'rel': 'stylesheet',
@@ -73,12 +105,22 @@ webfont.DomHelper.prototype.createCssLink = function(src) {
73
105
  });
74
106
  };
75
107
 
108
+ /**
109
+ * Creates a link to a javascript document.
110
+ * @param {string} src The URL of the script.
111
+ * @return {Element} a script element.
112
+ */
76
113
  webfont.DomHelper.prototype.createScriptSrc = function(src) {
77
114
  return this.createElement('script', {
78
115
  'src': src
79
116
  });
80
117
  };
81
118
 
119
+ /**
120
+ * Appends a name to an element's class attribute.
121
+ * @param {Element} e The element.
122
+ * @param {string} name The class name to add.
123
+ */
82
124
  webfont.DomHelper.prototype.appendClassName = function(e, name) {
83
125
  var classes = e.className.split(/\s+/);
84
126
  for (var i = 0, len = classes.length; i < len; i++) {
@@ -90,6 +132,11 @@ webfont.DomHelper.prototype.appendClassName = function(e, name) {
90
132
  e.className = classes.join(' ').replace(/^\s+/, '');
91
133
  };
92
134
 
135
+ /**
136
+ * Removes a name to an element's class attribute.
137
+ * @param {Element} e The element.
138
+ * @param {string} name The class name to remove.
139
+ */
93
140
  webfont.DomHelper.prototype.removeClassName = function(e, name) {
94
141
  var classes = e.className.split(/\s+/);
95
142
  var remainingClasses = [];
@@ -1,4 +1,8 @@
1
1
  /**
2
+ * @param {webfont.DomHelper} domHelper
3
+ * @param {HTMLElement} htmlElement
4
+ * @param {Object} callbacks
5
+ * @param {string=} opt_namespace
2
6
  * @constructor
3
7
  */
4
8
  webfont.EventDispatcher = function(domHelper, htmlElement, callbacks,
@@ -10,10 +14,34 @@ webfont.EventDispatcher = function(domHelper, htmlElement, callbacks,
10
14
  this.cssClassName_ = new webfont.CssClassName('-');
11
15
  };
12
16
 
17
+ /**
18
+ * @const
19
+ * @type {string}
20
+ */
13
21
  webfont.EventDispatcher.DEFAULT_NAMESPACE = 'wf';
22
+
23
+ /**
24
+ * @const
25
+ * @type {string}
26
+ */
14
27
  webfont.EventDispatcher.LOADING = 'loading';
28
+
29
+ /**
30
+ * @const
31
+ * @type {string}
32
+ */
15
33
  webfont.EventDispatcher.ACTIVE = 'active';
34
+
35
+ /**
36
+ * @const
37
+ * @type {string}
38
+ */
16
39
  webfont.EventDispatcher.INACTIVE = 'inactive';
40
+
41
+ /**
42
+ * @const
43
+ * @type {string}
44
+ */
17
45
  webfont.EventDispatcher.FONT = 'font';
18
46
 
19
47
  webfont.EventDispatcher.prototype.dispatchLoading = function() {
@@ -23,6 +51,10 @@ webfont.EventDispatcher.prototype.dispatchLoading = function() {
23
51
  this.dispatch_(webfont.EventDispatcher.LOADING);
24
52
  };
25
53
 
54
+ /**
55
+ * @param {string} fontFamily
56
+ * @param {string} fontDescription
57
+ */
26
58
  webfont.EventDispatcher.prototype.dispatchFontLoading = function(fontFamily, fontDescription) {
27
59
  this.domHelper_.appendClassName(this.htmlElement_,
28
60
  this.cssClassName_.build(
@@ -31,6 +63,10 @@ webfont.EventDispatcher.prototype.dispatchFontLoading = function(fontFamily, fon
31
63
  webfont.EventDispatcher.FONT + webfont.EventDispatcher.LOADING, fontFamily, fontDescription);
32
64
  };
33
65
 
66
+ /**
67
+ * @param {string} fontFamily
68
+ * @param {string} fontDescription
69
+ */
34
70
  webfont.EventDispatcher.prototype.dispatchFontActive = function(fontFamily, fontDescription) {
35
71
  this.domHelper_.removeClassName(this.htmlElement_,
36
72
  this.cssClassName_.build(
@@ -42,6 +78,10 @@ webfont.EventDispatcher.prototype.dispatchFontActive = function(fontFamily, font
42
78
  webfont.EventDispatcher.FONT + webfont.EventDispatcher.ACTIVE, fontFamily, fontDescription);
43
79
  };
44
80
 
81
+ /**
82
+ * @param {string} fontFamily
83
+ * @param {string} fontDescription
84
+ */
45
85
  webfont.EventDispatcher.prototype.dispatchFontInactive = function(fontFamily, fontDescription) {
46
86
  this.domHelper_.removeClassName(this.htmlElement_,
47
87
  this.cssClassName_.build(
@@ -71,6 +111,11 @@ webfont.EventDispatcher.prototype.dispatchActive = function() {
71
111
  this.dispatch_(webfont.EventDispatcher.ACTIVE);
72
112
  };
73
113
 
114
+ /**
115
+ * @param {string} event
116
+ * @param {string=} opt_arg1
117
+ * @param {string=} opt_arg2
118
+ */
74
119
  webfont.EventDispatcher.prototype.dispatch_ = function(event, opt_arg1, opt_arg2) {
75
120
  if (this.callbacks_[event]) {
76
121
  this.callbacks_[event](opt_arg1, opt_arg2);
@@ -6,11 +6,17 @@ webfont.FontVariationDescription = function() {
6
6
  this.values_ = webfont.FontVariationDescription.VALUES;
7
7
  };
8
8
 
9
+ /**
10
+ * @const
11
+ */
9
12
  webfont.FontVariationDescription.PROPERTIES = [
10
13
  'font-style',
11
14
  'font-weight'
12
15
  ];
13
16
 
17
+ /**
18
+ * @const
19
+ */
14
20
  webfont.FontVariationDescription.VALUES = {
15
21
  'font-style': [
16
22
  ['n', 'normal'],
@@ -33,6 +39,7 @@ webfont.FontVariationDescription.VALUES = {
33
39
  };
34
40
 
35
41
  /**
42
+ * @private
36
43
  * @constructor
37
44
  */
38
45
  webfont.FontVariationDescription.Item = function(index, property, values) {
@@ -59,6 +66,12 @@ webfont.FontVariationDescription.Item.prototype.expand = function(output, value)
59
66
  }
60
67
  }
61
68
 
69
+ /**
70
+ * Compacts CSS declarations into an FVD.
71
+ * @param {string} input A string of CSS declarations such as
72
+ * 'font-weight:normal;font-style:italic'.
73
+ * @return {string} The equivalent FVD such as 'n4'.
74
+ */
62
75
  webfont.FontVariationDescription.prototype.compact = function(input) {
63
76
  var result = ['n', '4'];
64
77
  var descriptors = input.split(';');
@@ -78,6 +91,12 @@ webfont.FontVariationDescription.prototype.compact = function(input) {
78
91
  return result.join('');
79
92
  };
80
93
 
94
+ /**
95
+ * Expands a FVD string into equivalent CSS declarations.
96
+ * @param {string} fvd The FVD string, such as 'n4'.
97
+ * @return {?string} The equivalent CSS such as
98
+ * 'font-weight:normal;font-style:italic' or null if it cannot be parsed.
99
+ */
81
100
  webfont.FontVariationDescription.prototype.expand = function(fvd) {
82
101
  if (fvd.length != 2) {
83
102
  return null;
@@ -100,6 +119,9 @@ webfont.FontVariationDescription.prototype.expand = function(fvd) {
100
119
  }
101
120
  }
102
121
 
122
+ /**
123
+ * @private
124
+ */
103
125
  webfont.FontVariationDescription.prototype.getItem_ = function(property) {
104
126
  for (var i = 0; i < this.properties_.length; i++) {
105
127
  if (property == this.properties_[i]) {
@@ -15,9 +15,25 @@ webfont.FontWatcher = function(domHelper, eventDispatcher, fontSizer,
15
15
  this.fvd_ = new webfont.FontVariationDescription();
16
16
  };
17
17
 
18
+ /**
19
+ * @type {string}
20
+ * @const
21
+ */
18
22
  webfont.FontWatcher.DEFAULT_FONT = '_,arial,helvetica';
23
+
24
+ /**
25
+ * @type {string}
26
+ * @const
27
+ */
19
28
  webfont.FontWatcher.DEFAULT_VARIATION = 'n4';
20
29
 
30
+ /**
31
+ * Watches a set of font families.
32
+ * @param {Array.<string>} fontFamilies The font family names to watch.
33
+ * @param {Object.<string, Array.<string>>} fontDescriptions The font variations
34
+ * of each family to watch. Described with FVD.
35
+ * @param {boolean} last True if this is the last set of families to watch.
36
+ */
21
37
  webfont.FontWatcher.prototype.watch = function(fontFamilies, fontDescriptions, last) {
22
38
  var length = fontFamilies.length;
23
39
 
@@ -46,6 +62,9 @@ webfont.FontWatcher.prototype.watch = function(fontFamilies, fontDescriptions, l
46
62
  }
47
63
  };
48
64
 
65
+ /**
66
+ * @private
67
+ */
49
68
  webfont.FontWatcher.prototype.watch_ = function(fontFamily, fontDescription, originalSize) {
50
69
  this.eventDispatcher_.dispatchFontLoading(fontFamily, fontDescription);
51
70
  var requestedFont = this.createHiddenElementWithFont_(this.nameHelper_.quote(fontFamily),
@@ -63,6 +82,9 @@ webfont.FontWatcher.prototype.watch_ = function(fontFamily, fontDescription, ori
63
82
  }
64
83
  };
65
84
 
85
+ /**
86
+ * @private
87
+ */
66
88
  webfont.FontWatcher.prototype.decreaseCurrentlyWatched_ = function() {
67
89
  if (--this.currentlyWatched_ == 0 && this.last_) {
68
90
  if (this.success_) {
@@ -73,6 +95,9 @@ webfont.FontWatcher.prototype.decreaseCurrentlyWatched_ = function() {
73
95
  }
74
96
  };
75
97
 
98
+ /**
99
+ * @private
100
+ */
76
101
  webfont.FontWatcher.prototype.check_ = function(started, originalSize,
77
102
  requestedFont, fontFamily, fontDescription) {
78
103
  var size = this.fontSizer_.getWidth(requestedFont);
@@ -91,6 +116,9 @@ webfont.FontWatcher.prototype.check_ = function(started, originalSize,
91
116
  }
92
117
  };
93
118
 
119
+ /**
120
+ * @private
121
+ */
94
122
  webfont.FontWatcher.prototype.asyncCheck_ = function(started, originalSize,
95
123
  requestedFont, fontFamily, fontDescription) {
96
124
  this.asyncCall_(function(context, func) {
@@ -100,6 +128,9 @@ webfont.FontWatcher.prototype.asyncCheck_ = function(started, originalSize,
100
128
  }(this, this.check_), 50);
101
129
  };
102
130
 
131
+ /**
132
+ * @private
133
+ */
103
134
  webfont.FontWatcher.prototype.getDefaultFontSize_ = function(fontDescription) {
104
135
  var defaultFont = this.createHiddenElementWithFont_(
105
136
  webfont.FontWatcher.DEFAULT_FONT, fontDescription);
@@ -109,6 +140,9 @@ webfont.FontWatcher.prototype.getDefaultFontSize_ = function(fontDescription) {
109
140
  return size;
110
141
  };
111
142
 
143
+ /**
144
+ * @private
145
+ */
112
146
  webfont.FontWatcher.prototype.createHiddenElementWithFont_ = function(
113
147
  fontFamily, fontDescription) {
114
148
  var variationCss = this.fvd_.expand(fontDescription);
@@ -1,5 +1,10 @@
1
1
  var webfont = {};
2
2
 
3
+ /**
4
+ * @param {Object} context
5
+ * @param {function(...[*])} func
6
+ * @param {...*} opt_args
7
+ */
3
8
  webfont.bind = function(context, func, opt_args) {
4
9
  var args = arguments.length > 2 ?
5
10
  Array.prototype.slice.call(arguments, 2) : [];
@@ -1,4 +1,11 @@
1
1
  /**
2
+ * @param {string} name
3
+ * @param {string} version
4
+ * @param {string} engine
5
+ * @param {string} engineVersion
6
+ * @param {string} platform
7
+ * @param {string} platformVersion
8
+ * @param {boolean} webFontSupport
2
9
  * @constructor
3
10
  */
4
11
  webfont.UserAgent = function(name, version, engine, engineVersion, platform,
@@ -12,30 +19,51 @@ webfont.UserAgent = function(name, version, engine, engineVersion, platform,
12
19
  this.webFontSupport_ = webFontSupport;
13
20
  };
14
21
 
22
+ /**
23
+ * @return {string}
24
+ */
15
25
  webfont.UserAgent.prototype.getName = function() {
16
26
  return this.name_;
17
27
  };
18
28
 
29
+ /**
30
+ * @return {string}
31
+ */
19
32
  webfont.UserAgent.prototype.getVersion = function() {
20
33
  return this.version_;
21
34
  };
22
35
 
36
+ /**
37
+ * @return {string}
38
+ */
23
39
  webfont.UserAgent.prototype.getEngine = function() {
24
40
  return this.engine_;
25
41
  };
26
42
 
43
+ /**
44
+ * @return {string}
45
+ */
27
46
  webfont.UserAgent.prototype.getEngineVersion = function() {
28
47
  return this.engineVersion_;
29
48
  };
30
49
 
50
+ /**
51
+ * @return {string}
52
+ */
31
53
  webfont.UserAgent.prototype.getPlatform = function() {
32
54
  return this.platform_;
33
55
  };
34
56
 
57
+ /**
58
+ * @return {string}
59
+ */
35
60
  webfont.UserAgent.prototype.getPlatformVersion = function() {
36
61
  return this.platformVersion_;
37
62
  };
38
63
 
64
+ /**
65
+ * @return {boolean}
66
+ */
39
67
  webfont.UserAgent.prototype.isSupportingWebFont = function() {
40
68
  return this.webFontSupport_;
41
69
  };
@@ -1,15 +1,34 @@
1
1
  /**
2
+ * @param {string} userAgent The browser userAgent string to parse.
2
3
  * @constructor
3
4
  */
4
5
  webfont.UserAgentParser = function(userAgent) {
5
6
  this.userAgent_ = userAgent;
6
7
  };
7
8
 
9
+ /**
10
+ * @const
11
+ * @type {string}
12
+ */
8
13
  webfont.UserAgentParser.UNKNOWN = "Unknown";
9
14
 
10
- webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(webfont.UserAgentParser.UNKNOWN,
11
- webfont.UserAgentParser.UNKNOWN, webfont.UserAgentParser.UNKNOWN, webfont.UserAgentParser.UNKNOWN, false);
15
+ /**
16
+ * @const
17
+ * @type {webfont.UserAgent}
18
+ */
19
+ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(
20
+ webfont.UserAgentParser.UNKNOWN,
21
+ webfont.UserAgentParser.UNKNOWN,
22
+ webfont.UserAgentParser.UNKNOWN,
23
+ webfont.UserAgentParser.UNKNOWN,
24
+ webfont.UserAgentParser.UNKNOWN,
25
+ webfont.UserAgentParser.UNKNOWN,
26
+ false);
12
27
 
28
+ /**
29
+ * Parses the user agent string and returns an object.
30
+ * @return {webfont.UserAgent}
31
+ */
13
32
  webfont.UserAgentParser.prototype.parse = function() {
14
33
  if (this.isIe_()) {
15
34
  return this.parseIeUserAgentString_();
@@ -24,6 +43,9 @@ webfont.UserAgentParser.prototype.parse = function() {
24
43
  }
25
44
  };
26
45
 
46
+ /**
47
+ * @private
48
+ */
27
49
  webfont.UserAgentParser.prototype.getPlatform_ = function() {
28
50
  var mobileOs = this.getMatchingGroup_(this.userAgent_,
29
51
  /(iPod|iPad|iPhone|Android)/, 1);
@@ -43,6 +65,9 @@ webfont.UserAgentParser.prototype.getPlatform_ = function() {
43
65
  return webfont.UserAgentParser.UNKNOWN;
44
66
  };
45
67
 
68
+ /**
69
+ * @private
70
+ */
46
71
  webfont.UserAgentParser.prototype.getPlatformVersion_ = function() {
47
72
  var macVersion = this.getMatchingGroup_(this.userAgent_,
48
73
  /(OS X|Windows NT|Android) ([^;]+)/, 2);
@@ -63,10 +88,16 @@ webfont.UserAgentParser.prototype.getPlatformVersion_ = function() {
63
88
  return webfont.UserAgentParser.UNKNOWN;
64
89
  };
65
90
 
91
+ /**
92
+ * @private
93
+ */
66
94
  webfont.UserAgentParser.prototype.isIe_ = function() {
67
95
  return this.userAgent_.indexOf("MSIE") != -1;
68
96
  };
69
97
 
98
+ /**
99
+ * @private
100
+ */
70
101
  webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
71
102
  var browser = this.getMatchingGroup_(this.userAgent_, /(MSIE [\d\w\.]+)/, 1);
72
103
  var engineName = webfont.UserAgentParser.UNKNOWN;
@@ -87,10 +118,16 @@ webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
87
118
  this.getPlatform_(), this.getPlatformVersion_(), false);
88
119
  };
89
120
 
121
+ /**
122
+ * @private
123
+ */
90
124
  webfont.UserAgentParser.prototype.isOpera_ = function() {
91
125
  return this.userAgent_.indexOf("Opera") != -1;
92
126
  };
93
127
 
128
+ /**
129
+ * @private
130
+ */
94
131
  webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
95
132
  var engineName = webfont.UserAgentParser.UNKNOWN;
96
133
  var engineVersion = webfont.UserAgentParser.UNKNOWN;
@@ -125,18 +162,24 @@ webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
125
162
 
126
163
  if (version != "") {
127
164
  return new webfont.UserAgent("Opera", version, engineName, engineVersion,
128
- this.getPlatform_(), this.getPlatformVersion_(),
165
+ this.getPlatform_(), this.getPlatformVersion_(),
129
166
  this.getMajorVersion_(version) >= 10);
130
167
  }
131
168
  return new webfont.UserAgent("Opera", webfont.UserAgentParser.UNKNOWN,
132
- engineName, engineVersion,
169
+ engineName, engineVersion,
133
170
  this.getPlatform_(), this.getPlatformVersion_(), false);
134
171
  };
135
172
 
173
+ /**
174
+ * @private
175
+ */
136
176
  webfont.UserAgentParser.prototype.isWebKit_ = function() {
137
177
  return this.userAgent_.indexOf("AppleWebKit") != -1;
138
178
  };
139
179
 
180
+ /**
181
+ * @private
182
+ */
140
183
  webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
141
184
  var platform = this.getPlatform_();
142
185
  var platformVersion = this.getPlatformVersion_();
@@ -166,13 +209,19 @@ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
166
209
 
167
210
  return new webfont.UserAgent(name, version, "AppleWebKit", webKitVersion,
168
211
  platform, platformVersion, this.getMajorVersion_(webKitVersion) >= 526 ||
169
- this.getMajorVersion_(webKitVersion) >= 525 && parseInt(minor) >= 13);
212
+ this.getMajorVersion_(webKitVersion) >= 525 && parseInt(minor, 10) >= 13);
170
213
  };
171
214
 
215
+ /**
216
+ * @private
217
+ */
172
218
  webfont.UserAgentParser.prototype.isGecko_ = function() {
173
219
  return this.userAgent_.indexOf("Gecko") != -1;
174
220
  };
175
221
 
222
+ /**
223
+ * @private
224
+ */
176
225
  webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
177
226
  var name = webfont.UserAgentParser.UNKNOWN;
178
227
  var version = webfont.UserAgentParser.UNKNOWN;
@@ -188,7 +237,7 @@ webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
188
237
 
189
238
  version = versionNum;
190
239
  supportWebFont = versionNum != "" && this.getMajorVersion_(versionNum) >= 3 &&
191
- parseInt(minor) >= 5;
240
+ parseInt(minor, 10) >= 5;
192
241
  }
193
242
  } else if (this.userAgent_.indexOf("Mozilla") != -1) {
194
243
  name = "Mozilla";
@@ -200,8 +249,8 @@ webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
200
249
  } else {
201
250
  if (!supportWebFont) {
202
251
  var majorVersion = this.getMajorVersion_(geckoVersion);
203
- var intMinorVersion = parseInt(this.getMatchingGroup_(geckoVersion, /\d+\.(\d+)/, 1));
204
- var subVersion = parseInt(this.getMatchingGroup_(geckoVersion, /\d+\.\d+\.(\d+)/, 1));
252
+ var intMinorVersion = parseInt(this.getMatchingGroup_(geckoVersion, /\d+\.(\d+)/, 1), 10);
253
+ var subVersion = parseInt(this.getMatchingGroup_(geckoVersion, /\d+\.\d+\.(\d+)/, 1), 10);
205
254
 
206
255
  supportWebFont = majorVersion > 1 ||
207
256
  majorVersion == 1 && intMinorVersion > 9 ||
@@ -214,15 +263,21 @@ webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
214
263
  this.getPlatform_(), this.getPlatformVersion_(), supportWebFont);
215
264
  };
216
265
 
266
+ /**
267
+ * @private
268
+ */
217
269
  webfont.UserAgentParser.prototype.getMajorVersion_ = function(version) {
218
270
  var majorVersion = this.getMatchingGroup_(version, /(\d+)/, 1);
219
271
 
220
272
  if (majorVersion != "") {
221
- return parseInt(majorVersion);
273
+ return parseInt(majorVersion, 10);
222
274
  }
223
275
  return -1;
224
276
  };
225
277
 
278
+ /**
279
+ * @private
280
+ */
226
281
  webfont.UserAgentParser.prototype.getMatchingGroup_ = function(str,
227
282
  regexp, index) {
228
283
  var groups = str.match(regexp);
@@ -31,7 +31,9 @@ webfont.CustomCss.prototype.supportUserAgent = function(userAgent, support) {
31
31
  return support(userAgent.isSupportingWebFont());
32
32
  };
33
33
 
34
- WebFont.addModule(webfont.CustomCss.NAME, function(configuration) {
35
- return new webfont.CustomCss(new webfont.DomHelper(document),
36
- configuration);
34
+ window['WebFont'].addModule(webfont.CustomCss.NAME, function(configuration) {
35
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
36
+ var userAgent = userAgentParser.parse();
37
+ var domHelper = new webfont.DomHelper(document, userAgent);
38
+ return new webfont.CustomCss(domHelper, configuration);
37
39
  });
@@ -41,9 +41,9 @@ webfont.GoogleFontApi.prototype.load = function(onReady) {
41
41
  onReady(fontApiParser.getFontFamilies(), fontApiParser.getVariations());
42
42
  };
43
43
 
44
- WebFont.addModule(webfont.GoogleFontApi.NAME, function(configuration) {
44
+ window['WebFont'].addModule(webfont.GoogleFontApi.NAME, function(configuration) {
45
45
  var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
46
46
  var userAgent = userAgentParser.parse();
47
47
  return new webfont.GoogleFontApi(userAgent,
48
- new webfont.DomHelper(document), configuration);
48
+ new webfont.DomHelper(document, userAgent), configuration);
49
49
  });
@@ -52,7 +52,10 @@ webfont.TypekitScript.prototype.load = function(onReady) {
52
52
  onReady(this.fontFamilies_, this.fontVariations_);
53
53
  };
54
54
 
55
- WebFont.addModule(webfont.TypekitScript.NAME, function(configuration) {
56
- return new webfont.TypekitScript(window, new webfont.DomHelper(document), configuration);
55
+ window['WebFont'].addModule(webfont.TypekitScript.NAME, function(configuration) {
56
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
57
+ var userAgent = userAgentParser.parse();
58
+ var domHelper = new webfont.DomHelper(document, userAgent);
59
+ return new webfont.TypekitScript(window, domHelper, configuration);
57
60
  });
58
61
 
@@ -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.5'
17
- s.date = '2010-07-12'
16
+ s.version = '1.0.6'
17
+ s.date = '2010-07-20'
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
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: 2010-07-12 00:00:00 -07:00
19
+ date: 2010-07-20 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency