app/assets/javascripts/twitter/bootstrap/tooltip.js in bootstrap-sass-rails-3.0.0.0.rc1 vs app/assets/javascripts/twitter/bootstrap/tooltip.js in bootstrap-sass-rails-3.0.0.0.rc2
- old
+ new
@@ -1,8 +1,8 @@
/* ========================================================================
* Bootstrap: tooltip.js v3.0.0
- * http://twbs.github.com/bootstrap/javascript.html#affix
+ * http://twbs.github.com/bootstrap/javascript.html#tooltip
* Inspired by the original jQuery.tipsy by Jason Frame
* ========================================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,11 +62,11 @@
this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
} else if (trigger != 'manual') {
var eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
var eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
- this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
+ this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
}
}
this.options.selector ?
@@ -89,20 +89,24 @@
}
return options
}
- Tooltip.prototype.enter = function (obj) {
- var defaults = this.getDefaults()
+ Tooltip.prototype.getDelegateOptions = function () {
var options = {}
+ var defaults = this.getDefaults()
this._options && $.each(this._options, function (key, value) {
if (defaults[key] != value) options[key] = value
})
+ return options
+ }
+
+ Tooltip.prototype.enter = function (obj) {
var self = obj instanceof this.constructor ?
- obj : $(obj.currentTarget)[this.type](options).data('bs.' + this.type)
+ obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
clearTimeout(self.timeout)
if (!self.options.delay || !self.options.delay.show) return self.show()
@@ -112,11 +116,11 @@
}, self.options.delay.show)
}
Tooltip.prototype.leave = function (obj) {
var self = obj instanceof this.constructor ?
- obj : $(obj.currentTarget)[this.type](this._options).data('bs.' + this.type)
+ obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
clearTimeout(self.timeout)
if (!self.options.delay || !self.options.delay.hide) return self.hide()
@@ -177,16 +181,13 @@
$tip
.removeClass(orgPlacement)
.addClass(placement)
}
- var tp = placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
- placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
- placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
- /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
+ var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
- this.applyPlacement(tp, placement)
+ this.applyPlacement(calculatedOffset, placement)
this.$element.trigger('shown.bs.' + this.type)
}
}
Tooltip.prototype.applyPlacement = function(offset, placement) {
@@ -194,29 +195,37 @@
var $tip = this.tip()
var width = $tip[0].offsetWidth
var height = $tip[0].offsetHeight
// manually read margins because getBoundingClientRect includes difference
- offset.top = offset.top + parseInt($tip.css('margin-top'), 10)
- offset.left = offset.left + parseInt($tip.css('margin-left'), 10)
+ var marginTop = parseInt($tip.css('margin-top'), 10)
+ var marginLeft = parseInt($tip.css('margin-left'), 10)
+ // we must check for NaN for ie 8/9
+ if (isNaN(marginTop)) marginTop = 0
+ if (isNaN(marginLeft)) marginLeft = 0
+
+ offset.top = offset.top + marginTop
+ offset.left = offset.left + marginLeft
+
$tip
.offset(offset)
.addClass('in')
+ // check to see if placing tip in new offset caused the tip to resize itself
var actualWidth = $tip[0].offsetWidth
var actualHeight = $tip[0].offsetHeight
if (placement == 'top' && actualHeight != height) {
replace = true
- offset.top = offset.top + height - actualHeight
+ offset.top = offset.top + height - actualHeight
}
- if (placement == 'bottom' || placement == 'top') {
+ if (/bottom|top/.test(placement)) {
var delta = 0
- if (offset.left < 0){
+ if (offset.left < 0) {
delta = offset.left * -2
offset.left = 0
$tip.offset(offset)
@@ -247,21 +256,23 @@
Tooltip.prototype.hide = function () {
var that = this
var $tip = this.tip()
var e = $.Event('hide.bs.' + this.type)
+ function complete() { $tip.detach() }
+
this.$element.trigger(e)
if (e.isDefaultPrevented()) return
$tip.removeClass('in')
$.support.transition && this.$tip.hasClass('fade') ?
$tip
- .one($.support.transition.end, $tip.detach)
+ .one($.support.transition.end, complete)
.emulateTransitionEnd(150) :
- $tip.detach()
+ complete()
this.$element.trigger('hidden.bs.' + this.type)
return this
}
@@ -283,10 +294,17 @@
width: el.offsetWidth
, height: el.offsetHeight
}, this.$element.offset())
}
+ Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
+ return placement == 'bottom' ? { top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 } :
+ placement == 'top' ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
+ placement == 'left' ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
+ /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
+ }
+
Tooltip.prototype.getTitle = function () {
var title
var $e = this.$element
var o = this.options
@@ -298,12 +316,12 @@
Tooltip.prototype.tip = function () {
return this.$tip = this.$tip || $(this.options.template)
}
- Tooltip.prototype.arrow =function(){
- return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
+ Tooltip.prototype.arrow = function () {
+ return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')
}
Tooltip.prototype.validate = function () {
if (!this.$element[0].parentNode) {
this.hide()
@@ -323,10 +341,10 @@
Tooltip.prototype.toggleEnabled = function () {
this.enabled = !this.enabled
}
Tooltip.prototype.toggle = function (e) {
- var self = e ? $(e.currentTarget)[this.type](this._options).data('bs.' + this.type) : this
+ var self = e ? $(e.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) : this
self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
}
Tooltip.prototype.destroy = function () {
this.hide().$element.off('.' + this.type).removeData('bs.' + this.type)