Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
/**
1
/**
2
 * --------------------------------------------------------------------------
2
 * --------------------------------------------------------------------------
3
 * Bootstrap (v4.6.2): toast.js
3
 * Bootstrap toast.js
4
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
4
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
 * --------------------------------------------------------------------------
5
 * --------------------------------------------------------------------------
6
 */
6
 */
Línea 7... Línea 7...
7
 
7
 
8
import $ from 'jquery'
8
import BaseComponent from './base-component'
-
 
9
import EventHandler from './dom/event-handler'
-
 
10
import { enableDismissTrigger } from './util/component-functions'
Línea 9... Línea 11...
9
import Util from './util'
11
import { defineJQueryPlugin, reflow } from './util/index'
10
 
12
 
11
/**
13
/**
Línea 12... Línea 14...
12
 * Constants
14
 * Constants
13
 */
-
 
14
 
15
 */
15
const NAME = 'toast'
16
 
16
const VERSION = '4.6.2'
-
 
Línea 17... Línea -...
17
const DATA_KEY = 'bs.toast'
-
 
18
const EVENT_KEY = `.${DATA_KEY}`
17
const NAME = 'toast'
19
const JQUERY_NO_CONFLICT = $.fn[NAME]
18
const DATA_KEY = 'bs.toast'
20
 
19
const EVENT_KEY = `.${DATA_KEY}`
21
const CLASS_NAME_FADE = 'fade'
-
 
22
const CLASS_NAME_HIDE = 'hide'
20
 
23
const CLASS_NAME_SHOW = 'show'
21
const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`
24
const CLASS_NAME_SHOWING = 'showing'
22
const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`
25
 
23
const EVENT_FOCUSIN = `focusin${EVENT_KEY}`
26
const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
24
const EVENT_FOCUSOUT = `focusout${EVENT_KEY}`
Línea 27... Línea 25...
27
const EVENT_HIDE = `hide${EVENT_KEY}`
25
const EVENT_HIDE = `hide${EVENT_KEY}`
28
const EVENT_HIDDEN = `hidden${EVENT_KEY}`
-
 
-
 
26
const EVENT_HIDDEN = `hidden${EVENT_KEY}`
29
const EVENT_SHOW = `show${EVENT_KEY}`
27
const EVENT_SHOW = `show${EVENT_KEY}`
30
const EVENT_SHOWN = `shown${EVENT_KEY}`
28
const EVENT_SHOWN = `shown${EVENT_KEY}`
31
 
-
 
32
const SELECTOR_DATA_DISMISS = '[data-dismiss="toast"]'
-
 
33
 
-
 
Línea 34... Línea 29...
34
const Default = {
29
 
35
  animation: true,
30
const CLASS_NAME_FADE = 'fade'
36
  autohide: true,
31
const CLASS_NAME_HIDE = 'hide' // @deprecated - kept here only for backwards compatibility
37
  delay: 500
32
const CLASS_NAME_SHOW = 'show'
38
}
33
const CLASS_NAME_SHOWING = 'showing'
Línea -... Línea 34...
-
 
34
 
-
 
35
const DefaultType = {
-
 
36
  animation: 'boolean',
-
 
37
  autohide: 'boolean',
-
 
38
  delay: 'number'
-
 
39
}
39
 
40
 
40
const DefaultType = {
41
const Default = {
41
  animation: 'boolean',
42
  animation: true,
Línea 42... Línea 43...
42
  autohide: 'boolean',
43
  autohide: true,
43
  delay: 'number'
44
  delay: 5000
44
}
45
}
45
 
-
 
-
 
46
 
46
/**
47
/**
-
 
48
 * Class definition
-
 
49
 */
47
 * Class definition
50
 
48
 */
