I'm using Views Slideshow in a project and I need to customize the pagerAnchorBuilder with a function like:

function (index, slide) {
  return '<li><a href="#">' + index + '</a></li>';
}

In views option, I set "pagerAnchorBuilder" option with the string "return '<li><a href="#">' + index + '</a></li>';" but when the code is evaluated within views_slideshow_cycle.js with the "eval()" function, it reports an error "return not in function".

This is my Drupal.settings array:

<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {"basePath":"\/cesca\/", ... ,"viewsSlideshow":{"banner_portada-block_1":{"methods":["viewsSlideshowPagerFields","viewsSlideshowControlsText","viewsSlideshowSlideCounter","viewsSlideshowCycle"],"paused":0}},"viewsSlideshowCycle":{"#views_slideshow_cycle_main_banner_portada-block_1":{"num_divs":2,"id_prefix":"#views_slideshow_cycle_main_","div_prefix":"#views_slideshow_cycle_div_","vss_id":"banner_portada-block_1","effect":"fade","transition_advanced":0,"timeout":5000,"speed":700,"delay":0,"sync":1,"random":0,"pause":1,"pause_on_click":0,"start_paused":0,"remember_slide":0,"remember_slide_days":1,"pause_when_hidden":0,"pause_when_hidden_type":"full","amount_allowed_visible":"","nowrap":0,"fixed_height":1,"items_per_slide":1,"wait_for_image_load":1,"cleartype":0,"cleartypenobg":0,"advanced_options":"{"pager":".slideshow .pager","pagerAnchorBuilder":"return '\u003cli\u003e\u003ca href=\"#\"\u003e' +index + '\u003c\/a\u003e\u003c\/li\u003e';"}","action_advanced":0,"advanced_options_choices":"pagerAnchorBuilder","advanced_options_entry":"return '\u003cli\u003e\u003ca href="#"\u003e' +index + '\u003c\/a\u003e\u003c\/li\u003e';"}},"tableHeaderOffset":"Drupal.toolbar.height"});
//--><!]]>
Files: 
CommentFileSizeAuthor
#12 1079960-d7-2.patch681 bytesredndahead
#10 1079960-d7-1.patch600 bytesredndahead

Comments

redndahead’s picture

Status:Active» Postponed (maintainer needs more info)

don't use the function wrapper. Only use the code that goes inside the function.

rvilar’s picture

Status:Postponed (maintainer needs more info)» Active

Ok, but if I use only de code inside the function:

return '<li><a href="#">' + index + '</a></li>';

When this code is evaluated by eval() function, this returns the error "return not in function".

redndahead’s picture

Status:Active» Postponed (maintainer needs more info)

Which advanced option are you using?

rvilar’s picture

pagerAnchorBuilder

rvilar’s picture

Status:Postponed (maintainer needs more info)» Active

Changing state

redndahead’s picture

grr. Advanced options are a pain. I'll have to look into another way to handle methods that return values. It will probably end up having you not specify the return and setting a specific variable as the return value. It'll be an ugly hack, but at least something that will work.

motgioinfo’s picture

Hi redndahead,
What I have to change code of rvilar return '<li><a href="#">' + index + '</a></li>'; to? Or I just remove return statement and define new variable
var return_var = return '<li><a href="#">' + index + '</a></li>';

redndahead’s picture

It's not fixed yet. It will more than likely be the last one.

redndahead’s picture

Title:Advanced options that are functions doesn't work» Advanced options that require return values do not work
redndahead’s picture

Status:Active» Needs review
StatusFileSize
new600 bytes

Here is the patch. You need to set the return value to returnVal After looking through all of jquery cycle it seems that pagerAnchorBuilder is the only one that needs this.

rvilar’s picture

Status:Needs review» Needs work

Previously to the eval statement, you have to declare the returnVal variable, because otherwise, its scope will be global and this could be a problem

redndahead’s picture

Status:Needs work» Needs review
StatusFileSize
new681 bytes

Good catch

redndahead’s picture

Status:Needs review» Fixed

This has been committed.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jesss’s picture

Status:Closed (fixed)» Active

I'm getting the same "return not in function" error message for the timeoutFn option.

This is the demo I'm trying to recreate:
http://jquery.malsup.com/cycle/timeout.html

  • redndahead committed a2ffdaf on 8.x-1.x
    Issue #1079960 by redndahead | rvilar: Fixed Advanced options that...

  • redndahead committed a2ffdaf on 8.x-3.x
    Issue #1079960 by redndahead | rvilar: Fixed Advanced options that...

  • redndahead committed a2ffdaf on 8.x-4.x
    Issue #1079960 by redndahead | rvilar: Fixed Advanced options that...