By robertgarrigos on
I'm integrating highcharts (http://www.highcharts.com) for a client and found a problem related to the way drupal adds js code. I use drupal_add_js() function to add the javascript into the head of the web page. This is ok.
The problem comes when the code passed through the drupal_add_js() function is not just an array of strings or integers but also contains some javascript code or even html. Then, the drupal_to_js() function, called during that process, sanitizes the code. My question is if someone, who could have been in this trouble, found a solution.
Thank you.
Comments
What does your code look
What does your code look like, are you using the 'inline' option?
No, setting. the code
No, setting.
the code includes an array like this:
and then passed through the drupal_add_js() function with the 'setting' param.
Using $opts =
Using
it does what I expect, I am guessing the problem is which the click function.
You could write that as
"click" => "function() { location.href = this.options.url; }",or I would define the function outside the setting in .js file and set click to the function name.
Found the problem: highcharts
Found the problem: highcharts javascript object doesn't wrap the function() element with quotes, which drupal does with every string passed through drupal_add_js() function. The only solution I've found is by hacking core :-(
Hi Robert, I'd be grateful if
Hi Robert,
I'd be grateful if you could please tell me what exactly you did to "hack the core" in order to enable the highcharts.js to work.
thanks.
Madhav
Hello Sir, I also want to
Hello Sir, I also want to know how to do it.Please tell me?
Thanks,
Sumit Madan
hacking the core is not a
hacking the core is not a good idea, but you can, of course, change the way drupal_to_js() function filters your code. This was my first solution. However, I finally found a better way of sorting this out: instead of having drupal to create a js code on the fly, create a new js file which collects your data sent by drupal. You can, then, hardcode the problematic code within the js file.
Yep, we handled that a little
Yep, we handled that a little differently. See #1466016-7: Tooltip formatter
Scott Rigby
http://basekamp.com
http://PlausibleArtworlds.org
http://UtopiaSchool.org