/*! * JavaScript - loadGoogleMaps( version, apiKey, language, sensor ) * * - Load Google Maps API using jQuery Deferred. * Useful if you want to only load the Google Maps API on-demand. * - Requires jQuery 1.5 * * UPDATES by Gavin Foley * - Tidied JS & made it JSLint compliant * - Updated script request to Google Maps API to be protocol relative * - Added "sensor" parameter which defaults to false if not present * * Copyright (c) 2011 Glenn Baker * Dual licensed under the MIT and GPL licenses. */ /*globals window, google, jQuery*/ var loadGoogleMaps = (function ($) { "use strict"; var now = $.now(), promise; return function (version, apiKey, language, sensor) { if (promise) { return promise; } //Create a Deferred Object var deferred = $.Deferred(), //Declare a resolve function, pass google.maps for the done functions resolve = function () { deferred.resolve(window.google && window.google.maps ? window.google.maps : false); }, //global callback name callbackName = "loadGoogleMaps_" + (now++), // Default Parameters params = $.extend({ "sensor": sensor || "false" }, apiKey ? { "key": apiKey } : {}, language ? { "language": language } : {}); //If google.maps exists, then Google Maps API was probably loaded with the