diff --git a/modules/core/map/js/farm_map.js b/modules/core/map/js/farm_map.js index ea4adc2eb..9038bbfc8 100644 --- a/modules/core/map/js/farm_map.js +++ b/modules/core/map/js/farm_map.js @@ -1,7 +1,6 @@ (function (Drupal) { Drupal.behaviors.farm_map = { attach: function (context, settings) { - context.querySelectorAll('[data-map-instantiator="farm_map"]').forEach(function (element) { // Only create a map once per element. @@ -14,27 +13,6 @@ const mapInstanceOptions = {}; Drupal.behaviors.farm_map.createMapInstance(context, element, drupalSettingsKey, mapInstanceOptions); }); - - // Add an event listener to update the map size when the Gin toolbar is toggled. - if (context === document) { - document.addEventListener('toolbar-toggle', function(e) { - - // Only continue if map instances are provided. - if (typeof farmOS !== 'undefined' && farmOS.map.instances !== 'undefined') { - - // Set a timeout so the computed CSS properties are applied - // before updating the map size. - setTimeout(function () { - // Update the map size of all map instances. - farmOS.map.instances.forEach(function (instance) { - instance.map.updateSize(); - }); - - }, 200); - } - }); - } - }, createMapInstance: function(context, element, drupalSettingsKey, mapInstanceOptions) { diff --git a/modules/ui/theme/farm_ui_theme.libraries.yml b/modules/ui/theme/farm_ui_theme.libraries.yml index b95429e4d..5a2def1e7 100644 --- a/modules/ui/theme/farm_ui_theme.libraries.yml +++ b/modules/ui/theme/farm_ui_theme.libraries.yml @@ -14,6 +14,11 @@ map: css: theme: css/map.css: { } + js: + theme: + js/map.js: { } + dependencies: + - farm_map/farm_map toolbar: css: theme: diff --git a/modules/ui/theme/js/map.js b/modules/ui/theme/js/map.js new file mode 100644 index 000000000..0e4f581b3 --- /dev/null +++ b/modules/ui/theme/js/map.js @@ -0,0 +1,26 @@ +(function (Drupal) { + Drupal.behaviors.farm_ui_theme_map = { + attach: function (context, settings) { + + // Add an event listener to update the map size when the Gin toolbar is toggled. + if (context === document) { + document.addEventListener('toolbar-toggle', function(e) { + + // Only continue if map instances are provided. + if (typeof farmOS !== 'undefined' && farmOS.map.instances !== 'undefined') { + + // Set a timeout so the computed CSS properties are applied + // before updating the map size. + setTimeout(function () { + // Update the map size of all map instances. + farmOS.map.instances.forEach(function (instance) { + instance.map.updateSize(); + }); + + }, 200); + } + }); + } + } + }; +}(Drupal));