PageSourceSearch

https://gorzkow.eu/templates/pcj-jgmina-blue/js/tooltip.js

js gorzkow.eu collected 2026-10-02 22:09:56 UTC 15,577 bytes, 473 lines download raw bytes

1/* ========================================================================
2 * Bootstrap: tooltip.js v3.3.2
3 * http://getbootstrap.com/javascript/#tooltip
4 * Inspired by the original jQuery.tipsy by Jason Frame
5 * ========================================================================
6 * Copyright 2011-2015 Twitter, Inc.
7 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
8 * ======================================================================== */
9
10
11+function ($) {
12  'use strict';
13
14  // TOOLTIP PUBLIC CLASS DEFINITION
15  // ===============================
16
17  var Tooltip = function (element, options) {
18    this.type       =
19    this.options    =
20    this.enabled    =
21    this.timeout    =
22    this.hoverState =
23    this.$element   = null
24
25    this.init('tooltip', element, options)
26  }
27
28  Tooltip.VERSION  = '3.3.2'
29
30  Tooltip.TRANSITION_DURATION = 150
31
32  Tooltip.DEFAULTS = {
33    animation: true,
34    placement: 'top',
35    selector: false,
36    template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
37    trigger: 'hover focus',
38    title: '',
39    delay: 0,
40    html: false,
41    container: false,
42    viewport: {
43      selector: 'body',
44      padding: 0
45    }
46  }
47
48  Tooltip.prototype.init = function (type, element, options) {
49    this.enabled   = true
50    this.type      = type
51    this.$element  = $(element)
52    this.options   = this.getOptions(options)
53    this.$viewport = this.options.viewport && $(this.options.viewport.selector || this.options.viewport)
54
55    var triggers = this.options.trigger.split(' ')
56
57    for (var i = triggers.length; i--;) {
58      var trigger = triggers[i]
59
60      if (trigger == 'click') {
61        this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
62      } else if (trigger != 'manual') {
63        var eventIn  = trigger == 'hover' ? 'mouseenter' : 'focusin'
64        var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
65
66        this.$element.on(eventIn  + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
67        this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
68      }
69    }
70
71    this.options.selector ?
72      (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
73      this.fixTitle()
74  }
75
76  Tooltip.prototype.getDefaults = function () {
77    return Tooltip.DEFAULTS
78  }
79
80  Tooltip.prototype.getOptions = function (options) {
81    options = $.extend({}, this.getDefaults(), this.$element.data(), options)
82
83    if (options.delay && typeof options.delay == 'number') {
84      options.delay = {
85        show: options.delay,
86        hide: options.delay
87      }
88    }
89
90    return options
91  }
92
93  Tooltip.prototype.getDelegateOptions = function () {
94    var options  = {}
95    var defaults = this.getDefaults()
96
97    this._options && $.each(this._options, function (key, value) {
98      if (defaults[key] != value) options[key] = value
99    })
100
101    return options
102  }
103
104  Tooltip.prototype.enter = function (obj) {
105    var self = obj instanceof this.constructor ?
106      obj : $(obj.currentTarget).data('bs.' + this.type)
107
108    if (self && self.$tip && self.$tip.is(':visible')) {
109      self.hoverState = 'in'
110      return
111    }
112
113    if (!self) {
114      self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
115      $(obj.currentTarget).data('bs.' + this.type, self)
116    }
117
118    clearTimeout(self.timeout)
119
120    self.hoverState = 'in'
121
122    if (!self.options.delay || !self.options.delay.show) return self.show()
123
124    self.timeout = setTimeout(function () {
125      if (self.hoverState == 'in') self.show()
126    }, self.options.delay.show)
127  }
128
129  Tooltip.prototype.leave = function (obj) {
130    var self = obj instanceof this.constructor ?
131      obj : $(obj.currentTarget).data('bs.' + this.type)
132
133    if (!self) {
134      self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
135      $(obj.currentTarget).data('bs.' + this.type, self)
136    }
137
138    clearTimeout(self.timeout)
139
140    self.hoverState = 'out'
141
142    if (!self.options.delay || !self.options.delay.hide) return self.hide()
143
144    self.timeout = setTimeout(function () {
145      if (self.hoverState == 'out') self.hide()
146    }, self.options.delay.hide)
147  }
148
149  Tooltip.prototype.show = function () {
150    var e = $.Event('show.bs.' + this.type)
151
152    if (this.hasContent() && this.enabled) {
153      this.$element.trigger(e)
154
155      var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0])
156      if (e.isDefaultPrevented() || !inDom) return
157      var that = this
158
159      var $tip = this.tip()
160
161      var tipId = this.getUID(this.type)
162
163      this.setContent()
vendor: 7,931 bytes, lines 164-370
164      $tip.attr('id', tipId)
165      this.$element.attr('aria-describedby', tipId)
166
167      if (this.options.animation) $tip.addClass('fade')
168
169      var placement = typeof this.options.placement == 'function' ?
170        this.options.placement.call(this, $tip[0], this.$element[0]) :
171        this.options.placement
172
173      var autoToken = /\s?auto?\s?/i
174      var autoPlace = autoToken.test(placement)
175      if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
176
177      $tip
178        .detach()
179        .css({ top: 0, left: 0, display: 'block' })
180        .addClass(placement)
181        .data('bs.' + this.type, this)
182
183      this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
184
185      var pos          = this.getPosition()
186      var actualWidth  = $tip[0].offsetWidth
187      var actualHeight = $tip[0].offsetHeight
188
189      if (autoPlace) {
190        var orgPlacement = placement
191        var $container   = this.options.container ? $(this.options.container) : this.$element.parent()
192        var containerDim = this.getPosition($container)
193
194        placement = placement == 'bottom' && pos.bottom + actualHeight > containerDim.bottom ? 'top'    :
195                    placement == 'top'    && pos.top    - actualHeight < containerDim.top    ? 'bottom' :
196                    placement == 'right'  && pos.right  + actualWidth  > containerDim.width  ? 'left'   :
197                    placement == 'left'   && pos.left   - actualWidth  < containerDim.left   ? 'right'  :
198                    placement
199
200        $tip
201          .removeClass(orgPlacement)
202          .addClass(placement)
203      }
204
205      var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
206
207      this.applyPlacement(calculatedOffset, placement)
208
209      var complete = function () {
210        var prevHoverState = that.hoverState
211        that.$element.trigger('shown.bs.' + that.type)
212        that.hoverState = null
213
214        if (prevHoverState == 'out') that.leave(that)
215      }
216
217      $.support.transition && this.$tip.hasClass('fade') ?
218        $tip
219          .one('bsTransitionEnd', complete)
220          .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
221        complete()
222    }
223  }
224
225  Tooltip.prototype.applyPlacement = function (offset, placement) {
226    var $tip   = this.tip()
227    var width  = $tip[0].offsetWidth
228    var height = $tip[0].offsetHeight
229
230    // manually read margins because getBoundingClientRect includes difference
231    var marginTop = parseInt($tip.css('margin-top'), 10)
232    var marginLeft = parseInt($tip.css('margin-left'), 10)
233
234    // we must check for NaN for ie 8/9
235    if (isNaN(marginTop))  marginTop  = 0
236    if (isNaN(marginLeft)) marginLeft = 0
237
238    offset.top  = offset.top  + marginTop
239    offset.left = offset.left + marginLeft
240
241    // $.fn.offset doesn't round pixel values
242    // so we use setOffset directly with our own function B-0
243    $.offset.setOffset($tip[0], $.extend({
244      using: function (props) {
245        $tip.css({
246          top: Math.round(props.top),
247          left: Math.round(props.left)
248        })
249      }
250    }, offset), 0)
251
252    $tip.addClass('in')
253
254    // check to see if placing tip in new offset caused the tip to resize itself
255    var actualWidth  = $tip[0].offsetWidth
256    var actualHeight = $tip[0].offsetHeight
257
258    if (placement == 'top' && actualHeight != height) {
259      offset.top = offset.top + height - actualHeight
260    }
261
262    var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
263
264    if (delta.left) offset.left += delta.left
265    else offset.top += delta.top
266
267    var isVertical          = /top|bottom/.test(placement)
268    var arrowDelta          = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
269    var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
270
271    $tip.offset(offset)
272    this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical)
273  }
274
275  Tooltip.prototype.replaceArrow = function (delta, dimension, isHorizontal) {
276    this.arrow()
277      .css(isHorizontal ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
278      .css(isHorizontal ? 'top' : 'left', '')
279  }
280
281  Tooltip.prototype.setContent = function () {
282    var $tip  = this.tip()
283    var title = this.getTitle()
284
285    $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
286    $tip.removeClass('fade in top bottom left right')
287  }
288
289  Tooltip.prototype.hide = function (callback) {
290    var that = this
291    var $tip = this.tip()
292    var e    = $.Event('hide.bs.' + this.type)
293
294    function complete() {
295      if (that.hoverState != 'in') $tip.detach()
296      that.$element
297        .removeAttr('aria-describedby')
298        .trigger('hidden.bs.' + that.type)
299      callback && callback()
300    }
301
302    this.$element.trigger(e)
303
304    if (e.isDefaultPrevented()) return
305
306    $tip.removeClass('in')
307
308
309    $.support.transition && this.$tip.hasClass('fade') ?
310      $tip
311        .one('bsTransitionEnd', complete)
312        .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
313      complete()
314
315    this.hoverState = null
316
317    return this
318  }
319
320  Tooltip.prototype.fixTitle = function () {
321    var $e = this.$element
322    if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') {
323      $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
324    }
325  }
326
327  Tooltip.prototype.hasContent = function () {
328    return this.getTitle()
329  }
330
331  Tooltip.prototype.getPosition = function ($element) {
332    $element   = $element || this.$element
333
334    var el     = $element[0]
335    var isBody = el.tagName == 'BODY'
336
337    var elRect    = el.getBoundingClientRect()
338    if (elRect.width == null) {
339      // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093
340      elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top })
341    }
342    var elOffset  = isBody ? { top: 0, left: 0 } : $element.offset()
343    var scroll    = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }
344    var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null
345
346    return $.extend({}, elRect, scroll, outerDims, elOffset)
347  }
348
349  Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
350    return placement == 'bottom' ? { top: pos.top + pos.height,   left: pos.left + pos.width / 2 - actualWidth / 2 } :
351           placement == 'top'    ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
352           placement == 'left'   ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
353        /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
354
355  }
356
357  Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
358    var delta = { top: 0, left: 0 }
359    if (!this.$viewport) return delta
360
361    var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
362    var viewportDimensions = this.getPosition(this.$viewport)
363
364    if (/right|left/.test(placement)) {
365      var topEdgeOffset    = pos.top - viewportPadding - viewportDimensions.scroll
366      var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
367      if (topEdgeOffset < viewportDimensions.top) { // top overflow
368        delta.top = viewportDimensions.top - topEdgeOffset
369      } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
370        delta.top = viewportDimensions.top + viewportDimensions.height - bottom
370EdgeOffset
371      }
372    } else {
373      var leftEdgeOffset  = pos.left - viewportPadding
374      var rightEdgeOffset = pos.left + viewportPadding + actualWidth
375      if (leftEdgeOffset < viewportDimensions.left) { // left overflow
376        delta.left = viewportDimensions.left - leftEdgeOffset
377      } else if (rightEdgeOffset > viewportDimensions.width) { // right overflow
378        delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
379      }
380    }
381
382    return delta
383  }
384
385  Tooltip.prototype.getTitle = function () {
386    var title
387    var $e = this.$element
388    var o  = this.options
389
390    title = $e.attr('data-original-title')
391      || (typeof o.title == 'function' ? o.title.call($e[0]) :  o.title)
392
393    return title
394  }
395
396  Tooltip.prototype.getUID = function (prefix) {
397    do prefix += ~~(Math.random() * 1000000)
398    while (document.getElementById(prefix))
399    return prefix
400  }
401
402  Tooltip.prototype.tip = function () {
403    return (this.$tip = this.$tip || $(this.options.template))
404  }
405
406  Tooltip.prototype.arrow = function () {
407    return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow'))
408  }
409
410  Tooltip.prototype.enable = function () {
411    this.enabled = true
412  }
413
414  Tooltip.prototype.disable = function () {
415    this.enabled = false
416  }
417
418  Tooltip.prototype.toggleEnabled = function () {
419    this.enabled = !this.enabled
420  }
421
422  Tooltip.prototype.toggle = function (e) {
423    var self = this
424    if (e) {
425      self = $(e.currentTarget).data('bs.' + this.type)
426      if (!self) {
427        self = new this.constructor(e.currentTarget, this.getDelegateOptions())
428        $(e.currentTarget).data('bs.' + this.type, self)
429      }
430    }
431
432    self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
433  }
434
435  Tooltip.prototype.destroy = function () {
436    var that = this
437    clearTimeout(this.timeout)
438    this.hide(function () {
439      that.$element.off('.' + that.type).removeData('bs.' + that.type)
440    })
441  }
442
443
444  // TOOLTIP PLUGIN DEFINITION
445  // =========================
446
447  function Plugin(option) {
448    return this.each(function () {
449      var $this   = $(this)
450      var data    = $this.data('bs.tooltip')
451      var options = typeof option == 'object' && option
452
453      if (!data && option == 'destroy') return
454      if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
455      if (typeof option == 'string') data[option]()
456    })
457  }
458
459  var old = $.fn.tooltip
460
461  $.fn.tooltip             = Plugin
462  $.fn.tooltip.Constructor = Tooltip
463
464
465  // TOOLTIP NO CONFLICT
466  // ===================
467
468  $.fn.tooltip.noConflict = function () {
469    $.fn.tooltip = old
470    return this
471  }
472
473}(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.