Skip to content

Commit 086046c

Browse files
backdropSibling option added to solve issue 38
Fix by ibastevan for #38
1 parent 3f3d766 commit 086046c

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
77

8+
## [0.3.2]
9+
10+
### Added
11+
- backdropOptions.backdropSibling added by [@ibastevan] to solve [position fixed and zindex issues] (https://github.com/IGreatlyDislikeJavascript/bootstrap-tourist/issues/38)
12+
13+
### Changed
14+
- Updated docs
15+
16+
817
## [0.3.1]
918

1019
### Added

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ Tourist now has documentation included in the repo under the `/docs/` folder. Ta
549549
backdropOptions: {
550550
highlightOpacity: 0.8,
551551
highlightColor: '#FFF',
552+
backdropSibling: false,
552553
animation: {
553554
// can be string of css class or function signature: function(domElement, step) {}
554555
backdropShow: function(domElement) {
@@ -570,6 +571,7 @@ Tourist now has documentation included in the repo under the `/docs/` folder. Ta
570571
```
571572
- `backdropOptions.highlightOpacity`: the alpha value of the div used to highlight the step element. You can control how visible/occluded the element is.
572573
- `backdropOptions.highlightColor`: the hex color code for the highlight. Normally you will want to use a white highlight (#FFF). However if your step element has a dark or black background, you may want to use a black highlight (#000). Experiment with the best colors for your UX.
574+
- `backdropOptions.backdropSibling`: solves display issues when step.element is a child of an element with fixed position or zindex specified
573575
- `backdropOptions.animation`: The options can be either string literals specifying a CSS class, or a function. The application of these features work in exactly the same way for all backdropOptions.animation options. These options apply as per the following:
574576
- `backdropShow`: when a previously hidden backdrop is shown
575577
- `backdropHide`: when a previously visible backdrop is hidden

bootstrap-tourist.css

+8
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,11 @@
9494
.popover[class*="tour-"].orphan .arrow {
9595
display: none;
9696
}
97+
98+
.tour-behind {
99+
z-index: -1;
100+
}
101+
102+
.tour-zindexFix {
103+
z-index: 1029;
104+
}

bootstrap-tourist.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ========================================================================
22
*
3-
* Bootstrap Tourist v0.3.0
3+
* Bootstrap Tourist v0.3.2
44
* Copyright FFS 2019
55
* @ IGreatlyDislikeJavascript on Github
66
*
@@ -11,16 +11,10 @@
1111
*
1212
* The entire purpose of this fork is to start rewriting bootstrap-tour
1313
* into native ES6 instead of the original coffeescript, and to implement
14-
* the features and fixes requested in the github repo. Ideally this fork
15-
* will then be taken back into the main repo and become part of
16-
* bootstrap-tour again - this is not a fork to create a new plugin!
14+
* the features and fixes requested.
1715
*
1816
* I'm not a JS coder, so suggest you test very carefully and read the
19-
* docs (comments) below before using.
20-
*
21-
* If anyone would like to take on the creation of proper docs for
22-
* Tourist, please feel free and post here:
23-
* https://github.com/IGreatlyDislikeJavascript/bootstrap-tourist/issues/15
17+
* docs before using.
2418
*
2519
* ========================================================================
2620
* ENTIRELY BASED UPON:
@@ -56,7 +50,9 @@
5650
})(window, function ($) {
5751

5852
const DOMID_BACKDROP = "#tourBackdrop";
53+
const DOMID_BACKDROP_TEMP = "#tourBackdrop-temp"; // used for @ibastevan zindex fix: https://github.com/IGreatlyDislikeJavascript/bootstrap-tourist/issues/38
5954
const DOMID_HIGHLIGHT = "#tourHighlight";
55+
const DOMID_HIGHLIGHT_TEMP = "#tourHighlight-temp"; // used for @ibastevan zindex fix: https://github.com/IGreatlyDislikeJavascript/bootstrap-tourist/issues/38
6056
const DOMID_PREVENT = "#tourPrevent";
6157

6258
var Tour, document, objTemplates, objTemplatesButtonTexts;
@@ -114,6 +110,7 @@
114110
backdropOptions: {
115111
highlightOpacity: 0.9,
116112
highlightColor: "#FFF",
113+
backdropSibling: false,
117114
animation: {
118115
// can be string of css class or function signature: function(domElement, step) {}
119116
backdropShow: function(domElement, step)
@@ -329,7 +326,7 @@
329326
host: '',
330327
placement: 'right',
331328
positioning:{
332-
adjustRelative: null
329+
adjustRelative: null // this does nothing at the moment
333330
},
334331
title: '',
335332
content: '<p></p>',
@@ -436,7 +433,6 @@
436433

437434
// BS3: resize event must destroy and recreate both popper and background to ensure correct positioning
438435
// BS4: resize must destroy and recreate background, but popper.js handles popper positioning.
439-
// TODO: currently we destroy and recreate for both BS3 and BS4. Improvement could be to reposition backdrop overlay only when using BS4
440436
var _this = this;
441437
$(window).on("resize.tour-" + _this._options.name, function()
442438
{
@@ -1848,6 +1844,8 @@
18481844
{
18491845
$(DOMID_BACKDROP).hide(0);
18501846
$(DOMID_HIGHLIGHT).hide(0);
1847+
$(DOMID_BACKDROP_TEMP).remove();
1848+
$(DOMID_HIGHLIGHT_TEMP).remove();
18511849
}
18521850
};
18531851

@@ -2136,6 +2134,22 @@
21362134
}
21372135
}
21382136
}
2137+
2138+
// purpose of this code is due to elements with position: fixed and z-index: https://github.com/IGreatlyDislikeJavascript/bootstrap-tourist/issues/38
2139+
$(DOMID_BACKDROP_TEMP).remove();
2140+
$(DOMID_HIGHLIGHT_TEMP).remove();
2141+
if (step.backdropOptions.backdropSibling == true)
2142+
{
2143+
$(DOMID_HIGHLIGHT).addClass('tour-behind');
2144+
$(DOMID_BACKDROP).addClass('tour-zindexFix');
2145+
$(DOMID_HIGHLIGHT).clone().prop('id', DOMID_HIGHLIGHT_TEMP.substring(1)).removeClass('tour-behind').insertAfter(".tour-highlight-element");
2146+
$(DOMID_BACKDROP).clone().prop('id', DOMID_BACKDROP_TEMP.substring(1)).removeClass('tour-zindexFix').insertAfter(".tour-highlight-element");
2147+
}
2148+
else
2149+
{
2150+
$(DOMID_HIGHLIGHT).removeClass('tour-behind');
2151+
$(DOMID_BACKDROP).removeClass('tour-zindexFix');
2152+
}
21392153
};
21402154

21412155
// Updates visibility of the preventInteraction div and any other overlay elements added in future features

docs/Docs.html

+19-4
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ <h3 id="tour-options">Global options</h3>
527527
</tr>
528528
<tr class="success">
529529
<td><span class="label label-info"><b>*</b></span></td>
530-
<td>backdropOptions <span class="label label-success">NEW v0.3.0</span></td>
530+
<td>backdropOptions <span class="label label-success">NEW v0.3.2</span></td>
531531
<td>Object</td>
532532
<td>
533533
<p>
@@ -544,6 +544,7 @@ <h3 id="tour-options">Global options</h3>
544544
backdropOptions: {<br>
545545
<div class="tab40">highlightOpacity: 0.8,<br>
546546
highlightColor: #FFF,<br>
547+
backdropSibling: false,<br>
547548
animation: {}<br>
548549
</div>}<br>
549550
</code>
@@ -554,17 +555,31 @@ <h3 id="tour-options">Global options</h3>
554555
<td><span class="label label-info"><b>*</b></span></td>
555556
<td><span class="tab40"<i>backdropOptions.</i>highlightOpacity</span></td>
556557
<td>Float</td>
557-
<td>The alpha / opacity value for the highlight element - the div that floats on top of a tour step's element to visually identify it</td>
558+
<td>The alpha / opacity value for the highlight element - the div that floats on top of a tour step's element to visually identify it.
559+
Set the predominant option here, and override per step as required.</td>
558560
<td><code>0.8</code></td>
559561
</tr>
560562
<tr>
561563
<td><span class="label label-info"><b>*</b></span></td>
562564
<td><span class="tab40"<i>backdropOptions.</i>highlightColor</span></td>
563565
<td>Hex value</td>
564-
<td>The RGB hex value of the highlight. Normally, this will be white / #FFF. However if your step element has a black or dark backgroup then you may
565-
wish to set this to #000 or some other color.</td>
566+
<td>The RGB hex value of the highlight. Normally, this will be white / #FFF. However if your step element has a black or dark background then you may
567+
wish to set this to #000 or some other color. Set the predominant option here, and override per step as required.</td>
566568
<td><code>#FFF</code></td>
567569
</tr>
570+
<tr>
571+
<td><span class="label label-info"><b>*</b></span></td>
572+
<td><span class="tab40"<i>backdropOptions.</i>backdropSibling</span></td>
573+
<td>Boolean</td>
574+
<td>
575+
If a step element is a DOM child of an element that has <code>position: fixed</code> or a <code>z-index</code>, CSS and rendering rules will
576+
cause the step backdrop and highlight to be displayed incorrectly. This is due to CSS standards and is not a bug in Tourist.<br><br>
577+
Setting this option to <code>true</code> will instruct Tourist to create cloned overlays for the backdrop and highlight, which visually
578+
solves this issue. You can read more about the <code>z-index</code> CSS considerations at <a target="_blank" href="https://coder-coder.com/z-index-isnt-working/">this website</a>, and more about this specific
579+
Tourist option in <a target="_blank" href="https://github.com/IGreatlyDislikeJavascript/bootstrap-tourist/issues/38">this Github issue</a>.
580+
</td>
581+
<td><code>false</code></td>
582+
</tr>
568583

569584
<tr>
570585
<td><span class="label label-info"><b>*</b></span></td>

0 commit comments

Comments
 (0)