How to make a Modal Window using Prototype?

May 16, 2007

Okay, its been somedays I was working on how to create a simple, beautiful yet powerful modal window for a project I am working on.

Modal Window sometimes called as Modal Dialogue box, are widely used across to increase the user experience.

After doing a lot of {re}search, I came across, Lightbox by Lokesh. Then, I came across this LightBox Gone Wild, yes by the folks behind Wufoo.

I must admit, these guys have done a great job!!! Thanks for sharing this.

Now, coming back to our tutorial.

You must have prototype AJAX library to use this {sorry for Non-prototype lovers}. Once, you have both Prototype and Lightbox Gone Wild.

Just add them to your html page.

<link rel=”stylesheet” href=”css/lightbox.css” mce_href=”css/lightbox.css” type=”text/css” />
<script src=”scripts/prototype.js” mce_src=”scripts/prototype.js” type=”text/javascript”></script>
<script src=”scripts/lightbox.js” mce_src=”scripts/lightbox.js” type=”text/javascript”></script>

Once, we have added the libraries to the html page. Now, we move on to create the lightboxes {a.k.a simple html files which will be shown in our Modal Window.}

Some HTML files, lets us say About.html

<p> About Us Page</p>
<h3>This is a simple About Me page, where you can add all HTML tags.</h3>

Now the important task: Activating the Lightbox

<a href=”About.html” mce_href=”About.html” class=”lbOn”>About Me</a>

Notice: the italics class=”lbOn”, onclick this will call the function to load the lightbox.

We can add all the HTML tags inside a lightbox, which means there are N number of options for you to surprise your friends.

De-Activating the Lightbox

<a href=”#” mce_href=”#” class=”lbAction” rel=”deactivate”>Close Lightbox.</a>
A simple link, clicking on which will take you back to the page.

Linking it to another Lighbox inside:

<a href=”confirm.html” mce_href=”confirm.html” class=”lbAction” rel=”insert”>Go to Another Lightbox</a>

Till here we saw how to Activate, Deactivate and Insert a lightbox inside a lightbox.

Now, AJAX stuff.

Lets say you want to give, a form to fill to user and collect the data using the modal window. We can do it, with the help of Prototype library. Use the following piece of code.

insert: function(e){
   link = Event.element(e).parentNode;
   Element.remove($(’lbContent’));
   var myAjax = new Ajax.Request(
          link.href,
          {method: ‘post’, parameters: “”, onComplete: this.processInfo.bindAsEventListener(this)}
   );
}

I am writing a code to add some more functionality like onload, on mouseover etc. Once done will share the code as well.

Cheerz
Sridhar

Entry Filed under: AJAX, Education, FOSS Stuff, How-To's, Javascript, Prototype, Techie, Web 2.0. .

1 Comment Add your own

  • 1. ronen  |  March 16, 2008 at 5:46 pm

    For some reason the insert doesn’t work when you want to activate a second light box from the first one.

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Pages

Quote of the Day

"A Dream is not something you see in your dreams, but Dream is something which will not let you sleep"

Top Posts

Recent Posts

Recent Comments

Sanjeev on Introducing iWinkr Studio
braynx on Contact Me
swiss on Advanced Word Count for P…
derek on Tutorial: How to store UTF8 (i…
Anurag Litoriya on Tutorial: How to store UTF8 (i…
Juan Felipe on Simple Ajax with YUI!!!
hiteshsathawane on Contact Me
hiteshsathawane on Tutorial: How to store UTF8 (i…

Take Some Feeds

Powered by FeedBurner

Some More Feeds

Categories

Top Clicks

Lyrics Of The Week

From the top to the bottom Bottom to top I stop At the core I've forgotten In the middle of my thoughts Taken far from my safety The picture is there The memory won't escape me But why should I care..... Forgotten, Linkin Park

Archives

My Tag Cloud

AJAX Autobiography BarCamp Blogging CSS Designing Education Entrepreneurs FOSS Stuff Fun General How-To's India 2.0 Indictrans Team Inspirational Javascript Localization MySQL News OpenIndx Personal PHP Script.aculo.us Social Techie Tutorial UI Uncategorized Unconferences Web 2.0

Calendar

May 2007
M T W T F S S
« Apr   Jun »
 123456
78910111213
14151617181920
21222324252627
28293031  

Blog Stats

Categories

Spam Blocked

FeedBurner

Enter your email address:

Delivered by FeedBurner

Digg This

Links