Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ignitetch
GitHub Repository: ignitetch/advphishing
Path: blob/master/sites/whatsapp-phishing/vendor/bootstrap/js/tooltip.js
739 views
1
/**!
2
* @fileOverview Kickass library to create and place poppers near their reference elements.
3
* @version 1.1.5
4
* @license
5
* Copyright (c) 2016 Federico Zivolo and contributors
6
*
7
* Permission is hereby granted, free of charge, to any person obtaining a copy
8
* of this software and associated documentation files (the "Software"), to deal
9
* in the Software without restriction, including without limitation the rights
10
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
* copies of the Software, and to permit persons to whom the Software is
12
* furnished to do so, subject to the following conditions:
13
*
14
* The above copyright notice and this permission notice shall be included in all
15
* copies or substantial portions of the Software.
16
*
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
* SOFTWARE.
24
*/
25
(function (global, factory) {
26
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('popper.js')) :
27
typeof define === 'function' && define.amd ? define(['popper.js'], factory) :
28
(global.Tooltip = factory(global.Popper));
29
}(this, (function (Popper) { 'use strict';
30
31
Popper = Popper && 'default' in Popper ? Popper['default'] : Popper;
32
33
/**
34
* Check if the given variable is a function
35
* @method
36
* @memberof Popper.Utils
37
* @argument {Any} functionToCheck - variable to check
38
* @returns {Boolean} answer to: is a function?
39
*/
40
function isFunction(functionToCheck) {
41
var getType = {};
42
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
43
}
44
45
var classCallCheck = function (instance, Constructor) {
46
if (!(instance instanceof Constructor)) {
47
throw new TypeError("Cannot call a class as a function");
48
}
49
};
50
51
var createClass = function () {
52
function defineProperties(target, props) {
53
for (var i = 0; i < props.length; i++) {
54
var descriptor = props[i];
55
descriptor.enumerable = descriptor.enumerable || false;
56
descriptor.configurable = true;
57
if ("value" in descriptor) descriptor.writable = true;
58
Object.defineProperty(target, descriptor.key, descriptor);
59
}
60
}
61
62
return function (Constructor, protoProps, staticProps) {
63
if (protoProps) defineProperties(Constructor.prototype, protoProps);
64
if (staticProps) defineProperties(Constructor, staticProps);
65
return Constructor;
66
};
67
}();
68
69
70
71
72
73
74
75
var _extends = Object.assign || function (target) {
76
for (var i = 1; i < arguments.length; i++) {
77
var source = arguments[i];
78
79
for (var key in source) {
80
if (Object.prototype.hasOwnProperty.call(source, key)) {
81
target[key] = source[key];
82
}
83
}
84
}
85
86
return target;
87
};
88
89
var DEFAULT_OPTIONS = {
90
container: false,
91
delay: 0,
92
html: false,
93
placement: 'top',
94
title: '',
95
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
96
trigger: 'hover focus',
97
offset: 0
98
};
99
100
var Tooltip = function () {
101
/**
102
* Create a new Tooltip.js instance
103
* @class Tooltip
104
* @param {HTMLElement} reference - The DOM node used as reference of the tooltip (it can be a jQuery element).
105
* @param {Object} options
106
* @param {String} options.placement=bottom
107
* Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -end),
108
* left(-start, -end)`
109
* @param {HTMLElement|String|false} options.container=false - Append the tooltip to a specific element.
110
* @param {Number|Object} options.delay=0
111
* Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type.
112
* If a number is supplied, delay is applied to both hide/show.
113
* Object structure is: `{ show: 500, hide: 100 }`
114
* @param {Boolean} options.html=false - Insert HTML into the tooltip. If false, the content will inserted with `innerText`.
115
* @param {String|PlacementFunction} options.placement='top' - One of the allowed placements, or a function returning one of them.
116
* @param {String} [options.template='<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>']
117
* Base HTML to used when creating the tooltip.
118
* The tooltip's `title` will be injected into the `.tooltip-inner` or `.tooltip__inner`.
119
* `.tooltip-arrow` or `.tooltip__arrow` will become the tooltip's arrow.
120
* The outermost wrapper element should have the `.tooltip` class.
121
* @param {String|HTMLElement|TitleFunction} options.title='' - Default title value if `title` attribute isn't present.
122
* @param {String} [options.trigger='hover focus']
123
* How tooltip is triggered - click, hover, focus, manual.
124
* You may pass multiple triggers; separate them with a space. `manual` cannot be combined with any other trigger.
125
* @param {HTMLElement} options.boundariesElement
126
* The element used as boundaries for the tooltip. For more information refer to Popper.js'
127
* [boundariesElement docs](https://popper.js.org/popper-documentation.html)
128
* @param {Number|String} options.offset=0 - Offset of the tooltip relative to its reference. For more information refer to Popper.js'
129
* [offset docs](https://popper.js.org/popper-documentation.html)
130
* @param {Object} options.popperOptions={} - Popper options, will be passed directly to popper instance. For more information refer to Popper.js'
131
* [options docs](https://popper.js.org/popper-documentation.html)
132
* @return {Object} instance - The generated tooltip instance
133
*/
134
function Tooltip(reference, options) {
135
classCallCheck(this, Tooltip);
136
137
_initialiseProps.call(this);
138
139
// apply user options over default ones
140
options = _extends({}, DEFAULT_OPTIONS, options);
141
142
reference.jquery && (reference = reference[0]);
143
144
// cache reference and options
145
this.reference = reference;
146
this.options = options;
147
148
// get events list
149
var events = typeof options.trigger === 'string' ? options.trigger.split(' ').filter(function (trigger) {
150
return ['click', 'hover', 'focus'].indexOf(trigger) !== -1;
151
}) : [];
152
153
// set initial state
154
this._isOpen = false;
155
156
// set event listeners
157
this._setEventListeners(reference, events, options);
158
}
159
160
//
161
// Public methods
162
//
163
164
/**
165
* Reveals an element's tooltip. This is considered a "manual" triggering of the tooltip.
166
* Tooltips with zero-length titles are never displayed.
167
* @method Tooltip#show
168
* @memberof Tooltip
169
*/
170
171
172
/**
173
* Hides an element’s tooltip. This is considered a “manual” triggering of the tooltip.
174
* @method Tooltip#hide
175
* @memberof Tooltip
176
*/
177
178
179
/**
180
* Hides and destroys an element’s tooltip.
181
* @method Tooltip#dispose
182
* @memberof Tooltip
183
*/
184
185
186
/**
187
* Toggles an element’s tooltip. This is considered a “manual” triggering of the tooltip.
188
* @method Tooltip#toggle
189
* @memberof Tooltip
190
*/
191
192
193
//
194
// Defaults
195
//
196
197
198
//
199
// Private methods
200
//
201
202
createClass(Tooltip, [{
203
key: '_create',
204
205
206
/**
207
* Creates a new tooltip node
208
* @memberof Tooltip
209
* @private
210
* @param {HTMLElement} reference
211
* @param {String} template
212
* @param {String|HTMLElement|TitleFunction} title
213
* @param {Boolean} allowHtml
214
* @return {HTMLelement} tooltipNode
215
*/
216
value: function _create(reference, template, title, allowHtml) {
217
// create tooltip element
218
var tooltipGenerator = window.document.createElement('div');
219
tooltipGenerator.innerHTML = template.trim();
220
var tooltipNode = tooltipGenerator.childNodes[0];
221
222
// add unique ID to our tooltip (needed for accessibility reasons)
223
tooltipNode.id = 'tooltip_' + Math.random().toString(36).substr(2, 10);
224
225
// set initial `aria-hidden` state to `false` (it's visible!)
226
tooltipNode.setAttribute('aria-hidden', 'false');
227
228
// add title to tooltip
229
var titleNode = tooltipGenerator.querySelector(this.innerSelector);
230
if (title.nodeType === 1) {
231
// if title is a node, append it only if allowHtml is true
232
allowHtml && titleNode.appendChild(title);
233
} else if (isFunction(title)) {
234
// if title is a function, call it and set innerText or innerHtml depending by `allowHtml` value
235
var titleText = title.call(reference);
236
allowHtml ? titleNode.innerHTML = titleText : titleNode.innerText = titleText;
237
} else {
238
// if it's just a simple text, set innerText or innerHtml depending by `allowHtml` value
239
allowHtml ? titleNode.innerHTML = title : titleNode.innerText = title;
240
}
241
242
// return the generated tooltip node
243
return tooltipNode;
244
}
245
}, {
246
key: '_show',
247
value: function _show(reference, options) {
248
// don't show if it's already visible
249
if (this._isOpen) {
250
return this;
251
}
252
this._isOpen = true;
253
254
// if the tooltipNode already exists, just show it
255
if (this._tooltipNode) {
256
this._tooltipNode.style.display = '';
257
this._tooltipNode.setAttribute('aria-hidden', 'false');
258
this.popperInstance.update();
259
return this;
260
}
261
262
// get title
263
var title = reference.getAttribute('title') || options.title;
264
265
// don't show tooltip if no title is defined
266
if (!title) {
267
return this;
268
}
269
270
// create tooltip node
271
var tooltipNode = this._create(reference, options.template, title, options.html);
272
273
// Add `aria-describedby` to our reference element for accessibility reasons
274
reference.setAttribute('aria-describedby', tooltipNode.id);
275
276
// append tooltip to container
277
var container = this._findContainer(options.container, reference);
278
279
this._append(tooltipNode, container);
280
281
var popperOptions = _extends({}, options.popperOptions, {
282
placement: options.placement
283
});
284
285
popperOptions.modifiers = _extends({}, popperOptions.modifiers, {
286
arrow: {
287
element: this.arrowSelector
288
}
289
});
290
291
if (options.boundariesElement) {
292
popperOptions.modifiers.preventOverflow = {
293
boundariesElement: options.boundariesElement
294
};
295
}
296
297
this.popperInstance = new Popper(reference, tooltipNode, popperOptions);
298
299
this._tooltipNode = tooltipNode;
300
301
return this;
302
}
303
}, {
304
key: '_hide',
305
value: function _hide() /*reference, options*/{
306
// don't hide if it's already hidden
307
if (!this._isOpen) {
308
return this;
309
}
310
311
this._isOpen = false;
312
313
// hide tooltipNode
314
this._tooltipNode.style.display = 'none';
315
this._tooltipNode.setAttribute('aria-hidden', 'true');
316
317
return this;
318
}
319
}, {
320
key: '_dispose',
321
value: function _dispose() {
322
var _this = this;
323
324
if (this._tooltipNode) {
325
this._hide();
326
327
// destroy instance
328
this.popperInstance.destroy();
329
330
// remove event listeners
331
this._events.forEach(function (_ref) {
332
var func = _ref.func,
333
event = _ref.event;
334
335
_this.reference.removeEventListener(event, func);
336
});
337
this._events = [];
338
339
// destroy tooltipNode
340
this._tooltipNode.parentNode.removeChild(this._tooltipNode);
341
this._tooltipNode = null;
342
}
343
return this;
344
}
345
}, {
346
key: '_findContainer',
347
value: function _findContainer(container, reference) {
348
// if container is a query, get the relative element
349
if (typeof container === 'string') {
350
container = window.document.querySelector(container);
351
} else if (container === false) {
352
// if container is `false`, set it to reference parent
353
container = reference.parentNode;
354
}
355
return container;
356
}
357
358
/**
359
* Append tooltip to container
360
* @memberof Tooltip
361
* @private
362
* @param {HTMLElement} tooltip
363
* @param {HTMLElement|String|false} container
364
*/
365
366
}, {
367
key: '_append',
368
value: function _append(tooltipNode, container) {
369
container.appendChild(tooltipNode);
370
}
371
}, {
372
key: '_setEventListeners',
373
value: function _setEventListeners(reference, events, options) {
374
var _this2 = this;
375
376
var directEvents = [];
377
var oppositeEvents = [];
378
379
events.forEach(function (event) {
380
switch (event) {
381
case 'hover':
382
directEvents.push('mouseenter');
383
oppositeEvents.push('mouseleave');
384
break;
385
case 'focus':
386
directEvents.push('focus');
387
oppositeEvents.push('blur');
388
break;
389
case 'click':
390
directEvents.push('click');
391
oppositeEvents.push('click');
392
break;
393
}
394
});
395
396
// schedule show tooltip
397
directEvents.forEach(function (event) {
398
var func = function func(evt) {
399
if (_this2._isOpen === true) {
400
return;
401
}
402
evt.usedByTooltip = true;
403
_this2._scheduleShow(reference, options.delay, options, evt);
404
};
405
_this2._events.push({ event: event, func: func });
406
reference.addEventListener(event, func);
407
});
408
409
// schedule hide tooltip
410
oppositeEvents.forEach(function (event) {
411
var func = function func(evt) {
412
if (evt.usedByTooltip === true) {
413
return;
414
}
415
_this2._scheduleHide(reference, options.delay, options, evt);
416
};
417
_this2._events.push({ event: event, func: func });
418
reference.addEventListener(event, func);
419
});
420
}
421
}, {
422
key: '_scheduleShow',
423
value: function _scheduleShow(reference, delay, options /*, evt */) {
424
var _this3 = this;
425
426
// defaults to 0
427
var computedDelay = delay && delay.show || delay || 0;
428
window.setTimeout(function () {
429
return _this3._show(reference, options);
430
}, computedDelay);
431
}
432
}, {
433
key: '_scheduleHide',
434
value: function _scheduleHide(reference, delay, options, evt) {
435
var _this4 = this;
436
437
// defaults to 0
438
var computedDelay = delay && delay.hide || delay || 0;
439
window.setTimeout(function () {
440
if (_this4._isOpen === false) {
441
return;
442
}
443
if (!document.body.contains(_this4._tooltipNode)) {
444
return;
445
}
446
447
// if we are hiding because of a mouseleave, we must check that the new
448
// reference isn't the tooltip, because in this case we don't want to hide it
449
if (evt.type === 'mouseleave') {
450
var isSet = _this4._setTooltipNodeEvent(evt, reference, delay, options);
451
452
// if we set the new event, don't hide the tooltip yet
453
// the new event will take care to hide it if necessary
454
if (isSet) {
455
return;
456
}
457
}
458
459
_this4._hide(reference, options);
460
}, computedDelay);
461
}
462
}]);
463
return Tooltip;
464
}();
465
466
/**
467
* Placement function, its context is the Tooltip instance.
468
* @memberof Tooltip
469
* @callback PlacementFunction
470
* @param {HTMLElement} tooltip - tooltip DOM node.
471
* @param {HTMLElement} reference - reference DOM node.
472
* @return {String} placement - One of the allowed placement options.
473
*/
474
475
/**
476
* Title function, its context is the Tooltip instance.
477
* @memberof Tooltip
478
* @callback TitleFunction
479
* @return {String} placement - The desired title.
480
*/
481
482
483
var _initialiseProps = function _initialiseProps() {
484
var _this5 = this;
485
486
this.show = function () {
487
return _this5._show(_this5.reference, _this5.options);
488
};
489
490
this.hide = function () {
491
return _this5._hide();
492
};
493
494
this.dispose = function () {
495
return _this5._dispose();
496
};
497
498
this.toggle = function () {
499
if (_this5._isOpen) {
500
return _this5.hide();
501
} else {
502
return _this5.show();
503
}
504
};
505
506
this.arrowSelector = '.tooltip-arrow, .tooltip__arrow';
507
this.innerSelector = '.tooltip-inner, .tooltip__inner';
508
this._events = [];
509
510
this._setTooltipNodeEvent = function (evt, reference, delay, options) {
511
var relatedreference = evt.relatedreference || evt.toElement;
512
513
var callback = function callback(evt2) {
514
var relatedreference2 = evt2.relatedreference || evt2.toElement;
515
516
// Remove event listener after call
517
_this5._tooltipNode.removeEventListener(evt.type, callback);
518
519
// If the new reference is not the reference element
520
if (!reference.contains(relatedreference2)) {
521
// Schedule to hide tooltip
522
_this5._scheduleHide(reference, options.delay, options, evt2);
523
}
524
};
525
526
if (_this5._tooltipNode.contains(relatedreference)) {
527
// listen to mouseleave on the tooltip element to be able to hide the tooltip
528
_this5._tooltipNode.addEventListener(evt.type, callback);
529
return true;
530
}
531
532
return false;
533
};
534
};
535
536
return Tooltip;
537
538
})));
539
//# sourceMappingURL=tooltip.js.map
540
541