diff --git a/jquery_countdown.module b/jquery_countdown.module index c394f38..7d60e7a 100644 --- a/jquery_countdown.module +++ b/jquery_countdown.module @@ -38,7 +38,6 @@ function jquery_countdown_block_info() { $blocks = array(); $blocks['jquery_countdown']['info'] = t('jQuery Countdown Block'); - $blocks['jquery_countdown']['cache'] = DRUPAL_NO_CACHE; return $blocks; @@ -93,45 +92,26 @@ function _jquery_countdown_block_content($delta = '') { 'onExpiry' => 'Drupal.jQueryCountdownEvent', 'expiryText' => check_plain(variable_get('jquery_countdown_exp_txt', '')) ); + + $selector = drupal_html_id('jquery_countdown-' . $delta); - return theme('jquery_countdown', array('options' => $options, 'id' => 'jquery_countdown-' . $delta )); + return array( + '#markup' => theme('jquery_countdown', array('id' => $selector )), + '#attached' => array( + 'js' => array( + array( + 'data' => array('jquery_countdown' => array('#' . $selector => $options)), + 'type' => 'setting' + ), + ), + 'library' => array( + array('jquery_countdown', 'jquery.countdown'), + ), + ), + ); }// end function _jquery_countdown_block_content; /** - * Adds a jQuery Countdown JavaScript element to the page. - * - * @param $selector - * (optional) The jQuery selector to apply the countdown to. If a - * selector isn't provided, the jQuery Countdown plugin will just be - * added to the page. - * @param $options - * (optional) The jQuery Countdown parameters to pass to the creation - * of the element. The available parameters can be found at: - * http://keith-wood.name/countdown.html#quick - * - * The date arguments (until or since), can either be a number - * representing the number of seconds, a string used to construct - * the JavaScript Date object, or the argument list passed to the - * JavaScript Date object. - * - * The onExpiry and onTick arguments is JavaScript that will be - * passed through "eval()" when the events are called. - */ -function jquery_countdown_add($selector = NULL, $options = array()) { - // Add jQuery Countdown only if it hasn't been added yet. - drupal_add_library('jquery_countdown', 'jquery.countdown'); - - // Make sure to only add the same selector once. - static $added_selectors = array(); - if (!empty($selector) && !isset($added_selectors[$selector])) { - $added_selectors[$selector] = $options; - - // Add the countdown element to the settings so that it's processed by the behaviours. - drupal_add_js(array('jquery_countdown' => array($selector => $options)), 'setting'); - } -} - -/** * Implementation of hook_library() * provides the jquery.countdown script with css as library */ @@ -238,7 +218,6 @@ function jquery_countdown_theme($existing, $type, $theme, $path) { return array( 'jquery_countdown' => array( 'variables' => array( - 'options' => NULL, 'id' => NULL, 'content' => NULL, ), @@ -260,14 +239,8 @@ function jquery_countdown_theme($existing, $type, $theme, $path) { function theme_jquery_countdown($variables) { //@TODO: add javascript fallback for target time as possible $content ?! $id = $variables['id']; - $options = $variables['options']; $content = $variables['content']; - // Construct the ID name and add the JavaScript. - $id = drupal_html_id($id); - // add the Javascript - jquery_countdown_add('#'. $id, $options); - // Construct the HTML. return '
' . $content . '
'; }