Permalink
Browse files

Merge pull request #57 from typekit/urlbuilder_cleanup

Updated FontApiUrlBuilder to properly take into account empty variations...
  • Loading branch information...
2 parents 125188f + 28cff37 commit f17410f5a319b6037d234e3b1efed8b6d87ad3cf Sean McBride committed Jul 26, 2012
Showing with 17 additions and 2 deletions.
  1. +11 −0 src-test/google/fontapiurlbuildertest.js
  2. +6 −2 src/google/fontapiurlbuilder.js
@@ -37,3 +37,14 @@ FontApiUrlBuilderTest.prototype.testBuildProperUrlWithSubsets = function() {
'?family=Font1:bold%7CFont2:italic%7CFont3' +
'&subset=greek,cyrillic', fontApiUrlBuilder.build());
};
+
+FontApiUrlBuilderTest.prototype.testBuildProperUrlWithSubsetsNoVariations =
+ function() {
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder();
+
+ fontApiUrlBuilder.setFontFamilies([ 'Font1:bold,italic:greek,cyrillic',
+ 'Font2:italic', 'Font3::latin' ]);
+ assertEquals("http:" + webfont.FontApiUrlBuilder.DEFAULT_API_URL +
+ '?family=Font1:bold,italic%7CFont2:italic%7CFont3' +
+ '&subset=greek,cyrillic,latin', fontApiUrlBuilder.build());
+};
@@ -8,7 +8,7 @@ webfont.FontApiUrlBuilder = function(apiUrl) {
var protocol = 'https:' == window.location.protocol ? 'https:' : 'http:';
this.apiUrl_ = protocol + webfont.FontApiUrlBuilder.DEFAULT_API_URL;
- }
+ }
this.fontFamilies_ = [];
this.subsets_ = [];
};
@@ -32,7 +32,11 @@ webfont.FontApiUrlBuilder.prototype.parseFontFamilies_ =
if (elements.length == 3) {
this.subsets_.push(elements.pop());
}
- this.fontFamilies_.push(elements.join(':'));
+ var joinCharacter = '';
+ if (elements.length == 2 && elements[1] != ''){
+ joinCharacter = ':';
+ }
+ this.fontFamilies_.push(elements.join(joinCharacter));
}
};

0 comments on commit f17410f

Please sign in to comment.