Ignore:
Timestamp:
Sep 19, 2009, 1:02:09 PM (15 years ago)
Author:
nikrou
Message:

Bug 1159: fix
Medium image are loaded in ajax mode.

Location:
extensions/akBookStyle/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/akBookStyle/trunk/include/akContent.class.php

    r3844 r3876  
    3535    $this->previous_picture = null;
    3636    $this->applicable = false;
     37
     38    $this->picture_pattern_format = '`^%s/(?:start\-\d+/)?picture/(\d+)$`';
    3739  }
    3840
    3941  public function page_force() {
    4042    global $page;
    41     if ( isset($page['category']) ) {
     43
     44    if (isset($page['category'])) {
    4245      $cat_filter = $this->plugin_config->ak_categories;
    4346      $this->applicable = (stripos($page['category']['name'], $cat_filter) === false) ? false:true;
     
    5053  public function loc_begin_index_thumbnails($images) {
    5154    global $template;
     55
    5256    if ($this->applicable === false) return;
    5357    $this->category_url = make_index_url(array('section' => 'category',
    54                  'category' => $GLOBALS['page']['category'],
    55                  'start' => $GLOBALS['page']['start']
    56                  )
    57            );
     58                                               'category' => $GLOBALS['page']['category'],
     59                                               'start' => $GLOBALS['page']['start']
     60                                               )
     61                                         );
     62    $this->picture_pattern = sprintf($this->picture_pattern_format,
     63                                     str_replace('?', '\?', $this->category_url)
     64                                     );
     65                                     
    5866    $this->current_picture = $this->getPictureId($images);
    5967
     
    8088    if ($this->applicable === false) return $tpl_vars;
    8189    foreach ($tpl_vars as &$tpl_var) {
    82       $tpl_var['AK_URL'] = $this->makeAkUrl($tpl_var);
    83 
    8490      list($thumbnail_width, $thumbnail_height) = getimagesize($tpl_var['TN_SRC']);
    8591      $thumbnail_x_center = $thumbnail_width/2;
     
    94100  }
    95101
     102  public function loc_end_picture() {
     103    if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])
     104        && ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest')) {     
     105      header("Content-Type: application/json");
     106
     107      $response = array();
     108      $tpl_vars = $GLOBALS['template']->smarty->_tpl_vars;
     109      $response['AK_PIC_SRC'] = $tpl_vars['SRC_IMG'];
     110      $response['AK_PIC_ALT'] = $tpl_vars['ALT_IMG'];
     111      if (isset($tpl_vars['ALT_IMG'])) {
     112        $response['AK_PIC_TITLE'] = $tpl_vars['ALT_IMG'];
     113      } else {
     114        $response['AK_PIC_TITLE'] = '';
     115      }
     116
     117      if (isset($tpl_vars['previous'])) {
     118        $response['AK_PREVIOUS'] = $tpl_vars['previous']['url'];
     119      }
     120      if (isset($tpl_vars['next'])) {
     121        $response['AK_NEXT'] = $tpl_vars['next']['url'];
     122      }
     123      echo json_encode($response);
     124      exit();
     125
     126    }
     127  }
     128
    96129  /*** privates methods ***/
    97130  private function makeAkUrl($image) {
    98131    return sprintf('%s/picture/%d', $this->category_url, $image['ID']);
    99 
    100132  }
    101133
     
    113145    }
    114146    $rewritten = make_index_url().$rewritten;
    115     $pattern = sprintf('`^%s/(?:start\-\d+/)?picture/(\d+)$`',
    116            str_replace('?', '\?', $this->category_url)
    117            );
    118147
    119     if (preg_match($pattern, $rewritten, $matches)) {
     148    if (preg_match($this->picture_pattern, $rewritten, $matches)) {
    120149      foreach ($images as $index => $image) {
    121150        if ($image['id']==$matches[1]) {
     
    130159
    131160  private function getPreviousPicture($current, $images) {
    132     $previous = $current--;
     161    $previous = $current-1;
    133162    if ($previous>0) {
    134163      return $this->makeAkUrl(array('ID' => $images[$previous]['id']));
     
    139168
    140169  private function getNextPicture($current, $images) {
    141     $index_current = null;
    142     foreach ($images as $index => $image) {
    143       if ($image['id']==$current) {
    144         $index_current = $index;
    145         break;
    146       }
    147     }
    148 
    149     $next = $index_current+1;
     170    $next = $current+1;
    150171    if ($next<count($images)) {
    151172      return $this->makeAkUrl(array('ID' => $images[$next]['id']));
  • extensions/akBookStyle/trunk/js/ak_jquery-load.js

    r3838 r3876  
    33      .bind(ak_mouse_event, function() {
    44          $a = $(this);
    5           $thumbnails = $('.thumbnails a[class="load"]');
    6           $nbThumbnails = $thumbnails.length;
     5          try {
     6            $.get($a.attr('href'),{},
     7                  function success(data) {                 
     8                    $('#akPicture')
     9                      .attr('src', data.AK_PIC_SRC)
     10                      .attr('alt', data.AK_PIC_ALT)
     11                      .attr('title', data.AK_PIC_TITLE);
    712
    8           $previous_link = $current_link = $next_link = null;
    9          
    10           $('.thumbnails a[class="load"]')
    11             .each( function(i) {
    12                 if ($(this).attr('href')==$a.attr('href')) {
    13                   $current_link = $(this);
    14                   if (i>0) {
    15                     $previous_link = $thumbnails[i-1];
    16                   }
    17                   if (i<$nbThumbnails) {
    18                     $next_link = $thumbnails[i+1];
    19                   }
    20                 }
    21               });
    22 
    23           $current_link = $('.thumbnails a[href='+$(this).attr('href')+']');
    24           $src = $current_link.children('img').attr('src');
    25           $src = $src.replace(dir_thumbnail+'\/'+prefix_thumbnail, '');
    26 
    27           $('#akPicture').attr('src', $src);
    28           if ($previous_link) {
    29             if ($('#akPreviousPicture').hasClass('hide')) {
    30               $('#akPreviousPicture').removeClass('hide');
    31             }
    32             $('#akPreviousPicture').attr('href', $($previous_link).attr('href'));
    33           } else {
    34             $('#akPreviousPicture').addClass('hide');
    35           }
    36           if ($next_link) {
    37             if ($('#akNextPicture').hasClass('hide')) {
    38               $('#akNextPicture').removeClass('hide');
    39             }
    40             $('#akNextPicture').attr('href', $($next_link).attr('href'));
    41           } else {
    42             $('#akNextPicture').addClass('hide');
     13                    if (data.AK_PREVIOUS) {
     14                      $('#akPreviousPicture')
     15                        .removeClass('hide')
     16                        .attr('href', data.AK_PREVIOUS);
     17                    } else {
     18                      $('#akPreviousPicture').addClass('hide');
     19                    }
     20                    if (data.AK_NEXT) {
     21                      $('#akNextPicture')
     22                        .removeClass('hide')
     23                        .attr('href', data.AK_NEXT);
     24                    } else {
     25                      $('#akNextPicture').addClass('hide');
     26                    }
     27                    $a.click(function(e) { e.preventDefault();});
     28                  },
     29                  'json');         
     30          } catch (e) {
     31            // alert(e);
    4332          }
    4433          return false;
    4534        });
    46 });
     35  });
  • extensions/akBookStyle/trunk/public.php

    r3843 r3876  
    2828
    2929$public_content = new akContent($plugin_config);
    30     /* Only on category request */
     30/* Only on category request */
    3131add_event_handler('loc_begin_index_thumbnails',
    32                         array($public_content, 'loc_begin_index_thumbnails')
    33                         );
     32                  array($public_content, 'loc_begin_index_thumbnails')
     33                  );
    3434add_event_handler('loc_end_index_thumbnails',
    35                         array($public_content, 'loc_end_index_thumbnails'),
    36                         EVENT_HANDLER_PRIORITY_NEUTRAL,
    37                         2             
    38                 );
     35                  array($public_content, 'loc_end_index_thumbnails'),
     36                  EVENT_HANDLER_PRIORITY_NEUTRAL,
     37                  2           
     38                  );
    3939add_event_handler('loc_begin_index',
    40                         array($public_content, 'page_force')
    41                         );
     40                  array($public_content, 'page_force')
     41                  );
     42
     43add_event_handler('loc_end_picture',
     44                  array($public_content, 'loc_end_picture')
     45                  );
    4246?>
  • extensions/akBookStyle/trunk/template/ak_horizontal.tpl

    r3830 r3876  
    88      {/if}
    99      {if ($smarty.foreach.tn.first) and !empty($navbar) and isset($navbar.URL_PREV)}
    10           <td class="ncol" rowspan="{$AK_BY_LINE}">{* Left thumbnail navigation
    11             *}<div class="navbar fright">
    12               <a class="navButton" href="{$navbar.URL_PREV}"
    13                  title="{'previous_page'|@translate}">
    14                 <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png"
    15                      class="button" alt="{'previous_page'|@translate}">
     10          <td class="ncol" rowspan="{$AK_BY_LINE}">{* Left thumbnail navigation *}
     11            <div class="navbar fright">
     12              <a class="navButton" href="{$navbar.URL_PREV}" title="{'previous_page'|@translate}">
     13                <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png" class="button" alt="{'previous_page'|@translate}">
    1614              </a>       
    1715            </div>
     
    1917      {/if}
    2018      <td class="ncol">
    21                                 <div class="clipwrapper" style="width:{$AK_THUMBNAIL_SIZE}px;height:{$AK_THUMBNAIL_SIZE}px">
    22                                         <div class="clip" style="clip:rect({$thumbnail.CLIP_TOP}px {$thumbnail.CLIP_RIGHT}px {$thumbnail.CLIP_BOTTOM}px {$thumbnail.CLIP_LEFT}px);top:-{$thumbnail.CLIP_TOP}px;left:-{$thumbnail.CLIP_LEFT}px">
    23                                                 <a href="{$thumbnail.AK_URL}" class="load">
    24                                                         <img class="thumbnail" src="{$thumbnail.TN_SRC}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
    25                                                 </a>
    26                                         </div>
    27                                 </div>
     19        <div class="clipwrapper" style="width:{$AK_THUMBNAIL_SIZE}px;height:{$AK_THUMBNAIL_SIZE}px">
     20          <div class="clip" style="clip:rect({$thumbnail.CLIP_TOP}px {$thumbnail.CLIP_RIGHT}px {$thumbnail.CLIP_BOTTOM}px {$thumbnail.CLIP_LEFT}px);top:-{$thumbnail.CLIP_TOP}px;left:-{$thumbnail.CLIP_LEFT}px">
     21            <a href="{$thumbnail.URL}" class="load">
     22              <img class="thumbnail" src="{$thumbnail.TN_SRC}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
     23            </a>
     24          </div>
     25        </div>
    2826      </td>
    2927      {if ($smarty.foreach.tn.iteration % $AK_BY_COLUMNS == 0) or $smarty.foreach.tn.last }
    30               {if ( !empty($navbar) and isset($navbar.URL_NEXT) and !isset($done) )}
    31                                 {assign var=done value=true}
    32               <td class="ncol" rowspan="{$AK_BY_LINE}">{* Right thumbnail navigation *}
    33                 <div class="navbar fleft">
    34                   <a class="navButton" href="{$navbar.URL_NEXT}" title="{'next_page'|@translate}">
    35                     <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png" class="button" alt="{'next_page'|@translate}">
    36                   </a>
    37                 </div>
    38               </td>
    39               {/if}
    40       </tr>
     28      {if ( !empty($navbar) and isset($navbar.URL_NEXT) and !isset($done) )}
     29      {assign var=done value=true}
     30      <td class="ncol" rowspan="{$AK_BY_LINE}">{* Right thumbnail navigation *}
     31        <div class="navbar fleft">
     32          <a class="navButton" href="{$navbar.URL_NEXT}" title="{'next_page'|@translate}">
     33            <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png" class="button" alt="{'next_page'|@translate}">
     34          </a>
     35        </div>
     36      </td>
     37      {/if}
     38    </tr>
    4139    {/if}
    4240    {/foreach}
  • extensions/akBookStyle/trunk/template/ak_reloaded_image.tpl

    r3860 r3876  
    44    <tr class="nline">
    55      <td class="ncol">
    6         <a id="akPreviousPicture" class="{if empty($AK_PREVIOUS)}hide {/if}load navButton" href="{$AK_PREVIOUS}"
    7            title="{'previous_page'|@translate}{* : {$AK_PREVIOUS.TITLE}*}"
    8            rel="prev">
    9           <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png"
    10                class="button" alt="{'previous_page'|@translate}" id="akPicPrev">
     6        <a id="akPreviousPicture" class="{if empty($AK_PREVIOUS)}hide {/if}load navButton" href="{$AK_PREVIOUS}" title="{'previous_page'|@translate}{* : {$AK_PREVIOUS.TITLE}*}" rel="prev">
     7          <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png" class="button" alt="{'previous_page'|@translate}">
    118        </a>
    129      </td>
     
    1613      </td>
    1714      <td class="ncol">
    18         <a id="akNextPicture" class="{if empty($AK_NEXT)}hide {/if}load navButton" href="{$AK_NEXT}"
    19            title="{'next_page'|@translate}{* : {$AK_NEXT.TITLE}*}"
    20            rel="next">
    21           <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png"
    22                class="button" alt="{'next_page'|@translate}" id="akPicNext">
     15        <a id="akNextPicture" class="{if empty($AK_NEXT)}hide {/if}load navButton" href="{$AK_NEXT}" title="{'next_page'|@translate}{* : {$AK_NEXT.TITLE}*}" rel="next">
     16          <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png" class="button" alt="{'next_page'|@translate}">
    2317        </a>
    2418      </td>
  • extensions/akBookStyle/trunk/template/ak_vertical.tpl

    r3829 r3876  
    55          {if !empty($navbar) and isset($navbar.URL_PREV)}
    66            <div class="navbar fleft">
    7               <a class="navButton" href="{$navbar.URL_PREV}"
    8                  title="{'previous_page'|@translate}">
    9                 <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png"
    10                      class="button" alt="{'previous_page'|@translate}">
     7              <a class="navButton" href="{$navbar.URL_PREV}" title="{'previous_page'|@translate}">
     8                <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png" class="button" alt="{'previous_page'|@translate}">
    119              </a>       
    1210            </div>
    13           {/if}
     11            {/if}
    1412          {if !empty($navbar) and isset($navbar.URL_NEXT)}
    1513            <div class="navbar fright">
    16               <a class="navButton" href="{$navbar.URL_NEXT}"
    17                  title="{'next_page'|@translate}">
    18                 <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png"
    19                      class="button" alt="{'next_page'|@translate}">
     14              <a class="navButton" href="{$navbar.URL_NEXT}" title="{'next_page'|@translate}">
     15                <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png" class="button" alt="{'next_page'|@translate}">
    2016              </a>
    2117            </div>
     
    3026            <div class="clipwrapper" style="width:{$AK_THUMBNAIL_SIZE}px;height:{$AK_THUMBNAIL_SIZE}px">
    3127              <div class="clip" style="clip:rect({$thumbnail.CLIP_TOP}px {$thumbnail.CLIP_RIGHT}px {$thumbnail.CLIP_BOTTOM}px {$thumbnail.CLIP_LEFT}px);top:-{$thumbnail.CLIP_TOP}px;left:-{$thumbnail.CLIP_LEFT}px">
    32                 <a href="{$thumbnail.AK_URL}" class="load">
     28                <a href="{$thumbnail.URL}" class="load">
    3329                  <img class="thumbnail" src="{$thumbnail.TN_SRC}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}">
    3430                </a>
     
    4440          {if !empty($navbar) and isset($navbar.URL_PREV)}
    4541            <div class="navbar fleft">
    46               <a class="navButton" href="{$navbar.URL_PREV}"
    47                  title="{'previous_page'|@translate}">
    48                 <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png"
    49                      class="button" alt="{'previous_page'|@translate}">
     42              <a class="navButton" href="{$navbar.URL_PREV}" title="{'previous_page'|@translate}">
     43                <img src="{$ROOT_URL}{$themeconf.icon_dir}/left.png" class="button" alt="{'previous_page'|@translate}">
    5044              </a>       
    5145            </div>
     
    5347          {if !empty($navbar) and isset($navbar.URL_NEXT)}
    5448            <div class="navbar fright">
    55               <a class="navButton" href="{$navbar.URL_NEXT}"
    56                  title="{'next_page'|@translate}">
    57                 <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png"
    58                      class="button" alt="{'next_page'|@translate}">
     49              <a class="navButton" href="{$navbar.URL_NEXT}" title="{'next_page'|@translate}">
     50                <img src="{$ROOT_URL}{$themeconf.icon_dir}/right.png" class="button" alt="{'next_page'|@translate}">
    5951              </a>
    6052            </div>
     
    6254          </td>
    6355        </tr>
    64         </table> {* end of Thumbnails *}
     56      </table> {* end of Thumbnails *}
    6557    </td>
Note: See TracChangeset for help on using the changeset viewer.