You are here

function opening_hours_add_js in Opening hours 6

Same name and namespace in other branches
  1. 7 opening_hours.module \opening_hours_add_js()

Helper function to load our JavaScript dependencies.

2 calls to opening_hours_add_js()
opening_hours_node_edit_page in includes/opening_hours.pages.inc
Page for editing the opening hours for a specific node.
template_preprocess_opening_hours_week in ./opening_hours.module
Preprocess variables for the week template.

File

./opening_hours.module, line 424
Opening hours module.

Code

function opening_hours_add_js($type = 'presentation', $nid = FALSE) {
  $files = array(
    'opening_hours.prototype.js',
    'opening_hours.core.js',
  );

  // If jQuery Update is configured to use development versions of
  // jQuery, it's probably safe to assume that we want development
  // versions of Backbone and Underscore.
  $uncompressed = variable_get('jquery_update_compression_type', '') == 'none';
  $files[] = $uncompressed ? 'underscore.js' : 'underscore-min.js';
  $settings = array(
    'blockedDays' => variable_get('opening_hours_blocked_days', array()),
    'firstDayOfWeek' => (int) variable_get('date_first_day', 1),
    // Options for the jQuery UI datepicker date formatter.
    'formatDate' => array(
      'monthNames' => array(
        t('January'),
        t('February'),
        t('March'),
        t('April'),
        t('May'),
        t('June'),
        t('July'),
        t('August'),
        t('September'),
        t('October'),
        t('November'),
        t('December'),
      ),
      'dayNames' => array(
        t('Sunday'),
        t('Monday'),
        t('Tuesday'),
        t('Wednesday'),
        t('Thursday'),
        t('Friday'),
        t('Saturday'),
      ),
    ),
  );

  // We need the datepicker plugin for formatting and selecting dates.
  date_popup_load();
  if ($type == 'admin') {

    // We use jQuery UI dialogs for editing opening hours.
    jquery_ui_add('ui.dialog');
    $files[] = $uncompressed ? 'backbone.js' : 'backbone-min.js';
    $files[] = 'opening_hours.models.js';
    $files[] = 'opening_hours.collections.js';
    $files[] = 'opening_hours.views.js';
    $files[] = 'opening_hours.routers.js';
    $files[] = 'opening_hours.admin.js';

    // For the admin page, we need the node ID, passed from the page callback.
    $settings['nid'] = $nid;
    $settings['path'] = base_path() . drupal_get_path('module', 'opening_hours');
  }
  elseif ($type == 'presentation') {
    $files[] = 'opening_hours.presentation.js';
  }
  $path = drupal_get_path('module', 'opening_hours');
  foreach ($files as $filename) {
    drupal_add_js($path . '/js/' . $filename);
  }
  drupal_add_js(array(
    'OpeningHours' => $settings,
  ), 'setting');
}