font.js
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** @license
* RequireJS plugin for loading web fonts using the WebFont Loader
* Author: Miller Medeiros
* Version: 0.2.0 (2011/12/06)
* Released under the MIT license
*/
define(['propertyParser'], function (propertyParser) {
var rParts = /^([^,]+),([^\|]+)\|?/;
function parseName(name) {
var data = {},
vendors = name.split('|'),
n = vendors.length,
match;
while (n--) {
match = rParts.exec(vendors[n]);
data[ match[1] ] = propertyParser.parseProperties(match[2]);
}
return data;
}
// API
return {
//example: font!google,families:[Tangerine,Cantarell,Yanone Kaffeesatz:700]
load : function(name, req, onLoad, config){
if (config.isBuild) {
onLoad(null); //avoid errors on the optimizer
} else {
var data = parseName(name);
data.active = onLoad;
data.inactive = function(){
onLoad(false);
};
req([(document.location.protocol === 'https:'? 'https' : 'http') +'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'], function(){
WebFont.load(data);
});
}
}
};
});