alert.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* ========================================================================
  2. * Bootstrap: alert.js v3.1.1
  3. * http://getbootstrap.com/javascript/#alerts
  4. * ========================================================================
  5. * Copyright 2011-2014 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.prototype.close = function (e) {
  17. var $this = $(this)
  18. var selector = $this.attr('data-target')
  19. if (!selector) {
  20. selector = $this.attr('href')
  21. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
  22. }
  23. var $parent = $(selector)
  24. if (e) e.preventDefault()
  25. if (!$parent.length) {
  26. $parent = $this.hasClass('alert') ? $this : $this.parent()
  27. }
  28. $parent.trigger(e = $.Event('close.bs.alert'))
  29. if (e.isDefaultPrevented()) return
  30. $parent.removeClass('in')
  31. function removeElement() {
  32. $parent.trigger('closed.bs.alert').remove()
  33. }
  34. $.support.transition && $parent.hasClass('fade') ?
  35. $parent
  36. .one($.support.transition.end, removeElement)
  37. .emulateTransitionEnd(150) :
  38. removeElement()
  39. }
  40. // ALERT PLUGIN DEFINITION
  41. // =======================
  42. var old = $.fn.alert
  43. $.fn.alert = function (option) {
  44. return this.each(function () {
  45. var $this = $(this)
  46. var data = $this.data('bs.alert')
  47. if (!data) $this.data('bs.alert', (data = new Alert(this)))
  48. if (typeof option == 'string') data[option].call($this)
  49. })
  50. }
  51. $.fn.alert.Constructor = Alert
  52. // ALERT NO CONFLICT
  53. // =================
  54. $.fn.alert.noConflict = function () {
  55. $.fn.alert = old
  56. return this
  57. }
  58. // ALERT DATA-API
  59. // ==============
  60. $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close)
  61. }(jQuery);