ASP and a Dynamic Slide Show Control

This is a quick, simple (functional yet inelegant?) piece of IIS-friendly code for a user-driven slide show that I was asked to whip up.

A user wanted to post an mp3 along with some slides that the viewer could flip through along with listening to the audio.  In an effort to not have to revisit the code each time they had new slides to post I wrote a page (in classic ASP as the server supported it) that will monitor a folder for .JPG ’slides’ and build/manage the forward and back navigation of slides for you while enumerating your postion in the slides versus the total.  If the slides are in alphabetical order this just works and they can add/remove/edit slides all day with no changes needed to the slide code.  The forward and back buttons (not included) appear and disappear as appropriate.

Full code and comments after the jump.

Notes:  You’ll need to modify the path passed to the function ‘buildClientSideArray’ below to point to your slide repository.

============================

Place before the body or at least before the ‘in page code’ below:

This looks at the file system and builds the array in client side script

<%
DIM imgCounter
imgCounter = -1
DIM imgArray() ' Array to store qualifying images

' Start process
buildClientSideArray "H:\inetpub\ftproot\foobar\slides"

FUNCTION buildClientSideArray(path)
DIM fs, folder, file, item, imageCounter
SET fs = CreateObject("Scripting.FileSystemObject")
SET folder = fs.GetFolder(path)

response.write "<script language='javascript'>" & vbCrLf
response.write "var a = new Array();" & vbCrLf

FOR EACH item in folder.Files
if INSTR(LCASE(item.Name),".jpg") <> 0 THEN
imgCounter = imgCounter + 1
response.write "a[" & imgCounter & "] = '" & item.name & "';" & vbCrLf
END IF
NEXT

response.write "var aLen = " & imgCounter & vbCrLf
response.write "</script>"  & vbCrLf

END FUNCTION
%>
<script language="javascript">
window.onload = loadSlideOne;
var slideCounter = 0;
var totalSlides = <%=imgCounter + 1%>;

function incrementSlide()
{
if (slideCounter + 1 != totalSlides)
{
getObj('slide').src= 'slides/' + a[slideCounter + 1];
getObj('slideCountDisplay').innerHTML = slideCounter + 2;
slideCounter += 1;
updateButtons();
}
}
function decrementSlide()
{
if (slideCounter != 0)
{
getObj('slide').src= 'slides/' + a[slideCounter - 1];
getObj('slideCountDisplay').innerHTML = slideCounter;
slideCounter -= 1;
updateButtons();
}
}
function updateButtons()
{
if (slideCounter < totalSlides - 1){getObj('forwardNav').style.visibility = "visible";}
else{getObj('forwardNav').style.visibility = "hidden";}

if (slideCounter > 0){getObj('backNav').style.visibility = "visible";}
else{getObj('backNav').style.visibility = "hidden";}
}
function loadSlideOne()
{
getObj('slide').src="slides/" + a[0];
}
function getObj(objID)
{
if (document.getElementById) {return document.getElementById(objID);}
else if (document.all) {return document.all[objID];}
else if (document.layers) {return document.layers[objID];}
}
</script>

============================
Place in your page, note it is looking for back and forward arrows for images:

<img id="backNav" src="images/back.gif"
style="visibility:hidden;cursor:pointer;" onclick="decrementSlide()">
SLIDE <span id="slideCountDisplay">1</span> / <%=imgCounter + 1%>
<img id="forwardNav" src="images/forward.gif"
style="visibility:visible;cursor:pointer;" onclick="incrementSlide()"><br>

<img id="slide">

 
 
 

One Response to “ASP and a Dynamic Slide Show Control”

  1. WAYNE
    20. July 2010 at 21:27


    Medicamentspot.com. Canadian Health&Care.No prescription online pharmacy.Best quality drugs.Special Internet Prices. High quality pills. Order pills online

    Buy:Tramadol.Viagra Super Force.Viagra Super Active+.Viagra Soft Tabs.Maxaman.Viagra.Cialis Super Active+.Soma.Zithromax.VPXL.Viagra Professional.Cialis.Super Active ED Pack.Cialis Professional.Propecia.Levitra.Cialis Soft Tabs….

Leave a Reply

You must be logged in to post a comment.