Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.5
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 Jan 2013 at 23:05 UTC
Updated:
17 Jan 2013 at 00:50 UTC
I have a style plugin, which admin uses to specify some options.
For example, admin specifies the value of 'myvar': $options['myvar'] = 'abcd';
I also have a javascript file which defines some behaviors associated with this style plugin.
My Question: Is it possible to access $options when defining Drupal.behaviors?
(function ($) {
Drupal.behaviors.mymodule = {
attach: function (context, settings) {
var myvar = $options['myvar']; // How can I access $options?
...
}
};
})(jQuery);
What is the best way to accomplish this?
I suppose I could call drupal_add_js from within the plugin, to add all the $option variables to Drupal.settings. But I am wondering if there is a better way?
Thanks very much!
Comments
Comment #1
kobnim commentedI suppose another possibility might be to move my Drupal-behavior javascript inside one of the class definitions in my custom style plugin, for example inside
function pre_render($result)Would this be a reasonable approach?
If so, do you have any suggestions on which class to use? (I don't need access to $result, I only need access to $this->output, so perhaps pre_render is not the best choice.)
Thanks.
Comment #2
merlinofchaos commentedI think the drupal_add_js() to add your options to the settings so the javascript can read them is probably the better choice.
Comment #3
kobnim commentedthank you!