Permalink
Browse files

Merge pull request #75 from hash3g/master

Adding suppport for "Optimizing your font requests (Beta)"
  • Loading branch information...
2 parents 834cd8b + a2fea1a commit 8fc28e1f7a9fb1f93548e6d6fbff0fc93a677d9c @bramstein bramstein committed Jan 21, 2013
Showing with 28 additions and 2 deletions.
  1. +21 −0 src-test/google/fontapiurlbuildertest.js
  2. +6 −1 src/google/fontapiurlbuilder.js
  3. +1 −1 src/google/googlefontapi.js
@@ -48,3 +48,24 @@ FontApiUrlBuilderTest.prototype.testBuildProperUrlWithSubsetsNoVariations =
'?family=Font1:bold,italic%7CFont2:italic%7CFont3' +
'&subset=greek,cyrillic,latin', fontApiUrlBuilder.build());
};
+
+
+FontApiUrlBuilderTest.prototype.testBuildProperUrlWithText = function() {
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(undefined, "http:", "lorem ipsum");
+
+ fontApiUrlBuilder.setFontFamilies([ 'Font1', 'Font2' ]);
+ assertEquals("http:" + webfont.FontApiUrlBuilder.DEFAULT_API_URL +
+ '?family=Font1%7CFont2' +
+ '&text=lorem%20ipsum', fontApiUrlBuilder.build());
+};
+
+
+FontApiUrlBuilderTest.prototype.testBuildProperUrlWithEmptyText = function() {
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(undefined, "http:", "");
+
+ fontApiUrlBuilder.setFontFamilies([ 'Font1:bold:greek,cyrillic',
+ 'Font2:italic', 'Font3' ]);
+ assertEquals("http:" + webfont.FontApiUrlBuilder.DEFAULT_API_URL +
+ '?family=Font1:bold%7CFont2:italic%7CFont3' +
+ '&subset=greek,cyrillic', fontApiUrlBuilder.build());
+};
@@ -1,14 +1,15 @@
/**
* @constructor
*/
-webfont.FontApiUrlBuilder = function(apiUrl, protocol) {
+webfont.FontApiUrlBuilder = function(apiUrl, protocol, text) {
if (apiUrl) {
this.apiUrl_ = apiUrl;
} else {
this.apiUrl_ = protocol + webfont.FontApiUrlBuilder.DEFAULT_API_URL;
}
this.fontFamilies_ = [];
this.subsets_ = [];
+ this.text_ = text || '';
};
@@ -63,5 +64,9 @@ webfont.FontApiUrlBuilder.prototype.build = function() {
url += '&subset=' + this.subsets_.join(',');
}
+ if (this.text_.length > 0) {
+ url += '&text=' + encodeURIComponent(this.text_);
+ }
+
return url;
};
@@ -35,7 +35,7 @@ webfont.GoogleFontApi.prototype.load = function(onReady) {
webfont.GoogleFontApi.prototype.insertLink_ = function(onReady) {
var domHelper = this.domHelper_;
var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(
- this.configuration_['api'], domHelper.getProtocol());
+ this.configuration_['api'], domHelper.getProtocol(), this.configuration_['text']);
var fontFamilies = this.configuration_['families'];
fontApiUrlBuilder.setFontFamilies(fontFamilies);

0 comments on commit 8fc28e1

Please sign in to comment.