Initializing objects in GreyBox

GreyBox is built with extendability in mind and one can pass an options object to customize the behavior of GreyBox. In this little blog post I will show how it works.

Let's say we want a GB_show method that does not show the loading screen. The standard GB_show looks like this:

GB_show = function(caption, url, /* optional */ height, width, callback_fn) {
    var options = {
        caption: caption,
        height: height || 500,
        width: width || 500,
        fullscreen: false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}

The important aspects, in the above code, are:

  • options: An object that holds our options.
  • new GB_Window(options): GB_Window is a class that extends the base GreyBox class. It customizes the class so windows are shown.

Now if one opens greybox/base/base.js one will find the GreyBox class, its init function sets the default behavior, it looks like this:

init: function(options) {
        this.type = "page";
        this.overlay_click_close = false;
        this.salt = 0;
        this.root_dir = GB_ROOT_DIR;
        this.callback_fns = [];
        this.reload_on_close = false;
        this.src_loader = this.root_dir + 'loader_frame.html';
        this.show_loading = true;
        AJS.update(this, options);
    },

Notice this.show_loading = true, we want to change that to false. So we simply create a new function called GB_myShow:

GB_myShow = function(caption, url, /* optional */ height, width, callback_fn) {
    var options = {
        caption: caption,
        height: height || 500,
        width: width || 500,
        fullscreen: false,
        show_loading: false,
        callback_fn: callback_fn
    }
    var win = new GB_Window(options);
    return win.show(url);
}

And that's it, now one can do following:

<a href="http://google.com/" onclick="return GB_myShow('Google', this.href)">Visit Google</a>

Google will be shown instantly, i.e. with out the "Loading..." screen.

Scroll down to the bottom of GryeBox examples page to see a demo.

Code · JavaScript · Tips 29. Dec 2006
30 comments so far

Is it possible to display a greybox window with the header? I don't see any options related to the header. I just need to create an empty box that loads a page (which will contaiIn the greybox close button).

That should be a greybox window WITHOUT the header.

Hi.
MI name is Gustavo Borjas and i'm from venezuela, i wanted to ask you something.

I used to use in my forms links to pop-ups windows to select multiple values instead of a input select, for example, I wanted to select a country name and put the country name in a input Text (in the parent form), because there are too many countries I put the country list in another window (the pop up one), in my first form I called the popup then i clicked on a country name and I return a value to my form with window.opener.exampleFunction to a input text. How can I use this method in GreyBox? I will really really appreciate your help.

Thanks in advance.

Ing. Gustavo Borjas.

Hi all,
When I display a GB window, I need to set a field value on the underlaying window. Ex. I have a field X in the page A, now I open a GB_window (page B), here I've a field Y.
Under some circumstances, I need to set field X (page A)equal to field Y(page B).
I tried to do this with window.opener.... or getEmelentById but I can't reach the element on page A from page B.

Someone can help me ?
Thanks All in advance.

Matt

Toc Toc ?

i need to translate the "close" word xD... i take a look on *ja files and pages and css and i couldn't find! maybe is me sleeping, i need also the source of that gif loading picture..

It is possible to use greybox with custom HTML inside it. I'd quite to replace my own dodgy ajax window with this one. I make a call to a script then display the results in the window (all standard HTML).

Is it possible to make a page set of websites with a custom window size and not at fullscreen? Can you please show how this works?

Greybox has been tested and works fine on Mac OS X / Safari and WindowsXP / IE7.

However, there is a small error with WindowsXP / Firefox. When I launch a photo gallery, all the images load fine. However, after I close greybox, the "back" button in Firefox will not go back to the previous page.

I also found that if I visit say 2 images in image gallery, the close greybox, then click on back button a few times, it still doesn't work.

Please advise on how to fix problem, or if fault is in greybox code, please fix bug there and advise.

NOTE: The same error, bug, happens with the Image Gallery example posted on your Web page: http://orangoo.com/labs/GreyBo... So, its not something that I messed-up on my end...

Thanks for greybox!!! I love it!

How could I alter the timing in which the code loads?

I can only have the greybox code working if I hard code it on the page.

I would like to be able to write in the link with an external JavaScript...

/* START: NavFooter */
function navfooter() {
var navfooter = getObj('navfooter');

if (navfooter) {
navfooter.innerHTML = 'Site Map';
}
}

Is there a way to use the grey box to pull up a menu, so that when you click a link on the page displayed by GB, it would close the GB and take you to that page in your original browser window?

Hi,

Is there any example that shows how callback function is executed? I have a wizard implemented using greybox and would like to trigger a call back function to change main page's html content(by using dom) after the last step of my wizard has completed.

thanks

Hi,

I'have installed the greybox and everything works fine. Many thanks!

Now, I would like to change the header_bg.gif. The original is 223x35px. I'd like mine to be only 223x20px.

I've modified the *.gif and replace it.

But it doesn't work... the size still stays at 35px height.

How can I change the height? I've tried to change many things in the CSS, without result.

I would be very grateful for an answer!

Thanks in advance!

Nice work.
I made a small change of script and css.
Check the implementation in www.macrostandard.com.
(Chose the Accordion Container “Blogurile active MacrostandarD”.)

Hi There,

I like the way Grey Box works but I can manage to integrate into my Zen Cart shop... at the moment the bigger pictures pop up with Java and the "tlp_modules_main_product_image.php" code looks like this:

/**
* Module Template
*
* @package templateSystem
* @copyright Copyright 2003-2005 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/licens... GNU Public License V2.0
* @version $Id: tpl_modules_main_product_image.php 3208 2006-03-19 16:48:57Z birdbrain $
*/
?>