我有一个用Drupal 8
和构建的网站Bootstrap 3
。当用户访问该站点时,会Tour
自动启动。完成Tour
后,将在访问者的浏览器中放置一个 cookie,以便Tour
在用户重新加载页面时不会启动。
我的问题 :
我在左侧菜单上创建了一个按钮Commencer la visite
,以便用户Tour
手动访问。
每次我Tour
手动重启时,都会时不时出现一个bug。必须在不同的页面上重新启动几次才能看到错误。
如何纠正这个?
这是我在bs-tour.js
文件末尾添加的代码:
// Restart the tour
var startTour = $('#bs-tour-restart');
startTour.click(function (event) {
event.preventDefault();
var tourObject = drupalSettings.bs_tour.currentTour;
if (tourObject && tourObject._options.steps.length) {
tourObject.start(true);
}
});
// Close collapse navigation
$('#bs-tour-restart').click(function () {
$('#navbar-collapse-first, #navbar-collapse-second').collapse('hide');
});
这是我的 bs-tour.js 文件:
(function ($, _, Drupal, drupalSettings) {
'use strict';
Drupal.behaviors.bsTour = {
attach: function (context, settings) {
$(window).on('load', function (event) {
try
{
var tourOptions = $(drupalSettings.bs_tour.tour)[0];
var tips = tourOptions.steps;
var keyboard = tourOptions.keyboard;
var debug = tourOptions.debug;
var steps = [];
for (var i = 0; i < tips.length; i++) {
if ($(tips[i].element).length > 0) {
tips[i].backdropPadding.top = parseInt(tips[i].backdropPadding.top);
tips[i].backdropPadding.right = parseInt(tips[i].backdropPadding.right);
tips[i].backdropPadding.bottom = parseInt(tips[i].backdropPadding.bottom);
tips[i].backdropPadding.left = parseInt(tips[i].backdropPadding.left);
switch (tips[i].backdrop) {
case "0":
tips[i].backdrop = false;
break;
case "1":
tips[i].backdrop = true;
break;
}
steps.push(tips[i]);
}
}
if (steps.length) {
var tour = new Tour({
debug: debug,
keyboard: keyboard,
template: "<div class='popover tour'>\
<div class='arrow'></div>\
<h3 class='popover-title'></h3>\
<div class='popover-content'></div>\
<div class='popover-navigation'>\
<button class='btn btn-default' data-role='prev'>« " + Drupal.t('Prev') + "</button>\
<span data-role='separator'>|</span>\
<button class='btn btn-default' data-role='next'>" + Drupal.t('Next') + " »</button>\
<button class='btn btn-default' data-role='end'>" + Drupal.t('Skip tour') + "</button>\
</div>\
</div>",
});
// Add steps to the tour
tour.addSteps(steps);
// Initialize the tour
tour.init();
// Start the tour
tour.start();
// Restart the tour
var startTour = $('#bs-tour-restart');
startTour.click(function (event) {
event.preventDefault();
var tourObject = drupalSettings.bs_tour.currentTour;
if (tourObject && tourObject._options.steps.length) {
tourObject.start(true);
}
});
// Close collapse navigation
$('#bs-tour-restart').click(function () {
$('#navbar-collapse-first, #navbar-collapse-second').collapse('hide');
});
// Add tour object to drupalSettings to allow manipulating tour from other modules.
// Example: drupalSettings.bs_tour.currentTour.end();
drupalSettings.bs_tour.currentTour = tour;
}
} catch (e) {
// catch any fitvids errors
window.console && console.warn('Bootstrap tour stopped with the following exception');
window.console && console.error(e);
}
});
}
};
})(window.jQuery, window._, window.Drupal, window.drupalSettings);
当我启动时Tour
,背景是黑色的: