PageSourceSearch

https://redacademy.it/wp-content/plugins/tlp-team/assets/js/rt-tooltip.js?ver=1790948596

js redacademy.it collected 2026-10-02 13:44:18 UTC 16,557 bytes, 479 lines download raw bytes

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

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.