alert.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* ========================================================================
  2. * Bootstrap: alert.js v3.4.1
  3. * https://getbootstrap.com/docs/3.4/javascript/#alerts
  4. * ========================================================================
  5. * Copyright 2011-2019 Twitter, Inc.
  6. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  7. * ======================================================================== */
  8. +function ($) {
  9. 'use strict';
  10. // ALERT CLASS DEFINITION
  11. // ======================
  12. var dismiss = '[data-dismiss="alert"]'
  13. var Alert = function (el) {
  14. $(el).on('click', dismiss, this.close)
  15. }
  16. Alert.VERSION = '3.4.1'
  17. Alert.TRANSITION_DURATION = 150
  18. Alert.prototype.close = function (e) {
  19. var $this = $(this)
  20. var selector = $this.attr('data-target')
  21. if (!selector) {
  22. selector = $this.attr('href')
  23. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
  24. }
  25. selector = selector === '#' ? [] : selector
  26. var $parent = $(document).find(selector)
  27. if (e) e.preventDefault()
  28. if (!$parent.length) {
  29. $parent = $this.closest('.alert')
  30. }
  31. $parent.trigger(e = $.Event('close.bs.alert'))
  32. if (e.isDefaultPrevented()) return
  33. $parent.removeClass('in')
  34. function removeElement() {
  35. // detach from parent, fire event then clean up data
  36. $parent.detach().trigger('closed.bs.alert').remove()
  37. }
  38. $.support.transition && $parent.hasClass('fade') ?
  39. $parent
  40. .one('bsTransitionEnd', removeElement)
  41. .emulateTransitionEnd(Alert.TRANSITION_DURATION) :
  42. removeElement()
  43. }
  44. // ALERT PLUGIN DEFINITION
  45. // =======================
  46. function Plugin(option) {
  47. return this.each(function () {
  48. var $this = $(this)
  49. var data = $this.data('bs.alert')
  50. if (!data) $this.data('bs.alert', (data = new Alert(this)))
  51. if (typeof option == 'string') data[option].call($this)
  52. })
  53. }
  54. var old = $.fn.alert
  55. $.fn.alert = Plugin
  56. $.fn.alert.Constructor = Alert
  57. // ALERT NO CONFLICT
  58. // =================
  59. $.fn.alert.noConflict = function () {
  60. $.fn.alert = old
  61. return this
  62. }
  63. // ALERT DATA-API
  64. // ==============
  65. $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close)
  66. }(jQuery);