[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/vendor/bootstrap/js/ -> toast.js (source)

   1  import { e as enableDismissTrigger, d as defineJQueryPlugin, B as BaseComponent, E as EventHandler, r as reflow, M as Manipulator, a as typeCheckConfig } from './dom.js?5.1.3';
   2  
   3  /**
   4   * --------------------------------------------------------------------------
   5   * Bootstrap (v5.1.3): toast.js
   6   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
   7   * --------------------------------------------------------------------------
   8   */
   9  /**
  10   * ------------------------------------------------------------------------
  11   * Constants
  12   * ------------------------------------------------------------------------
  13   */
  14  
  15  const NAME = 'toast';
  16  const DATA_KEY = 'bs.toast';
  17  const EVENT_KEY = `.$DATA_KEY}`;
  18  const EVENT_MOUSEOVER = `mouseover$EVENT_KEY}`;
  19  const EVENT_MOUSEOUT = `mouseout$EVENT_KEY}`;
  20  const EVENT_FOCUSIN = `focusin$EVENT_KEY}`;
  21  const EVENT_FOCUSOUT = `focusout$EVENT_KEY}`;
  22  const EVENT_HIDE = `hide$EVENT_KEY}`;
  23  const EVENT_HIDDEN = `hidden$EVENT_KEY}`;
  24  const EVENT_SHOW = `show$EVENT_KEY}`;
  25  const EVENT_SHOWN = `shown$EVENT_KEY}`;
  26  const CLASS_NAME_FADE = 'fade';
  27  const CLASS_NAME_HIDE = 'hide'; // @deprecated - kept here only for backwards compatibility
  28  
  29  const CLASS_NAME_SHOW = 'show';
  30  const CLASS_NAME_SHOWING = 'showing';
  31  const DefaultType = {
  32    animation: 'boolean',
  33    autohide: 'boolean',
  34    delay: 'number'
  35  };
  36  const Default = {
  37    animation: true,
  38    autohide: true,
  39    delay: 5000
  40  };
  41  /**
  42   * ------------------------------------------------------------------------
  43   * Class Definition
  44   * ------------------------------------------------------------------------
  45   */
  46  
  47  class Toast extends BaseComponent {
  48    constructor(element, config) {
  49      super(element);
  50      this._config = this._getConfig(config);
  51      this._timeout = null;
  52      this._hasMouseInteraction = false;
  53      this._hasKeyboardInteraction = false;
  54  
  55      this._setListeners();
  56    } // Getters
  57  
  58  
  59    static get DefaultType() {
  60      return DefaultType;
  61    }
  62  
  63    static get Default() {
  64      return Default;
  65    }
  66  
  67    static get NAME() {
  68      return NAME;
  69    } // Public
  70  
  71  
  72    show() {
  73      const showEvent = EventHandler.trigger(this._element, EVENT_SHOW);
  74  
  75      if (showEvent.defaultPrevented) {
  76        return;
  77      }
  78  
  79      this._clearTimeout();
  80  
  81      if (this._config.animation) {
  82        this._element.classList.add(CLASS_NAME_FADE);
  83      }
  84  
  85      const complete = () => {
  86        this._element.classList.remove(CLASS_NAME_SHOWING);
  87  
  88        EventHandler.trigger(this._element, EVENT_SHOWN);
  89  
  90        this._maybeScheduleHide();
  91      };
  92  
  93      this._element.classList.remove(CLASS_NAME_HIDE); // @deprecated
  94  
  95  
  96      reflow(this._element);
  97  
  98      this._element.classList.add(CLASS_NAME_SHOW);
  99  
 100      this._element.classList.add(CLASS_NAME_SHOWING);
 101  
 102      this._queueCallback(complete, this._element, this._config.animation);
 103    }
 104  
 105    hide() {
 106      if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
 107        return;
 108      }
 109  
 110      const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE);
 111  
 112      if (hideEvent.defaultPrevented) {
 113        return;
 114      }
 115  
 116      const complete = () => {
 117        this._element.classList.add(CLASS_NAME_HIDE); // @deprecated
 118  
 119  
 120        this._element.classList.remove(CLASS_NAME_SHOWING);
 121  
 122        this._element.classList.remove(CLASS_NAME_SHOW);
 123  
 124        EventHandler.trigger(this._element, EVENT_HIDDEN);
 125      };
 126  
 127      this._element.classList.add(CLASS_NAME_SHOWING);
 128  
 129      this._queueCallback(complete, this._element, this._config.animation);
 130    }
 131  
 132    dispose() {
 133      this._clearTimeout();
 134  
 135      if (this._element.classList.contains(CLASS_NAME_SHOW)) {
 136        this._element.classList.remove(CLASS_NAME_SHOW);
 137      }
 138  
 139      super.dispose();
 140    } // Private
 141  
 142  
 143    _getConfig(config) {
 144      config = { ...Default,
 145        ...Manipulator.getDataAttributes(this._element),
 146        ...(typeof config === 'object' && config ? config : {})
 147      };
 148      typeCheckConfig(NAME, config, this.constructor.DefaultType);
 149      return config;
 150    }
 151  
 152    _maybeScheduleHide() {
 153      if (!this._config.autohide) {
 154        return;
 155      }
 156  
 157      if (this._hasMouseInteraction || this._hasKeyboardInteraction) {
 158        return;
 159      }
 160  
 161      this._timeout = setTimeout(() => {
 162        this.hide();
 163      }, this._config.delay);
 164    }
 165  
 166    _onInteraction(event, isInteracting) {
 167      switch (event.type) {
 168        case 'mouseover':
 169        case 'mouseout':
 170          this._hasMouseInteraction = isInteracting;
 171          break;
 172  
 173        case 'focusin':
 174        case 'focusout':
 175          this._hasKeyboardInteraction = isInteracting;
 176          break;
 177      }
 178  
 179      if (isInteracting) {
 180        this._clearTimeout();
 181  
 182        return;
 183      }
 184  
 185      const nextElement = event.relatedTarget;
 186  
 187      if (this._element === nextElement || this._element.contains(nextElement)) {
 188        return;
 189      }
 190  
 191      this._maybeScheduleHide();
 192    }
 193  
 194    _setListeners() {
 195      EventHandler.on(this._element, EVENT_MOUSEOVER, event => this._onInteraction(event, true));
 196      EventHandler.on(this._element, EVENT_MOUSEOUT, event => this._onInteraction(event, false));
 197      EventHandler.on(this._element, EVENT_FOCUSIN, event => this._onInteraction(event, true));
 198      EventHandler.on(this._element, EVENT_FOCUSOUT, event => this._onInteraction(event, false));
 199    }
 200  
 201    _clearTimeout() {
 202      clearTimeout(this._timeout);
 203      this._timeout = null;
 204    } // Static
 205  
 206  
 207    static jQueryInterface(config) {
 208      return this.each(function () {
 209        const data = Toast.getOrCreateInstance(this, config);
 210  
 211        if (typeof config === 'string') {
 212          if (typeof data[config] === 'undefined') {
 213            throw new TypeError(`No method named "$config}"`);
 214          }
 215  
 216          data[config](this);
 217        }
 218      });
 219    }
 220  
 221  }
 222  
 223  enableDismissTrigger(Toast);
 224  /**
 225   * ------------------------------------------------------------------------
 226   * jQuery
 227   * ------------------------------------------------------------------------
 228   * add .Toast to jQuery only if jQuery is present
 229   */
 230  
 231  defineJQueryPlugin(Toast);
 232  
 233  window.bootstrap = window.bootstrap || {};
 234  window.bootstrap.Toast = Toast;
 235  
 236  if (Joomla && Joomla.getOptions) {
 237    // Get the elements/configurations from the PHP
 238    const toasts = Joomla.getOptions('bootstrap.toast'); // Initialise the elements
 239  
 240    if (typeof toasts === 'object' && toasts !== null) {
 241      Object.keys(toasts).forEach(toast => {
 242        const opt = toasts[toast];
 243        const options = {
 244          animation: opt.animation ? opt.animation : true,
 245          autohide: opt.autohide ? opt.autohide : true,
 246          delay: opt.delay ? opt.delay : 5000
 247        };
 248        const elements = Array.from(document.querySelectorAll(toast));
 249  
 250        if (elements.length) {
 251          elements.map(el => new window.bootstrap.Toast(el, options));
 252        }
 253      });
 254    }
 255  }
 256  
 257  export { Toast as T };


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