You are here

function date_popup_js_settings_class in Date 6

Same name and namespace in other branches
  1. 5.2 date_popup/date_popup.module \date_popup_js_settings_class()

Create a unique CSS class name and output a single inline JS block for each unique combination of startup function to call and settings array to pass it. This allows the dynamic use of any number of custom settings without requiring a duplicate copy for every element that uses them.

@returns The CSS class name to assign to an element that should have $func($settings) invoked on it.

Parameters

$pfx: The CSS class prefix to search the DOM for.

$func: The jQuery function to invoke on each DOM element containing the returned CSS class.

$settings: The settings array to pass to the jQuery function.

1 call to date_popup_js_settings_class()
date_popup_process_date in date_popup/date_popup.module
Process the date portion of the element.

File

date_popup/date_popup.module, line 62
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_js_settings_class($pfx, $func, $settings) {
  static $cache = array();
  static $cnt = 0;
  $serial = serialize($settings);
  $key = $pfx . ':' . $func;
  if (!isset($cache[$key][$serial])) {
    $class = $cache[$key][$serial] = $pfx . '-' . $cnt++;
    drupal_add_js('// Global Killswitch
    if (Drupal.jsEnabled) {
      $(document).ready(function() {$(\'.' . $class . '\').' . $func . '({' . $settings . '});
      })}', 'inline');
  }
  return $cache[$key][$serial];
}