Rich-text Reply

Variation jQuery Plugin JS

aydus 02-24-16

Variation jQuery Plugin JS

Is there a way to access an existing jquery plugin (on the page) from variation js?

Specifically, we'd like to run tests on a rotating banner powered by the popular jquery plugin cycle2: http://jquery.malsup.com/cycle2/

The cycle2 plugin has an API but we can't find a way to get a reference to the banner cycle object. For example, this code doesn't work and we've tried everything we can think of.

$('.mySlideshows').cycle();


Thanks!

Level 1

AllisonR 02-25-16
 

Re: Variation jQuery Plugin JS

Hi there,

 

You absolutely should be able to access this API from within your Optimizely variaiton code. This can be done using the Code Editor. The trick will be to get the scoping and timing right. 

 

Firstly, since Optimizely executes as your page is loading, the variation code is most likely run before the plugin is loaded (more information about this is here). So you'll want to tell Optimizely to wait until all the scripts are loaded on your page before running the variation code. You can do this, for example, by wrapping the variation code in a $(document).ready() function. 

 

Secondly, the .cycle() method is not available within the scope of Optimizely. To access this method within the variation code, you'll need to scope this function to the window level using the "window." prefix. 

 

Does this solve your issue? 

 

Best,
Allison

Allison
Sr. Technical Support Engineer
Optimizely | EMEA
Optimizely