51
class Toast extends BaseComponent {
Línea 49... Línea 52...
49
 
52
  constructor(element, config) {
50
class Toast {
53
    super(element, config)
51
  constructor(element, config) {
54
 
52
    this._element = element
55
    this._timeout = null
Línea 53... Línea 56...
53
    this._config = this._getConfig(config)
56
    this._hasMouseInteraction = false
54
    this._timeout = null
57
    this._hasKeyboardInteraction = false
55
    this._setListeners()
58
    this._setListeners()
Línea 56... Línea 59...
56
  }
59
  }
57
 
60
 
58
  // Getters
61
  // Getters
Línea 59... Línea 62...
59
  static get VERSION() {
62
  static get Default() {
60
    return VERSION
63
    return Default
61
  }
64
  }
Línea 62... Línea -...
62
 
-
 
63
  static get DefaultType() {
65
 
64
    return DefaultType
66
  static get DefaultType() {
65
  }
67
    return DefaultType
Línea 66... Línea 68...
66
 
68
  }
Línea 83... Línea 85...
83
      this._element.classList.add(CLASS_NAME_FADE)
85
      this._element.classList.add(CLASS_NAME_FADE)
84
    }
86
    }
Línea 85... Línea 87...
85
 
87
 
86
    const complete = () => {
88
    const complete = () => {
87
      this._element.classList.remove(CLASS_NAME_SHOWING)
89
      this._element.classList.remove(CLASS_NAME_SHOWING)
Línea 88... Línea -...
88
      this._element.classList.add(CLASS_NAME_SHOW)
-
 
89
 
-
 
90
      $(this._element).trigger(EVENT_SHOWN)
90
      EventHandler.trigger(this._element, EVENT_SHOWN)
91
 
-
 
92
      if (this._config.autohide) {
-
 
93
        this._timeout = setTimeout(() => {
-
 
94
          this.hide()
-
 
95
        }, this._config.delay)
91
 
Línea 96... Línea 92...
96
      }
92
      this._maybeScheduleHide()
97
    }
93
    }
98
 
94
 
99
    this._element.classList.remove(CLASS_NAME_HIDE)
-
 
100
    Util.reflow(this._element)
-
 
Línea 101... Línea -...
101
    this._element.classList.add(CLASS_NAME_SHOWING)
-
 
102
    if (this._config.animation) {
-
 
103
      const transitionDuration = Util.getTransitionDurationFromElement(this._element)
95
    this._element.classList.remove(CLASS_NAME_HIDE) // @deprecated
104
 
-
 
105
      $(this._element)
-
 
106
        .one(Util.TRANSITION_END, complete)
-
 
107
        .emulateTransitionEnd(transitionDuration)
96
    reflow(this._element)
Línea 108... Línea 97...
108
    } else {
97
    this._element.classList.add(CLASS_NAME_SHOW, CLASS_NAME_SHOWING)
109
      complete()
98
 
110
    }
99
    this._queueCallback(complete, this._element, this._config.animation)
111
  }
100
  }
Línea 112... Línea 101...
112
 
101
 
Línea 113... Línea -...
113
  hide() {
-
 
114
    if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
102
  hide() {
115
      return
103
    if (!this.isShown()) {
116
    }
104
      return
Línea 117... Línea 105...
117
 
105
    }
-
 
106
 
-
 
107
    const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE)
-
 
108
 
-
 
109
    if (hideEvent.defaultPrevented) {
-
 
110
      return
-
 
111
    }
-
 
112
 
118
    const hideEvent = $.Event(EVENT_HIDE)
113
    const complete = () => {
Línea 119... Línea 114...
119
 
114
      this._element.classList.add(CLASS_NAME_HIDE) // @deprecated
120
    $(this._element).trigger(hideEvent)
115
      this._element.classList.remove(CLASS_NAME_SHOWING, CLASS_NAME_SHOW)
Línea 121... Línea 116...
121
    if (hideEvent.isDefaultPrevented()) {
116
      EventHandler.trigger(this._element, EVENT_HIDDEN)
122
      return
117
    }
123
    }
118
 
Línea 124... Línea 119...
124
 
119
    this._element.classList.add(CLASS_NAME_SHOWING)
-
 
120
    this._queueCallback(complete, this._element, this._config.animation)
Línea 125... Línea -...
125
    this._close()
-
 
126
  }
121
  }
127
 
122
 
