You are here

function joyride_context_reaction_add::execute in Joyride JQuery for Drupal Site Tours 7

File

plugins/context/joyride_context_reaction_add.inc, line 44

Class

joyride_context_reaction_add

Code

function execute(&$vars = NULL) {
  $contexts = $this
    ->get_contexts();
  foreach ($contexts as $context) {
    if (!empty($context->reactions[$this->plugin])) {
      $library = libraries_load('joyride');
      $library_loaded = $library && !empty($library['loaded']);
      drupal_add_library('system', 'jquery.cookie');
      $js_name = 'jquery.joyride.js';
      $base_path = 'sites/all/libraries/joyride';
      if (!$library_loaded) {
        drupal_set_message(t('Can\'t load Joyride library. Please download !url jQuery plugin and extract it to @path, so @js can be found at @full_path. Also please purge version info from Joyride file names (both .js and .css)', array(
          '!url' => l(t('Zurb Joyride'), 'https://github.com/zurb/joyride'),
          '@path' => $base_path,
          '@js' => $js_name,
          '@full_path' => $base_path . '/' . $js_name,
        )), 'error');
        return FALSE;
      }
      drupal_add_js(drupal_get_path('module', 'joyride') . '/inc/js/joyride_context.js');
      $tips_content = $context->reactions[$this->plugin]['joyride_tour_content'];
      if (empty($tips_content)) {
        return FALSE;
      }
      $js_settings = array(
        'joyrideContext' => array(
          'tips_content' => theme('joyride_tips', array(
            'tips_content' => $tips_content,
          )),
          'auto_start' => (bool) $context->reactions[$this->plugin]['joyride_auto_start'],
          'play_once' => (bool) $context->reactions[$this->plugin]['joyride_play_once'],
        ),
      );
      drupal_add_js($js_settings, 'setting');
    }
  }
}