*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 5 Nov 2006 13:27:16 +0000 (13:27 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Sun, 5 Nov 2006 13:27:16 +0000 (13:27 +0000)
mmsoftware/js/js-sh/app/thumb/thumb.js

index 381e40e..fff90ba 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: thumb.js,v 1.4 2006/11/05 13:00:16 mmondor Exp $ */
+/* $Id: thumb.js,v 1.5 2006/11/05 13:27:16 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -10,8 +10,6 @@
  * - Implement getopt-like class and allow to provide command line arguments
  * - Generate multiple indexes with list of index links at top and bottom
  *   for large directories
- * - Instead of showing directory name link, show one of the thumbnails inside
- *   as clickable collection preview link
  * - Work on better presentation
  */
 
@@ -175,10 +173,25 @@ function thumbnail_dir(path, xmax, ymax)
                                    "\n");
                                for (i in index) {
                                        f = index[i];
-                                       if (f.t == 'DIR')
-                                               fh.write('<a href="' + f.l +
-                                                   '/index.html">' + f.l +
-                                                   "/</a><br>\n");
+                                       if (f.t == 'DIR') {
+                                               var t;
+
+                                               if ((t = dir_findthumb(path +
+                                                   '/' + f.l)) != null)
+                                                       fh.write('<a href="' +
+                                                           f.l +
+                                                           '/index.html">' +
+                                                           '<img src="' +
+                                                           f.l + '/' + t +
+                                                           '"></a>' + "\n");
+                                               else
+                                                       fh.write(
+                                                           '<br><a href="' +
+                                                           f.l +
+                                                           '/index.html">' +
+                                                           f.l +
+                                                           "/</a><br>\n");
+                                       }
                                }
                                for (i in index) {
                                        f = index[i];
@@ -208,4 +221,32 @@ function thumbnail_dir(path, xmax, ymax)
        return ret;
 }
 
+function dir_findthumb(path)
+{
+       var ret = null;
+       var dir, e, o, s = 0;
+
+       for (;;) {
+               try {
+                       dir = new Dir(path);
+                       while ((e = dir.read()) != null) {
+                               if (e.name.match(/_thumb/)) {
+                                       o = FS.stat(path + '/' + e.name);
+                                       if (o.st_size > s)
+                                               ret = e.name;
+                               }
+                       }
+               } catch (x) {
+                       Syslog.log(Syslog.LOG_NOTICE, x.toString());
+                       break;
+               }
+       }
+
+       try {
+               dir.close();
+       } catch (x) {}
+
+       return ret;
+}
+
 thumbnail_dir('/home/data/jshttpd/mmondor/testimg', 64, 64);