This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
/*! | ||
* GMAP3 Plugin for jQuery | ||
* Version : 7.0 | ||
* Date : 2016/03/28 | ||
* Version : 7.1 | ||
* Date : 2016/04/17 | ||
* Author : DEMONTE Jean-Baptiste | ||
* Contact : [email protected] | ||
* Web site : http://gmap3.net | ||
* Licence : GPL-3.0+ | ||
*/ | ||
(function ($, window) { | ||
(function ($, window, document) { | ||
"use strict"; | ||
|
||
var gm, services = {}, | ||
var gm, services = {}, loadOptions, | ||
|
||
// Proxify functions to get shorter minimized code | ||
// Proxify functions to get shorter minimized code | ||
when = $.when, | ||
extend = $.extend, | ||
isArray = $.isArray, | ||
|
@@ -88,6 +88,20 @@ | |
return 1000 * 6371 * m.acos(m.min(cos(e) * cos(g) * cos(f) * cos(h) + cos(e) * sin(f) * cos(g) * sin(h) + sin(e) * sin(g), 1)); | ||
} | ||
|
||
function ready(fn) { | ||
if (document.readyState != 'loading'){ | ||
fn(); | ||
} else { | ||
document.addEventListener('DOMContentLoaded', fn); | ||
} | ||
} | ||
|
||
function serialize(obj) { | ||
return objectKeys(obj).map(function (key) { | ||
return encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]); | ||
}).join("&"); | ||
} | ||
|
||
// Auto-load google maps library if needed | ||
(function () { | ||
var dfd = deferred(), | ||
|
@@ -96,19 +110,22 @@ | |
|
||
$.holdReady(true); | ||
|
||
if (window.google && window.google.maps) { | ||
dfd.resolve(); | ||
} else { | ||
// callback function - resolving promise after maps successfully loaded | ||
window[cbName] = function () { | ||
delete window[cbName]; | ||
ready(function () { | ||
if (window.google && window.google.maps || loadOptions === false) { | ||
dfd.resolve(); | ||
}; | ||
script = window.document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = 'https://maps.googleapis.com/maps/api/js?callback=' + cbName; | ||
$("head").append(script); | ||
} | ||
} else { | ||
// callback function - resolving promise after maps successfully loaded | ||
window[cbName] = function () { | ||
delete window[cbName]; | ||
dfd.resolve(); | ||
}; | ||
script = document.createElement('script'); | ||
script.type = 'text/javascript'; | ||
script.src = 'https://maps.googleapis.com/maps/api/js?callback=' + cbName + (loadOptions ? '&' + (typeof loadOptions === 'string' ? loadOptions : serialize(loadOptions)) : ''); | ||
$("head").append(script); | ||
} | ||
}); | ||
|
||
return dfd.promise(); | ||
})().then(function () { | ||
$.holdReady(false); | ||
|
@@ -737,6 +754,14 @@ | |
}, 10); | ||
} | ||
|
||
/** | ||
* Configure google maps loading library | ||
* @param {string|object} options | ||
*/ | ||
$.gmap3 = function (options) { | ||
loadOptions = options; | ||
}; | ||
|
||
/** | ||
* jQuery Plugin | ||
*/ | ||
|
@@ -1091,6 +1116,9 @@ | |
return isArray(instance) ? instance.slice() : instance; | ||
}); | ||
} else { | ||
if (index < 0) { | ||
index = previousResults.length + index; | ||
} | ||
return isArray(previousResults[index]) ? previousResults[index].slice() : previousResults[index]; | ||
} | ||
}; | ||
|
@@ -1100,4 +1128,4 @@ | |
} | ||
} | ||
|
||
})(jQuery, window); | ||
})(jQuery, window, document); |
Oops, something went wrong.