From 122c05dbd87d9708086da4d097f7e715233f3b2c Mon Sep 17 00:00:00 2001 From: "j.corns" Date: Wed, 14 May 2014 10:36:32 -0700 Subject: Add tooltip self-reference to address #12320 primarily adds a data- attribute to the tooltip (and thus, the popover) to create a self-reference. --- js/tooltip.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/tooltip.js') diff --git a/js/tooltip.js b/js/tooltip.js index d985f96e3..076f2fa1c 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -166,6 +166,7 @@ .detach() .css({ top: 0, left: 0, display: 'block' }) .addClass(placement) + .data('bs.' + this.type, this) this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element) -- cgit v1.2.3 From a70da16f6fb8c665f22b78b49a1dff998f1da8a7 Mon Sep 17 00:00:00 2001 From: Steven Bassett Date: Thu, 8 May 2014 20:19:12 -0700 Subject: Adds aria described by to tooltip plugin for accessibility Generates a unique id for tooltip and adds [aria-describedby] to the element it is called on. Resolves issue #13480 - set up test - linted the code styles - passed the tests - integrated feedback from @cvrebert --- js/tooltip.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'js/tooltip.js') diff --git a/js/tooltip.js b/js/tooltip.js index d985f96e3..936424830 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -150,7 +150,11 @@ var $tip = this.tip() + var tipId = this.getUID(this.type) + this.setContent() + $tip.attr('id', tipId) + this.$element.attr('aria-describedby', tipId) if (this.options.animation) $tip.addClass('fade') @@ -273,6 +277,8 @@ var $tip = this.tip() var e = $.Event('hide.bs.' + this.type) + this.$element.removeAttr('aria-describedby') + function complete() { if (that.hoverState != 'in') $tip.detach() that.$element.trigger('hidden.bs.' + that.type) @@ -364,6 +370,12 @@ return title } + Tooltip.prototype.getUID = function (prefix) { + do prefix += ~~(Math.random() * 1000000) + while (document.getElementById(prefix)) + return prefix + } + Tooltip.prototype.tip = function () { return this.$tip = this.$tip || $(this.options.template) } -- cgit v1.2.3 From 7b0acf14d8a7c7c6089035a848cba540ed963f36 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 17 Mar 2014 09:12:55 +0200 Subject: Comply to the new style. --- js/tooltip.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/tooltip.js') diff --git a/js/tooltip.js b/js/tooltip.js index f0f8a7c18..0dd4c1fa6 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -199,7 +199,7 @@ this.applyPlacement(calculatedOffset, placement) this.hoverState = null - var complete = function() { + var complete = function () { that.$element.trigger('shown.bs.' + that.type) } @@ -321,7 +321,7 @@ scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop(), width: isBody ? $(window).width() : $element.outerWidth(), height: isBody ? $(window).height() : $element.outerHeight() - }, isBody ? {top: 0, left: 0} : $element.offset()) + }, isBody ? { top: 0, left: 0 } : $element.offset()) } Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) { @@ -378,11 +378,11 @@ } Tooltip.prototype.tip = function () { - return this.$tip = this.$tip || $(this.options.template) + return (this.$tip = this.$tip || $(this.options.template)) } Tooltip.prototype.arrow = function () { - return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow') + return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')) } Tooltip.prototype.validate = function () { -- cgit v1.2.3 From e2cabe4971927e3dbbbda4c81ae8f74abdee2d15 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 29 May 2014 07:35:22 +0300 Subject: Minor style tweaks. --- js/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/tooltip.js') diff --git a/js/tooltip.js b/js/tooltip.js index 0dd4c1fa6..3b8ac17f6 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -304,7 +304,7 @@ Tooltip.prototype.fixTitle = function () { var $e = this.$element - if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') { + if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') { $e.attr('data-original-title', $e.attr('title') || '').attr('title', '') } } -- cgit v1.2.3 From 21de05c8c09b0ff9c11651596a84442b312381bb Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 6 Jun 2014 15:34:56 -0700 Subject: don't show tooltips/popovers whose element isn't in the DOM; fixes #13268 --- js/tooltip.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'js/tooltip.js') diff --git a/js/tooltip.js b/js/tooltip.js index 3b8ac17f6..b4ced6d2a 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -145,8 +145,9 @@ if (this.hasContent() && this.enabled) { this.$element.trigger(e) - if (e.isDefaultPrevented()) return - var that = this; + var inDom = $.contains(document.documentElement, this.$element[0]) + if (e.isDefaultPrevented() || !inDom) return + var that = this var $tip = this.tip() -- cgit v1.2.3