You are here

function availability_calendar_add_viewport_js in Availability Calendars 7.3

Same name and namespace in other branches
  1. 7.5 availability_calendar.theme.inc \availability_calendar_add_viewport_js()
  2. 7.4 availability_calendar.theme.inc \availability_calendar_add_viewport_js()

Adds the necessary javascript to be able to show an (interactive) calendar in a viepwort.

Parameters

int|string $cid: Existing cid (int) or temporary cid for new calendars (string).

String $name:

array $settings: Combination of formatter, instance and field settings.

string $mode: One of none|available|all.

1 call to availability_calendar_add_viewport_js()
theme_availability_calendar_viewport in ./availability_calendar.theme.inc
Themes the availability calendar field in a viewport.

File

./availability_calendar.theme.inc, line 395

Code

function availability_calendar_add_viewport_js($cid, $name, $settings, $mode) {
  static $viewport_count = 0;
  $viewport_count++;
  availability_calendar_add_calendar_js($cid, $name, $settings['allocation_type'], $settings['show_split_day'], $mode);
  drupal_add_js(drupal_get_path('module', 'availability_calendar') . '/availability_calendar.viewport.js');
  drupal_add_js(array(
    'availabilityCalendar' => array(
      "viewport{$viewport_count}" => array(
        'cols' => (int) $settings['viewport']['cols'],
        'rows' => (int) $settings['viewport']['rows'],
        'scroll' => (int) $settings['viewport']['scroll'],
      ),
    ),
  ), array(
    'type' => 'setting',
  ));
  $cid_quoted = $cid == (string) (int) $cid ? $cid : "'{$cid}'";
  drupal_add_js("Drupal.behaviors.availabilityCalendarViewport{$viewport_count} = {\n  attach: function(context, settings) {\n    Drupal.availabilityCalendar.getViewport({$cid_quoted}, 'viewport{$viewport_count}');\n  }\n};", array(
    'type' => 'inline',
    'scope' => 'footer',
  ));
}