Well, yeah if I knew how to use firebug. oh well.
This is the code I'm using.
the ajax call that is giving me trouble is found in the showLightbox
"function".
// Make sure that Scriptaculous is loaded, since its required for this
to work!
if (typeof Scriptaculous == 'undefined') {
alert("Scriptaculous could not be found!\n Please make sure it is
installed,\n or this script won't work");
} else {
//General settings.
lbSettings = {
Opacity: '0.6',
fadeTime: '0.6'
}
/*these values will be added to the end of the url called via ajax.
ex.
urlArray = {
value: '1',
otherparam: '2'
};
will be added as
?value=1&otherparam=2
*/
var urlArray = Object.toQueryString(
url = {
//values go here... remember commas the right places!
raw: '1',
lightboxClose: '1'
});
//Class creation, this will contain all functions used for this
script.
var Lightbox = Class.create ({
// Initializes the Lightbox, and inserts the Lightbox html to the
DOM.
initialize: function() {
//listen for key presses, so we can check if KEY_ESC is pressed
document.observe('keydown', this.escapeHandler.bind(this));
//prevent double insertion of our DIV elements.
if($('lightbox')) {
} else {
if (!document.getElementsByTagName){ return; }
var anchor = document.getElementsByTagName("a");
var anchorArray = $A(anchor);
//make sure its properly bound
var boundShowLightbox = this.showLightbox.bind(this);
// loop through all anchor tags
anchorArray.each(function(element) {
if (element.getAttribute("href") && (element.getAttribute("rel")
== "lightbox")){
var lBox = this;
$(element).observe('click', boundShowLightbox);
}
});
//Fetch ALL <body> tags, ( there should be only one, so we select
the first entry just in case theres more)
var objBody = $$('body')[0];
/*create and insert our Lightbox html, it should look like this:
<div id="overlay"></div>
<div id="lightbox">
<div id="lbHeader"></div>
<div id="lbContent">Loading...</div>
</div>
*/
objBody.appendChild(Builder.node('div', {id:'overlay'}));
var objLightbox = Builder.node('div', {id:'lightbox'}, [
Builder.node('div', {id:'lbHeader'}, ' '),
Builder.node('div', {id:'lbContent'}, 'Loading...')
]);
objBody.appendChild(objLightbox);
}
//Hide the Div elements immediatly.
$('overlay').hide();
$('lightbox').hide();
},
//display the lightbox
showLightbox: function(event) {
var element = event.findElement('a');
event.stop();
//add parameters after the original URL.
if(element.href.indexOf("?") >= 0){
element.href += '&' + urlArray;
} else {
element.href += '?' + urlArray;
}
//make a Ajax call, and retrieve the content
new Ajax.Request(element.href, {
method: 'get',
onSuccess: function(transport) {
$('lbContent').update(transport.responseText);
},
evalJS: true
});
//make the lightbox fade in
new Effect.Appear($('overlay'), {duration: lbSettings.fadeTime,
from: 0.0, to: lbSettings.Opacity});
new Effect.Appear($('lightbox'), {duration: lbSettings.fadeTime});
//resize NOT WORKING.
var dimensions = $('lbContent').getDimensions();
alert(dimensions.width + ', ' + dimensions.height);
$('lightbox').setStyle({
width: dimensions.width,
height: dimensions.height
});
},
//We're checking if the key pressed is KEY_ESC, if so, we trigger
hideLightbox();
escapeHandler: function(e) {
if (Event.KEY_ESC != e.keyCode) return;
this.hideLightbox();
},
hideLightbox: function() {
new Effect.Fade($('overlay'), {duration: lbSettings.fadeTime});
new Effect.Fade($('lightbox'), {duration: lbSettings.fadeTime});
}
});
//make it all work by initializing the Lightbox class when the DOM has
loaded.
document.observe('dom:loaded', function () { new Lightbox(); });
}