]>
git.ipfire.org Git - ipfire.org.git/blob - src/scss/bootstrap-4.0.0-alpha.6/js/dist/tooltip.js
1 var _typeof
= typeof Symbol
=== "function" && typeof Symbol
.iterator
=== "symbol" ? function (obj
) { return typeof obj
; } : function (obj
) { return obj
&& typeof Symbol
=== "function" && obj
.constructor === Symbol
&& obj
!== Symbol
.prototype ? "symbol" : typeof obj
; };
3 var _createClass = function () { function defineProperties(target
, props
) { for (var i
= 0; i
< props
.length
; i
++) { var descriptor
= props
[i
]; descriptor
.enumerable
= descriptor
.enumerable
|| false; descriptor
.configurable
= true; if ("value" in descriptor
) descriptor
.writable
= true; Object
.defineProperty(target
, descriptor
.key
, descriptor
); } } return function (Constructor
, protoProps
, staticProps
) { if (protoProps
) defineProperties(Constructor
.prototype, protoProps
); if (staticProps
) defineProperties(Constructor
, staticProps
); return Constructor
; }; }();
5 function _classCallCheck(instance
, Constructor
) { if (!(instance
instanceof Constructor
)) { throw new TypeError("Cannot call a class as a function"); } }
8 * --------------------------------------------------------------------------
9 * Bootstrap (v4.0.0-alpha.6): tooltip.js
10 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
11 * --------------------------------------------------------------------------
14 var Tooltip = function ($) {
17 * Check for Tether dependency
18 * Tether - http://tether.io/
20 if (typeof Tether
=== 'undefined') {
21 throw new Error('Bootstrap tooltips require Tether (http://tether.io/)');
25 * ------------------------------------------------------------------------
27 * ------------------------------------------------------------------------
31 var VERSION
= '4.0.0-alpha.6';
32 var DATA_KEY
= 'bs.tooltip';
33 var EVENT_KEY
= '.' + DATA_KEY
;
34 var JQUERY_NO_CONFLICT
= $.fn
[NAME
];
35 var TRANSITION_DURATION
= 150;
36 var CLASS_PREFIX
= 'bs-tether';
40 template
: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-inner"></div></div>',
41 trigger
: 'hover focus',
55 title
: '(string|element|function)',
57 delay
: '(number|object)',
59 selector
: '(string|boolean)',
60 placement
: '(string|function)',
63 container
: '(string|element|boolean)'
79 HIDE
: 'hide' + EVENT_KEY
,
80 HIDDEN
: 'hidden' + EVENT_KEY
,
81 SHOW
: 'show' + EVENT_KEY
,
82 SHOWN
: 'shown' + EVENT_KEY
,
83 INSERTED
: 'inserted' + EVENT_KEY
,
84 CLICK
: 'click' + EVENT_KEY
,
85 FOCUSIN
: 'focusin' + EVENT_KEY
,
86 FOCUSOUT
: 'focusout' + EVENT_KEY
,
87 MOUSEENTER
: 'mouseenter' + EVENT_KEY
,
88 MOUSELEAVE
: 'mouseleave' + EVENT_KEY
98 TOOLTIP_INNER
: '.tooltip-inner'
114 * ------------------------------------------------------------------------
116 * ------------------------------------------------------------------------
119 var Tooltip = function () {
120 function Tooltip(element
, config
) {
121 _classCallCheck(this, Tooltip
);
124 this._isEnabled
= true;
126 this._hoverState
= '';
127 this._activeTrigger
= {};
128 this._isTransitioning
= false;
132 this.element
= element
;
133 this.config
= this._getConfig(config
);
136 this._setListeners();
143 Tooltip
.prototype.enable
= function enable() {
144 this._isEnabled
= true;
147 Tooltip
.prototype.disable
= function disable() {
148 this._isEnabled
= false;
151 Tooltip
.prototype.toggleEnabled
= function toggleEnabled() {
152 this._isEnabled
= !this._isEnabled
;
155 Tooltip
.prototype.toggle
= function toggle(event
) {
157 var dataKey
= this.constructor.DATA_KEY
;
158 var context
= $(event
.currentTarget
).data(dataKey
);
161 context
= new this.constructor(event
.currentTarget
, this._getDelegateConfig());
162 $(event
.currentTarget
).data(dataKey
, context
);
165 context
._activeTrigger
.click
= !context
._activeTrigger
.click
;
167 if (context
._isWithActiveTrigger()) {
168 context
._enter(null, context
);
170 context
._leave(null, context
);
174 if ($(this.getTipElement()).hasClass(ClassName
.SHOW
)) {
175 this._leave(null, this);
179 this._enter(null, this);
183 Tooltip
.prototype.dispose
= function dispose() {
184 clearTimeout(this._timeout
);
186 this.cleanupTether();
188 $.removeData(this.element
, this.constructor.DATA_KEY
);
190 $(this.element
).off(this.constructor.EVENT_KEY
);
191 $(this.element
).closest('.modal').off('hide.bs.modal');
194 $(this.tip
).remove();
197 this._isEnabled
= null;
198 this._timeout
= null;
199 this._hoverState
= null;
200 this._activeTrigger
= null;
208 Tooltip
.prototype.show
= function show() {
211 if ($(this.element
).css('display') === 'none') {
212 throw new Error('Please use show on visible elements');
215 var showEvent
= $.Event(this.constructor.Event
.SHOW
);
216 if (this.isWithContent() && this._isEnabled
) {
217 if (this._isTransitioning
) {
218 throw new Error('Tooltip is transitioning');
220 $(this.element
).trigger(showEvent
);
222 var isInTheDom
= $.contains(this.element
.ownerDocument
.documentElement
, this.element
);
224 if (showEvent
.isDefaultPrevented() || !isInTheDom
) {
228 var tip
= this.getTipElement();
229 var tipId
= Util
.getUID(this.constructor.NAME
);
231 tip
.setAttribute('id', tipId
);
232 this.element
.setAttribute('aria-describedby', tipId
);
236 if (this.config
.animation
) {
237 $(tip
).addClass(ClassName
.FADE
);
240 var placement
= typeof this.config
.placement
=== 'function' ? this.config
.placement
.call(this, tip
, this.element
) : this.config
.placement
;
242 var attachment
= this._getAttachment(placement
);
244 var container
= this.config
.container
=== false ? document
.body
: $(this.config
.container
);
246 $(tip
).data(this.constructor.DATA_KEY
, this).appendTo(container
);
248 $(this.element
).trigger(this.constructor.Event
.INSERTED
);
250 this._tether
= new Tether({
251 attachment
: attachment
,
253 target
: this.element
,
254 classes
: TetherClass
,
255 classPrefix
: CLASS_PREFIX
,
256 offset
: this.config
.offset
,
257 constraints
: this.config
.constraints
,
258 addTargetClasses
: false
262 this._tether
.position();
264 $(tip
).addClass(ClassName
.SHOW
);
266 var complete
= function complete() {
267 var prevHoverState
= _this
._hoverState
;
268 _this
._hoverState
= null;
269 _this
._isTransitioning
= false;
271 $(_this
.element
).trigger(_this
.constructor.Event
.SHOWN
);
273 if (prevHoverState
=== HoverState
.OUT
) {
274 _this
._leave(null, _this
);
278 if (Util
.supportsTransitionEnd() && $(this.tip
).hasClass(ClassName
.FADE
)) {
279 this._isTransitioning
= true;
280 $(this.tip
).one(Util
.TRANSITION_END
, complete
).emulateTransitionEnd(Tooltip
._TRANSITION_DURATION
);
288 Tooltip
.prototype.hide
= function hide(callback
) {
291 var tip
= this.getTipElement();
292 var hideEvent
= $.Event(this.constructor.Event
.HIDE
);
293 if (this._isTransitioning
) {
294 throw new Error('Tooltip is transitioning');
296 var complete
= function complete() {
297 if (_this2
._hoverState
!== HoverState
.SHOW
&& tip
.parentNode
) {
298 tip
.parentNode
.removeChild(tip
);
301 _this2
.element
.removeAttribute('aria-describedby');
302 $(_this2
.element
).trigger(_this2
.constructor.Event
.HIDDEN
);
303 _this2
._isTransitioning
= false;
304 _this2
.cleanupTether();
311 $(this.element
).trigger(hideEvent
);
313 if (hideEvent
.isDefaultPrevented()) {
317 $(tip
).removeClass(ClassName
.SHOW
);
319 this._activeTrigger
[Trigger
.CLICK
] = false;
320 this._activeTrigger
[Trigger
.FOCUS
] = false;
321 this._activeTrigger
[Trigger
.HOVER
] = false;
323 if (Util
.supportsTransitionEnd() && $(this.tip
).hasClass(ClassName
.FADE
)) {
324 this._isTransitioning
= true;
325 $(tip
).one(Util
.TRANSITION_END
, complete
).emulateTransitionEnd(TRANSITION_DURATION
);
330 this._hoverState
= '';
335 Tooltip
.prototype.isWithContent
= function isWithContent() {
336 return Boolean(this.getTitle());
339 Tooltip
.prototype.getTipElement
= function getTipElement() {
340 return this.tip
= this.tip
|| $(this.config
.template
)[0];
343 Tooltip
.prototype.setContent
= function setContent() {
344 var $tip
= $(this.getTipElement());
346 this.setElementContent($tip
.find(Selector
.TOOLTIP_INNER
), this.getTitle());
348 $tip
.removeClass(ClassName
.FADE
+ ' ' + ClassName
.SHOW
);
350 this.cleanupTether();
353 Tooltip
.prototype.setElementContent
= function setElementContent($element
, content
) {
354 var html
= this.config
.html
;
355 if ((typeof content
=== 'undefined' ? 'undefined' : _typeof(content
)) === 'object' && (content
.nodeType
|| content
.jquery
)) {
356 // content is a DOM node or a jQuery
358 if (!$(content
).parent().is($element
)) {
359 $element
.empty().append(content
);
362 $element
.text($(content
).text());
365 $element
[html
? 'html' : 'text'](content
);
369 Tooltip
.prototype.getTitle
= function getTitle() {
370 var title
= this.element
.getAttribute('data-original-title');
373 title
= typeof this.config
.title
=== 'function' ? this.config
.title
.call(this.element
) : this.config
.title
;
379 Tooltip
.prototype.cleanupTether
= function cleanupTether() {
381 this._tether
.destroy();
387 Tooltip
.prototype._getAttachment
= function _getAttachment(placement
) {
388 return AttachmentMap
[placement
.toUpperCase()];
391 Tooltip
.prototype._setListeners
= function _setListeners() {
394 var triggers
= this.config
.trigger
.split(' ');
396 triggers
.forEach(function (trigger
) {
397 if (trigger
=== 'click') {
398 $(_this3
.element
).on(_this3
.constructor.Event
.CLICK
, _this3
.config
.selector
, function (event
) {
399 return _this3
.toggle(event
);
401 } else if (trigger
!== Trigger
.MANUAL
) {
402 var eventIn
= trigger
=== Trigger
.HOVER
? _this3
.constructor.Event
.MOUSEENTER
: _this3
.constructor.Event
.FOCUSIN
;
403 var eventOut
= trigger
=== Trigger
.HOVER
? _this3
.constructor.Event
.MOUSELEAVE
: _this3
.constructor.Event
.FOCUSOUT
;
405 $(_this3
.element
).on(eventIn
, _this3
.config
.selector
, function (event
) {
406 return _this3
._enter(event
);
407 }).on(eventOut
, _this3
.config
.selector
, function (event
) {
408 return _this3
._leave(event
);
412 $(_this3
.element
).closest('.modal').on('hide.bs.modal', function () {
413 return _this3
.hide();
417 if (this.config
.selector
) {
418 this.config
= $.extend({}, this.config
, {
427 Tooltip
.prototype._fixTitle
= function _fixTitle() {
428 var titleType
= _typeof(this.element
.getAttribute('data-original-title'));
429 if (this.element
.getAttribute('title') || titleType
!== 'string') {
430 this.element
.setAttribute('data-original-title', this.element
.getAttribute('title') || '');
431 this.element
.setAttribute('title', '');
435 Tooltip
.prototype._enter
= function _enter(event
, context
) {
436 var dataKey
= this.constructor.DATA_KEY
;
438 context
= context
|| $(event
.currentTarget
).data(dataKey
);
441 context
= new this.constructor(event
.currentTarget
, this._getDelegateConfig());
442 $(event
.currentTarget
).data(dataKey
, context
);
446 context
._activeTrigger
[event
.type
=== 'focusin' ? Trigger
.FOCUS
: Trigger
.HOVER
] = true;
449 if ($(context
.getTipElement()).hasClass(ClassName
.SHOW
) || context
._hoverState
=== HoverState
.SHOW
) {
450 context
._hoverState
= HoverState
.SHOW
;
454 clearTimeout(context
._timeout
);
456 context
._hoverState
= HoverState
.SHOW
;
458 if (!context
.config
.delay
|| !context
.config
.delay
.show
) {
463 context
._timeout
= setTimeout(function () {
464 if (context
._hoverState
=== HoverState
.SHOW
) {
467 }, context
.config
.delay
.show
);
470 Tooltip
.prototype._leave
= function _leave(event
, context
) {
471 var dataKey
= this.constructor.DATA_KEY
;
473 context
= context
|| $(event
.currentTarget
).data(dataKey
);
476 context
= new this.constructor(event
.currentTarget
, this._getDelegateConfig());
477 $(event
.currentTarget
).data(dataKey
, context
);
481 context
._activeTrigger
[event
.type
=== 'focusout' ? Trigger
.FOCUS
: Trigger
.HOVER
] = false;
484 if (context
._isWithActiveTrigger()) {
488 clearTimeout(context
._timeout
);
490 context
._hoverState
= HoverState
.OUT
;
492 if (!context
.config
.delay
|| !context
.config
.delay
.hide
) {
497 context
._timeout
= setTimeout(function () {
498 if (context
._hoverState
=== HoverState
.OUT
) {
501 }, context
.config
.delay
.hide
);
504 Tooltip
.prototype._isWithActiveTrigger
= function _isWithActiveTrigger() {
505 for (var trigger
in this._activeTrigger
) {
506 if (this._activeTrigger
[trigger
]) {
514 Tooltip
.prototype._getConfig
= function _getConfig(config
) {
515 config
= $.extend({}, this.constructor.Default
, $(this.element
).data(), config
);
517 if (config
.delay
&& typeof config
.delay
=== 'number') {
524 Util
.typeCheckConfig(NAME
, config
, this.constructor.DefaultType
);
529 Tooltip
.prototype._getDelegateConfig
= function _getDelegateConfig() {
533 for (var key
in this.config
) {
534 if (this.constructor.Default
[key
] !== this.config
[key
]) {
535 config
[key
] = this.config
[key
];
545 Tooltip
._jQueryInterface
= function _jQueryInterface(config
) {
546 return this.each(function () {
547 var data
= $(this).data(DATA_KEY
);
548 var _config
= (typeof config
=== 'undefined' ? 'undefined' : _typeof(config
)) === 'object' && config
;
550 if (!data
&& /dispose|hide/.test(config
)) {
555 data
= new Tooltip(this, _config
);
556 $(this).data(DATA_KEY
, data
);
559 if (typeof config
=== 'string') {
560 if (data
[config
] === undefined) {
561 throw new Error('No method named "' + config
+ '"');
568 _createClass(Tooltip
, null, [{
570 get: function get() {
575 get: function get() {
580 get: function get() {
585 get: function get() {
590 get: function get() {
595 get: function get() {
600 get: function get() {
609 * ------------------------------------------------------------------------
611 * ------------------------------------------------------------------------
614 $.fn
[NAME
] = Tooltip
._jQueryInterface
;
615 $.fn
[NAME
].Constructor
= Tooltip
;
616 $.fn
[NAME
].noConflict = function () {
617 $.fn
[NAME
] = JQUERY_NO_CONFLICT
;
618 return Tooltip
._jQueryInterface
;
622 }(jQuery
); /* global Tether */
623 //# sourceMappingURL=tooltip.js.map