Drupal Easy Ajax Content, Lightbox2, Nodes and a few hacks

Drupal Easy Ajax Content, Lightbox2, Nodes and a few hacks

It seems like every new site I build, there is a need to pull another node in via Ajax. This can be done with the lightbox overlay or by emptying a div and refilling it with another node.

 


Hacking Lightbox2

Lightbox2 Module has this functionality built in with one flaw. It will pull the whole page in when using the rel="lightmodal" call. To fix this is a easy two step fix:

Number one: Put a ID on the node.tpl content div. This allows jquery to just grab your node.

We added the ID AjaxMe above.

Next in lightbox.js located in the lightbox2 module then js folder we need to add the content div id to the lightmodal .load function. For Drupal 5 it is located at line #608 and for Drupal 6 at line #613 (these numbers will change as updates are made).


else {
  $("#modalContainer").load(src);
}
//Change this line to:

>

else {
  $("#modalContainer").load(src + " #AjaxMe");
}
//Now change it to add the #AjaxMe id.  Other wise it loads the whole page;

That is it. Now if you have a link on your site with the rel="lightmodal" added to it will grab the node and serve it up in a lightbox.

Test it out: Lightbox Ajax Test Link


 

Next, Using jquery to AJAX a node in to a layout.

you will need the above modified Node.tpl file and jQuery loading on your pages with add_js

Setup your target div:

This is the div we are going to empty then ajax in our node content. This can be text, images or a video. Lets say you make a view of a list of nodes. You would use the view ID then the a tag to target that list.

First the link:

Next the Javascript:

That is it! Try it out:

Content to be emptied!

Test it out: Ajax Test Link

Without the Ajax: View the page without Ajax

Comments

Problem with activation

Hi there, I dont know if I am writing in a proper board but I have got a problem with activation, link i receive in email is not working... http://www.hedindesign.com/?7d4f7a50f92d5a7e385a8da9bc2,

Anonymous Thu, 07/08/2010 - 04:01
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Web Gibblets

The blog is where we post little tidbits of information. Building and designing sites is done in fresh snow. A lot of times you find a new way to do something that is relatively undocumented. Luckily for us all of our peeps are just a google search away.

Monthly archive