From f6a837cbf1eb24429a4356ef95d7a52e6da35b43 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 5 Jan 2015 14:22:49 -0800 Subject: [PATCH 1/2] Make $(document).tooltip({...}) without a `selector` throw an error Closes #15484 --- js/tests/unit/popover.js | 7 +++++++ js/tests/unit/tooltip.js | 6 ++++++ js/tooltip.js | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index e1a2edef71..b18366a7ea 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -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!')) + }) + }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 2264ca3727..32892f12ba 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -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!')) + }) + }) diff --git a/js/tooltip.js b/js/tooltip.js index a1140d2479..b47c010f37 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -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--;) { From 34f88e94fcc75d212a0076124c8d550bb9f7095d Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 5 Jan 2015 14:47:33 -0800 Subject: [PATCH 2/2] window.Document doesn't exist in IE8 --- js/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/tooltip.js b/js/tooltip.js index b47c010f37..5830c4af19 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -52,7 +52,7 @@ 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) { + if (this.$element[0] instanceof document.constructor && !this.options.selector) { throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!'); }