[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/vendor/joomla-custom-elements/js/ -> joomla-alert-es5.js (source)

   1  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
   2  
   3  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
   4  
   5  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
   6  
   7  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
   8  
   9  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10  
  11  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); } }
  12  
  13  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  14  
  15  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  16  
  17  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  18  
  19  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  20  
  21  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  22  
  23  function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
  24  
  25  function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
  26  
  27  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  28  
  29  function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
  30  
  31  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  32  
  33  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  34  
  35  var AlertElement = /*#__PURE__*/function (_HTMLElement) {
  36    _inherits(AlertElement, _HTMLElement);
  37  
  38    var _super = _createSuper(AlertElement);
  39  
  40    function AlertElement() {
  41      var _this;
  42  
  43      _classCallCheck(this, AlertElement);
  44  
  45      _this = _super.call(this); // Bindings
  46  
  47      _this.close = _this.close.bind(_assertThisInitialized(_this));
  48      _this.destroyCloseButton = _this.destroyCloseButton.bind(_assertThisInitialized(_this));
  49      _this.createCloseButton = _this.createCloseButton.bind(_assertThisInitialized(_this));
  50      _this.onMutation = _this.onMutation.bind(_assertThisInitialized(_this));
  51      _this.observer = new MutationObserver(_this.onMutation);
  52  
  53      _this.observer.observe(_assertThisInitialized(_this), {
  54        attributes: false,
  55        childList: true,
  56        subtree: true
  57      }); // Handle the fade in animation
  58  
  59  
  60      _this.addEventListener('animationend', function (event) {
  61        if (event.animationName === 'joomla-alert-fade-in' && event.target === _assertThisInitialized(_this)) {
  62          _this.dispatchEvent(new CustomEvent('joomla.alert.shown'));
  63  
  64          _this.style.removeProperty('animationName');
  65        }
  66      }); // Handle the fade out animation
  67  
  68  
  69      _this.addEventListener('animationend', function (event) {
  70        if (event.animationName === 'joomla-alert-fade-out' && event.target === _assertThisInitialized(_this)) {
  71          _this.dispatchEvent(new CustomEvent('joomla.alert.closed'));
  72  
  73          _this.remove();
  74        }
  75      });
  76  
  77      return _this;
  78    }
  79    /* Attributes to monitor */
  80  
  81  
  82    _createClass(AlertElement, [{
  83      key: "type",
  84      get: function get() {
  85        return this.getAttribute('type');
  86      },
  87      set: function set(value) {
  88        this.setAttribute('type', value);
  89      }
  90    }, {
  91      key: "role",
  92      get: function get() {
  93        return this.getAttribute('role');
  94      },
  95      set: function set(value) {
  96        this.setAttribute('role', value);
  97      }
  98    }, {
  99      key: "closeText",
 100      get: function get() {
 101        return this.getAttribute('close-text');
 102      },
 103      set: function set(value) {
 104        this.setAttribute('close-text', value);
 105      }
 106    }, {
 107      key: "dismiss",
 108      get: function get() {
 109        return this.getAttribute('dismiss');
 110      },
 111      set: function set(value) {
 112        this.setAttribute('dismiss', value);
 113      }
 114    }, {
 115      key: "autodismiss",
 116      get: function get() {
 117        return this.getAttribute('auto-dismiss');
 118      },
 119      set: function set(value) {
 120        this.setAttribute('auto-dismiss', value);
 121      }
 122      /* Lifecycle, element appended to the DOM */
 123  
 124    }, {
 125      key: "connectedCallback",
 126      value: function connectedCallback() {
 127        this.dispatchEvent(new CustomEvent('joomla.alert.show'));
 128        this.style.animationName = 'joomla-alert-fade-in'; // Default to info
 129  
 130        if (!this.type || !['info', 'warning', 'danger', 'success'].includes(this.type)) {
 131          this.setAttribute('type', 'info');
 132        } // Default to alert
 133  
 134  
 135        if (!this.role || !['alert', 'alertdialog'].includes(this.role)) {
 136          this.setAttribute('role', 'alert');
 137        } // Hydrate the button
 138  
 139  
 140        if (this.firstElementChild && this.firstElementChild.tagName === 'BUTTON') {
 141          this.button = this.firstElementChild;
 142  
 143          if (this.button.classList.contains('joomla-alert--close')) {
 144            this.button.classList.add('joomla-alert--close');
 145          }
 146  
 147          if (this.button.innerHTML === '') {
 148            this.button.innerHTML = '<span aria-hidden="true">&times;</span>';
 149          }
 150  
 151          if (!this.button.hasAttribute('aria-label')) {
 152            this.button.setAttribute('aria-label', this.closeText);
 153          }
 154        } // Append button
 155  
 156  
 157        if (this.hasAttribute('dismiss') && !this.button) {
 158          this.createCloseButton();
 159        }
 160  
 161        if (this.hasAttribute('auto-dismiss')) {
 162          this.autoDismiss();
 163        }
 164      }
 165      /* Lifecycle, element removed from the DOM */
 166  
 167    }, {
 168      key: "disconnectedCallback",
 169      value: function disconnectedCallback() {
 170        if (this.button) {
 171          this.button.removeEventListener('click', this.close);
 172        }
 173  
 174        this.observer.disconnect();
 175      }
 176      /* Respond to attribute changes */
 177  
 178    }, {
 179      key: "attributeChangedCallback",
 180      value: function attributeChangedCallback(attr, oldValue, newValue) {
 181        switch (attr) {
 182          case 'type':
 183            if (!newValue || newValue && ['info', 'warning', 'danger', 'success'].indexOf(newValue) === -1) {
 184              this.type = 'info';
 185            }
 186  
 187            break;
 188  
 189          case 'role':
 190            if (!newValue || newValue && ['alert', 'alertdialog'].indexOf(newValue) === -1) {
 191              this.role = 'alert';
 192            }
 193  
 194            break;
 195  
 196          case 'dismiss':
 197            if ((!newValue || newValue === '') && (!oldValue || oldValue === '')) {
 198              if (this.button && !this.hasAttribute('dismiss')) {
 199                this.destroyCloseButton();
 200              } else if (!this.button && this.hasAttribute('dismiss')) {
 201                this.createCloseButton();
 202              }
 203            } else if (this.button && newValue === 'false') {
 204              this.destroyCloseButton();
 205            } else if (!this.button && newValue !== 'false') {
 206              this.createCloseButton();
 207            }
 208  
 209            break;
 210  
 211          case 'close-text':
 212            if (!newValue || newValue !== oldValue) {
 213              if (this.button) {
 214                this.button.setAttribute('aria-label', newValue);
 215              }
 216            }
 217  
 218            break;
 219  
 220          case 'auto-dismiss':
 221            this.autoDismiss();
 222            break;
 223        }
 224      }
 225      /* Observe added elements */
 226  
 227    }, {
 228      key: "onMutation",
 229      value: function onMutation(mutationsList) {
 230        // eslint-disable-next-line no-restricted-syntax
 231        var _iterator = _createForOfIteratorHelper(mutationsList),
 232            _step;
 233  
 234        try {
 235          for (_iterator.s(); !(_step = _iterator.n()).done;) {
 236            var mutation = _step.value;
 237  
 238            if (mutation.type === 'childList') {
 239              if (mutation.addedNodes.length) {
 240                // Make sure that the button is always the first element
 241                if (this.button && this.firstElementChild !== this.button) {
 242                  this.prepend(this.button);
 243                }
 244              }
 245            }
 246          }
 247        } catch (err) {
 248          _iterator.e(err);
 249        } finally {
 250          _iterator.f();
 251        }
 252      }
 253      /* Method to close the alert */
 254  
 255    }, {
 256      key: "close",
 257      value: function close() {
 258        this.dispatchEvent(new CustomEvent('joomla.alert.close'));
 259        this.style.animationName = 'joomla-alert-fade-out';
 260      }
 261      /* Method to create the close button */
 262  
 263    }, {
 264      key: "createCloseButton",
 265      value: function createCloseButton() {
 266        this.button = document.createElement('button');
 267        this.button.setAttribute('type', 'button');
 268        this.button.classList.add('joomla-alert--close');
 269        this.button.innerHTML = '<span aria-hidden="true">&times;</span>';
 270        this.button.setAttribute('aria-label', this.closeText);
 271        this.insertAdjacentElement('afterbegin', this.button);
 272        /* Add the required listener */
 273  
 274        this.button.addEventListener('click', this.close);
 275      }
 276      /* Method to remove the close button */
 277  
 278    }, {
 279      key: "destroyCloseButton",
 280      value: function destroyCloseButton() {
 281        if (this.button) {
 282          this.button.removeEventListener('click', this.close);
 283          this.button.parentNode.removeChild(this.button);
 284          this.button = null;
 285        }
 286      }
 287      /* Method to auto-dismiss */
 288  
 289    }, {
 290      key: "autoDismiss",
 291      value: function autoDismiss() {
 292        var timer = parseInt(this.getAttribute('auto-dismiss'), 10);
 293        setTimeout(this.close, timer >= 10 ? timer : 3000);
 294      }
 295    }], [{
 296      key: "observedAttributes",
 297      get: function get() {
 298        return ['type', 'role', 'dismiss', 'auto-dismiss', 'close-text'];
 299      }
 300    }]);
 301  
 302    return AlertElement;
 303  }( /*#__PURE__*/_wrapNativeSuper(HTMLElement));
 304  
 305  if (!customElements.get('joomla-alert')) {
 306    customElements.define('joomla-alert', AlertElement);
 307  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer