|
This work is licensed under a Creative Commons License.
|
|
|
Javascript Photo Gallery
Functions
function | description |
---|
adding images functions | addImg | add an image to the photo gallery | addImg90 | same as addImg but uses default width as the height and default height as the width | reorderArgs | set the ordering of the arguments for addImg and addImg90 | setDefault | set default value for a given image attribute. for valid attributes see reorderArgs. Usage:
setDefault( "title", "Surfing Lessons" ); | setDefDims | shorthand combines setDefault for width and height (in pixels) in one command Usage:
setDefDims( 500, 333 ); | navigation functions | gotoPrevPic | display the picture before the current one as defined by addImg | gotoNextPic | display the picture after the current one as defined by addImg | gotoFirstPic | display the first picture | gotoLastPic | display the last picture | gotoThumbs | switch from image detail page to thumbnail page. Function passes additional information to the thumbnail page that will allow it to display the appropriate set of thumbs that include the current image, something not possible using a static link to the thumbnail page. | showHelp | display the keyboard and version information in browser alert box | showAll | displays all of the thumbnails, using the number of columns set with setCols but with as many rows as necessary | startSlideshow | begins the slideshow beginning with the current image. loop-around behavior determined by setWrap value | stopSlideshow | stops the slideshow (if running) | toggleSlideshow | starts/stops slideshow. Returns the new slideshow state; true if slideshow has been started, false if it has been stopped. | setup functions | writeGallery | displays appropriate gallery sections, image or thumbnail or both, by modifiing the HTML through Javascript. this relies upon the web page's DOM sufficiently complete insofar as element id's are concerned. must be called after all id'ed tags and after all other photo gallery function calls. | enableQuickKeys | call to enable keyboard shortcuts such as 'N' for next image and 'S' to toggle slideshow | setElementId | attribute plus valid HTML element id | setCallback | provide a function (reference) that will be called after an image is loaded. The function will be called with one parameter: the index of the just selected image. Use this to retrieve information using the getValue function. Usage:
setCallback( ImageIsLoadedFn ); | setDelay | set the slideshow delay in miliseconds. For a 3 second delay pass in 3000. | setWrap | set true to allow users to wrap from last-to-first image when clicking next (and vice versa). default is true. | setRows | set the number of rows displayed in the thumbnail grid | setCols | set the number of columns displayed in the thumbnail grid | setThumbClass | stylesheet class name for the TD containing a single thumbnail, plus its title if that option is set | setThumbEmptyClass | stylesheet class name for any TD required to fill out a partial thumbnail grid. For example, if the dimensions are 6 columns by 4 rows a total of 24 thumbnail "slots" are available. If only 17 images are defined the remaining 7 (24 less 17) table cells will use the spacer gif and be set to this class (if defined). | setThumbWidth | the width, in pixels, of thumbnails. if an image is taller than wide this value is used for the height | setThumbSpacing | distance, in pixels, between thumbnails in the thumbnail grid | setThumbTitles | if set true the title, if present, for an image is emitted below its thumbnail | setThumbAll | if set true ... Usage:
setThumbAll( true ); | setThumbDir | path (relative or absolute) to the thumbnail directory Usage:
setThumbDir( "/images/myphotos/thumbnails/" ); | setImgDir | path (relative or absolute) to the full-sized image directory Usage:
setImgDir( "/images/myphotos/" ); | setThumbPage | name of the thumbnail web page. leave blank if thumbnails and images are emitted on the same page Usage:
setThumbPage( "thumbnails.htm" ); | setImgPage | name of the thumbnail web page. leave blank if thumbnails and images are emitted on the same page Usage:
setImgPage( "image.htm" ); | setSpacer | URL (relative or absolute) to a transparent spacer (shim) image. required when showing the thumbnail grid Usage:
setSpacer( "/images/spacer.gif" ); | setLoadingImg | URL (relative or absolute) to an image that is displayed on the image detail page while the image is being loaded (optional) Usage:
setLoadingImg( "/images/loading.gif" ); | information functions | getValue | returns value of specified attribute for a given image. if no image index is specified the current image's information is returned. Useful in callback function. Usage:
myString= getValue( "extra1", 7 ); | getIsSlideshow | returns true if slideshow is currently playing | getCount | returns the number of images that have been defined via addImg or addImg90. Equivalent to getValue("count") |
top of page
addImg
Adds an image to the gallery. All parameters except file are optional; missing values inherit the default value for that parameter. To explicitly use the default value for a attribute pass in null. See examples.
All values are strings except width and height.
Only values associated with an HTML element you've identified using setElementId are displayed. All values are accessible through the getValue method.
addImg( variable_list );
Note: the parameters below are listed in their default ordering. This may be changed to suit your needs via the reorderArgs function.
Parameter |
Description |
file |
file name (required) Thumbnails and images must use the same file name. thumbs and full-sized images are typically located in different directories, but this is not required. |
description |
(optional) |
width |
image width in pixels |
height |
image height in pixels |
title |
(optional) if set and the option is enabled this value displays beneath thumbnail |
date |
(optional) |
extra1 |
(optional) |
extra2 |
(optional) |
extra3 |
(optional) |
extra4 |
(optional) |
Examples:
<script language="javascript" type="text/javascript">
addImg( "22.jpg", "Me on top of marshmallows", 440,323 );
addImg( "23.jpg", "Janet making pie sans crust?", 440, 582,
"Pie Lady", "21 December, 2002", "© 2003 CookingBlunders.net");
addImg( "24.jpg", "Conventions are fun!", 440,323 );
addImg( "25.jpg", "No idea what this is a picture of", 440,323 );
addImg( "41.jpg", null, 440, 323, null, "6 June, 2004" );
</script>
top of page
reorderArgs
Set the function parameter ordering for addImg and addImg90 . Used with setDefault this all but eliminates redundant data entry. It is recommended that the first parameter always be the file name.
All of the attributes need not be specified. Those not listed will be added automatically in the default order. See example.
reorderArgs( argument_list );
Parameter |
Description |
attribute(s) |
comma separated list of the parameters for addImg |
Example:
<script language="javascript" type="text/javascript">
reorderArgs( "file", "title", "extra1", "date" );
addImg( "22.jpg", "Marshmallows", "wholesale only", "21 December, 2002");
// using null to explicitly use default values
addImg( "41.jpg", null, null, "March 1997" );
// assigning values to attributes not changed in reorderArgs
addImg( "22.jpg", "Ice Cream", "retail", null, "", 400, 500 );
// implictly using defaults
addImg( "grapeleaves.jpg" );
</script>
In the above example four attributes were defined. What will be the fifth, six, etc? description, width, height, and so on until extra4. The order resumes using the remaining unxpecified attribues
of addImg in the default order. If this is confusing the best practice would be to explicitly name all of the attributes in the order you want.
You may change the order at any time, even after you've begun adding images.
top of page
getValue
Returns an attribute's value for a given image or configuration variable such as directory.
If no image index specified the current image is used. Not all attributes require an index.
getValue( attribute, [index] );
Parameter |
Description |
attribute |
name of the attribute. valid attributes include all addImg values plus these (the attributes below do not use an image index, if provided it is ignored):
- image: pbtsImg object
- dir: the value set in
setImgDir
- thumbdir: the value set in
setThumbDir
- pathname: complete path to the image. value set in
setImgDir concatenated with file. Example: images/photos/cake.jpg
- count: number of images in the gallery (number of calls to
addImg or addImg90 )
- current: index of current image
- maxwidth: width of gallery's widest image
- maxheight: height of gallery's tallest image
|
index |
(optional) zero-based index of an image for which information is requested. if ommitted the current image is used. |
Example:
<script language="javascript" type="text/javascript">
var myStr="";
myStr= getValue( "title" );
</script>
top of page
setElementId
defines parts of your HTML document to be used by the Photo Gallery script. The contents of these elements will be overwritten,
with the exception of the image element which must be assigned to an img (image tag).
setElementId( attribute, id );
Parameter |
Description |
attribute |
name of the attribute.
- image: an id on an
img tag
- description: image description
- title: image title
- extra1: image extra1
- extra2: image extra2
- extra3: image extra3
- extra4: image extra4
- date: image extra5
- info: recieves file info, made up of the file name plus image dimensions (width x height)
- pages: thumbnail page links
- thumbs: receives thumbnail grid (a table)
|
id |
value of a tag's id |
Example:
<img src="images/spacer.gif" border="0" width="1" height="1" id="thephoto">
<p id="caption"></p>
<p id="photoinfo"></p>
<span id="mythumbs"></span>
<script language="javascript" type="text/javascript">
setElementId( "image", "thephoto" );
setElementId( "info", "photoinfo" );
setElementId( "description", "caption" );
setElementId( "thumbs", "mythumbs" );
</script>
top of page
|