PageSourceSearch

https://poraj.com/sklep/wp-content/plugins/tubapay-v2/assets/js/tooltip.js?ver=4.0.0

js poraj.com collected 2026-10-02 22:33:53 UTC 4,248 bytes, 128 lines download raw bytes

1/**
2 * TubaPay Tooltip — gateway icon tooltip on checkout.
3 *
4 * Provides:
5 *   - TubaPayTooltip class
6 *   - Auto-initializes tooltips on page load
7 */
8(function () {
9    'use strict';
10
11    /**
12     * Poll for an element to appear in the DOM.
13     * @param {string} selector
14     * @param {function(Element)} callback
15     * @param {number} [interval=200]
16     * @param {number} [timeout=10000]
17     */
18    function waitForElement(selector, callback, interval, timeout) {
19        interval = interval || 200;
20        timeout = timeout || 10000;
21        var start = Date.now();
22
23        var timer = setInterval(function () {
24            var el = document.querySelector(selector);
25            if (el) {
26                clearInterval(timer);
27                callback(el);
28            } else if (Date.now() - start > timeout) {
29                clearInterval(timer);
30            }
31        }, interval);
32    }
33
34    class TubaPayTooltip {
35        constructor() {
36            this.videoPopup = new TubaPayVideoPopup();
37            this._boundClickOutside = null;
38            this._popupOpened = null;
39            this._popupClosed = null;
40        }
41
42        showTooltip() {
43            var tooltip = document.querySelector('.custom-gateway-tooltip');
44            var trigger = document.querySelector('.custom-gateway-tooltip-trigger');
45
46            if (!tooltip || !trigger) {
47                return;
48            }
49
50            tooltip.classList.toggle('mm-show');
51            trigger.classList.toggle('mm-show');
52
53            this._bindEvents();
54
55            var self = this;
56            this._popupOpened = function () { self._unbindEvents(); };
57            this._popupClosed = function () { self._bindEvents(); };
58
59            document.addEventListener('popupOpened', this._popupOpened);
60            document.addEventListener('popupClosed', this._popupClosed);
61        }
62
63        hideTooltip() {
64            var tooltip = document.querySelector('.custom-gateway-tooltip');
65            var trigger = document.querySelector('.custom-gateway-tooltip-trigger');
66
67            if (tooltip) tooltip.classList.remove('mm-show');
68            if (trigger) trigger.classList.remove('mm-show');
69
70            this._unbindEvents();
71
72            if (this._popupOpened) {
73                document.removeEventListener('popupOpened', this._popupOpened);
74            }
75            if (this._popupClosed) {
76                document.removeEventListener('popupClosed', this._popupClosed);
77            }
78        }
79
80        _bindEvents() {
81            var self = this;
82            this._boundClickOutside = function (event) {
83                if (
84                    !event.target.closest('.custom-gateway-tooltip') &&
85                    !event.target.closest('.custom-gateway-tooltip-trigger')
86                ) {
87                    self.hideTooltip();
88                }
89            };
90
91            setTimeout(function () {
92                document.addEventListener('click', self._boundClickOutside, true);
93            }, 0);
94
95            // Video popup trigger inside tooltip
96            var popupTrigger = document.querySelector('.custom-gateway-tooltip .mn-tuba-popup-trigger');
97            if (popupTrigger) {
98                popupTrigger.addEventListener('click', function (event) {
99                    event.preventDefault();
100                    self.videoPopup.showVideoPopup(event);
101                });
102            }
103        }
104
105        _unbindEvents() {
106            if (this._boundClickOutside) {
107                document.removeEventListener('click', this._boundClickOutside, true);
108            }
109        }
110    }
111
112    // Expose globally for inline scripts
113    window.TubaPayTooltip = TubaPayTooltip;
114
115    // Auto-initialize tooltip clicks on page load
116    document.addEventListener('DOMContentLoaded', function () {
117        waitForElement('.custom-gateway-tooltip-trigger', function () {
118            var tooltip = new TubaPayTooltip();
119            var trigger = document.querySelector('.custom-gateway-tooltip-trigger');
120            if (trigger) {
121                trigger.addEventListener('click', function (event) {
122                    event.preventDefault();
123                    tooltip.showTooltip();
124                });
125            }
126        });
127    });
128})();

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.