Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Commit a364890

Browse files
committed
Merge pull request #153 from zimmi88/className
Tour ID as part of classes
2 parents d34a193 + d802566 commit a364890

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/js/hopscotch.js

+32-5
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@
10621062
numChildren,
10631063
node,
10641064
i,
1065+
currTour,
10651066
opt;
10661067

10671068
//Register DOM element for this bubble.
@@ -1086,6 +1087,11 @@
10861087
el.className = 'hopscotch-bubble animated';
10871088
if (!opt.isTourBubble) {
10881089
utils.addClass(el, 'hopscotch-callout no-number');
1090+
} else {
1091+
currTour = winHopscotch.getCurrTour();
1092+
if(currTour){
1093+
utils.addClass(el, 'tour-' + currTour.id);
1094+
}
10891095
}
10901096

10911097
/**
@@ -1319,6 +1325,19 @@
13191325
return bubble;
13201326
},
13211327

1328+
/**
1329+
* Destroy the bubble currently associated with Hopscotch.
1330+
* This is done when we end the current tour.
1331+
*
1332+
* @private
1333+
*/
1334+
destroyBubble = function() {
1335+
if(bubble){
1336+
bubble.destroy();
1337+
bubble = null;
1338+
}
1339+
},
1340+
13221341
/**
13231342
* Convenience method for getting an option. Returns custom config option
13241343
* or the default config option if no custom value exists.
@@ -1823,16 +1842,23 @@
18231842
skippedSteps = {},
18241843
self = this;
18251844

1826-
// Check validity of tour ID. If invalid, throw an error.
1827-
if(!tour.id || !validIdRegEx.test(tour.id)) {
1828-
throw new Error('Tour ID is using an invalid format. Use alphanumeric, underscores, and/or hyphens only. First character must be a letter.');
1829-
}
1830-
18311845
// loadTour if we are calling startTour directly. (When we call startTour
18321846
// from window onLoad handler, we'll use currTour)
18331847
if (!currTour) {
1848+
1849+
// Sanity check! Is there a tour?
1850+
if(!tour){
1851+
throw new Error('Tour data is required for startTour.');
1852+
}
1853+
1854+
// Check validity of tour ID. If invalid, throw an error.
1855+
if(!tour.id || !validIdRegEx.test(tour.id)) {
1856+
throw new Error('Tour ID is using an invalid format. Use alphanumeric, underscores, and/or hyphens only. First character must be a letter.');
1857+
}
1858+
18341859
currTour = tour;
18351860
loadTour.call(this, tour);
1861+
18361862
}
18371863

18381864
if (typeof stepNum !== undefinedStr) {
@@ -1985,6 +2011,7 @@
19852011

19862012
this.removeCallbacks(null, true);
19872013
this.resetDefaultOptions();
2014+
destroyBubble();
19882015

19892016
currTour = null;
19902017

test/js/test.hopscotch.js

+22
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ describe('Hopscotch', function() {
153153
]
154154
}, 1);
155155
expect(hopscotch.getCurrStepNum()).toBe(1);
156+
hopscotch.endTour();
157+
});
158+
159+
it('should complain if no tour data is passed in', function(){
160+
expect(function(){
161+
hopscotch.startTour();
162+
}).toThrow(new Error('Tour data is required for startTour.'));
156163
});
157164

158165
it('should reject tour IDs that include invalid characters', function(){
@@ -1284,6 +1291,21 @@ describe('HopscotchBubble', function() {
12841291
expect(content).toBe('It\'s a shopping list');
12851292
hopscotch.endTour();
12861293
});
1294+
1295+
it('Should include tour ID as part of bubble classes', function(){
1296+
hopscotch.startTour({
1297+
id: 'hs-test-tour-class',
1298+
steps: [ {
1299+
target: 'shopping-list',
1300+
placement: 'left',
1301+
title: 'Shopping List',
1302+
content: 'It\'s a shopping list'
1303+
} ]
1304+
});
1305+
bubble = document.querySelector('.hopscotch-bubble.tour-hs-test-tour-class');
1306+
expect(bubble).not.toBe(null);
1307+
hopscotch.endTour();
1308+
});
12871309
});
12881310

12891311
describe('Step Number', function() {

0 commit comments

Comments
 (0)