jekyll-maps 2.3.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/History.md +9 -0
- data/lib/jekyll-maps/google_map_api.js +2 -1
- data/lib/jekyll-maps/google_map_api.rb +68 -1
- data/lib/jekyll-maps/google_map_tag.rb +11 -3
- data/lib/jekyll-maps/options_parser.rb +1 -0
- data/lib/jekyll-maps/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ee441d000168a4757b582f119515fea422526ed2ed1e592289526178fab0ed5
|
4
|
+
data.tar.gz: af9633bbd30002ebf716dca99d9fe492df65e5d569dda8067a571b5371c6f2b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5057ae7574e03e9a4dfdd17d1b42189ec9b99fee460f85b07be12fcb7dd4e7e60f05908f8736bd449ee5be075cbaa6df00ab61c672ae00f407cfd40c6856e770
|
7
|
+
data.tar.gz: 7649ede5d3a491311dd24c74d5fb63bd69cb1d3a294b2631021a79a1c84252c61a26d519376d9a1ab0da37b00ea80e469a09b1c546a6d485d483937414adf425
|
data/.travis.yml
CHANGED
data/History.md
CHANGED
@@ -2,6 +2,7 @@ module Jekyll
|
|
2
2
|
module Maps
|
3
3
|
class GoogleMapApi
|
4
4
|
HEAD_END_TAG = %r!</[\s\t]*head>!
|
5
|
+
BODY_END_TAG = %r!</[\s\t]*body>!
|
5
6
|
|
6
7
|
class << self
|
7
8
|
def prepend_api_code(doc)
|
@@ -14,12 +15,28 @@ module Jekyll
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
def prepend_google_api_code(doc)
|
19
|
+
@config = doc.site.config
|
20
|
+
if doc.output =~ BODY_END_TAG
|
21
|
+
# Insert API code before body's end if this document has one.
|
22
|
+
doc.output.gsub!(BODY_END_TAG, %(#{google_api_code}#{Regexp.last_match}))
|
23
|
+
else
|
24
|
+
doc.output.prepend(api_code)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
private
|
18
29
|
def api_code
|
19
30
|
<<HTML
|
20
31
|
<script type='text/javascript'>
|
21
32
|
#{js_lib_contents}
|
22
33
|
</script>
|
34
|
+
HTML
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def google_api_code
|
39
|
+
<<HTML
|
23
40
|
#{load_google_maps_api}
|
24
41
|
#{load_marker_cluster}
|
25
42
|
HTML
|
@@ -31,7 +48,56 @@ HTML
|
|
31
48
|
.fetch("google", {})
|
32
49
|
.fetch("api_key", "")
|
33
50
|
<<HTML
|
34
|
-
<script async defer
|
51
|
+
<script async defer>
|
52
|
+
|
53
|
+
|
54
|
+
// Load maps only when DOM is loaded
|
55
|
+
document.addEventListener("DOMContentLoaded", function() {
|
56
|
+
if (window.google && window.google.maps && jekyllMaps) {
|
57
|
+
// Maps script already loaded -> Execute callback method
|
58
|
+
jekyllMaps.initializeMap();
|
59
|
+
} else if (!('IntersectionObserver' in window) ||
|
60
|
+
!('IntersectionObserverEntry' in window) ||
|
61
|
+
!('intersectionRatio' in window.IntersectionObserverEntry.prototype)) {
|
62
|
+
// Intersection Observer -> Backup solution : load maps now
|
63
|
+
lazyLoadGoogleMap();
|
64
|
+
} else {
|
65
|
+
// Google Maps not loaded & Intersection Observer working -> Enable it
|
66
|
+
enableMapsObserver();
|
67
|
+
}
|
68
|
+
});
|
69
|
+
|
70
|
+
function enableMapsObserver() {
|
71
|
+
// Enable Observer on all Maps
|
72
|
+
var maps = document.getElementsByClassName('jekyll-map');
|
73
|
+
|
74
|
+
const observer = new IntersectionObserver(function(entries, observer) {
|
75
|
+
// Test if one of the maps is in the viewport
|
76
|
+
var isIntersecting = typeof entries[0].isIntersecting === 'boolean' ? entries[0].isIntersecting : entries[0].intersectionRatio > 0;
|
77
|
+
if (isIntersecting) {
|
78
|
+
lazyLoadGoogleMap();
|
79
|
+
observer.disconnect();
|
80
|
+
}
|
81
|
+
});
|
82
|
+
|
83
|
+
for(var i = 0; i < maps.length; i++) {
|
84
|
+
observer.observe(maps[i]);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
function lazyLoadGoogleMap() {
|
89
|
+
// If google maps api script not already loaded
|
90
|
+
if(!window.google || !window.google.maps) {
|
91
|
+
var fjs = document.getElementsByTagName('script')[0];
|
92
|
+
var js = document.createElement('script');
|
93
|
+
js.id = 'gmap-api';
|
94
|
+
js.setAttribute('async', '');
|
95
|
+
js.setAttribute('defer', '');
|
96
|
+
js.src = "//maps.google.com/maps/api/js?key=#{api_key}&callback=#{Jekyll::Maps::GoogleMapTag::JS_LIB_NAME}.initializeMap";
|
97
|
+
fjs.parentNode.insertBefore(js, fjs);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
</script>
|
35
101
|
HTML
|
36
102
|
end
|
37
103
|
|
@@ -68,5 +134,6 @@ end
|
|
68
134
|
Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
|
69
135
|
if doc.output =~ %r!#{Jekyll::Maps::GoogleMapTag::JS_LIB_NAME}!
|
70
136
|
Jekyll::Maps::GoogleMapApi.prepend_api_code(doc)
|
137
|
+
Jekyll::Maps::GoogleMapApi.prepend_google_api_code(doc)
|
71
138
|
end
|
72
139
|
end
|
@@ -32,7 +32,7 @@ HTML
|
|
32
32
|
attributes = []
|
33
33
|
attributes << "id='#{@args[:attributes][:id]}'"
|
34
34
|
attributes << render_dimensions
|
35
|
-
attributes << render_class
|
35
|
+
attributes << render_class
|
36
36
|
attributes.join(" ")
|
37
37
|
end
|
38
38
|
|
@@ -49,7 +49,14 @@ HTML
|
|
49
49
|
def render_class
|
50
50
|
css = @args[:attributes][:class]
|
51
51
|
css = css.join(" ") if css.is_a?(Array)
|
52
|
-
%(class='#{css}')
|
52
|
+
%(class='#{css} jekyll-map')
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def render_styles(site)
|
57
|
+
style_name = @args[:attributes][:styles] || "default"
|
58
|
+
maps_styles = site.data["maps_styles"] || {}
|
59
|
+
maps_styles[style_name] || "[]"
|
53
60
|
end
|
54
61
|
|
55
62
|
private
|
@@ -59,7 +66,8 @@ HTML
|
|
59
66
|
:useCluster => !@args[:flags][:no_cluster],
|
60
67
|
:showMarker => @args[:attributes][:show_marker] != "false",
|
61
68
|
:showMarkerPopup => @args[:attributes][:show_popup] != "false",
|
62
|
-
:markerIcon => @args[:attributes][:marker_icon]
|
69
|
+
:markerIcon => @args[:attributes][:marker_icon],
|
70
|
+
:styles => render_styles(site)
|
63
71
|
}
|
64
72
|
if @args[:attributes][:zoom]
|
65
73
|
opts[:customZoom] = @args[:attributes][:zoom].to_i
|
data/lib/jekyll-maps/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoliy Yastreb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|