issue117, auto-scroll photo-index if thumbnails are out of sight after a page-refresh
authorAndreas Unterkircher <unki@netshadow.at>
Fri, 25 Apr 2008 17:59:11 +0000 (19:59 +0200)
committerAndreas Unterkircher <unki@netshadow.at>
Fri, 25 Apr 2008 17:59:11 +0000 (19:59 +0200)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
themes/default/templates/photo_index.tpl

index bf235d3a0152487913e3272651300fc87a3dff06..82f49596576234d13ee386c1914415c3f7261eed 100644 (file)
 <br class="clearboth" />
 <script type="text/javascript" language="JavaScript">
 <!--
+   /*** image preloading ***/
    { counter start=-1 }
 
    var current;
    var image_urls = new Array();
+   var last_thumb;
 
    {section name="thumb" loop=$thumbs step=1}
       {if $images[thumb] }
          image_urls[{counter}] = 'phpfspot_img.php?idx={$images[thumb]}&width={$width}';
+         last_thumb = {$images[thumb]};
       {/if}
    {/section}
 
    preloadPhotos(image_urls);
+
+   // auto-scroll
+   //
+   // if browser is to far down the page, that he can't see the photo at all
+   // scroll it up so that at least the last photo becomes visisble.
+   { literal }
+
+   var ywnd = 0;
+   var yimg = 0;
+   // check where we are with the browser
+   if (window.pageYOffset) {
+      ywnd = window.pageYOffset;
+   } else if (document.body && document.body.scrollTop) {
+      ywnd = document.body.scrollTop;
+   }
+   // check the y-pos of the last thumbnail
+   if(thumbimg = document.getElementById('thumbimg' + last_thumb)) {
+      yimg = findPos(thumbimg,'top');
+   }
+   // if the browser-window is scrolled further then the last_thumb, scroll back
+   if(ywnd > yimg) {
+      window.scrollTo(0, yimg-100);
+   }
+
+   { /literal }
+   // auto-scroll
+
 -->
 </script>
 <!-- /Photo Index -->