This is a lightbox that is created with the help of YUI2. It purposely does not use YUI's Panel. Panel is nice sometimes, but it comes with some baggage I find annoying. Likewise, I don't always use YUI for every possible interaction, such as setting styles. All my target browsers support the same syntax for that action. The one exception is opacity which is not the same across browsers. Basically, I use YUI to make dealing with the hard parts of javascript easier. Nothing more, nothing less.
Features
Lightbox and contents can be created via:
Javascript
Existing markup
Asynchronus (AJAX) request (contents only)
Lightbox will close when ESC is pressed
Rounded corners and box shadow using CSS3.
Compatibility
Firefox 3.5+
Chrome 4+
Safari 5+
Internet Explorer 9 (Animation is not working due to YUI's lack of opacity support in IE9)
Internet Explorer 8 (Via IE9 in IE8 compatibility mode. No rounded corners, no shadows)
Internet Explorer 7 (Via IE9 in IE7 compatibility mode. No rounded corners, no shadows)
Optionally you can use the DN object for its selector function. If you don't want to use it, you can replace the DN.selector calls in Lightbox with YAHOO.util.Selector.query and rename DN.Lightbox to just Lightbox.
YUI Requirements
Dom
Event
Connection Core
JSON
Selector
Animation (if animate set to tru)
Examples
Creating it all in javascript
You can pass in the contents of the lighbox when creating it.
var lb1 = new DN.Lightbox(
{
contentString: '<h1>This is dynamic content from javascript</h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit nibh sit amet lectus blandit egestas. Integer ac rutrum erat. Donec nec auctor risus. Ut dapibus eleifend turpis, ut adipiscing ligula tempor eu. Ut volutpat nisl non sem mollis feugiat. Praesent ornare lobortis erat, in imperdiet metus congue et. Cras orci massa, venenatis rhoncus convallis eu, ultricies nec velit. Aenean in libero vitae odio auctor ullamcorper. Suspendisse vestibulum pretium mi eget tempus. Nam vitae lacus massa, vel dictum lacus. Nulla quam odio, tempor a rhoncus eget, consectetur ac ante. Vivamus a turpis eu velit mollis eleifend. Fusce a odio ac turpis gravida fringilla. Aliquam vestibulum, neque in venenatis dictum, massa turpis gravida sem, pellentesque auctor sapien felis ut leo. Phasellus ac urna non risus fermentum aliquet pharetra sed nibh.',
animate: true,
maxWidth: 500
}
);
YAHOO.util.Event.addListener("showMe1", "click", lb1.show, lb1, true);
Using existing markup
You can set contentElement to an existing element name to use existing markup for the lightbox. Here we use existing markup with the lb-bx-dk class set on the inner box so that it has a black background suitable for showing an image.