1
0

bootstrap-alert.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* ==========================================================
  2. * bootstrap-alert.js v2.3.2
  3. * http://getbootstrap.com/2.3.2/javascript.html#alerts
  4. * ==========================================================
  5. * Copyright 2013 Twitter, Inc.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ========================================================== */
  19. !function ($) {
  20. "use strict"; // jshint ;_;
  21. /* ALERT CLASS DEFINITION
  22. * ====================== */
  23. var dismiss = '[data-dismiss="alert"]'
  24. , Alert = function (el) {
  25. $(el).on('click', dismiss, this.close)
  26. }
  27. Alert.prototype.close = function (e) {
  28. var $this = $(this)
  29. , selector = $this.attr('data-target')
  30. , $parent
  31. if (!selector) {
  32. selector = $this.attr('href')
  33. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
  34. }
  35. $parent = $(selector)
  36. e && e.preventDefault()
  37. $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
  38. $parent.trigger(e = $.Event('close'))
  39. if (e.isDefaultPrevented()) return
  40. $parent.removeClass('in')
  41. function removeElement() {
  42. $parent
  43. .trigger('closed')
  44. .remove()
  45. }
  46. $.support.transition && $parent.hasClass('fade') ?
  47. $parent.on($.support.transition.end, removeElement) :
  48. removeElement()
  49. }
  50. /* ALERT PLUGIN DEFINITION
  51. * ======================= */
  52. var old = $.fn.alert
  53. $.fn.alert = function (option) {
  54. return this.each(function () {
  55. var $this = $(this)
  56. , data = $this.data('alert')
  57. if (!data) $this.data('alert', (data = new Alert(this)))
  58. if (typeof option == 'string') data[option].call($this)
  59. })
  60. }
  61. $.fn.alert.Constructor = Alert
  62. /* ALERT NO CONFLICT
  63. * ================= */
  64. $.fn.alert.noConflict = function () {
  65. $.fn.alert = old
  66. return this
  67. }
  68. /* ALERT DATA-API
  69. * ============== */
  70. $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)
  71. }(window.jQuery);