Wrong path to sizzle.js and swfobject.js
tedl - August 24, 2009 - 17:27
| Project: | Shadowbox |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
I upgraded to 3.x-dev and ran into some trouble using the shadowbox module with a swf file. The path to the javascript files get the base path to the page - "content/example/libraries/sizzle/sizzle.js" - and not "sites/all/plugins/shadowbox/libraries/sizzle/sizzle.js".
Best regards
/ted

#1
Tried disabling "Optimize JavaScript files" and and got the shodowbox working again. Makes any sense? Tried clearing the cache but it wont work with the optimization enabled. /ted
#2
Running 6.x-3.0, I can confirm this as well.
With Optimize JavaScript files enabled, /libraries/sizzle/sizzle.js and (if enabled) /libraries/swfobject/swfobject.js point to a relative path rather than the desired path to the shadowbox plugin.
What's causing it?
The reason this occurs is due to the the path discovery routine used by shadowbox to find the path to the plugin directory.
This bit of code in particular, found in shadowbox.js
if(!S.path){var path_re=/(.+)shadowbox\.js/i,path;
each(document.getElementsByTagName("script"),function(s){
if((path=path_re.exec(s.src))!=null){
S.path=path[1];
return false
}
})
}
The path discovery routine relies on the shadowbox.js being in a script tag. With JavaScript optimization enabled, shadowbox.js is no longer referenced and the path is never discovered, leaving S.path=="". When shadowbox then attempts to dynamically load the respective scripts:
U.include(S.path+"libraries/sizzle/sizzle.js"), it will fail.Shadowbox also uses the same dynamic method to load in language, player, and adapter script files.
Workaround:
I will assume that you installed the shadowbox plugin to /sites/all/plugins/shadowbox/
In shadowbox.js, find:
path:""and change it to:
path:"/sites/all/plugins/shadowbox/"That's it. You should be able to re-enable JavaScript optimization without any further issues.
If you are already using the jQuery update module or have jQuery >= v1.3, you can go one step further and comment out
U.include(S.path+"libraries/sizzle/sizzle.js"). jQuery since 1.3 has used the Sizzle engine so no need to load it twice (although the current release of jQuery (1.3.2) is using a slightly older version of Sizzle, but I see no harm).Hope this helps!
Regards,
Eugene
#3
Thanks Eugene for your thorough report. I don't think there is much I can do about it. Any thoughts on how we could fix this in the Drupal module?
#4
Eugene, firstly thanks for the explanation. I can see the files you are talking about and the explanation makes sense... However this fix does not work for me. It introduces more path related errors related to the same files.
My drupal installation is in another sub directory below the web site's root, and I have tried various combinations of path modifications to try and compensate for that, but to no effect. Those have included paths which make assumptions about the current location the call is made from, and also taking the path right back to the site's "virtual root" etc.
I am wondering if there is anything else I should be looking at?
Thanks for any comments.
#5
@psynaptic: I don't see any straightforward solution. You could force Drupal to not cache JS files, but that would be highly inefficient. I'll give it some thought today but I'm at a loss right now.
@scratt: Did you try commenting out
U.include(S.path+"libraries/sizzle/sizzle.js")? As I mentioned above, you probably don't need to load in the Sizzle library as jQuery has already provided it for you.#6
Thanks for replying so fast..
My VI skills were obviously lacking as I could not even find the second path instruction. :)
I have remedied that with some swift remedial reading and removed it. I now get two errors instead of 4!
One is still for libraries/sizzle/sizzle.js while the other is for libraries/swfobject/swfobject.js
I presume I am still missing something.
I am changing the correct initial path command aren't I? That is the first in the file and the only one with a : after path. Right?
Sorry if I am being dense. :)
#7
You might want to make sure you clear your cached files in Drupal:
/admin/settings/performance > at bottom of page click [Clear cached data]
Note that you will still probably get an error for swfobject.js.
To solve this issues, you should be able to do the following:
In shadowbox.js, find and replace the code:
S.path+"libraries/swfobject/swfobject.js"with:
"http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"If that still doesn't do the trick, send me a private message and I will try to help you out.
#8
Brilliant Eugene. Thanks. That seems to have tidied it all up. :)
#9
It might not be a bad idea to put a little notice on the Shadowbox admin page, saying if you plan you use JS aggregation you need to edit the path property in shadowbox.js.
Even better, display a warning/error in site status if JS aggregation is enabled and the path hasn't been specified in shadowbox.js.
#10
Removed as it contained erroneous information.
#11
I found that the redirect was throwing syntax errors to the console as it was reading the XHTML page of the redirect rather than the destination file so #10 is not a solution.
I searched around the official Shadowbox forum and found a thread related to this issue:
http://www.shadowbox-js.com/forum.html#nabble-f1309102
I have added the useSizzle option to the module and will commit it later when we have a resolution to the swfobject.js problem.
#12
A solution to this issue was found by the author of Shadowbox. Details on the above thread.
I have committed this to DRUPAL-6--3 and will make a new release today.
#13
Perfect. Good work everyone that looked into this. /ted
#14
*snip* I fixed a problem I had detailed here and then moved to a new thread : http://drupal.org/node/625082
However I still get warnings about swfobject.js so I think I messed up the custom build of the Shadowbox plugin, can you clarify what settings we should make in the "custom build" of the Shadowbox plugin please.
Thanks. :)
EDIT : Looking more closely at the swfobject related error, the path seems to be broken..
sites/all/plugins/shadowboxlibraries/swfobject/swfobject.jsShouldn't there be a / between shadowbox and libraries?
#15
Automatically closed -- issue fixed for 2 weeks with no activity.
#16
Where are you seeing this path scratt?
In my footer I have:
Shadowbox.path = Drupal.settings.basePath + "sites/all/libraries/shadowbox";