]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/pretty-json/node_modules/jsonminify/report/assets/scripts/vendor/bootstrap-tooltip.js
89802287a32cece7dcfd0d2543f652d3b7918d55
1 /* ========================================================================
2 * Bootstrap: tooltip.js v3.0.0
3 * http://twbs.github.com/bootstrap/javascript.html#tooltip
4 * Inspired by the original jQuery.tipsy by Jason Frame
5 * ========================================================================
6 * Copyright 2012 Twitter, Inc.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ======================================================================== */
22 +function ($) { "use strict";
24 // TOOLTIP PUBLIC CLASS DEFINITION
25 // ===============================
27 var Tooltip = function (element
, options
) {
35 this.init('tooltip', element
, options
)
42 , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
43 , trigger: 'hover focus'
50 Tooltip
.prototype.init = function (type
, element
, options
) {
53 this.$element
= $(element
)
54 this.options
= this.getOptions(options
)
56 var triggers
= this.options
.trigger
.split(' ')
58 for (var i
= triggers
.length
; i
--;) {
59 var trigger
= triggers
[i
]
61 if (trigger
== 'click') {
62 this.$element
.on('click.' + this.type
, this.options
.selector
, $.proxy(this.toggle
, this))
63 } else if (trigger
!= 'manual') {
64 var eventIn
= trigger
== 'hover' ? 'mouseenter' : 'focus'
65 var eventOut
= trigger
== 'hover' ? 'mouseleave' : 'blur'
67 this.$element
.on(eventIn
+ '.' + this.type
, this.options
.selector
, $.proxy(this.enter
, this))
68 this.$element
.on(eventOut
+ '.' + this.type
, this.options
.selector
, $.proxy(this.leave
, this))
72 this.options
.selector
?
73 (this._options
= $.extend({}, this.options
, { trigger: 'manual', selector: '' })) :
77 Tooltip
.prototype.getDefaults = function () {
78 return Tooltip
.DEFAULTS
81 Tooltip
.prototype.getOptions = function (options
) {
82 options
= $.extend({}, this.getDefaults(), this.$element
.data(), options
)
84 if (options
.delay
&& typeof options
.delay
== 'number') {
94 Tooltip
.prototype.getDelegateOptions = function () {
96 var defaults
= this.getDefaults()
98 this._options
&& $.each(this._options
, function (key
, value
) {
99 if (defaults
[key
] != value
) options
[key
] = value
105 Tooltip
.prototype.enter = function (obj
) {
106 var self
= obj
instanceof this.constructor ?
107 obj : $(obj
.currentTarget
)[this.type
](this.getDelegateOptions()).data('bs.' + this.type
)
109 clearTimeout(self
.timeout
)
111 self
.hoverState
= 'in'
113 if (!self
.options
.delay
|| !self
.options
.delay
.show
) return self
.show()
115 self
.timeout
= setTimeout(function () {
116 if (self
.hoverState
== 'in') self
.show()
117 }, self
.options
.delay
.show
)
120 Tooltip
.prototype.leave = function (obj
) {
121 var self
= obj
instanceof this.constructor ?
122 obj : $(obj
.currentTarget
)[this.type
](this.getDelegateOptions()).data('bs.' + this.type
)
124 clearTimeout(self
.timeout
)
126 self
.hoverState
= 'out'
128 if (!self
.options
.delay
|| !self
.options
.delay
.hide
) return self
.hide()
130 self
.timeout
= setTimeout(function () {
131 if (self
.hoverState
== 'out') self
.hide()
132 }, self
.options
.delay
.hide
)
135 Tooltip
.prototype.show = function () {
136 var e
= $.Event('show.bs.'+ this.type
)
138 if (this.hasContent() && this.enabled
) {
139 this.$element
.trigger(e
)
141 if (e
.isDefaultPrevented()) return
143 var $tip
= this.tip()
147 if (this.options
.animation
) $tip
.addClass('fade')
149 var placement
= typeof this.options
.placement
== 'function' ?
150 this.options
.placement
.call(this, $tip
[0], this.$element
[0]) :
151 this.options
.placement
153 var autoToken
= /\s?auto?\s?/i
154 var autoPlace
= autoToken
.test(placement
)
155 if (autoPlace
) placement
= placement
.replace(autoToken
, '') || 'top'
159 .css({ top: 0, left: 0, display: 'block' })
162 this.options
.container
? $tip
.appendTo(this.options
.container
) : $tip
.insertAfter(this.$element
)
164 var pos
= this.getPosition()
165 var actualWidth
= $tip
[0].offsetWidth
166 var actualHeight
= $tip
[0].offsetHeight
169 var $parent
= this.$element
.parent()
171 var orgPlacement
= placement
172 var docScroll
= document
.documentElement
.scrollTop
|| document
.body
.scrollTop
173 var parentWidth
= this.options
.container
== 'body' ? window
.innerWidth : $parent
.outerWidth()
174 var parentHeight
= this.options
.container
== 'body' ? window
.innerHeight : $parent
.outerHeight()
175 var parentLeft
= this.options
.container
== 'body' ? 0 : $parent
.offset().left
177 placement
= placement
== 'bottom' && pos
.top
+ pos
.height
+ actualHeight
- docScroll
> parentHeight
? 'top' :
178 placement
== 'top' && pos
.top
- docScroll
- actualHeight
< 0 ? 'bottom' :
179 placement
== 'right' && pos
.right
+ actualWidth
> parentWidth
? 'left' :
180 placement
== 'left' && pos
.left
- actualWidth
< parentLeft
? 'right' :
184 .removeClass(orgPlacement
)
188 var calculatedOffset
= this.getCalculatedOffset(placement
, pos
, actualWidth
, actualHeight
)
190 this.applyPlacement(calculatedOffset
, placement
)
191 this.$element
.trigger('shown.bs.' + this.type
)
195 Tooltip
.prototype.applyPlacement = function(offset
, placement
) {
197 var $tip
= this.tip()
198 var width
= $tip
[0].offsetWidth
199 var height
= $tip
[0].offsetHeight
201 // manually read margins because getBoundingClientRect includes difference
202 var marginTop
= parseInt($tip
.css('margin-top'), 10)
203 var marginLeft
= parseInt($tip
.css('margin-left'), 10)
205 // we must check for NaN for ie 8/9
206 if (isNaN(marginTop
)) marginTop
= 0
207 if (isNaN(marginLeft
)) marginLeft
= 0
209 offset
.top
= offset
.top
+ marginTop
210 offset
.left
= offset
.left
+ marginLeft
216 // check to see if placing tip in new offset caused the tip to resize itself
217 var actualWidth
= $tip
[0].offsetWidth
218 var actualHeight
= $tip
[0].offsetHeight
220 if (placement
== 'top' && actualHeight
!= height
) {
222 offset
.top
= offset
.top
+ height
- actualHeight
225 if (/bottom|top/.test(placement
)) {
228 if (offset
.left
< 0) {
229 delta
= offset
.left
* -2
234 actualWidth
= $tip
[0].offsetWidth
235 actualHeight
= $tip
[0].offsetHeight
238 this.replaceArrow(delta
- width
+ actualWidth
, actualWidth
, 'left')
240 this.replaceArrow(actualHeight
- height
, actualHeight
, 'top')
243 if (replace
) $tip
.offset(offset
)
246 Tooltip
.prototype.replaceArrow = function(delta
, dimension
, position
) {
247 this.arrow().css(position
, delta
? (50 * (1 - delta
/ dimension
) + "%") : '')
250 Tooltip
.prototype.setContent = function () {
251 var $tip
= this.tip()
252 var title
= this.getTitle()
254 $tip
.find('.tooltip-inner')[this.options
.html
? 'html' : 'text'](title
)
255 $tip
.removeClass('fade in top bottom left right')
258 Tooltip
.prototype.hide = function () {
260 var $tip
= this.tip()
261 var e
= $.Event('hide.bs.' + this.type
)
263 function complete() {
264 if (that
.hoverState
!= 'in') $tip
.detach()
267 this.$element
.trigger(e
)
269 if (e
.isDefaultPrevented()) return
271 $tip
.removeClass('in')
273 $.support
.transition
&& this.$tip
.hasClass('fade') ?
275 .one($.support
.transition
.end
, complete
)
276 .emulateTransitionEnd(150) :
279 this.$element
.trigger('hidden.bs.' + this.type
)
284 Tooltip
.prototype.fixTitle = function () {
285 var $e
= this.$element
286 if ($e
.attr('title') || typeof($e
.attr('data-original-title')) != 'string') {
287 $e
.attr('data-original-title', $e
.attr('title') || '').attr('title', '')
291 Tooltip
.prototype.hasContent = function () {
292 return this.getTitle()
295 Tooltip
.prototype.getPosition = function () {
296 var el
= this.$element
[0]
297 return $.extend({}, (typeof el
.getBoundingClientRect
== 'function') ? el
.getBoundingClientRect() : {
298 width: el
.offsetWidth
299 , height: el
.offsetHeight
300 }, this.$element
.offset())
303 Tooltip
.prototype.getCalculatedOffset = function (placement
, pos
, actualWidth
, actualHeight
) {
304 return placement
== 'bottom' ? { top: pos
.top
+ pos
.height
, left: pos
.left
+ pos
.width
/ 2 - actualWidth
/ 2 } :
305 placement
== 'top' ? { top: pos
.top
- actualHeight
, left: pos
.left
+ pos
.width
/ 2 - actualWidth
/ 2 } :
306 placement
== 'left' ? { top: pos
.top
+ pos
.height
/ 2 - actualHeight
/ 2, left: pos
.left
- actualWidth
} :
307 /* placement == 'right' */ { top: pos
.top
+ pos
.height
/ 2 - actualHeight
/ 2, left: pos
.left
+ pos
.width
}
310 Tooltip
.prototype.getTitle = function () {
312 var $e
= this.$element
315 title
= $e
.attr('data-original-title')
316 || (typeof o
.title
== 'function' ? o
.title
.call($e
[0]) : o
.title
)
321 Tooltip
.prototype.tip = function () {
322 return this.$tip
= this.$tip
|| $(this.options
.template
)
325 Tooltip
.prototype.arrow = function () {
326 return this.$arrow
= this.$arrow
|| this.tip().find('.tooltip-arrow')
329 Tooltip
.prototype.validate = function () {
330 if (!this.$element
[0].parentNode
) {
337 Tooltip
.prototype.enable = function () {
341 Tooltip
.prototype.disable = function () {
345 Tooltip
.prototype.toggleEnabled = function () {
346 this.enabled
= !this.enabled
349 Tooltip
.prototype.toggle = function (e
) {
350 var self
= e
? $(e
.currentTarget
)[this.type
](this.getDelegateOptions()).data('bs.' + this.type
) : this
351 self
.tip().hasClass('in') ? self
.leave(self
) : self
.enter(self
)
354 Tooltip
.prototype.destroy = function () {
355 this.hide().$element
.off('.' + this.type
).removeData('bs.' + this.type
)
359 // TOOLTIP PLUGIN DEFINITION
360 // =========================
362 var old
= $.fn
.tooltip
364 $.fn
.tooltip = function (option
) {
365 return this.each(function () {
367 var data
= $this.data('bs.tooltip')
368 var options
= typeof option
== 'object' && option
370 if (!data
) $this.data('bs.tooltip', (data
= new Tooltip(this, options
)))
371 if (typeof option
== 'string') data
[option
]()
375 $.fn
.tooltip
.Constructor
= Tooltip
378 // TOOLTIP NO CONFLICT
379 // ===================
381 $.fn
.tooltip
.noConflict = function () {