Creative Commons License
This work is licensed under a Creative Commons License.

Javascript Photo Gallery

Functions

list functions : alphabetically  |   by category
show only functions for : thumbnail page  |   detail image page  |   both

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", "&copy; 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

 

Script from PizzaByTheSlice.com. Visit the Javascript tips for instructions and latest version.