three months agoUpdate to addSizes (v0.3)
I have released version 0.3 of the addSizes script with various fixes and more file types. The code now looks at links to documents of the following types: pdf, doc, zip, mp3, ogg, m4u, jpg, png, swf. If you are using the script and want to add your own, feel free—let me know though, I would be interested to see how people use it.
Thanks to Marko Mrdjenovič for pointing out in a comment on the previous entry that I should in fact be using encodeURIComponent() instead of encodeURI() before sending the URL to json-head. It turns out encodeURI() assumes it is given an entire URL and does not escape & and other reserved characters.encodeURIComponent() on the other hand makes no such assumption and will escape all characters in the given string. Since json-head needs to take a fully escaped URI in order to get the head data, encodeURIComponent() should work better.
In the original entry I should have stated more explicitly that this script will only work properly with files json-head can see. They need to be publicly visible on the web, ie files behind https may not behave as expected. I am still working on methods of getting around the issue with protected files.
A major fix to this version is that the code now works with relative file paths. Bizarly the issue relates to how I was getting the href of the link. With the previous versions I was using jQuery to get the href, $(this).attr('href'), for relative file paths this returns the exact value, eg "media/test.doc". Changing this to use this.href, fixes the issue as it actually interpretes the link to get the absolute URL. Magic.
The code is released under the BSD license.

Excellent plugin, thanks.
When I tried to implement it I got an error. I'm not a javascript expert, but the error had something to do with the "console.log(url);" line. I removed this and the script works like a charm.
Kevin 30th September 2008 18:33
Thank you very much for sharing this awesome script!
Pieter 7th October 2008 09:47