I want to pass params via Drupal to my JS file. I have no problem fetching them with the code below, the problem is that as the $(document).bind('leaflet.map' function executes FIRST, it is not able to find the user_name parameter
my_module.module
function my_module_preprocess_html(&$variables) {
$user_name=$GLOBALS['user']->name;
drupal_add_js(array('my_module' => array('user_name' => $user_name)), array('type' => 'setting'));
drupal_add_js(drupal_get_path('module', 'my_module') . '/js/external.js');
}
external.js
(function($) {
Drupal.behaviors.fewo_map= {
attach: function (context, settings) {
alert('get params');
//we can fetch the data
user_name=settings.fewo_map.user_name;
}
}
$(document).bind('leaflet.map', function(e, map, lMap) {
//it fires first, so is unable to get user_name data
alert('leaflet')
console.info(user_name)
})
If I do...
(function($) {
Drupal.behaviors.fewo_map= {
attach: function (context, settings) {
$(document).bind('leaflet.map', function(e, map, lMap) {
alert('leaflet')
console.info(user_name)
})
}
}
})
the result is the same
Also tried using JS injector, no success neither. I need the user_name as parameter to define the settings inside leaflet 'function' Thanks