Z
Z
Ziklon2013-07-28 13:55:04
PHP
Ziklon, 2013-07-28 13:55:04

Drupal 6 - jQuery Timer not counting correctly?

Good afternoon, there is such a problem, the jQuery Timer script is installed on the Drupal 6 site. It counts the time until a certain event and shows how many days are left. If you leave the page open for a while (5-10 minutes), then the script starts counting the time faster. Prompt, with what it can be connected? The site works caching through the boost module. Disabled js caching, didn't help.

Maybe you can add a line to the script so that the counter changes only after the page is reloaded?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
@
@mactator, 2013-07-28
_

Perhaps the timer is initialized more than once. Check behavior and contexts in it.

@
@mactator, 2013-07-29
_

I understand it has already been redone. because I did not find the use of jQuery timer. Set_timer_js is now responsible for this in setInterval.

Z
Ziklon, 2013-07-29
@Ziklon

I found a piece of code in template.php, apparently there is some kind of error here.

<code>//функция генерит разметку для таймера.
function theme_timer ($time_to_event) {

  $time = $time_to_event - time();

  $timer = array();

  $timer['days'] = floor($time / (60 * 60 * 24));
  
  $timer['hours'] = floor(($time - $timer['days'] * 60 * 60 * 24) / (60 * 60));
  $timer['minutes'] = floor(($time - $timer['days'] * 60 * 60 * 24 - $timer['hours'] * 60 * 60) / 60);
  /*
  if(!drupal_is_front_page()) { //закоментить после установки главной
    $timer['second'] = $time - $timer['days'] * 60 * 60 * 24 - $timer['hours'] * 60 * 60 - $timer['minutes'] * 60;
  }
  */
  $time_part_output = array();
  foreach ($timer as $part => $int) {
    if(strlen($int) < 2) {
      $timer[$part] = '0' . $int;
    }
    
    if ( in_array($part, array('hours', 'minutes', 'second')) ) {
     $letter_line = ''; 
    }
    else {
      $letter_line =  '<span class="letter-line ">';
    }
    
    foreach (str_split($timer[$part]) as $key => $symvol) {
      $time_part_output[$part] .= '<span class="letter-wrapper">' . $letter_line . '</span><span class="letter letter-' . $part . ' int_' . $key . '">' . $symvol . '</span></span>';
    }
    
  }
  /*
    if(!drupal_is_front_page()) { 
    return $time_part_output['days'] .
         $time_part_output['hours'] . '<span class="to_dot"> : </span>' .
         $time_part_output['minutes'] . '<span class="to_dot"> : </span>' .
         $time_part_output['second'];
   }
  */
    return $time_part_output['days'].
         $time_part_output['hours'] .
         $time_part_output['minutes'] .
         $time_part_output['second'];
  
}

/*ФУНКЦИИ ВОЗВРАЩАЮТ РАЗМЕТКУ ЗАГОЛОВКА СТРАНИЦЫ*/
</code>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question