I had a look at newest version of Lightbox2 (v2.03.3) script at huddletogether.com website for a way to add the "closing on background" feature to the current Drupal version on my site. As it looks, it's a pretty small piece of code so I thought to post it here for others.

File to be changed: lightbox.js (in your module directory: /lightbox2/js/lightbox.js)

I added the following code:

		objLightbox.onclick = function(e) {	// close Lightbox if user clicks shadow overlay
			if (!e) var e = window.event;
			var clickObj = Event.element(e).id;
			if ( clickObj == 'lightbox') {
				myLightbox.end();
			}
		};

after the line:

		objLightbox.style.display = 'none';

and before line:

		objBody.appendChild(objLightbox);

I tested in Firefox and IE6 with Lightbox2 Plus enabled. I don't use any other images related modules so please test it first if you do!

Comments

stella’s picture

Assigned: Unassigned » stella
Status: Active » Fixed

I've added this patch to CVS for both 5.x and 4.7.x versions and it will be included in the next release. Thanks!

This issue was also raised in #149634.

Cheers,
Stella

Anonymous’s picture

Status: Fixed » Closed (fixed)
stella’s picture

This has been released in 5.x-2.0 and 6.x-1.0.

Cheers,
Stella

mry4n’s picture

How can I disable this feature and instead implement either a button or a hyperlink that would close the window. I know there are nav buttons that allow this when viewing a slideshow made up of Images. But what about when you're viewing another web site in an iframe?

stella’s picture

I don't plan on disabling the feature where clicking on the background closes the lightbox. If you really want this feature, please open a new feature request with reasons why you think the change should be made.

There are however, two other methods of closing the lightbox.

A close X button is provided to close the lightbox (except in the lite version where a x hyperlink is provided). The Close X button is located either on the top right corner or bottom right corner - depending on the layout you're using. If you're using a RTL language, then it may be located on the left hand side instead. If this isn't working or appearing for you, please open a new support request / bug report issue.

You can close the lightbox using keyboard shortcuts. In the most current version, you can close the lightbox with the keys 'c', 'x' and ESC. In the latest dev version, you can configure the keyboard shortcuts yourself.

Cheers,
Stella