Javascript not loading correct image when Product is under sub-path

j0rd - July 22, 2008 - 11:23
Project:Ubercart Option Images
Version:5.x-1.0-3
Component:Code
Category:bug report
Priority:critical
Assigned:tjholowaychuk
Status:active
Description

Seems the javascript in uc_option_image.js tries to load the image from a relative path. This is fine and dandy if the product is website.com/my-product-link but it won't work for products under sub-paths website.com/product-category/my-product-link .

There is a simple fix for this which I've already applied to my version.

Simply change:

/**                                                                            
* Switch the imagepath based on the selected effect.                          
*/                                                                            
UCOI.switchImageEffect = function(image, imagepath) {                          
  switch(this.effect){                                                         
    case 'fade':                                                               
      $(image).fadeOut(200, function(){                                        
        $(this).attr('src', imagepath).fadeIn(200);                      
      });                                                                      
      break;                                                                   
                                                                               
    default:                                                                   
      $(image).attr('src', imagepath);                                   
  }                                                                            
};                                                                             

to
/**                                                                            
* Switch the imagepath based on the selected effect.                          
*/                                                                            
UCOI.switchImageEffect = function(image, imagepath) {                          
  switch(this.effect){                                                         
    case 'fade':                                                               
      $(image).fadeOut(200, function(){                                        
        $(this).attr('src', "/" + imagepath).fadeIn(200);                      
      });                                                                      
      break;                                                                   
                                                                               
    default:                                                                   
      $(image).attr('src', "/" + imagepath);                                   
  }                                                                            
};                                                                             

Notice "/" + imagepath instead of just imagepath on 2 lines.

#1

tjholowaychuk - July 22, 2008 - 14:17
Assigned to:Anonymous» tjholowaychuk

Yikes! thats strange the base path should be incorporated in imagepath before reaching JavaScript, I will have to take a look at my script. Thanks!

 
 

Drupal is a registered trademark of Dries Buytaert.