Path: blob/master/sites/whatsapp-phishing/vendor/bootstrap/js/tooltip.js
739 views
/**!1* @fileOverview Kickass library to create and place poppers near their reference elements.2* @version 1.1.53* @license4* Copyright (c) 2016 Federico Zivolo and contributors5*6* Permission is hereby granted, free of charge, to any person obtaining a copy7* of this software and associated documentation files (the "Software"), to deal8* in the Software without restriction, including without limitation the rights9* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell10* copies of the Software, and to permit persons to whom the Software is11* furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included in all14* copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE19* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22* SOFTWARE.23*/24(function (global, factory) {25typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('popper.js')) :26typeof define === 'function' && define.amd ? define(['popper.js'], factory) :27(global.Tooltip = factory(global.Popper));28}(this, (function (Popper) { 'use strict';2930Popper = Popper && 'default' in Popper ? Popper['default'] : Popper;3132/**33* Check if the given variable is a function34* @method35* @memberof Popper.Utils36* @argument {Any} functionToCheck - variable to check37* @returns {Boolean} answer to: is a function?38*/39function isFunction(functionToCheck) {40var getType = {};41return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';42}4344var classCallCheck = function (instance, Constructor) {45if (!(instance instanceof Constructor)) {46throw new TypeError("Cannot call a class as a function");47}48};4950var createClass = function () {51function defineProperties(target, props) {52for (var i = 0; i < props.length; i++) {53var descriptor = props[i];54descriptor.enumerable = descriptor.enumerable || false;55descriptor.configurable = true;56if ("value" in descriptor) descriptor.writable = true;57Object.defineProperty(target, descriptor.key, descriptor);58}59}6061return function (Constructor, protoProps, staticProps) {62if (protoProps) defineProperties(Constructor.prototype, protoProps);63if (staticProps) defineProperties(Constructor, staticProps);64return Constructor;65};66}();6768697071727374var _extends = Object.assign || function (target) {75for (var i = 1; i < arguments.length; i++) {76var source = arguments[i];7778for (var key in source) {79if (Object.prototype.hasOwnProperty.call(source, key)) {80target[key] = source[key];81}82}83}8485return target;86};8788var DEFAULT_OPTIONS = {89container: false,90delay: 0,91html: false,92placement: 'top',93title: '',94template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',95trigger: 'hover focus',96offset: 097};9899var Tooltip = function () {100/**101* Create a new Tooltip.js instance102* @class Tooltip103* @param {HTMLElement} reference - The DOM node used as reference of the tooltip (it can be a jQuery element).104* @param {Object} options105* @param {String} options.placement=bottom106* Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -end),107* left(-start, -end)`108* @param {HTMLElement|String|false} options.container=false - Append the tooltip to a specific element.109* @param {Number|Object} options.delay=0110* Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type.111* If a number is supplied, delay is applied to both hide/show.112* Object structure is: `{ show: 500, hide: 100 }`113* @param {Boolean} options.html=false - Insert HTML into the tooltip. If false, the content will inserted with `innerText`.114* @param {String|PlacementFunction} options.placement='top' - One of the allowed placements, or a function returning one of them.115* @param {String} [options.template='<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>']116* Base HTML to used when creating the tooltip.117* The tooltip's `title` will be injected into the `.tooltip-inner` or `.tooltip__inner`.118* `.tooltip-arrow` or `.tooltip__arrow` will become the tooltip's arrow.119* The outermost wrapper element should have the `.tooltip` class.120* @param {String|HTMLElement|TitleFunction} options.title='' - Default title value if `title` attribute isn't present.121* @param {String} [options.trigger='hover focus']122* How tooltip is triggered - click, hover, focus, manual.123* You may pass multiple triggers; separate them with a space. `manual` cannot be combined with any other trigger.124* @param {HTMLElement} options.boundariesElement125* The element used as boundaries for the tooltip. For more information refer to Popper.js'126* [boundariesElement docs](https://popper.js.org/popper-documentation.html)127* @param {Number|String} options.offset=0 - Offset of the tooltip relative to its reference. For more information refer to Popper.js'128* [offset docs](https://popper.js.org/popper-documentation.html)129* @param {Object} options.popperOptions={} - Popper options, will be passed directly to popper instance. For more information refer to Popper.js'130* [options docs](https://popper.js.org/popper-documentation.html)131* @return {Object} instance - The generated tooltip instance132*/133function Tooltip(reference, options) {134classCallCheck(this, Tooltip);135136_initialiseProps.call(this);137138// apply user options over default ones139options = _extends({}, DEFAULT_OPTIONS, options);140141reference.jquery && (reference = reference[0]);142143// cache reference and options144this.reference = reference;145this.options = options;146147// get events list148var events = typeof options.trigger === 'string' ? options.trigger.split(' ').filter(function (trigger) {149return ['click', 'hover', 'focus'].indexOf(trigger) !== -1;150}) : [];151152// set initial state153this._isOpen = false;154155// set event listeners156this._setEventListeners(reference, events, options);157}158159//160// Public methods161//162163/**164* Reveals an element's tooltip. This is considered a "manual" triggering of the tooltip.165* Tooltips with zero-length titles are never displayed.166* @method Tooltip#show167* @memberof Tooltip168*/169170171/**172* Hides an element’s tooltip. This is considered a “manual” triggering of the tooltip.173* @method Tooltip#hide174* @memberof Tooltip175*/176177178/**179* Hides and destroys an element’s tooltip.180* @method Tooltip#dispose181* @memberof Tooltip182*/183184185/**186* Toggles an element’s tooltip. This is considered a “manual” triggering of the tooltip.187* @method Tooltip#toggle188* @memberof Tooltip189*/190191192//193// Defaults194//195196197//198// Private methods199//200201createClass(Tooltip, [{202key: '_create',203204205/**206* Creates a new tooltip node207* @memberof Tooltip208* @private209* @param {HTMLElement} reference210* @param {String} template211* @param {String|HTMLElement|TitleFunction} title212* @param {Boolean} allowHtml213* @return {HTMLelement} tooltipNode214*/215value: function _create(reference, template, title, allowHtml) {216// create tooltip element217var tooltipGenerator = window.document.createElement('div');218tooltipGenerator.innerHTML = template.trim();219var tooltipNode = tooltipGenerator.childNodes[0];220221// add unique ID to our tooltip (needed for accessibility reasons)222tooltipNode.id = 'tooltip_' + Math.random().toString(36).substr(2, 10);223224// set initial `aria-hidden` state to `false` (it's visible!)225tooltipNode.setAttribute('aria-hidden', 'false');226227// add title to tooltip228var titleNode = tooltipGenerator.querySelector(this.innerSelector);229if (title.nodeType === 1) {230// if title is a node, append it only if allowHtml is true231allowHtml && titleNode.appendChild(title);232} else if (isFunction(title)) {233// if title is a function, call it and set innerText or innerHtml depending by `allowHtml` value234var titleText = title.call(reference);235allowHtml ? titleNode.innerHTML = titleText : titleNode.innerText = titleText;236} else {237// if it's just a simple text, set innerText or innerHtml depending by `allowHtml` value238allowHtml ? titleNode.innerHTML = title : titleNode.innerText = title;239}240241// return the generated tooltip node242return tooltipNode;243}244}, {245key: '_show',246value: function _show(reference, options) {247// don't show if it's already visible248if (this._isOpen) {249return this;250}251this._isOpen = true;252253// if the tooltipNode already exists, just show it254if (this._tooltipNode) {255this._tooltipNode.style.display = '';256this._tooltipNode.setAttribute('aria-hidden', 'false');257this.popperInstance.update();258return this;259}260261// get title262var title = reference.getAttribute('title') || options.title;263264// don't show tooltip if no title is defined265if (!title) {266return this;267}268269// create tooltip node270var tooltipNode = this._create(reference, options.template, title, options.html);271272// Add `aria-describedby` to our reference element for accessibility reasons273reference.setAttribute('aria-describedby', tooltipNode.id);274275// append tooltip to container276var container = this._findContainer(options.container, reference);277278this._append(tooltipNode, container);279280var popperOptions = _extends({}, options.popperOptions, {281placement: options.placement282});283284popperOptions.modifiers = _extends({}, popperOptions.modifiers, {285arrow: {286element: this.arrowSelector287}288});289290if (options.boundariesElement) {291popperOptions.modifiers.preventOverflow = {292boundariesElement: options.boundariesElement293};294}295296this.popperInstance = new Popper(reference, tooltipNode, popperOptions);297298this._tooltipNode = tooltipNode;299300return this;301}302}, {303key: '_hide',304value: function _hide() /*reference, options*/{305// don't hide if it's already hidden306if (!this._isOpen) {307return this;308}309310this._isOpen = false;311312// hide tooltipNode313this._tooltipNode.style.display = 'none';314this._tooltipNode.setAttribute('aria-hidden', 'true');315316return this;317}318}, {319key: '_dispose',320value: function _dispose() {321var _this = this;322323if (this._tooltipNode) {324this._hide();325326// destroy instance327this.popperInstance.destroy();328329// remove event listeners330this._events.forEach(function (_ref) {331var func = _ref.func,332event = _ref.event;333334_this.reference.removeEventListener(event, func);335});336this._events = [];337338// destroy tooltipNode339this._tooltipNode.parentNode.removeChild(this._tooltipNode);340this._tooltipNode = null;341}342return this;343}344}, {345key: '_findContainer',346value: function _findContainer(container, reference) {347// if container is a query, get the relative element348if (typeof container === 'string') {349container = window.document.querySelector(container);350} else if (container === false) {351// if container is `false`, set it to reference parent352container = reference.parentNode;353}354return container;355}356357/**358* Append tooltip to container359* @memberof Tooltip360* @private361* @param {HTMLElement} tooltip362* @param {HTMLElement|String|false} container363*/364365}, {366key: '_append',367value: function _append(tooltipNode, container) {368container.appendChild(tooltipNode);369}370}, {371key: '_setEventListeners',372value: function _setEventListeners(reference, events, options) {373var _this2 = this;374375var directEvents = [];376var oppositeEvents = [];377378events.forEach(function (event) {379switch (event) {380case 'hover':381directEvents.push('mouseenter');382oppositeEvents.push('mouseleave');383break;384case 'focus':385directEvents.push('focus');386oppositeEvents.push('blur');387break;388case 'click':389directEvents.push('click');390oppositeEvents.push('click');391break;392}393});394395// schedule show tooltip396directEvents.forEach(function (event) {397var func = function func(evt) {398if (_this2._isOpen === true) {399return;400}401evt.usedByTooltip = true;402_this2._scheduleShow(reference, options.delay, options, evt);403};404_this2._events.push({ event: event, func: func });405reference.addEventListener(event, func);406});407408// schedule hide tooltip409oppositeEvents.forEach(function (event) {410var func = function func(evt) {411if (evt.usedByTooltip === true) {412return;413}414_this2._scheduleHide(reference, options.delay, options, evt);415};416_this2._events.push({ event: event, func: func });417reference.addEventListener(event, func);418});419}420}, {421key: '_scheduleShow',422value: function _scheduleShow(reference, delay, options /*, evt */) {423var _this3 = this;424425// defaults to 0426var computedDelay = delay && delay.show || delay || 0;427window.setTimeout(function () {428return _this3._show(reference, options);429}, computedDelay);430}431}, {432key: '_scheduleHide',433value: function _scheduleHide(reference, delay, options, evt) {434var _this4 = this;435436// defaults to 0437var computedDelay = delay && delay.hide || delay || 0;438window.setTimeout(function () {439if (_this4._isOpen === false) {440return;441}442if (!document.body.contains(_this4._tooltipNode)) {443return;444}445446// if we are hiding because of a mouseleave, we must check that the new447// reference isn't the tooltip, because in this case we don't want to hide it448if (evt.type === 'mouseleave') {449var isSet = _this4._setTooltipNodeEvent(evt, reference, delay, options);450451// if we set the new event, don't hide the tooltip yet452// the new event will take care to hide it if necessary453if (isSet) {454return;455}456}457458_this4._hide(reference, options);459}, computedDelay);460}461}]);462return Tooltip;463}();464465/**466* Placement function, its context is the Tooltip instance.467* @memberof Tooltip468* @callback PlacementFunction469* @param {HTMLElement} tooltip - tooltip DOM node.470* @param {HTMLElement} reference - reference DOM node.471* @return {String} placement - One of the allowed placement options.472*/473474/**475* Title function, its context is the Tooltip instance.476* @memberof Tooltip477* @callback TitleFunction478* @return {String} placement - The desired title.479*/480481482var _initialiseProps = function _initialiseProps() {483var _this5 = this;484485this.show = function () {486return _this5._show(_this5.reference, _this5.options);487};488489this.hide = function () {490return _this5._hide();491};492493this.dispose = function () {494return _this5._dispose();495};496497this.toggle = function () {498if (_this5._isOpen) {499return _this5.hide();500} else {501return _this5.show();502}503};504505this.arrowSelector = '.tooltip-arrow, .tooltip__arrow';506this.innerSelector = '.tooltip-inner, .tooltip__inner';507this._events = [];508509this._setTooltipNodeEvent = function (evt, reference, delay, options) {510var relatedreference = evt.relatedreference || evt.toElement;511512var callback = function callback(evt2) {513var relatedreference2 = evt2.relatedreference || evt2.toElement;514515// Remove event listener after call516_this5._tooltipNode.removeEventListener(evt.type, callback);517518// If the new reference is not the reference element519if (!reference.contains(relatedreference2)) {520// Schedule to hide tooltip521_this5._scheduleHide(reference, options.delay, options, evt2);522}523};524525if (_this5._tooltipNode.contains(relatedreference)) {526// listen to mouseleave on the tooltip element to be able to hide the tooltip527_this5._tooltipNode.addEventListener(evt.type, callback);528return true;529}530531return false;532};533};534535return Tooltip;536537})));538//# sourceMappingURL=tooltip.js.map539540541