issue102, use javascript to jump to the correct thumbnail when returing from photo...
authorAndreas Unterkircher <unki@netshadow.at>
Sat, 19 Jan 2008 09:02:19 +0000 (10:02 +0100)
committerAndreas Unterkircher <unki@netshadow.at>
Sat, 19 Jan 2008 09:02:19 +0000 (10:02 +0100)
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
phpfspot.class.php
phpfspot.js
rpc.php
themes/default/templates/photo_index.tpl
themes/default/templates/single_photo.tpl

index 17ec45098abd8e4085a9f219f718055bed242a58..f1b0dc64dbf53702ab52e10c15a6b698dbfb1ca2 100644 (file)
@@ -503,7 +503,8 @@ class PHPFSPOT {
       $this->tmpl->assign('image_filename', $this->parse_uri($details['uri'], 'filename'));
 
       $this->tmpl->assign('tags', $this->get_photo_tags($photo));
-      $this->tmpl->assign('current', $this->getCurrentPage($current, $count));
+      $this->tmpl->assign('current_page', $this->getCurrentPage($current, $count));
+      $this->tmpl->assign('current_img', $photo);
 
       if($previous_img) {
          $this->tmpl->assign('previous_url', "javascript:showImage(". $previous_img .");");
@@ -952,9 +953,6 @@ class PHPFSPOT {
 
       $count = count($photos);
 
-      if(isset($_SESSION['begin_with']) && $_SESSION['begin_with'] != "")
-         $anchor = $_SESSION['begin_with'];
-
       /* if all thumbnails should be shown on one page */
       if(!isset($this->cfg->thumbs_per_page) || $this->cfg->thumbs_per_page == 0) {
          $begin_with = 0;
@@ -1130,8 +1128,14 @@ class PHPFSPOT {
 
       $this->tmpl->show("photo_index.tpl");
 
-      if(isset($anchor))
-         print "<script language=\"JavaScript\">self.location.hash = '#image". $anchor ."';</script>\n";
+      /* if we are returning to photo index from an photo-view,
+         scroll the window to the last shown photo-thumbnail.
+         after this, unset the last_photo session variable.
+      */
+      if(isset($_SESSION['last_photo'])) {
+         print "<script language=\"JavaScript\">moveToThumb(". $_SESSION['last_photo'] .");</script>\n";
+         unset($_SESSION['last_photo']);
+      }
 
    } // showPhotoIndex()
 
index 21a027af970748a4c54afdab1b561274b58d8e31..e24d0aa76195b3d9bf3f467b0532fa4e161f8e50 100644 (file)
@@ -8,6 +8,17 @@ function showImage(id, scrollup)
    }
 }
 
+function moveToThumb(thumb_id)
+{
+   if(thumb_id == undefined)
+      return;
+
+   if(thumbimg = document.getElementById('thumbimg' + thumb_id)) {
+      window.scrollTo(0, thumbimg.offsetTop-100);
+   }
+
+} // moveToThumb()
+
 function showCredits()
 {
    var credits = document.getElementById("content");
@@ -62,13 +73,17 @@ function refreshSelectedTags()
    selected_tags.innerHTML = HTML_AJAX.grab(encodeURI('rpc.php?action=show_selected_tags'));
 }
 
-function showPhotoIndex(begin_with)
+function showPhotoIndex(begin_with, last_photo)
 {
-   if(begin_with == undefined)
-      HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index'));
-   else
-      HTML_AJAX.replace(document.getElementById("content"), encodeURI('rpc.php?action=show_photo_index&begin_with=' + begin_with));
-}
+   var url = "rpc.php?action=show_photo_index";
+   if(begin_with != undefined)
+      url = url + '&begin_with=' + begin_with;
+   if(last_photo != undefined)
+      url = url + '&last_photo=' + last_photo;
+
+   HTML_AJAX.replace(document.getElementById("content"), encodeURI(url));
+
+} // showPhotoIndex()
 
 // if photo index is currently shown, refresh it
 function refreshPhotoIndex()
diff --git a/rpc.php b/rpc.php
index 4bb297331abbad7bff7d38a9e2c66704f8788743..ad80ca5eedcf2d4f7d8a66aab20b4e2c5315b858 100644 (file)
--- a/rpc.php
+++ b/rpc.php
@@ -99,6 +99,9 @@ class PHPFSPOT_RPC {
             else {
                unset($_SESSION['begin_with']);
             }
+            if(isset($_GET['last_photo']) && is_numeric($_GET['last_photo']))
+               $_SESSION['last_photo'] = $_GET['last_photo'];
+
             $fspot->showPhotoIndex();
             break;
    
index 717b3f21f4eaf8a61ce19a3e3e99da165b95bd4f..dff6ab1d15e54489940e0b798698bbac2f4aa51b 100644 (file)
 </div>
 
 <div id="index">
+
  {section name="thumb" loop=$thumbs step=1}
+
   {if $images[thumb] }
-    <div class="thumb" onmouseover="setBackGrdColor(this, 'mouseover');" onmouseout="setBackGrdColor(this, 'mouseout');" style="width: { $thumb_container_width }px; height: { $thumb_container_height }px;">
-     <a href="javascript:showImage({$images[thumb]}, 'scrollup');" id="{$images[thumb]}" name="image{$img_id[thumb]}" class="thumblink" onclick="click(this);" title="{$img_title[thumb]}">
-      <img class="thumb" id="{$images[thumb]}" src="phpfspot_img.php?idx={$images[thumb]}&amp;width={$width}" alt="thumb_{$images[thumb]}" width="{$img_width[thumb]}" height="{$img_height[thumb]}" />
-      <br />
-     {$img_name[thumb]}
-     </a>
-    </div>
-   {/if}
+
+   <div class="thumb" onmouseover="setBackGrdColor(this, 'mouseover');" onmouseout="setBackGrdColor(this, 'mouseout');" style="width: { $thumb_container_width }px; height: { $thumb_container_height }px;">
+    <a href="javascript:showImage({$images[thumb]}, 'scrollup');" id="thumblink{$images[thumb]}" name="image{$img_id[thumb]}" class="thumblink" onclick="click(this);" title="{$img_title[thumb]}">
+     <img class="thumb" id="thumbimg{$images[thumb]}" src="phpfspot_img.php?idx={$images[thumb]}&amp;width={$width}" alt="thumb_{$images[thumb]}" width="{$img_width[thumb]}" height="{$img_height[thumb]}" />
+     <br />
+    {$img_name[thumb]}
+    </a>
+   </div>
+
+  {/if}
+
  {/section} 
+
 </div>
 <br class="clearboth" />
 <div style="width: 100%; margin-top: 20px;">
index 2032f525896055678c0d41faa1e4f24324e17dc0..62a2bf77f2ac9c17ff5976dfdfe661e858777db9 100644 (file)
@@ -80,7 +80,7 @@
     <img src="resources/arrow_left.png" alt="previous photo" />
    </a>
   { /if }
-   <a href="javascript:showPhotoIndex({$current});" onclick="click(this);" title="click to go back to the index">
+   <a href="javascript:showPhotoIndex({$current_page}, {$current_img});" onclick="click(this);" title="click to go back to the index">
     <img src="resources/arrow_up.png" alt="photo index" />
    </a>
   { if $next_url == "" }