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

Commit 517f18f

Browse files
committed
Merge pull request #178 from kate2753/gh-177
Require exisitng target element for stand-alone callouts
2 parents 387759b + 7780068 commit 517f18f

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/js/hopscotch.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1193,19 +1193,20 @@
11931193
if (callouts[opt.id]) {
11941194
throw new Error('Callout by that id already exists. Please choose a unique id.');
11951195
}
1196+
if (!utils.getStepTarget(opt)) {
1197+
throw new Error('Must specify existing target element via \'target\' option.');
1198+
}
11961199
opt.showNextButton = opt.showPrevButton = false;
11971200
opt.isTourBubble = false;
11981201
callout = new HopscotchBubble(opt);
11991202
callouts[opt.id] = callout;
12001203
calloutOpts[opt.id] = opt;
1201-
if (opt.target) {
1202-
callout.render(opt, null, function() {
1203-
callout.show();
1204-
if (opt.onShow) {
1205-
utils.invokeCallback(opt.onShow);
1206-
}
1207-
});
1208-
}
1204+
callout.render(opt, null, function() {
1205+
callout.show();
1206+
if (opt.onShow) {
1207+
utils.invokeCallback(opt.onShow);
1208+
}
1209+
});
12091210
}
12101211
else {
12111212
throw new Error('Must specify a callout id.');

test/js/test.hopscotch.js

+15
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,21 @@ describe('Hopscotch', function() {
10161016

10171017
hopscotch.endTour();
10181018
});
1019+
1020+
it('should throw an exception when stand-alone callout target does not exist', function(){
1021+
var calloutMgr = hopscotch.getCalloutManager();
1022+
expect(function(){
1023+
calloutMgr.createCallout({
1024+
id: 'hopscotch-callout-test-123',
1025+
target: 'totally-does-not-exist',
1026+
placement: 'bottom',
1027+
title: 'This test is fun!',
1028+
content: 'This is how we test this library!'
1029+
});
1030+
}).toThrow(new Error('Must specify existing target element via \'target\' option.'));
1031+
1032+
});
1033+
10191034
});
10201035

10211036
describe('Saving state', function() {

0 commit comments

Comments
 (0)