diff options
| author | Mark Otto <[email protected]> | 2014-06-08 11:19:35 -0700 |
|---|---|---|
| committer | Mark Otto <[email protected]> | 2014-06-08 11:19:35 -0700 |
| commit | 34891de173f1ea1dfd470d4cdeed52f83d9a253b (patch) | |
| tree | a7cb7aaf85bdfce5e1f0a8165879193c327179b6 /js/tooltip.js | |
| parent | d66b65ddde1b2f1a5cb14f601d30c552c79d7626 (diff) | |
| parent | 1e3b93804fa88d247d8708529fb44b28d73fd91f (diff) | |
| download | bootstrap-34891de173f1ea1dfd470d4cdeed52f83d9a253b.tar.xz bootstrap-34891de173f1ea1dfd470d4cdeed52f83d9a253b.zip | |
grunt
Diffstat (limited to 'js/tooltip.js')
| -rw-r--r-- | js/tooltip.js | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/js/tooltip.js b/js/tooltip.js index d985f96e3..b4ced6d2a 100644 --- a/js/tooltip.js +++ b/js/tooltip.js @@ -145,12 +145,17 @@ 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() + 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') @@ -166,6 +171,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) @@ -194,7 +200,7 @@ this.applyPlacement(calculatedOffset, placement) this.hoverState = null - var complete = function() { + var complete = function () { that.$element.trigger('shown.bs.' + that.type) } @@ -273,6 +279,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) @@ -297,7 +305,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', '') } } @@ -314,7 +322,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) { @@ -364,12 +372,18 @@ 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) + 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 () { |
