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

Require exisitng target element for stand-alone callouts #178

Merged
merged 1 commit into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/js/hopscotch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1193,19 +1193,20 @@
if (callouts[opt.id]) {
throw new Error('Callout by that id already exists. Please choose a unique id.');
}
if (!utils.getStepTarget(opt)) {
throw new Error('Must specify existing target element via \'target\' option.');
}
opt.showNextButton = opt.showPrevButton = false;
opt.isTourBubble = false;
callout = new HopscotchBubble(opt);
callouts[opt.id] = callout;
calloutOpts[opt.id] = opt;
if (opt.target) {
callout.render(opt, null, function() {
callout.show();
if (opt.onShow) {
utils.invokeCallback(opt.onShow);
}
});
}
callout.render(opt, null, function() {
callout.show();
if (opt.onShow) {
utils.invokeCallback(opt.onShow);
}
});
}
else {
throw new Error('Must specify a callout id.');
Expand Down
15 changes: 15 additions & 0 deletions test/js/test.hopscotch.js
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,21 @@ describe('Hopscotch', function() {

hopscotch.endTour();
});

it('should throw an exception when stand-alone callout target does not exist', function(){
var calloutMgr = hopscotch.getCalloutManager();
expect(function(){
calloutMgr.createCallout({
id: 'hopscotch-callout-test-123',
target: 'totally-does-not-exist',
placement: 'bottom',
title: 'This test is fun!',
content: 'This is how we test this library!'
});
}).toThrow(new Error('Must specify existing target element via \'target\' option.'));

});

});

describe('Saving state', function() {
Expand Down