Skip to content

Commit

Permalink
Update to point at new Fontdeck JS interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahume committed Nov 9, 2011
1 parent 7fadf42 commit 72d28a0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/webfontloader/demo/public/fontdeck.html
Expand Up @@ -17,7 +17,7 @@
}
WebFont.load({
fontdeck: {
id: '2282'
id: 2282
},
loading: function() {
progress('loading');
Expand Down
76 changes: 62 additions & 14 deletions src-test/fontdeck/fontdeck_script_test.js
Expand Up @@ -5,10 +5,39 @@ FontdeckScriptTest.prototype.testSupportAndLoadLifecycle = function() {
'id': '2282'
};
var apiResponse = {
'css':'http://fontdeck.com/s/css/uH5+KWQnibDTJRYggGJ9XZLTAgw/webfontloader/2282.css',
'provides':[
{'font_size_adjust':null,'weight':'normal','style':'normal','name':'Fertigo Pro Regular'},
{'font_size_adjust':'0.5','weight':'bold','style':'italic','name':'Bodoni Display Bold Italic'}
"domain" : "localhost",
"cssurl" : "http://f.fontdeck.com/s/css/03BmCXiV2AHwX/Rp+OBFTfD2oFs/localhost/2282.css",
"project" : 2282,
"cssbase" : "http://f.fontdeck.com/s/css/03BmCXiV2AHwX/Rp+OBFTfD2oFs",
"fonts" : [
{
"font_family" : "'Fertigo Pro Regular', Fertigo, Constantia, Palatino, serif",
"font_size_adjust" : 0.508,
"name" : "Fertigo Pro Regular",
"style" : "normal",
"weight" : "normal",
"font_urls" : {
"eot" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.eot",
"ttf" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.ttf",
"woff" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.woff",
"svg" : "http://f.fontdeck.com/f/1/SUlFR0tid0kAA2vb11Ly/IGWDK+wV8TMAfV0J1Ej1J1GFRT1bssqrn6a.svg#104"
},
"id" : 104
},
{
"font_family" : "'Bodoni Display Bold Italic', Georgia, 'Times New Roman', Times, serif",
"font_size_adjust" : 0.45,
"name" : "Bodoni Display Bold Italic",
"style" : "italic",
"weight" : "bold",
"font_urls" : {
"eot" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.eot",
"ttf" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.ttf",
"woff" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.woff",
"svg" : "http://f.fontdeck.com/f/1/azJEbTVyc1QAA11+CAE5C93+l/bAQx1ipRo6Maba19w3Yy5ng+qVWlfj.svg#2256"
},
"id" : 2256
}
]
};
var insert = '';
Expand All @@ -19,10 +48,6 @@ FontdeckScriptTest.prototype.testSupportAndLoadLifecycle = function() {
},
createScriptSrc: function(srcLink) {
src = srcLink;
},
createCssLink: function(cssLink) {
css = cssLink;
return '<link href="' + css + '" type="text/css" />';
}
};
var global = {};
Expand All @@ -34,16 +59,39 @@ FontdeckScriptTest.prototype.testSupportAndLoadLifecycle = function() {

fontdeck.supportUserAgent(userAgent, function(support) { isSupport = support; });
assertEquals('head', insert);
assertEquals('http://fontdeck.com/api/v1/project-info?project=2282&domain=localhost&callback=window.__webfontfontdeckmodule__[2282]', src);
//assertEquals('http://f.fontdeck.com/s/css/json/localhost/2282.json', src);
assertEquals(null, isSupport);

assertNotNull(global.__webfontfontdeckmodule__);
assertNotNull(global.__webfontfontdeckmodule__['2282']);

// Call the callback function passing in dummy API response.
global.__webfontfontdeckmodule__['2282'](apiResponse);
global.__webfontfontdeckmodule__['2282'](true, apiResponse);

assertEquals(fontdeck.fontFamilies_, [apiResponse.fonts[0].name, apiResponse.fonts[1].name]);
assertEquals(fontdeck.fontVariations_[apiResponse.fonts[0].name], ['n4']);
assertEquals(fontdeck.fontVariations_[apiResponse.fonts[1].name], ['i7']);

assertEquals(true, isSupport);
};

FontdeckScriptTest.prototype.testNoProjectId = function() {
var configuration = {
'id': null
};
var insert = '';
var src = '';
var fakeDomHelper = {};
var global = {};
var fontdeck = new webfont.FontdeckScript(global, fakeDomHelper, configuration);

assertEquals(fontdeck.fontFamilies_, [apiResponse.provides[0].name, apiResponse.provides[1].name]);
assertEquals(fontdeck.fontVariations_[apiResponse.provides[0].name], ['n4']);
assertEquals(fontdeck.fontVariations_[apiResponse.provides[1].name], ['i7']);
};
// supportUserAgent
var userAgent = 'user agent';
var isSupport = null;

fontdeck.supportUserAgent(userAgent, function(support) { isSupport = support; });

assertEquals(fontdeck.fontFamilies_, []);
assertEquals(fontdeck.fontVariations_, []);
assertEquals(true, isSupport);
}
29 changes: 13 additions & 16 deletions src/fontdeck/fontdeck_script.js
Expand Up @@ -12,11 +12,11 @@ webfont.FontdeckScript = function(global, domHelper, configuration) {

webfont.FontdeckScript.NAME = 'fontdeck';
webfont.FontdeckScript.HOOK = '__webfontfontdeckmodule__';
webfont.FontdeckScript.API = 'http://fontdeck.com/api/v1/project-info?'
webfont.FontdeckScript.API = 'http://f.fontdeck.com/s/css/js/';

webfont.FontdeckScript.prototype.getScriptSrc = function(projectId) {
var api = this.configuration_['api'] || webfont.FontdeckScript.API;
return api + 'project=' + projectId + '&domain=' + document.location.hostname + '&callback=window.__webfontfontdeckmodule__[' + projectId + ']';
return api + document.location.hostname + '/' + projectId + '.js';
};

webfont.FontdeckScript.prototype.supportUserAgent = function(userAgent, support) {
Expand All @@ -30,20 +30,17 @@ webfont.FontdeckScript.prototype.supportUserAgent = function(userAgent, support)
this.global_[webfont.FontdeckScript.HOOK] = {};
}

// The API will call this function with a link to the CSS
// and a list of supported fonts.
this.global_[webfont.FontdeckScript.HOOK][projectId] = function(data) {
self.domHelper_.insertInto('head', self.domHelper_.createCssLink(data['css']));
for (var i = 0, j = data['provides'].length; i < j; ++i) {
var font = data['provides'][i];
self.fontFamilies_.push(font['name']);
self.fontVariations_[font['name']] = [self.fvd_.compact("font-weight:" + font['weight'] + ";font-style:" + font['style'])];
}
// If families were passed into load, then use them instead.
if (families !== null) {
self.fontFamilies_ = families;
}
support(true);
// Fontdeck will call this function to indicate support status
// and what fonts are provided.
this.global_[webfont.FontdeckScript.HOOK][projectId] = function(fontdeckSupports, data) {
var rules = '';
for (var i = 0, j = data['fonts'].length; i<j; ++i) {
var font = data['fonts'][i];
// Add the FVDs
self.fontFamilies_.push(font['name']);
self.fontVariations_[font['name']] = [self.fvd_.compact("font-weight:" + font['weight'] + ";font-style:" + font['style'])];
}
support(fontdeckSupports);
};

// Call the Fontdeck API.
Expand Down

0 comments on commit 72d28a0

Please sign in to comment.