Verbose Logging

software development with some really amazing hair

T + G I F R

A Better jQuery Script For Embedly

· · Posted in Programming
Tagged with

Embedly is a great service for generic embedding of content. Have you seen posterous? How they can just accept any link to a video on youtube, a picture on flickr, whatever, and it gets properly embedded? I imagine they could use Embedly to accomplish that.

Anyway. They have a jQuery script to do embedding, but in the middle of if is this behemoth of a code smell:

Oh noes a global variable! The implication of this is that you can only run one call to embedly at a time. This sucks if you have different needs for different things and want to run a few at the same time, since array values get overwritten between calls, and shenanigans ensue.

Fear not, because I wrote a better one. I didn’t fork the repo and whatnot since I wrote mine in coffeescript and the compiled Javascript isn’t really something I want to just patch over top of what they have.

I did use their file as my starting point and then sort of converted things as I went to not use the global array and be written in coffeescript, so the basic flow of the logic is all them, I just cleaned it up.

The coffeescript:

The compiled Javascript:

Go forth and enjoy.