PageSourceSearch

https://support.zabbix.com/includes/jira/eventDeferrer/eventDeferrer.js

js zabbix.com collected 2026-09-24 15:21:05 UTC 5,239 bytes, 110 lines download raw bytes

1function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
2function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4/**
5 * This module is responsible for deferring events on elements that have data-queued-click attribute.
6 * This can be useful when we want to queue events on elements that are not ready to be clicked yet, e.g. legacy add comment button.
7 *
8 * Assumptions:
9 * - we are only interested in two interactive elements - <a/> and <button/>
10 * - we are only interested in elements that have data-queued-click attribute
11 * - we are only interested in click events (which can be triggered by keyboard as well)
12 */
13(function () {
14  "use strict";
15
16  var QUEUED_CALLBACK_DATA_ATTRIBUTE = 'data-queued-click';
17  /**
18   * Only one callback should exist, as we don't want the user to queue multiple events at once
19   * and then have them triggered at the same time
20   */
21  var callbackToDefer;
22
23  /**
24   * The element that we want to potentially observe for deferring callbacks.
25   *
26   * @param event {Event}
27   * @returns {Element | null}
28   */
29  function getInteractiveElement(event) {
30    var isInteractive = ['A', 'BUTTON'].some(function (tagName) {
31      return event.target.tagName === tagName;
32    });
33    if (isInteractive) {
34      return event.target;
35    }
36    return event.target.closest('a, button');
37  }
38  function triggerCallback() {
39    callbackToDefer && callbackToDefer();
40    callbackToDefer = null;
41  }
42
43  /**
44   * Observes elements and triggers the callback only when other piece of code removes the {@link QUEUED_CALLBACK_DATA_ATTRIBUTE} attribute.
45   *
46   * @type {MutationObserver}
47   */
48  var mutationObserver = new MutationObserver(function (mutationsList, observer) {
49    var _iterator = _createForOfIteratorHelper(mutationsList),
50      _step;
51    try {
52      for (_iterator.s(); !(_step = _iterator.n()).done;) {
53        var mutation = _step.value;
54        if (mutation.type === 'attributes' && !mutation.target.hasAttribute(QUEUED_CALLBACK_DATA_ATTRIBUTE)) {
55          triggerCallback();
56          observer.disconnect();
57        }
58      }
59    } catch (err) {
60      _iterator.e(err);
61    } finally {
62      _iterator.f();
63    }
64  });
65  function disconnectObserver() {
66    callbackToDefer = null;
67    mutationObserver.disconnect();
68  }
69
70  /**
71   * The main piece of logic.
72   * If we don't detect interactive element with {@link QUEUED_CALLBACK_DATA_ATTRIBUTE} attribute, we don't do anything.
73   * Otherwise, we prevent the default action and stop the propagation of the event, store the callback to defer and start observing the element.
74   * When the element gets rid of {@link QUEUED_CALLBACK_DATA_ATTRIBUTE}, we trigger the callback and disconnect the observer.
75   *
76   * @param event
77   */
78  var clickHandler = function clickHandler(event) {
79    disconnectObserver();
80    var interactiveElement = getInteractiveElement(event);
81    // check event target and closest element for data-queued-click
82    var shouldDeferEventCallback = interactiveElement && interactiveElement.dataset.hasOwnProperty('queuedCl
82ick');
83    if (!shouldDeferEventCallback) {
84      return;
85    }
86    event.preventDefault();
87    event.stopPropagation();
88    callbackToDefer = function callbackToDefer() {
89      return interactiveElement.click();
90    };
91    document.body.addEventListener('keydown', disconnectObserver, {
92      once: true,
93      passive: true,
94      capture: true
95    });
96    mutationObserver.observe(interactiveElement, {
97      attributes: true
98    });
99  };
100  document.addEventListener('click', clickHandler, true);
101  window.resourcePhaseCheckpoint.interaction.then(function () {
102    // We delegate the callback to the next tick, so that the code that loads together with interaction phase
103    // triggers first, and then we can trigger the callback and disconnect the event deferrer.
104    setTimeout(function () {
105      document.removeEventListener('click', clickHandler, true);
106      triggerCallback();
107      disconnectObserver();
108    });
109  });
110})();

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.