font.js 1.3 KB

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