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.

2 comments

  1. 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:33permalink.

  2. Thank you very much for sharing this awesome script!

    Pieter 7th October 2008 09:47permalink.

Line breaks are preserved; URLs will be converted in to links.

Enter your own, valid XHTML. Allowed tags are: a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

18th September 2008

You are reading "Update to addSizes (v0.3)" written by Natalie Downe on the 18th of September 2008 at 12:26 am.

Next: Talk like a pirate, walk like a pirate

Previous: dConstruct and my sisters graduation, a busy week!