Invoke Lightbox2 on page load?
seanr - September 1, 2009 - 18:46
| Project: | Lightbox2 |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I received a feature request in the Splash module issue queue to offer Lightbox in addition to Thickbox as an option for displaying splash pages. I'm having a very difficult time figuring out how to do this because it appears that Lightbox2 is entirely link oriented - I can not find any way to invoke it from a javascript event (i.e. document.ready). Is there something I'm missing here or is this just not possible with Lightbox2?

#1
Check out the documentation at http://drupal.org/node/316727
Basically if the content you want to display in a lightbox is in a div like
<div id="lightboxAutoModal" rel="lightmodal[|height: 50px;]">then it will open up on page load. You can configure the height and width via the rel attribute.#2
I know you must be tiring of answering these questions but I too cannot get the lightbox to auto load whatsoever. I would like to auto load an image inside a lightbox when the page loads but figured I need to start at basics and try to generate any auto loaded lightbox so I aimed with attempting to auto load $messages to no avail.
I added the following to page.tpl.php:
<?php if ($show_messages && $messages): ?><div id="lightboxAutoModal" style="display: none;" ><?php print $messages; ?></div>
<?php endif; ?>
The above does not work instead no messages are displayed unless I remove 'style="display:none;"' then I can see messages again on the page but there is no lightbox. Lightbox works fine, as it should, with images and modals which is really what I use it for but none of the auto load recommendations I have tried have worked.
Source does look like it's tagging the line I added in page.tpl.php but there is no lightbox-processed? Is this okay?
<div id="lightboxAutoModal" style="display: none;" ><div class="messages status"><a href="/admin/settings/site-maintenance">Operating in off-line mode.</a></div>
</div>
I have also tried applying patch lightbox2_6x_294361.patch which added the following line to the end of lightbox.js:
// Attach lightbox to any links with lightbox rels.Lightbox.initList();
$('#lightboxAutoModal').triggerHandler('click');
};
I would really very much like to get this working. I love your lightbox module and i'm starting to think maybe something is conflicting with lightbox? I do use the jquery_update module, I do remember you asked someone about that, could this be my problem?
I'm using the following:
Drupal 6.14
Lightbox2 6.x-1.9
JQuery plugins 6.x-1.10
JQuery Update 6.x-1.1
Image Assist 6.x-3.x-dev
CTools 6.x-1.0
CCK 6.x-3.x-dev
I tried to avoid posting a Q but I have tried everything listed in the issues and the lightbox documentation to avoid posting a q but I am now at a loss. Thank you in advance for your help and thank you for bothering to code this module in the first place. It works great just the auto-load is a bit tricky, eh? :)
If you need more info let me know. Got tons. :)
#3
Any chance you could try the dev version?
#4
Stella,
Thanks for your response, will def try the dev, give me a couple days and I'll post the outcome
#5
Update:
I tried the dev version and sure enough AutoModal works fine with images inserted using img_assist, I couldn't get messages working but I neither needed it or spent as much time with. And it may be worth noting that not only is the AutoModal working I am using the Insert Node filter so my code to actually call the lightbox looks like follows:
<div id="lightboxAutoModal" rel="lightmodal">[node:12 body]
</div>
Here are the contents of node 12:
<span class="inline inline-center"><a href="http://www.mydomain.com/content/about"><img src="http://www.mydomain.com/images/globe_480x353.png" alt="Welcome to MySite!" title="Welcome to MySite!" class="image image-_original " width="480" height="353" /></a><span class="caption"><strong>Welcome to MySite!</strong></span></span>Now the only thing I wonder is if the ability to click vertical/horizontal scrollbars on/off is planned for the future? eh? ;) not critical and I will not delay production for it plus I believe if I use 'rel=' to resize the AutoModal box it should be a band-aid fix at the least, yes? Also, rounded corners would be cool. For future reference of course.
Thanks stella, dev is working as expected. i should note that I did remove
code belowfrom my page.tpl.php file as I was getting a blank white Modal when the lines were in, set back to default:<?php if ($show_messages && $messages): ?><div id="lightboxAutoModal" style="display: none;" ><?php print $messages; ?></div>
<?php endif; ?>
changed to:
<?php if ($show_messages && $messages): ?><?php print $messages; ?>
<?php endif; ?>
Thanks stella, you're fantastic
#6
Quick question: Has this been committed to the latest version of Lightbox2 or should I keep using the dev version?
Thanks stella!