[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  import { E as EventHandler, d as defineJQueryPlugin, B as BaseComponent } from './dom.js?5.1.3';
   2  
   3  /**
   4   * --------------------------------------------------------------------------
   5   * Bootstrap (v5.1.3): button.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 = 'button';
  16  const DATA_KEY = 'bs.button';
  17  const EVENT_KEY = `.$DATA_KEY}`;
  18  const DATA_API_KEY = '.data-api';
  19  const CLASS_NAME_ACTIVE = 'active';
  20  const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="button"]';
  21  const EVENT_CLICK_DATA_API = `click$EVENT_KEY}$DATA_API_KEY}`;
  22  /**
  23   * ------------------------------------------------------------------------
  24   * Class Definition
  25   * ------------------------------------------------------------------------
  26   */
  27  
  28  class Button extends BaseComponent {
  29    // Getters
  30    static get NAME() {
  31      return NAME;
  32    } // Public
  33  
  34  
  35    toggle() {
  36      // Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
  37      this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE));
  38    } // Static
  39  
  40  
  41    static jQueryInterface(config) {
  42      return this.each(function () {
  43        const data = Button.getOrCreateInstance(this);
  44  
  45        if (config === 'toggle') {
  46          data[config]();
  47        }
  48      });
  49    }
  50  
  51  }
  52  /**
  53   * ------------------------------------------------------------------------
  54   * Data Api implementation
  55   * ------------------------------------------------------------------------
  56   */
  57  
  58  
  59  EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, event => {
  60    event.preventDefault();
  61    const button = event.target.closest(SELECTOR_DATA_TOGGLE);
  62    const data = Button.getOrCreateInstance(button);
  63    data.toggle();
  64  });
  65  /**
  66   * ------------------------------------------------------------------------
  67   * jQuery
  68   * ------------------------------------------------------------------------
  69   * add .Button to jQuery only if jQuery is present
  70   */
  71  
  72  defineJQueryPlugin(Button);
  73  
  74  window.bootstrap = window.bootstrap || {};
  75  window.bootstrap.Button = Button;
  76  
  77  if (Joomla && Joomla.getOptions) {
  78    // Get the elements/configurations from the PHP
  79    const buttons = Joomla.getOptions('bootstrap.button'); // Initialise the elements
  80  
  81    if (buttons && buttons.length) {
  82      buttons.forEach(selector => {
  83        Array.from(document.querySelectorAll(selector)).map(el => new window.bootstrap.Button(el));
  84      });
  85    }
  86  }
  87  
  88  export { Button as B };


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