« Back to Index

Curl Google Plugin Example

View original Gist on GitHub

Tags: #js

Curl Google Plugin

// google! plugin:
var google; // will become defined by googleMain below
define({
    load: function (resourceId, req, loaded, config) {
        var googleMain = 'http://www.google.com/jsapi?key=' + config.apikey + 'callback=define',
            args = resourceId.split('/');
        // args = ['module-name', 'version', callbackFunc];
        args.push(function () { loaded(google[args[0]]); });
        // once main google library is available, get module
        req([googleMain], function () {
            google.load.apply(google, args);
        });
    }
});

Error returned

Uncaught Error: define() not found or duplicates found: http://www.google.com/jsapi?key=undefinedcallback=define

/*
Originally I didn't specify the path for the Google plugin and so the error I was getting (then) was:
GET http://curl:8888/Assets/Scripts/Curl/plugin/google.js 404 (Not Found)
Curl.js:4Uncaught Error: Syntax error or http error: Assets/Scripts/Curl/plugin/google.js
*/

index.html

<!doctype html>
<html dir="ltr" lang="en">
<head>
   <meta charset="utf-8">
	<title>Curl (Cujo Resource Loader)</title>
</head>
<body>

	<script type="text/javascript">
		curl = {
		    baseUrl: 'Assets/Scripts',
		    paths: {
		        curl: 'Curl',
		        google: 'Plugins/google'
		    }
		};
	</script>
	<script src="Assets/Scripts/Curl.js"></script>
	<script type="text/javascript">
		curl(['google!maps/3', 'google!visualization/1'], function(maps, viz) {		
			console.log(maps, viz);
		});
	</script>
	
</body>
</html>