I need to use jquery cycle plugin for my site.

And the following code works fine.

jquery_plugin_add('cycle');
drupal_add_js(' $(document).ready(function() {
  $("#myslides").cycle("fade");
  });','inline'
);

However, when I try to put some parameters to override the original one, I got problems. Is there any syntax error or I cannot override parameters in cycle.min ?

Here is the problematic code:

jquery_plugin_add('cycle');
drupal_add_js(' $(document).ready(function(){

$('#myslides').cycle({ 
    fx:      'scrollDown', 
    speed:    300, 
    timeout:  2000 
});

});','inline'
);

Comments

nevets’s picture

What sort of problems are you having?

mitchmac’s picture

Your javascript string should be enclosed with a different character than the actual content (or escape the single quotes).

To keep the code easier to read and maintain, the string of javascript could be set in a variable and then referenced in drupal_add_js like:

$js_string = "javascript here";
drupal_add_js($js_string, 'inline');
jhl.verona’s picture

For particularly gruesome JavaScript PHP Heredoc can help:

$js_string = <<<EOT
$(document).ready(function() {
  $('#myslides').cycle({
    fx:      'scrollDown',
    speed:    300,
    timeout:  2000
  });
});
EOT;
drupal_add_js($js_string, 'inline');
kelvinc’s picture

nice heredoc

Thank you for your help