Skip to content

Commit

Permalink
Make $(document).tooltip({...}) without a selector throw an error
Browse files Browse the repository at this point in the history
Closes #15484
  • Loading branch information
cvrebert committed Jan 5, 2015
1 parent 0841028 commit f6a837c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions js/tests/unit/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,11 @@ $(function () {
})
.bootstrapPopover('show')
})

test('should throw an error when initializing popover on the document object without specifying a delegation selector', function () {
throws(function () {
$(document).bootstrapPopover({ title: 'What am I on?', content: 'My selector is missing' })
}, new Error('`selector` option must be specified when initializing popover on the window.document object!'))
})

})
6 changes: 6 additions & 0 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -1107,4 +1107,10 @@ $(function () {
$element.bootstrapTooltip('show')
})

test('should throw an error when initializing tooltip on the document object without specifying a delegation selector', function () {
throws(function () {
$(document).bootstrapTooltip({ title: 'What am I on?' })
}, new Error('`selector` option must be specified when initializing tooltip on the window.document object!'))
})

})
4 changes: 4 additions & 0 deletions js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
this.options = this.getOptions(options)
this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport)

if (this.$element[0] instanceof window.Document && !this.options.selector) {
throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!');
}

var triggers = this.options.trigger.split(' ')

for (var i = triggers.length; i--;) {
Expand Down

1 comment on commit f6a837c

@Darkseal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's perfect! Thanks.

Please sign in to comment.