I'm using 7.x 2.0-alpha 2

When I attempt to pass a function though initCallback i get the javascript error

this.options.initCallback is not a function
[Break On This Error] (function(i){var q={vertical:false,rtl...rousel", new h(this,a))})}})(jQuery); 

I believe this isn't just a user error...here is the method I'm using to call jcarousel:

<?php

  $options = array(
    'scroll' => 3,
    'animation' => '8000',
    'wrap' => 'circular',
    'auto' => 10,
    'initCallback' => 'carousel_init_callback'
   ); 
   
   jcarousel_add('work-carousel', $options);

?>

Any idea if this is my method or a bug with jCarousel?

Comments

hadsie’s picture

I'm having the same issue. What's the right way to use the initCallback parameter here?

hadsie’s picture

Status: Active » Needs review
StatusFileSize
new598 bytes

Here's a patch that did the trick for me. It just re-assigns the value of initCallback to a function as opposed to a string.

quicksketch’s picture

StatusFileSize
new915 bytes

Thanks hadsie! This is a definite improvement but I think we should make this work for all callback functions, rather than just initCallback (see all the callbacks at http://sorgalla.com/projects/jcarousel/#Configuration). Could you try out this patch and see if it does the same job?

hadsie’s picture

Good point :). Testing out your updated patch now and it works perfectly for me so far.

taran2l’s picture

Version: 7.x-2.2-alpha1 » 5.x-1.x-dev
StatusFileSize
new1.61 KB

Hey guys,

Attached patch will not work with a namespaced function, like Drupal.object.initCallback();

I've attached a bit updated version to fix this issue.

Please review.

taran2l’s picture

Version: 5.x-1.x-dev » 7.x-2.x-dev
StatusFileSize
new1.47 KB

Sorry previous patch can't be applied, attached updated patch.

Also, this issue exists in 6-x.2.2 branch too.

quicksketch’s picture

Taran2I: Thanks, good point but the new patch now needs some work. We shouldn't claim such a broad namespace as "convertFunctionNameToFunction". Considering it's unnecessary to even have a function at all, I'd be happy just seeing this embeded directly in the currently location.

quicksketch’s picture

StatusFileSize
new1.08 KB

@Taran2l: Could you try out this version?

quicksketch’s picture

Title: initCallback not working in drupal 7 » jCarousel callback options do not work when added through jcarousel_add()
Status: Needs review » Fixed

I've committed the above patch after testing that it works with callbacks like "carousel_init_callback" as well as "Drupal.mymodule.carouselCallback".

taran2l’s picture

@quicksketch: thanks for committing this patch.

echoz’s picture

Using 6.x-2.3, for which this patch has been also committed, but I didn't think I should change the version on this issue.

The code added in the #8 patch gives me the following error for jcarousel.js:
"TypeError: Result of expression 'options[optionKey].split' [undefined] is not a function."
while using another module on the page, when it uses thickbox. This only occurs when I have AJAX set to yes in my carousel view. I am not using jcarousel_add().
Commenting out the code added in this patch makes the error go away, and allows the thickbox implementation to work, which is broken with this code added.

Ooops, moving to duplicate #1058028: Add guard-class and prevent JS error when using certain jCarousel options

Status: Fixed » Closed (fixed)

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

jonathanhuot’s picture

Title: jCarousel callback options do not work when added through jcarousel_add() » jCarousel callback options do not work
Status: Closed (fixed) » Needs work

I'm currently using a few callbacks, but I need to use onBeforeAnimation and onAfterAnimation (see itemFirstInCallback for example).

It seems that patch #8 fixed simple callback, but not array of callbacks. I already patch this in my code but it is really ugly:
Before testing if it is a string, I'm testing if callback is an array and copy/paste the same JS block twice, one for onBeforeAnimation and one for onAfterAnimation.

MICKtheBIG’s picture

If you want to fix it the jQuery way then just put this Javascript anywhere:

jQuery.extend(Drupal.settings.jcarousel.carousels["jcarousel-view--jcarousel--block-1"], {
"initCallback": jcarousel_initCallback
});

Then your callback function is "jcarousel_initCallback". You've just extended the jCarousel-Drupal-Configuration object.

Please be aware, that "jcarousel-view--jcarousel--block-1" depends on how many carousels you've got on your page and which you want to control.

@jonathanhuot: I'm pretty sure that this will work for your problem:

jQuery.extend(Drupal.settings.jcarousel.carousels["jcarousel-view--jcarousel--block-1"], {
itemVisibleInCallback: {
onBeforeAnimation: mycarousel_itemVisibleInCallbackBeforeAnimation,
onAfterAnimation: mycarousel_itemVisibleInCallbackAfterAnimation
},
itemVisibleOutCallback: {
onBeforeAnimation: mycarousel_itemVisibleOutCallbackBeforeAnimation,
onAfterAnimation: mycarousel_itemVisibleOutCallbackAfterAnimation
}
});

quicksketch’s picture

Status: Needs work » Closed (fixed)

It seems that patch #8 fixed simple callback, but not array of callbacks. I already patch this in my code but it is really ugly:

Please file a new issue for this problem (with a patch if you've already made some changes). It's really messy to have multiple patches in the same issue.