Dojo Lightbox

Dojo Lightbox



The dojox.image.Lightbox resource has many cool features:
  • Integrated theming and images
  • Keyboard accessible
  • Resizes when the viewport changes
  • Flexible with numerous options
  • Declarative or Programmatic instance creation
  • Works with Dojo data stores

The CSS

dojox.image.Lightbox doesn't require any of the Dijit themes but does require its own CSS file:


<style type="text/css">
/* post styles */
#imageHolder img { width:200px; }
/* Lightbox styles */
.tundra .dijitDialogUnderlay, 
.nihilo .dijitDialogUnderlay,
.soria .dijitDialogUnderlay {
 background-color:#000; 
}
.claro .dojoxLightbox .dijitDialogCloseIconHover,
.nihilo .dojoxLightbox .dijitDialogCloseIconHover,
.tundra .dojoxLightbox .dijitDialogCloseIconHover, 
.tundra .dojoxLightbox .dijitDialogCloseIconActive,
.nihilo .dojoxLightbox .dijitDialogCloseIconActive,
.claro .dojoxLightbox .dijitDialogCloseIconActive {
    background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/image/resources/images/close.png') no-repeat 0 0;
}
.claro .dojoxLightbox,
.soria .dojoxLightbox,
.nihilo .dojoxLightbox,
.tundra .dojoxLightbox {
 position:absolute;
 z-index:999;
 overflow:hidden;
 width:100px;
 height:100px; 
 border:11px solid #fff !important; 
 background:#fff url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/image/resources/images/loading.gif') no-repeat center center;
 
 -webkit-box-shadow: 0px 6px 10px #636363; 
 -webkit-border-radius: 3px;
 -moz-border-radius:4px;
 border-radius: 4px;
}
.dojoxLightboxContainer {
 position:absolute;
 top:0; left:0;
 background-color:#fff;
}
.dojoxLightboxFooter {
 padding-bottom:5px;
 position:relative;
 bottom:0;
 left:0;
 margin-top:8px;
 color:#333;
 z-index:1000;
 font-size:10pt;
}
.dojoxLightboxGroupText {
 color:#666; 
 font-size:8pt;
}
.LightboxNext,
.LightboxPrev,
.LightboxClose {
 float:right;
 width:16px;
 height:16px;
 cursor:pointer;
}
.claro .LightboxClose,
.nihilo .LightboxClose,
.LightboxClose {
 background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/image/resources/images/close.png') no-repeat center center;
}
.di_ie6 .claro .LightboxClose,
.di_ie6 .nihilo .LightboxClose,
.dj_ie6 .tundra .LightboxClose {
 background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/images/close.gif') no-repeat center center;
}
.claro .LightboxNext, 
.nihilo .LightboxNext,
.LightboxNext {
 background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/image/resources/images/right.png') no-repeat center center;
}
.dj_ie6 .claro .LightboxNext,
.dj_ie6 .nihilo .LightboxNext,
.dj_ie6 .tundra .LightboxNext {
 background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/images/right.gif') no-repeat center center;
}
.claro .LightboxPrev,
.nihilo .LightboxPrev,
.LightboxPrev {
 background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/image/resources/images/left.png') no-repeat center center;
}
.dj_ie6 .claro .LightboxPrev,
.dj_ie6 .nihilo .LightboxPrev,
.dj_ie6 .tundra .LightboxPrev {
 background:url('http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/images/left.gif') no-repeat center center;
}
.soria .LightboxClose,
.soria .LightboxNext,
.soria .LightboxPrev {
 width:15px;
 height:15px;
 background:url('chrome://interclue/content/cluecore/skins/default/sprites.png') no-repeat center center;
 background-position:-60px;
}
.soria .LightboxNext {
 background-position:-30px 0;
}
.soria .LightboxPrev {
 background-position:0 0;
}
.dojoxLightboxText {
 margin:0; padding:0; 
}

     </style>

All of the imagery required comes via the CSS file -- no need to add your own styles.

The HTML and JavaScript

The first step in using any Dojo resources is adding a SCRIPT tag with a path to Dojo within the page and requiring the desired Dojo Toolkit resources:


<script>
  // Parse the page upon load
  djConfig = { parseOnLoad: true };
  // When the DOM is ready and resources are loaded...
        dojo.ready(function() {
     // Create an instance
     var lightbox = new dojox.image.Lightbox({ title:"My Sons", group:"My Sons", href:"http://2.bp.blogspot.com/-LU4EmsfqCdk/TWfTuCXSptI/AAAAAAAAAfI/LoJDeuDApBA/s1600/My+Sons+1_490x395.jpg" });
     // Start it up!
     lightbox.startup();
        })
     </script>
 <!--bring in the lightbox CSS 
<link href='http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/image/resources/Lightbox.css' rel='stylesheet' type='text/css'/>-->
 <!--bring in the claro theme
<link href='http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css' rel='stylesheet' type='text/css'/>-->
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js" type="text/javascript"></script>
     <script type="text/javascript">
  // Request dependencies
  dojo.require("dojox.image.Lightbox");
     </script>

With parseOnLoad in place, you can add links to the page with the data-dojo-type attribute set to dojox.image.Lightbox and instance-specific options within the data-dojo-props attribute. Here's a sample:


<div id="imageHolder">
<a href="http://bambang-wicaksono.blogspot.com/" data-dojo-type="dojox.image.Lightbox" data-dojo-props="group:'My Sons',title:'My Sons',href:'http://2.bp.blogspot.com/-LU4EmsfqCdk/TWfTuCXSptI/AAAAAAAAAfI/LoJDeuDApBA/s1600/My+Sons+1_490x395.jpg'"><img src="http://2.bp.blogspot.com/-LU4EmsfqCdk/TWfTuCXSptI/AAAAAAAAAfI/LoJDeuDApBA/s320/My+Sons+1_490x395.jpg" alt="My Sons" /></a>
<a href="http://template4.blogspot.com/" data-dojo-type="dojox.image.Lightbox" data-dojo-props="group:'My Sons',title:'My Sons',href:'http://2.bp.blogspot.com/-nW4cyQ_AEyY/TXKGPSRUTdI/AAAAAAAAAh0/5n4Zi2gcpV4/s1600/My%2BSons%2B4_490x395.jpg'"><img src="http://2.bp.blogspot.com/-nW4cyQ_AEyY/TXKGPSRUTdI/AAAAAAAAAh0/5n4Zi2gcpV4/s320/My%2BSons%2B4_490x395.jpg" alt="My Sons" /></a>
<a href="http://template4ublog.blogspot.com/" data-dojo-type="dojox.image.Lightbox" data-dojo-props="group:'My Sons',title:'My Sons',href:'http://3.bp.blogspot.com/-LV4HFMBoMsc/TWfTwosYS0I/AAAAAAAAAfM/ekpsQCb3zdM/s1600/My+Sons+2_490x395.jpg'"><img src="http://3.bp.blogspot.com/-LV4HFMBoMsc/TWfTwosYS0I/AAAAAAAAAfM/ekpsQCb3zdM/s320/My+Sons+2_490x395.jpg" alt="My Sons" /></a>
<a href="http://template4.blogspot.com/" data-dojo-type="dojox.image.Lightbox" data-dojo-props="group:'My Sons',title:'My Sons',href:'http://2.bp.blogspot.com/-oj4vCVzT_jE/TWfTz_NGeiI/AAAAAAAAAfQ/44RjwesqmJc/s1600/My+Sons+3_490x395.jpg'"><img src="http://2.bp.blogspot.com/-oj4vCVzT_jE/TWfTz_NGeiI/AAAAAAAAAfQ/44RjwesqmJc/s320/My+Sons+3_490x395.jpg" alt="My Sons" /></a>
<a href="http://template4ublog.blogspot.com/" data-dojo-type="dojox.image.Lightbox" data-dojo-props="group:'My Sons',title:'My Sons',href:'http://2.bp.blogspot.com/-nW4cyQ_AEyY/TXKGPSRUTdI/AAAAAAAAAh0/5n4Zi2gcpV4/s1600/My%2BSons%2B4_490x395.jpg'"><img src="http://2.bp.blogspot.com/-nW4cyQ_AEyY/TXKGPSRUTdI/AAAAAAAAAh0/5n4Zi2gcpV4/s320/My%2BSons%2B4_490x395.jpg" alt="My Sons" /></a>
</div>

Groups allow you to have images available within...groups... with next and previous buttons. The title property provides a ...title... and the href property provides the content which should load within the lightbox. You may have any number of groups on the page. That's all that's needed to create a simple Dojo Lightbox declaratively!

With your instance created, start adding more images:


// Add another image by using the lightbox's _attachedDialog method...
lightbox._attachedDialog.addImage({
 title:"My Sons 2", 
 group:"My Sons",  // Can be same group or different!
 href:"MySons.jpg"
});

Regardless of declarative or programmatic implementation, you can show or hide the lightbox with the respective methods:


// Show the lightbox
lightbox.show();
// Hide the lightbox!
lightbox.hide();

As you'd expect with any Dojo Toolkit resource, dojox.image.Lightbox provides the usual onShow, onHide, and other utility methods that are helpful in customizing the Lightbox usage.

dojox.image.Lightbox and dojox.image.LightboxDialog are great resources available within Dojo's "treasure chest", DojoX. Other classes within the dojox.image namespace include Gallery, Slideshow, and Magnifier.

source article: David Walsh


Related Posts Plugin for WordPress, Blogger...

Leave a Reply

BLOG MENU
Top of Page