No Support => Modifications/Add-Ons/Hacks => Mods: Visuals => Topic started by: djpushplay on October 15, 2006, 12:47:42 am

Title: [Code Sample] Prev / Next image on tab
Post by: djpushplay on October 15, 2006, 12:47:42 am
Did a quick search and hopefully, this is not a repeat.  Newbie on this board but decided to give back to this great community.  A while back, I saw in the existing 1.4.9 code stubs for "Prev" and "Next" in the image tab so I took a shot at coding it.  So far it seems to work but I'm not positive it's gold.  I'm sure somebody on here will fix it if it's not.

The code will make the tab look like this:
<Prev 1 ... 5 6 7 8 9 10 ... 320 Next>

Code: [Select]
function theme_create_tabs($items, $curr_page, $total_pages, $template)
global $CONFIG, $lang_create_tabs;

    $maxTab = $CONFIG['max_tabs'];

    $tabs = sprintf($template['left_text'], $items, $total_pages);
    if (($total_pages == 1))
    return $tabs;

    $tabs .= $template['tab_header'];
$prev = $curr_page - 1;
$p = array('{PREV}' => $lang_create_tabs['previous']);
if ($prev < 1)
$tabs .= strtr( sprintf($template['active_prev_tab']), $p);
$tabs .= strtr( sprintf($template['inactive_prev_tab'],$prev), $p);

    if ($curr_page == 1) {
        $tabs .= sprintf($template['active_tab'], 1);
    } else {
        $tabs .= sprintf($template['inactive_tab'], 1, 1);
        if ($curr_page - floor($maxTab / 2) >= 2) //
        $tabs .= $template['dotdotdot']; //

    if ($total_pages > $maxTab){
        $start = max(2, $curr_page - floor(($maxTab - 2) / 2));
        $start = min($start, $total_pages - $maxTab + 2);
        $end = $start + $maxTab - 3;
    } else {
        $start = 2;
        $end = $total_pages - 1;

    for ($page = $start; $page <= $end; $page++) {
        if ($page == $curr_page) {
$tabs .= sprintf($template['active_tab'], $page);
        } else {
$tabs .= sprintf($template['inactive_tab'], $page, $page);

    if ($total_pages > 1) {
if ($curr_page == $total_pages) {
$tabs .= sprintf($template['active_tab'], $total_pages);

} else {
if ($curr_page + ($maxTab / 2) <= $total_pages) //
        $tabs .= $template['dotdotdot']; //
$tabs .= sprintf($template['inactive_tab'], $total_pages, $total_pages);

$next = $curr_page + 1;
$n = array('{NEXT}' => $lang_create_tabs['next']);
if ($next > $total_pages)
$tabs .= strtr( sprintf($template['active_next_tab']), $n);
$tabs .= strtr( sprintf($template['inactive_next_tab'],$next), $n);

    return $tabs . $template['tab_trailer'];

And the tab definitions are:
Code: [Select]
$template_tab_display = array(
'left_text' => '<td align="left" valign="middle" class="tableh1_compact" style="white-space: nowrap"><b>{LEFT_TEXT}</b></td>' . "\n",
    'tab_header' => '',
    'tab_trailer' => '',
    'dotdotdot' => '<td align="center" valign="middle">...</td>',
    'active_tab' => '<td align="center" valign="middle" class="navmenu_active">%d</td>',
    'inactive_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>%d</b></a></td>' . "\n",
    'active_prev_tab' => '<td align="center" valign="middle" class="navmenu_active">{PREV}</td>' . "\n",
    'inactive_prev_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>{PREV}</b></a></td>' . "\n",
    'active_next_tab' => '<td align="center" valign="middle" class="navmenu_active">{NEXT}</td>' . "\n",
    'inactive_next_tab' => '<td align="center" valign="middle" class="navmenu"><a href="{LINK}"><b>{NEXT}</b></a></td>' . "\n",

Code: [Select]
$lang_create_tabs = array(
  'previous' => '&lt;Prev', //cpg1.4 //
  'next' => 'Next&gt;', //cpg1.4 //

If you're wondering why I removed the comments from the code above, it's because this is a family board and I tend to write odd comments in my code.

If I forgot to include something here, let me know.  I wrote this a while ago so it's not so fresh in my memory anymore.

Also, I moved the navigation tabs to the top instead of the bottom.  This way, a user can keep his/her cursor on the "Next" and keep clicking without having to move the cursor each time.  Less work for the user.
Title: Re: [Code Sample] Prev / Next image on tab
Post by: benj_gos on November 12, 2006, 03:04:36 pm
This is really great  :D, thank you!!

1 question.
I always have the dotdotdot, even if the number of pages is same or higher then what's defined as max pages.
example - album has 5 pages i have set to show 10 pages and i see "1 2 3 4 ... 5".
How would i go about making sure that it shows only when it's above the set limit?

Title: Re: [Code Sample] Prev / Next image on tab
Post by: Hein Traag on November 17, 2006, 11:09:35 am
Added this mod to my CPG. So far so good. It adds a nice set of tabs to the thumbnail screen. Tested with two pages of thumbs.. adding more pictures to see if the same problem arises as benj_gos.

Title: Re: [Code Sample] Prev / Next image on tab
Post by: Gephri on January 17, 2007, 08:53:40 pm
Installed the mod easily enough, but now I don't have the ... in pages with lots of tabs.
For examples 1,2,3,4,5,6,7,8,9,10,324
Should be 1,2,3,4,5,6,7,8,9,10,...324

Can anyone point me towards the code that controls this?
Title: Re: [Code Sample] Prev / Next image on tab
Post by: ppFreddy on February 26, 2007, 02:00:41 am
Got it working on my testserver, nice and easy mod.

Modded a few things so that if you are on page 1, there is no "previous", and if you are on the last page, ther is nog "next"

Only: on the index, if your albums in your categories are tabbed too, the link you get is just "{LINK}"
The numbered ones are correct though.

Title: Re: [Code Sample] Prev / Next image on tab
Post by: skidpics on March 10, 2007, 01:26:55 pm
Awesome Mod!  ONly problem is that it is showing at the bottom of the page, not the top as described in the first post.  What do I change to place it at the top of the thumb view?

-- Skidpics
Title: Re: [Code Sample] Prev / Next image on tab
Post by: dke on June 24, 2007, 12:50:36 pm
really great mod! but i have the same problem aswell, the tabs displaying at the bottom insted of the top left corner, would be sweet not having to move the cursor :) anyway great mod thanks!