jquery

Setting JS Callbacks with Drupal, JSON and Some jQuery Sauce (for jCarousel controls)

Ethan's picture

Sometimes a few characters of code can make all the difference in the world. All coders know the scenario: the code looks fine, all the right values are in the right place, the code validates or compiles (or at least looks like it should), but when we run it we get...nada. Maybe the source of the problem is a comma following an array declaration (fine in PHP, but can be a killer in JS), an extra "$" in a variable name, or - as in the case of trying to define a callback for jQuery libraries like jCarousel using JSON - an extra pair of quotes around the callback function value.

Unfortunately, the difference of a few quotes is not always so easily overcome. In the case of extraneously quoted JSON function values, for instance, the issue originates from within the drupal_add_js function and PHP's own json_encode. Such situations can lead to desperate measures: grabbing the drupal_get_js output and munging it with regular expressions or other hackish means to make it do what we need. While use of such techniques is something of a religious dispute among Drupalists, I'm happy to announce that there's also another way to tackle JSON callbacks in Drupal, with nothing more out-of-line than drupal_add_js and a bit of simple jQuery magic.

Drupal 6.x + jQuery 1.4.2 = New Possibilities

Déja Augustine's picture

jQuery is the bread and butter of rapidly developing a highly-interactive websites, and Drupal has long made use of it, and indeed includes it as part of its core install.

Putting Yahoo! Pipes and jQuery Together

Tom Lee's picture

It's been a while since I gushed about Yahoo Pipes, hasn't it? Well, the RSS-combining service remains insanely powerful. This morning I decided to try using it with one of my other favorite web technologies: jQuery. When combined, the two can take the place of many aggregation tasks that previously required a server.

Here's the problem I set out to solve: a bunch of my friends write for more than one blog. They usually have a personal site and contribute to a number of other multi-author blogs. Sometimes they keep a list of their posts in a del.icio.us sidebar block. But maintaining that can be kind of a pain — they have to remember to create a new del.icio.us entry every time they post. Clients like Pukka make using del.icio.us a breeze, but this workflow is still not as automated as it could be (in that it exists at all).

As you know, Pipes makes it easy to combine and filter RSS feeds. Here's a pipe I threw together containing feeds from a couple of EchoDitto clients and our main blog. Naturally we love all of our clients equally, but for my friends' purposes a simple Pipes filter block could be applied to check the dc:author field, ensuring that no coauthors' posts are retrieved. The result will be an aggregated feed of the author's entries.

But how to retrieve them? jQuery 1.2 added in support for JSONP, an unbelievably slick technology that allows Javascript to load JSON data from different domains. There are two things you need to know to get this to work with Pipes: how to get the service to spit out JSON, and how to pass it a JSONP callback (which safely assigns the JSON to a given variable name — without this, loading cross-domain data would be a huge security hole). Both things are accomplished by adding parameters to your pipe's querystring.

jQuery 1.2! Woo!

Tom Lee's picture

I'm kind of a jQuery fanboy. Nontechnical friends following my Twitter feed are sick of hearing about it; my colleagues at EchoDitto have learned to avoid mentioning competing JS libraries around me, lest they be subjected to a long and increasingly enthusiastic speech about why they should be using jQuery instead. It's a bit embarrassing. I've used script.aculo.us, moo.fx, and read enough of the Dojo docs to become deeply confused. But jQuery's the one for me.

And, excitingly, a new version was released on Monday. Let's have a look at the biggest changes, shall we (or at least the ones that seem most immediately relevant to me)?