128
  dispose() {
123
  dispose() {
Línea 129... Línea 124...
129
    this._clearTimeout()
124
    this._clearTimeout()
-
 
125
 
130
 
126
    if (this.isShown()) {
131
    if (this._element.classList.contains(CLASS_NAME_SHOW)) {
127
      this._element.classList.remove(CLASS_NAME_SHOW)
132
      this._element.classList.remove(CLASS_NAME_SHOW)
128
    }
133
    }
-
 
134
 
-
 
135
    $(this._element).off(EVENT_CLICK_DISMISS)
129
 
Línea 136... Línea 130...
136
 
130
    super.dispose()
137
    $.removeData(this._element, DATA_KEY)
131
  }
138
    this._element = null
-
 
139
    this._config = null
-
 
140
  }
132
 
Línea -... Línea 133...
-
 
133
  isShown() {
141
 
134
    return this._element.classList.contains(CLASS_NAME_SHOW)
-
 
135
  }
142
  // Private
136
 
Línea -... Línea 137...
-
 
137
  // Private
143
  _getConfig(config) {
138
 
-
 
139
  _maybeScheduleHide() {
-
 
140
    if (!this._config.autohide) {
144
    config = {
141
      return
-
 
142
    }
145
      ...Default,
143
 
Línea 146... Línea 144...
146
      ...$(this._element).data(),
144
    if (this._hasMouseInteraction || this._hasKeyboardInteraction) {
147
      ...(typeof config === 'object' && config ? config : {})
145
      return
148
    }
146
    }
-
 
147
 
-
 
148
    this._timeout = setTimeout(() => {
-
 
149
      this.hide()
149
 
150
    }, this._config.delay)
-
 
151
  }
-
 
152
 
150
    Util.typeCheckConfig(
153
  _onInteraction(event, isInteracting) {
Línea 151... Línea 154...
151
      NAME,
154
    switch (event.type) {
152
      config,
155
      case 'mouseover':
153
      this.constructor.DefaultType
156
      case 'mouseout': {
-
 
157
        this._hasMouseInteraction = isInteracting
Línea 154... Línea -...
154
    )
-
 
155
 
158
        break
156
    return config
159
      }
157
  }
-
 
158
 
160
 
159
  _setListeners() {
161
      case 'focusin':
-
 
162
      case 'focusout': {
-
 
163
        this._hasKeyboardInteraction = isInteracting
-
 
164
        break
-
 
165
      }
-
 
166
 
-
 
167
      default: {
-
 
168
        break
-
 
169
      }
-
 
170
    }
160
    $(this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, () => this.hide())
171
 
Línea 161... Línea 172...
161
  }
172
    if (isInteracting) {
162
 
173
      this._clearTimeout()
163
  _close() {
174
      return
164
    const complete = () => {
175
    }
Línea 165... Línea 176...
165
      this._element.classList.add(CLASS_NAME_HIDE)
176
 
166
      $(this._element).trigger(EVENT_HIDDEN)
177
    const nextElement = event.relatedTarget
167
    }
178
    if (this._element === nextElement || this._element.contains(nextElement)) {
168
 
-
 
169
    this._element.classList.remove(CLASS_NAME_SHOW)
-
 
170
    if (this._config.animation) {
-
 
171
      const transitionDuration = Util.getTransitionDurationFromElement(this._element)
-
 
172
 
-
 
173
      $(this._element)
179
      return
174
        .one(Util.TRANSITION_END, complete)
-
 
175
        .emulateTransitionEnd(transitionDuration)
-
 
Línea 176... Línea 180...
176
    } else {
180
    }
177
      complete()
181
 
178
    }
182
    this._maybeScheduleHide()
179
  }
183
  }
Línea 205... Línea 209...
205
    })
209
    })
206
  }
210
  }
207
}
211
}
Línea 208... Línea 212...
208
 
212
 
-
 
213
/**
-
 
214
 * Data API implementation
-
 
215
 */
-
 
216
 
-
 
217
enableDismissTrigger(Toast)
-
 
218
 
209
/**
219
/**
210
 * jQuery
220
 * jQuery
Línea 211... Línea -...
211
 */
-
 
212
 
221
 */
213
$.fn[NAME] = Toast._jQueryInterface
-
 
214
$.fn[NAME].Constructor = Toast
-
 
215
$.fn[NAME].noConflict = () => {
-
 
216
  $.fn[NAME] = JQUERY_NO_CONFLICT
-
 
Línea 217... Línea 222...
217
  return Toast._jQueryInterface
222