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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53534cf686c7bb5946e00ed6b28aac02bddc055af3c4bfa511f055d172905d16
4
- data.tar.gz: f11f08cc40210be19b54b281336e0d56037c42861772fd7f6e03a8090d55c3c2
3
+ metadata.gz: 1ee441d000168a4757b582f119515fea422526ed2ed1e592289526178fab0ed5
4
+ data.tar.gz: af9633bbd30002ebf716dca99d9fe492df65e5d569dda8067a571b5371c6f2b0
5
5
  SHA512:
6
- metadata.gz: 178867ded8d3239cae7891a104340cc700b8d49a8113a7058a02f5382a88b45c5690ebb6234d7f3fe2d4218e5a5182c9fd22d590dd9146d16ede82df3ea52bff
7
- data.tar.gz: df233cfa1c933178ce6f3f2e6aa57c9f0733f6b89e1862d10c469eec9b7de0ab9a57d863a809ad31f0cfc62772dd73e38b9a2bc46b185258ff9579160683be88
6
+ metadata.gz: 5057ae7574e03e9a4dfdd17d1b42189ec9b99fee460f85b07be12fcb7dd4e7e60f05908f8736bd449ee5be075cbaa6df00ab61c672ae00f407cfd40c6856e770
7
+ data.tar.gz: 7649ede5d3a491311dd24c74d5fb63bd69cb1d3a294b2631021a79a1c84252c61a26d519376d9a1ab0da37b00ea80e469a09b1c546a6d485d483937414adf425
@@ -7,5 +7,4 @@ rvm:
7
7
  script: script/cibuild
8
8
  after_success:
9
9
  - bundle exec codeclimate-test-reporter
10
- sudo: false
11
10
  cache: bundler
data/History.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 2.3.2 / 2020-01-04
2
+
3
+ * Add support for Jekyll 4.x (#41)
4
+
5
+ ## 2.3.1 / 2019-03-02
6
+
7
+ * Fix filter checking logic (#38)
8
+ * Allow custom HTML in marker popups (#37)
9
+
1
10
  ## 2.3.0 / 2018-03-17
2
11
 
3
12
  * customize popup link text (#34)
@@ -22,7 +22,8 @@ var jekyllMaps = (function() {
22
22
  function initializeMap() {
23
23
  options = {
24
24
  mapTypeId: google.maps.MapTypeId.ROADMAP,
25
- center: new google.maps.LatLng(0, 0)
25
+ center: new google.maps.LatLng(0, 0),
26
+ styles: []
26
27
  }
27
28
  mapReady = true
28
29
  render()
@@ -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 src='https://maps.googleapis.com/maps/api/js?key=#{api_key}&callback=#{Jekyll::Maps::GoogleMapTag::JS_LIB_NAME}.initializeMap'></script>
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 if @args[:attributes][: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
@@ -20,6 +20,7 @@ module Jekyll
20
20
  marker_img
21
21
  marker_url
22
22
  marker_popup_html
23
+ styles
23
24
  ).freeze
24
25
 
25
26
  class << self
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Maps
3
- VERSION = "2.3.2".freeze
3
+ VERSION = "2.4.0".freeze
4
4
  end
5
5
  end
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.3.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-01-04 00:00:00.000000000 Z
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll