ffffng/app/bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert.js

96 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2014-05-12 20:08:19 +02:00
/* ========================================================================
2019-03-29 22:00:08 +01:00
* Bootstrap: alert.js v3.4.1
* https://getbootstrap.com/docs/3.4/javascript/#alerts
2014-05-12 20:08:19 +02:00
* ========================================================================
2019-03-29 22:00:08 +01:00
* Copyright 2011-2019 Twitter, Inc.
2014-05-12 20:08:19 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */
+function ($) {
'use strict';
// ALERT CLASS DEFINITION
// ======================
var dismiss = '[data-dismiss="alert"]'
var Alert = function (el) {
$(el).on('click', dismiss, this.close)
}
2019-03-29 22:00:08 +01:00
Alert.VERSION = '3.4.1'
2016-05-16 13:33:49 +02:00
Alert.TRANSITION_DURATION = 150
2014-08-10 12:02:48 +02:00
2014-05-12 20:08:19 +02:00
Alert.prototype.close = function (e) {
var $this = $(this)
var selector = $this.attr('data-target')
if (!selector) {
selector = $this.attr('href')
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
}
2019-03-29 22:00:08 +01:00
selector = selector === '#' ? [] : selector
var $parent = $(document).find(selector)
2014-05-12 20:08:19 +02:00
if (e) e.preventDefault()
if (!$parent.length) {
2016-05-16 13:33:49 +02:00
$parent = $this.closest('.alert')
2014-05-12 20:08:19 +02:00
}
$parent.trigger(e = $.Event('close.bs.alert'))
if (e.isDefaultPrevented()) return
$parent.removeClass('in')
function removeElement() {
2014-08-10 12:02:48 +02:00
// detach from parent, fire event then clean up data
$parent.detach().trigger('closed.bs.alert').remove()
2014-05-12 20:08:19 +02:00
}
$.support.transition && $parent.hasClass('fade') ?
$parent
2014-08-10 12:02:48 +02:00
.one('bsTransitionEnd', removeElement)
2016-05-16 13:33:49 +02:00
.emulateTransitionEnd(Alert.TRANSITION_DURATION) :
2014-05-12 20:08:19 +02:00
removeElement()
}
// ALERT PLUGIN DEFINITION
// =======================
2014-08-10 12:02:48 +02:00
function Plugin(option) {
2014-05-12 20:08:19 +02:00
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.alert')
if (!data) $this.data('bs.alert', (data = new Alert(this)))
if (typeof option == 'string') data[option].call($this)
})
}
2014-08-10 12:02:48 +02:00
var old = $.fn.alert
$.fn.alert = Plugin
2014-05-12 20:08:19 +02:00
$.fn.alert.Constructor = Alert
// ALERT NO CONFLICT
// =================
$.fn.alert.noConflict = function () {
$.fn.alert = old
return this
}
// ALERT DATA-API
// ==============
$(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close)
}(jQuery);