goog.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /** @license
  2. * RequireJS plugin for loading Google Ajax API modules thru `google.load`
  3. * Author: Miller Medeiros
  4. * Version: 0.2.0 (2011/12/06)
  5. * Released under the MIT license
  6. */
  7. define(['async', 'propertyParser'], function (async, propertyParser) {
  8. var rParts = /^([^,]+)(?:,([^,]+))?(?:,(.+))?/;
  9. function parseName(name){
  10. var match = rParts.exec(name),
  11. data = {
  12. moduleName : match[1],
  13. version : match[2] || '1'
  14. };
  15. data.settings = propertyParser.parseProperties(match[3]);
  16. return data;
  17. }
  18. return {
  19. load : function(name, req, onLoad, config){
  20. if (config.isBuild) {
  21. onLoad(null); //avoid errors on the optimizer
  22. } else {
  23. var data = parseName(name),
  24. settings = data.settings;
  25. settings.callback = onLoad;
  26. req(['async!'+ (document.location.protocol === 'https:'? 'https' : 'http') +'://www.google.com/jsapi'], function(){
  27. google.load(data.moduleName, data.version, settings);
  28. });
  29. }
  30. }
  31. };
  32. });