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