Refactor Drupal.behaviors.farm_map so that Drupal.settings.farm_map.maps is not needed.
This commit is contained in:
parent
7034539eed
commit
18e86f9550
|
@ -147,9 +147,6 @@ function theme_farm_map(&$vars) {
|
|||
$system_of_measurement = farm_quantity_system_of_measurement();
|
||||
$settings['farm_map']['units'] = $system_of_measurement;
|
||||
|
||||
// Add the map ID to the Drupal.settings.farm_map.maps JavaScript array.
|
||||
$settings['farm_map']['maps'] = array($id);
|
||||
|
||||
// If WKT is set, add it to the settings associated with the element ID.
|
||||
if (isset($element['#wkt'])) {
|
||||
$settings['farm_map']['wkt'][$id] = $element['#wkt'];
|
||||
|
@ -158,8 +155,7 @@ function theme_farm_map(&$vars) {
|
|||
// Add the JavaScript settings.
|
||||
drupal_add_js($settings, 'setting');
|
||||
|
||||
// Add farm_map.js, which will iterate over the map IDs and run
|
||||
// farmOS.map.create() on them.
|
||||
// Add farm_map.js, which will run farmOS.map.create().
|
||||
drupal_add_js(drupal_get_path('module', 'farm_map') . '/js/farm_map.js');
|
||||
|
||||
// Add farm_map.css.
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
(function ($) {
|
||||
Drupal.behaviors.farm_map = {
|
||||
attach: function (context, settings) {
|
||||
var units = Drupal.settings.farm_map.units;
|
||||
var interactions = { onFocusOnly: true };
|
||||
if (settings.farm_map.maps) {
|
||||
settings.farm_map.maps.forEach(function (target) {
|
||||
$('#' + target, context).once('farm-map', function () {
|
||||
$('#' + target, context).attr('tabIndex', 0);
|
||||
farmOS.map.create(target, { units: units, interactions: interactions });
|
||||
});
|
||||
var options = {
|
||||
units: Drupal.settings.farm_map.units,
|
||||
interactions: {
|
||||
onFocusOnly: true
|
||||
},
|
||||
};
|
||||
$('.farm-map', context).each(function (index, element) {
|
||||
$(element).once('farm-map', function () {
|
||||
$(element).attr('tabIndex', 0);
|
||||
farmOS.map.create($(element).attr('id'), options);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}(jQuery));
|
||||
|
|
Loading…
Reference in New Issue