[pLog-svn] r4868 - plog/branches/lifetype-1.2/class/template/smarty/plugins

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Feb 24 15:08:02 EST 2007


Author: oscar
Date: 2007-02-24 15:08:02 -0500 (Sat, 24 Feb 2007)
New Revision: 4868

Modified:
   plog/branches/lifetype-1.2/class/template/smarty/plugins/function.pager.php
Log:
Small usability improvement to the pager: added an "anchor" parameter that will be appended to each link to a page, so that we can get the browser to jump to that anchor in case the content doesn't start exactly at the top of the page.

Modified: plog/branches/lifetype-1.2/class/template/smarty/plugins/function.pager.php
===================================================================
--- plog/branches/lifetype-1.2/class/template/smarty/plugins/function.pager.php	2007-02-24 19:36:58 UTC (rev 4867)
+++ plog/branches/lifetype-1.2/class/template/smarty/plugins/function.pager.php	2007-02-24 20:08:02 UTC (rev 4868)
@@ -12,6 +12,9 @@
  * @param previous Text to be used to the link to the previous page in the sequence. If not present, it defaults to
  * whatever the current locale has defined for 'prev_post'
  * @param disablediv Whether not to enclose the pager data in a <div class="pager">...</pager> or not. Defaults to 'false'
+ * @param anchor Specify the name of an HTML anchor that will be appended to each one of the links in pages, so that
+ * we can get the browser to jump to the right section of the page (in case the paged content doesn't start at the
+ * top of the page)
  */
 function smarty_function_pager($params, &$smarty)	
 {
@@ -73,6 +76,9 @@
 	isset( $params["middle"] ) ? $middle = $params["middle"] : $middle = 5;
 	// Number of pages shown in the end
 	isset( $params["end"] ) ? $end = $params["end"] : $end = 3;
+	// whether we need to append an anchor reference to all links (in case the paged
+	// doesn't start immediately at the top of the page)
+	isset( $params["anchor"]) ? $anchor = $params["anchor"] : $anchor = "";
 	
 		
 	$base_url = $pager->getBaseUrl();
@@ -95,7 +101,7 @@
 			$init_page_max = ( $total_pages > $beginning ) ? $beginning : $total_pages;
 
 			for($i = 1; $i < $init_page_max + 1; $i++) {
-				$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i]."\">$i</a>";
+				$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 				if ( $i <  $init_page_max ) {
 					$page_string .= $separator;
 				}
@@ -109,7 +115,7 @@
 
 
 				for($i = $init_page_min - $middle; $i < $init_page_max + ($middle + 1); $i++) {
-					$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i]."\">$i</a>";
+					$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 					if ( $i <  $init_page_max + 1 ) {
 						$page_string .= $separator;
 					}
@@ -122,7 +128,7 @@
 			}
 			
 			for($i = $total_pages - ($end - 1); $i < $total_pages + 1; $i++) {
-				$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i]."\">$i</a>";
+				$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 				if( $i <  $total_pages ) {
 					$page_string .= $separator;
 				}
@@ -130,7 +136,7 @@
 		}
 		else {
 			for($i = 1; $i < $total_pages + 1; $i++) {
-				$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i]."\">$i</a>";
+				$page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 				if ( $i <  $total_pages ) {
 					$page_string .= $separator;
 				}
@@ -139,11 +145,11 @@
 
 		if ( $add_prevnext_text ) {
 			if ( $on_page > 1 ) {
-				$page_string = ' <a class="pagerLinkPrevPage" href="'.$pageLinks[$on_page - 1 ].'">'.$prevText.'</a>&nbsp;&nbsp;'.$page_string;
+				$page_string = ' <a class="pagerLinkPrevPage" href="'.$pageLinks[$on_page - 1 ].$anchor.'">'.$prevText.'</a>&nbsp;&nbsp;'.$page_string;
 			}
 
 			if ( $on_page < $total_pages ) {
-				$page_string .= '&nbsp;&nbsp;<a class="pagerLinkNextPage" href="'.$pageLinks[$on_page + 1].'">'.$nextText.'</a>';
+				$page_string .= '&nbsp;&nbsp;<a class="pagerLinkNextPage" href="'.$pageLinks[$on_page + 1].$anchor.'">'.$nextText.'</a>';
 			}			
 		}
 	}
@@ -161,7 +167,7 @@
 		<span class=\"pager\">";
 		if( !$pager->isFirstPage() && !$pager->isEmpty()) {
 			$page_string .= "<span class=\"list_action_button\">
-			   <a href=\"".$pager->getPrevPageLink()."\"><img src=\"imgs/admin/icon_left-16.png\" alt=\"$prevText\" /></a>
+			   <a href=\"".$pager->getPrevPageLink().$anchor."\"><img src=\"imgs/admin/icon_left-16.png\" alt=\"$prevText\" /></a>
 			 </span>";
 		}
 		$page_string .= "<select name=\"plogPager\" id=\"plogPager\" onChange=\"onPagerListChange(this)\""; 
@@ -170,7 +176,7 @@
 		}
 		$page_string .= ">";
 		foreach( $pager->getPageLinks() as $pageId => $pageLink ) {
-		    $page_string .= "<option value=\"$pageLink\"";
+		    $page_string .= "<option value=\"{$pageLink}{$anchor}\"";
 			if( $pageId == $pager->getCurrentPage())
 				$page_string .= "selected=\"selected\"";
 			$page_string .= ">$pageId</option>";
@@ -180,19 +186,19 @@
 		
 		if( !$pager->isLastPage() && !$pager->isEmpty()) {
 		 	$page_string .= "<span class=\"list_action_button\">";
-		    $page_string .= "<a href=\"".$pager->getNextPageLink()."\"><img src=\"imgs/admin/icon_right-16.png\" alt=\"$nextText\" /></a>";
+		    $page_string .= "<a href=\"".$pager->getNextPageLink().$anchor."\"><img src=\"imgs/admin/icon_right-16.png\" alt=\"$nextText\" /></a>";
 		 	$page_string .= "</span>";
 		}
 		$page_string .= "</span>";
 	}
 	elseif( $style == "prevonly" ) {
 		if (!$pager->isFirstPage() && !$pager->isEmpty()) {
-		   $page_string .= "<a class=\"pagerLinkPrevPage\" href=\"".$pager->getPrevPageLink()."\">$prevText</a>&nbsp;";
+		   $page_string .= "<a class=\"pagerLinkPrevPage\" href=\"".$pager->getPrevPageLink().$anchor."\">$prevText</a>&nbsp;";
 		}
 	}
 	elseif( $style == "nextonly" ) {
 		if (!$pager->isLastPage() && !$pager->isEmpty()) {
-		   $page_string .= "<a class=\"pagerLinkNextPage\" href=\"".$pager->getNextPageLink()."\">$nextText</a>&nbsp;";
+		   $page_string .= "<a class=\"pagerLinkNextPage\" href=\"".$pager->getNextPageLink().$anchor."\">$nextText</a>&nbsp;";
 		}		
 	}
 	else {



More information about the pLog-svn mailing list