You are here

function jquery_countdown_add in jQuery Countdown 7.2

Same name and namespace in other branches
  1. 5 jquery_countdown.module \jquery_countdown_add()
  2. 6 jquery_countdown.module \jquery_countdown_add()
  3. 7 jquery_countdown.module \jquery_countdown_add()

Adds a jQuery Countdown JavaScript element to the page.

Parameters

$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.

$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.

1 call to jquery_countdown_add()
theme_jquery_countdown in ./jquery_countdown.module
Constructs a jQuery Countdown element and adds the required JavaScript.
1 string reference to 'jquery_countdown_add'
jquery_countdown_jq in ./jquery_countdown.jq.inc
Implementation of hook_jq().

File

./jquery_countdown.module, line 120

Code

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');
  }
}