Linux.com

Feature: Web Development

GreyBox: Jazz up your Web site in 10 minutes

By Dmitri Popov on January 22, 2007 (8:00:00 AM)

Share    Print    Comments   

Want to add a couple of cool features to your Web site without delving into the world of Web programing? In this case, you might want to give GreyBox a try. It's a tiny (only 22KB) JavaScript-based tool, released under the LGPL, that allows you to add page-in-a-page and gallery features using just a few easy-to-understand lines of code (check GreyBox' Web site for some examples).

To install GreyBox, download the latest version of the package, unpack it, and upload the greybox folder onto your server. Add then the following code between the <head> and </head> tags in the page you want to spice up:

<script type="text/javascript">
var GB_ROOT_DIR = "http://myserveraddress/greybox/";
</script>

<script type="text/javascript" src="greybox/AJS.js"></script>
<script type="text/javascript" src="greybox/AJS_fx.js"></script>
<script type="text/javascript" src="greybox/gb_scripts.js"></script>
<link href="greybox/gb_styles.css" rel="stylesheet" type="text/css" />

Replace the myserveraddress with the actual server address, and you are good to go.

GreyBox allows you to do two things: you can add a page-in-a-page feature to a Web page, and you can create a photo gallery. The former effect can be put to several uses. For example, you and your visitors can search Wikipedia without leaving the currently viewed page. To do this, simply add the rel attribute to the link as follows:

<a href="http://en.wikipedia.org/wiki/Main_Page" title="Wikipedia" rel="gb_page_fs[]">Seach Wikipedia</a>

You can also specify parameters such as the width and height of the embedded window:

<a href="http://en.wikipedia.org/wiki/Main_Page" title="Wikipedia" rel="gb_page_fs[800 600 ]">Seach Wikipedia</a>

GreyBox can also handle a set of pages, so users can, for example, look up words in several references. This code creates a "gallery" containing specified Web sites, and users can switch between them using the Back and Forward buttons:

<a href="http://en.wikipedia.org/wiki/Main_Page" title="Wikipedia" rel="gb_pageset[my_web_pages]">Open Wikipedia</a>
<a href="http://dictionary.cambridge.org/" title="Cambridge Dictionaries Online" rel="gb_pageset[my_web_pages]">Open Cambridge Dictionaries Online</a>

To create a simple yet stylish photo gallery you can use a code block similar to the previous one:

<a href="http://farm1.static.flickr.com/106/263885161_6dd6926331.jpg" title="City at Night" rel="gb_imageset[my_flickr_photos]">City at Night</a>
<a href="http://farm1.static.flickr.com/77/223716448_fc1ee516e1.jpg" title="Berlin U-Bahn" rel="gb_imageset[my_flickr_photos]">Berlin U-Bahn</a>

This code creates a gallery that fetches your Flickr photos. There is one problem in the described example, though: each photo in the created gallery has its own link, which doesn't look particularly good on the page. But GreyBox has a solution to that problem too. Using the GB_showImageSet method, you can create a more elegant script and a single link that opens the photo gallery:

<script>
var my_flicker_photos = [{'caption': 'City at Night', 'url': 'http://farm1.static.flickr.com/106/263885161_6dd6926331.jpg'},
{'caption': 'Berlin U-Bahn', 'url': 'http://farm1.static.flickr.com/77/223716448_fc1ee516e1.jpg'}];
</script>
<a href="#" onclick="return GB_showImageSet(my_flicker_photos, 1)">Browse my Flickr photos</a>

And if you want to do the same with a set of Web pages, you can use the GB_showFullScreenSet method:

<script>
var my_web_pages = [{'caption': 'Wikipedia', 'url': 'http://en.wikipedia.org/wiki/Main_Page'},
{'caption': 'Cambridge Dictionaries Online', 'url': 'http://dictionary.cambridge.org/'}];
</script>
<a href="#" onclick="return GB_showFullScreenSet(my_web_pages, 1)">Open my Web pages</a>

That's all there is to it. If you want to spice up your Web site with two useful features with minimum fuss and with almost no coding, then GreyBox is just the ticket.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, German, and Danish computer magazines.

Dmitri Popov is a freelance writer whose articles have appeared in Russian, British, US, German, and Danish computer magazines.

Share    Print    Comments   

Comments

on GreyBox: Jazz up your Web site in 10 minutes

Note: Comments are owned by the poster. We are not responsible for their content.

painfully slow...

Posted by: Anonymous Coward on January 23, 2007 04:39 AM
Does anybody know why the greybox window is opening so painfully slow?

I have a pretty fast internet connection, does this have anything to do with me not having installed Java from Sun?

#

Re:painfully slow...

Posted by: Anonymous Coward on January 23, 2007 02:53 PM
JavaScript is different from Java

#

Re:painfully slow...

Posted by: Anonymous Coward on January 23, 2007 10:10 PM
So why is it so slow then? Does it have something to do with firefox?

#

Re:painfully slow...

Posted by: Anonymous Coward on January 25, 2007 11:18 AM
It is probably because you have not configured the scripts correctly and your browser is re-retrieving pages several times. Especially if you use mod_rewrite or some kind of 404 avoidance mechanism. Check your error_log and access_log for more info.

#

Re:painfully slow...

Posted by: Anonymous Coward on January 25, 2007 09:23 PM
I didn't configure the scripts at all, I'm actually talking about the scripts on the authors homepage!

#

Works great

Posted by: Anonymous Coward on January 24, 2007 09:59 AM
<a href="http://www.militarywebs.com/" title="militarywebs.com">My directory web site</a militarywebs.com> looks beautiful with GreyBox!


Thanks!

#

GreyBox: Jazz up your Web site in 10 minutes

Posted by: Anonymous [ip: 67.166.31.75] on March 11, 2008 05:57 AM
anyone? how do you use this for a video?

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya