Tuesday, May 5, 2015

Enable the Lightbox effect for an image hyperlink in a Label resource on your Moodle site

Photo credit: Lightbox-1 via photopin (license)

ightbox is a JavaScript library that displays images and videos by filling the screen, and dimming out the rest of the web page. The original JavaScript library was written by Lokesh Dhakar. The term Lightbox may also refer to other similar JavaScript libraries. Text is from: Lightbox (JavaScript) - Wikipedia, the free encyclopedia

In this post, I will show you how you can enable Lightbox for an image hyperlink in a Label resource on your Moodle site. The genesis of this post was the Blog Learning Rocks. Dan Roddy has written an average of one blog post a year for the last two years, and seven posts a year for the last six years. Which is not much, but this 2010 post of his has become my inspiration for today's post. In fact, thanks to Dan's post, I've also managed to enable the Lightbox effect on image files inside a Moodle folder resource! More on that later in another post on Moodurian.

Well, let's get started shall we?
Step 1: Surf to Dynamic Drive's Lightbox image viewer page.
Step 2: Download the file
Step 3: Extract the contents of the to your hard drive. You will see the folder named "lightbox" and its contents below:

Figure 1. Contents of

Step 4. FTP to your Moodle site and edit the file named /moodle/htdocs/theme/yourtheme/config.php

Step 5. Add the following yellow highlighted code to the file config.php:
$THEME->sheets = array('general','lightbox');

Step 6: Create a subfolder /moodle/htdocs/theme/yourtheme/lightbox

Step 7: Upload the image files close.gif,  loading.gif and overlay.png to your /moodle/htdocs/theme/yourtheme/lightbox subfolder.

Step 7: Upload the file lightbox.css to /moodle/htdocs/theme/yourtheme/css

Step 8: Edit the file /moodle/htdocs/theme/yourtheme/css/lightbox.css and add the following yellow highlighted code around lines 18 and 24:

#overlay{ background-image: url(; }


* html #overlay{
background-color: #333;
back\ground-color: transparent;
background-image: url(blank.gif);
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="", sizingMethod="scale");

Step 9: Store (upload transfer) the file lightbox.css to the style subfolder of your theme

Step 10: Upload the file lightbox.js to  /moodle/htdocs/theme/yourtheme/javascript

Step 11: Edit the file /moodle/htdocs/theme/yourtheme/javascript/lightbox.js and add the following yellow highlighted code (around line 41 and 42):

var loadingImage = '';
var closeButton = '''; 

Make sure you purge all caches before you start loading images. Below is the HTML code inside a Label resource.

<p><a rel="lightbox" href="">F16 Fighting Falcon</a></p>
<p><a rel="lightbox" href="">F15 Eagle</a></p>
<p><a rel="lightbox" href="" title="Death from the skies"><img src="" width="227" height="139" alt="f15" /></a><br />Click me</p>

Figure 2. HTML source code of a Label resource

Figure 3. WYSIWYG view of the Label resource inside the HTML editor.

Figure 4. The Label consists of two hyperlinks and one image thumbnail.

Figure 5. The user has clicked the link "F16 Fighting Falcon"
Notice the overlay effect which highlights the foreground
pop-out imagewhile graying out the rest of the background.
Figure 5. User has clicked the "F15 Eagle" link

Figure 6. User has clicked the F15 image thumbnail. Note that the image has a title.
So there you have it. You can have fun hyper-linking images for the Lightbox effect.

Frankie Kam

If you like this post or site
a small donation would be nice but would last only a day,
otherwise leaving a comment (or a compliment) below will last me a month!

No comments:

Post a Comment

Ratings and Recommendations by outbrain