Posted By

noah on 07/03/07


Tagged

regex javascript file html perl gallery heredoc 2001


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

icecreamboyy


show JPEGs in this directory in a simple HTML gallery


 / Published in: Perl
 

Creates an HTML page with the first image in the directory in the center. Forward and Back buttons scroll through all the images in the directory in order.

This is how I lived before Firefox ~.^

  1. #! /usr/bin/perl -w
  2. use strict;
  3.  
  4. #****************************************************************
  5. # To Do: display a thumbnail link to every image on every page *
  6. #****************************************************************
  7.  
  8.  
  9.  
  10. ####
  11. my $start;
  12. print "<html><head><title>Images In This Directory</title></head>\n";
  13. ####
  14. print <<BEGINSCRIPT;
  15. <script type="text/javascript">
  16. var counter = -1;
  17. var showstuff = new Array();
  18. BEGINSCRIPT
  19. ####
  20. print "showstuff=[";
  21. ####
  22. while (<*\.jp*>) { #regex scans working directory and captures any filename with extension beginning "JP"
  23. print "\"$_\","; #print each file name into the array
  24. $start = $_;
  25. }
  26. ####
  27. print "];\n";
  28. ####
  29. print <<STARTHTML;
  30. function next () {
  31.   if (showstuff[counter] != "" && counter < showstuff.length-1) {
  32.   document.graphic.src=showstuff[++counter];
  33. }
  34.   else {
  35.   counter = -1;
  36. next();
  37. }
  38. }
  39. function back () {
  40.   if (showstuff[counter] != "" && counter > 0) {
  41.   document.graphic.src=showstuff[--counter];
  42. }
  43.   else {
  44.   counter = showstuff.length;
  45. back();
  46. }
  47. }
  48. </script><body>
  49. <p style="text-align:center">
  50. <img src="" alt="Click one of the links below to see a different image." name="graphic" width="900" />
  51. <p style="text-align:center">
  52. <a href="javascript:back();" style="font-size:30pt;font-weight:bold;"><-- BACK</a>
  53. ...
  54. <a href="javascript:next();" style="font-size:30pt;font-weight:bold;">NEXT --></a>
  55. </body></html>
  56.  
  57.  
  58. <script>next();</script>
  59.  
  60. STARTHTML

Report this snippet  

You need to login to post a comment.