key => values switching in jcarousel.js

Qwaygon - November 1, 2009 - 08:30
Project:jCarousel
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:critical
Assigned:Qwaygon
Status:closed
Description

original code from jcarousel-6.x-1.1 (jcarousel.js)

      else if (typeof(options[callbackname]) == 'object' && (options[callbackname] instanceof Array)) {
        // Arrays are evaluated as a list of callback registrations. This is because callbacks
        // like itemVisibleInCallback can either be a function call back, or an array of callbacks
        // consisting of both onBeforeAnimation and onAfterAnimation.
        for (subcallback in options[callbackname]) {
          var name = options[callbackname][subcallback];
          options[callbackname][name] = eval(options[callbackname][name]);
        }
      }

this part

       for (subcallback in options[callbackname]) {
          var name = options[callbackname][subcallback];
          options[callbackname][name] = eval(options[callbackname][name]);
        }

basicly in php analog will do this (this is more cleary)
<?php
foreach ($options[$callbackname] as $subcallback => $name){
   
options[$callbackname][$name] = eval($options[$callbackname][$name]);
}
?>

so as you can see you swith $key=>$values in place and if i have lets say this (i DO actualy have this as part of my code in module)

<?php
    jcarousel_add
('#mycarousel'.$node->nid,
        array(
           
'itemLoadCallback' => 'mycarousel_itemLoadCallback',
           
'itemVisibleOutCallback' => array(
               
'onAfterAnimation' => 'mycarousel_onAfterAnimation',
            ),
        ),
    );
?>

the result will be (in your case)

options['itemVisibleOutCallback'][ 'mycarousel_onAfterAnimation'] = eval(options[ 'itemVisibleOutCallback'][ 'mycarousel_onAfterAnimation']);

where you evaluting non existed array item, and save it to unknown for jcarousel module callback.. and of course it will not work.

i changed that part to

        // Arrays are evaluated as a list of callback registrations. This is because callbacks
        // like itemVisibleInCallback can either be a function call back, or an array of callbacks
        // consisting of both onBeforeAnimation and onAfterAnimation.
        for (subcallback in options[callbackname]) {
          options[callbackname][subcallback] = eval(options[callbackname][subcallback]);
        }

and wooho! all callbacks starts to be callbacked... almost :)

here another thing (original code)

else if (typeof(options[callbackname]) == 'object' && (options[callbackname] instanceof Array)) {

i have to change to
else if (typeof(options[callbackname]) == 'object' || (options[callbackname] instanceof Array)) {

after that all is done - all subcallbacks were in places and were callbacked when they suposed to be called, in other words all start working as expected.

#1

Rob Loach - November 1, 2009 - 17:13

Hmmm, interesting!..... Maybe a patch would help ;-) .

#2

Rob Loach - November 5, 2009 - 23:48
Status:active» needs review

Like this?

AttachmentSize
620086.patch 2.5 KB

#3

Qwaygon - November 6, 2009 - 23:21

have not test it (im satisfying with my changes) but as it seems for me this bug is a big functionality lost so its better be fixed inside a new version of a module by author, however having a patch is always good to :)

#4

Rob Loach - November 9, 2009 - 15:56
Version:6.x-1.1» 6.x-1.x-dev

Well, if you test it, and say it's good, I'll commit it and make a new version :-) .

#5

Qwaygon - November 10, 2009 - 07:54

sorry for haven't posted long time but was a bit bisy, downloaded applyed tested - all works fine, well done :)

#6

Rob Loach - November 10, 2009 - 08:22
Status:needs review» reviewed & tested by the community

Thanks a lot for the help :) . I'll commit this tomorrow.

#7

Rob Loach - November 10, 2009 - 17:12
Status:reviewed & tested by the community» fixed

Thanks a lot! http://drupal.org/cvs?commit=287078

#8

Qwaygon - November 11, 2009 - 10:57

tty for good module

#9

System Message - November 25, 2009 - 11:00
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.