info343/labs/5/solution/lightbox-ex2.js

// lightbox-ex2.js
// Sample JavaScript solution code for Lab 5: Lightbox
// (Partial solution through Exercise 2.)
// INFO 343, Autumn 2012
// Morgan Doocy

// List of image filenames and captions to display in the gallery.
var IMAGES = [
   { file: 'http://info343.ischool.uw.edu/labs/5/avocado.jpg',    caption: 'Avocado' },
   { file: 'http://info343.ischool.uw.edu/labs/5/beach.jpg',      caption: 'Beach' },
   { file: 'http://info343.ischool.uw.edu/labs/5/biebs.jpg',      caption: 'Biebs' },
   { file: 'http://info343.ischool.uw.edu/labs/5/bling.jpg',      caption: 'Bling' },
   { file: 'http://info343.ischool.uw.edu/labs/5/cat.jpg',        caption: 'Cat' },
   { file: 'http://info343.ischool.uw.edu/labs/5/dew.jpg',        caption: 'Dew' },
   { file: 'http://info343.ischool.uw.edu/labs/5/fall.jpg',       caption: 'Fall' },
   { file: 'http://info343.ischool.uw.edu/labs/5/freeway.jpg',    caption: 'Freeway' },
   { file: 'http://info343.ischool.uw.edu/labs/5/hongkong.jpg',   caption: 'Hong Kong' },
   { file: 'http://info343.ischool.uw.edu/labs/5/leaves.jpg',     caption: 'Leaves' },
   { file: 'http://info343.ischool.uw.edu/labs/5/reflection.jpg', caption: 'Reflection' },
   { file: 'http://info343.ischool.uw.edu/labs/5/tuners.jpg',     caption: 'Tuners' }
];

// When the page is ready, create and inject images into #gallery.
$(document).ready(function() {
   $.each(IMAGES, function(i, image) {
      // Create the image with appropriate attributes.
      var $img = $('<img>').attr('src', image.file).attr('alt', image.caption);
      
      // Inject the image into the gallery.
      $img.appendTo('#gallery');
   });
});