Move toolbar-toggle map resize event listener JS to farm_ui_theme.
This commit is contained in:
parent
99eb69434a
commit
434b473e14
|
@ -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) {
|
||||
|
|
|
@ -14,6 +14,11 @@ map:
|
|||
css:
|
||||
theme:
|
||||
css/map.css: { }
|
||||
js:
|
||||
theme:
|
||||
js/map.js: { }
|
||||
dependencies:
|
||||
- farm_map/farm_map
|
||||
toolbar:
|
||||
css:
|
||||
theme:
|
||||
|
|
|
@ -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));
|
Loading…
Reference in New Issue