I'm using jQuery Cycle plugin to create a slideshow with thumbnails. The thumbnails are generated using the pagerAnchorBuilder callback, which receives the slide (i.e. an image) as an argument.

So I decided to stick the original image path in the image's element which I retrieve with jQuery Metadata and then when the pagerAnchorBuilder is called in the script, it can see the original path and generate a new path for a different imagecache preset.

For this I had to recreate the PHP version of theme_imagecache in JavaScript, and I think it works pretty well. I hope maybe this can be useful for other developers, and perhaps it can even be included in the module? I'm happy to fix it up if there's problems.

CommentFileSizeAuthor
#6 imagecache_791094.patch2.83 KBdrewish
imagecache-js.patch2.56 KBAnonymous (not verified)

Comments

drewish’s picture

Very interesting... might be better as a submodule since most people won't need it.

Anonymous’s picture

Really? The amount of PHP to load the script is very minimal, and the JavaScript is optional. It seems like terribly little for a module.

I'll make a module of it if you think that's better. Does that mean it could be in ImageCache? Or do you suggest an independent project?

uhohpolio’s picture

Category: feature » support

I'm doing the same thing on my site with duct tape code. I would love to use this, but am having some trouble.

I have my ImageCache patched with the above code. Do I need to now call imagecache_add_js() from somewhere?
Flushed my caches, checked the patched files.

Any help is greatly appreciated.

uhohpolio’s picture

Think I got it. Added a call to imagecache_add_js() at the end of theme_imagecache().

Thank you for the code.

drewish’s picture

I've come around on this. I don't think we should have "use strict"; in there unless it's in a closure because otherwise if JS aggregation is on it'll cause strict checking on the rest of the JS.

Did you test this with private file transfers? It doesn't seem like it would work correctly.

drewish’s picture

Category: support » task
StatusFileSize
new2.83 KB
YK85’s picture

subscribing

drewish’s picture

Status: Needs review » Fixed

Committed to 6.x-1.x

Status: Fixed » Closed (fixed)

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

Jevedor’s picture

I am having issues with this. So maybe I am using the code incorrectly. In any event I have the filepath of an image on a node which I am passing into the Drupal.theme.prototype.imagecache method. Seems straight forward. My preset is an imagecache name "product_image" however the url returned is the original filepath. Looking deeper into the code this is occurring because the expected value of the "preset" argument is what gets set via the javascript in the header, which just so happens to use the preset indexes not their machine names.

So I thought great, so I tried the index instead. Now the src kicked back does work but its returning a path that doesnt actually exist. Its using the index in the path where imagecache would normally use the machine name.

so for example its returning

http://domainname.com/sites/default/files/imagecache/1/products/img.jpg

when it should be returning

http://domainname.com/sites/default/files/imagecache/product_image/produ...

This to me seems like it just doesnt work, so I am wondering how I am supposed to use this javascript.

What is more, it seems like if the cached image has never actually been created this doesnt actually create the cached image file, but rather only builds a path to what hopefully is an already cached image.

SO I guess what I would like to be able to do is from javascript do a standard

theme("imagecache", "preset_name", "filepath");

or imagecache_create_path("preset_name","filepath");

and have the system both build the cached image AND output either the new img html or the new file path.

Any thoughts on what I might be doing incorrectly?