Setup: Module has its javascript file with the following functions:
(function ($, Drupal, undefined) {
Drupal.behaviors.mymodule = {
attach: function (context, settings) {
var userSettings = settings.mymodule;
var myFunction = userSettings.passedFunctionCallback;
function a() {
return 'a';
}
function b(){
return 'b';
}
}
}
})(jQuery, Drupal);
If I wanted to assign variable myFunction
a function i would simply do this in javascript:
myFunction = a;
Problem comes when I want to pass this callback via Drupals drupal_add_js
:
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/module.js');
drupal_add_js(array('mymodule' => array('passedFunctionCallback' => 'a')), array('type' => 'setting'));
In my js, passedFunctionCallback is a string and not a function callback:
myFunction = 'a';
Question is: How to pass the variable as function callback via drupal_add_js (if its possible)? Are there any workarounds?