Synchronizing the countdown timer with the server is essential for my application.

I would like to request adding support for jQuery Countdown's serverSync option, explained here:

http://keith-wood.name/countdownRef.html#serverSync

At quick glance this should be achieved by adding the function shown in the example to jquery_countdown.js plus a callback menu entry and function in jquery_countdown.module.

I will attempt to do this myself when time permits unless someone beats me to it.

Comments

johnhanley’s picture

To get the ball rolling on this I have added the following (on my local development environment) to jquery_countdown.module:

/**
 * Implementation of hook_menu().
 */
function jquery_countdown_menu() {
  $items = array();

  $items['servertime'] = array(
    'title' => 'Server Time',
    'page callback' => 'jquery_countdown_servertime',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK
  );

  return $items;
}

/**
* Return the current server time in a format used directly by the JavaScript callback. 
*/
function jquery_countdown_servertime() {
  $now = new DateTime(); 
  echo $now->format("M j, Y H:i:s O") ."\n"; 
}

I then added the following to jquery_countdown.js:

/**
 * Synchronize the client's time with that of the server.
 */
Drupal.jquery_countdown.serverTime = function() {
  var time = null; 
  $.ajax({
    url: 'http://mydomain.com/servertime',
    async: false,
    dataType: 'text', 
    success: function(text) { 
      time = new Date(text); 
    },
    error: function(http, message, exc) { 
      time = new Date();
    }
  }); 
  return time; 
}

And finally the output is as follows:

theme('jquery_countdown', array('until' => date('F j Y G:i:s', $end_date), 'format' => 'YOWDHMS', 'significant' => 2, 'serverSync' => 'serverTime'))

Unfortunately the serverSync option produces a JavaScript error:

Object doesn't support this property or method

My assumption is that the serverTime function is not firing because it's not part of the Drupal.jquery_countdown object.

The display works as expected when removing the "serverSync" option, albeit synchronized with the client and not the server. This is undesirable in my situation.

Does anyone have any suggestions?

Avaz Mano’s picture

Any progress on this? I would love this feature as well.

blackice2999’s picture

fixed and will be part of the next release of module

blackice2999’s picture

Status: Active » Closed (fixed)
mthomas’s picture

Can you post an example of your theme function with the working serversync code?