diff --git a/bootstrap_tour.module b/bootstrap_tour.module index 77fc028..6f889e1 100644 --- a/bootstrap_tour.module +++ b/bootstrap_tour.module @@ -79,6 +79,16 @@ function bootstrap_tour_menu() { 'access arguments' => array('administer bootstrap tours'), 'type' => MENU_NORMAL_ITEM, ); + + $items['admin/structure/tours/settings'] = array( + 'title' => 'Settings', + 'access arguments' => array('administer bootstrap tours'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('bootstrap_tour_admin_settings'), + 'file' => 'includes/bootstrap_tour.admin.inc', + 'type' => MENU_LOCAL_TASK, + ); + $items['bootstrap_tour/ajax/end_current_tour'] = array( 'title' => 'AJAX callback to end current tour', 'page callback' => 'bootstrap_tour_end_current_tour', @@ -126,7 +136,8 @@ function bootstrap_tour_libraries_info() { 'vendor url' => 'http://bootstraptour.com', 'download url' => 'https://github.com/sorich87/bootstrap-tour/releases', 'path' => 'build', - 'version' => '0.5.0', // @TODO: Move this into version_callback and version_arguments. + 'version' => '0.9.3', + // @TODO: Move this into version_callback and version_arguments. 'files' => array( 'js' => array( 'js/bootstrap-tour.min.js', @@ -156,6 +167,16 @@ function bootstrap_tour_libraries_info() { ), ), ), + 'standalone' => array( + 'files' => array( + 'js' => array( + 'js/bootstrap-tour-standalone.js', + ), + 'css' => array( + 'css/bootstrap-tour-standalone.min.css', + ), + ), + ), ), ); return $libraries; @@ -238,7 +259,7 @@ function bootstrap_tour_run_tour($id, $force = FALSE) { drupal_alter('bootstrap_tour', $tour); $step_path = ''; - foreach($tour->steps as $key => &$step) { + foreach ($tour->steps as $key => &$step) { // If a path isn't specified, then use the path from the previous step. if ($step->path) { $step_path = $step->path; @@ -259,15 +280,27 @@ function bootstrap_tour_run_tour($id, $force = FALSE) { $tour->force = $force; $tour->cleanUrls = variable_get('clean_url', 0); + $variant = (variable_get('bootstrap_tour_use_standalone') == 1) ? 'standalone' : NULL; drupal_add_js(array('bootstrapTour' => array('tour' => $tour)), 'setting'); if (module_exists('libraries') && ($library = libraries_detect('bootstrap_tour')) && !empty($library['installed'])) { - libraries_load('bootstrap_tour'); + libraries_load('bootstrap_tour', $variant); } else { + $libraries = bootstrap_tour_libraries_info(); + drupal_alter('libraries_info', $libraries); + $version = $libraries['bootstrap_tour']['version']; + // See if any hook_library_alter has changed the version to use. + // Grab the Bootstrap Tour JS from CDNJS if the library isn't installed. - bootstrap_tour_load_file('css','bootstrap-tour.min.css', 'cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.6.1/css/bootstrap-tour.min.css'); - bootstrap_tour_load_file('js','bootstrap-tour.js', 'cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.6.1/js/bootstrap-tour.js'); + if ($variant) { + bootstrap_tour_load_file('css', 'bootstrap-tour-standalone.min.css', 'cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/' . $version . '/css/bootstrap-tour-standalone.min.css'); + bootstrap_tour_load_file('js', 'bootstrap-tour-standalone.js', 'cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/' . $version . '/js/bootstrap-tour-standalone.js'); + } + else { + bootstrap_tour_load_file('css', 'bootstrap-tour.min.css', 'cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/' . $version . '/css/bootstrap-tour.min.css'); + bootstrap_tour_load_file('js', 'bootstrap-tour.min.js', 'cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/' . $version . '/js/bootstrap-tour.min.js'); + } } drupal_add_js(drupal_get_path('module', 'bootstrap_tour') . '/js/bootstrap-tour.js'); @@ -299,7 +332,7 @@ function bootstrap_tour_page_build(&$page) { } if (!empty($current_name)) { - foreach($tours as $id => $tour) { + foreach ($tours as $id => $tour) { if ($tour->name == $current_name) { bootstrap_tour_run_tour($id, TRUE); return; @@ -308,7 +341,7 @@ function bootstrap_tour_page_build(&$page) { } // Force the next tour to run if the tour name is in the session vars. if (!empty($_SESSION['nexttour'])) { - foreach($tours as $id => $tour) { + foreach ($tours as $id => $tour) { if ($_SESSION['nexttour'] == $tour->name) { bootstrap_tour_run_tour($id, TRUE); return; @@ -316,7 +349,7 @@ function bootstrap_tour_page_build(&$page) { } } // Otherwise, only run the tour if it's set to auto-run and we're on the path of one of the steps. - foreach($tours as $id => $tour) { + foreach ($tours as $id => $tour) { if ($tour->autorun) { $path = $tour->start_path; if ($path == current_path() || $path == request_path() || ($path == '' && request_path() == '')) { @@ -360,12 +393,13 @@ function bootstrap_tour_load($id) { return $tour; } + /** * Load all the tours (and caches them). */ function bootstrap_tour_load_all($reset = FALSE) { $all_tours = &drupal_static(__FUNCTION__); - if (!isset($all_tours)|| $reset) { + if (!isset($all_tours) || $reset) { if (!$reset && ($cache = cache_get('bootstrap_tours_all'))) { $all_tours = $cache->data; } diff --git a/includes/bootstrap_tour.admin.inc b/includes/bootstrap_tour.admin.inc index 6801cea..a7f3da7 100644 --- a/includes/bootstrap_tour.admin.inc +++ b/includes/bootstrap_tour.admin.inc @@ -114,3 +114,19 @@ function _bootstrap_tour_name_exists($name, $element, &$form_state) { $result = db_query('SELECT bootstrap_tour_id from {bootstrap_tour_tour} WHERE name = :name LIMIT 1', array(':name' => $name)); return ($result->rowCount()==0 ? FALSE : TRUE); } + +/** + * Admin settings form. + */ +function bootstrap_tour_admin_settings() { + $form = array(); + + $form['bootstrap_tour_use_standalone'] = array( + '#title' => t('Use standalone js and css'), + '#description' => t('If you use this module with a non-bootstrap theme, checking this will mean the module will not require bootstrap css and js to work'), + '#type' => 'checkbox', + '#default_value' => variable_get('bootstrap_tour_use_standalone'), + ); + + return system_settings_form($form); +}