assets/javascripts/bootstrap/alert.js
changeset 114 af15590802a4
equal deleted inserted replaced
113:d4ec02c51c91 114:af15590802a4
       
     1 /* ========================================================================
       
     2  * Bootstrap: alert.js v3.3.5
       
     3  * http://getbootstrap.com/javascript/#alerts
       
     4  * ========================================================================
       
     5  * Copyright 2011-2015 Twitter, Inc.
       
     6  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
       
     7  * ======================================================================== */
       
     8 
       
     9 
       
    10 +function ($) {
       
    11   'use strict';
       
    12 
       
    13   // ALERT CLASS DEFINITION
       
    14   // ======================
       
    15 
       
    16   var dismiss = '[data-dismiss="alert"]'
       
    17   var Alert   = function (el) {
       
    18     $(el).on('click', dismiss, this.close)
       
    19   }
       
    20 
       
    21   Alert.VERSION = '3.3.5'
       
    22 
       
    23   Alert.TRANSITION_DURATION = 150
       
    24 
       
    25   Alert.prototype.close = function (e) {
       
    26     var $this    = $(this)
       
    27     var selector = $this.attr('data-target')
       
    28 
       
    29     if (!selector) {
       
    30       selector = $this.attr('href')
       
    31       selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
       
    32     }
       
    33 
       
    34     var $parent = $(selector)
       
    35 
       
    36     if (e) e.preventDefault()
       
    37 
       
    38     if (!$parent.length) {
       
    39       $parent = $this.closest('.alert')
       
    40     }
       
    41 
       
    42     $parent.trigger(e = $.Event('close.bs.alert'))
       
    43 
       
    44     if (e.isDefaultPrevented()) return
       
    45 
       
    46     $parent.removeClass('in')
       
    47 
       
    48     function removeElement() {
       
    49       // detach from parent, fire event then clean up data
       
    50       $parent.detach().trigger('closed.bs.alert').remove()
       
    51     }
       
    52 
       
    53     $.support.transition && $parent.hasClass('fade') ?
       
    54       $parent
       
    55         .one('bsTransitionEnd', removeElement)
       
    56         .emulateTransitionEnd(Alert.TRANSITION_DURATION) :
       
    57       removeElement()
       
    58   }
       
    59 
       
    60 
       
    61   // ALERT PLUGIN DEFINITION
       
    62   // =======================
       
    63 
       
    64   function Plugin(option) {
       
    65     return this.each(function () {
       
    66       var $this = $(this)
       
    67       var data  = $this.data('bs.alert')
       
    68 
       
    69       if (!data) $this.data('bs.alert', (data = new Alert(this)))
       
    70       if (typeof option == 'string') data[option].call($this)
       
    71     })
       
    72   }
       
    73 
       
    74   var old = $.fn.alert
       
    75 
       
    76   $.fn.alert             = Plugin
       
    77   $.fn.alert.Constructor = Alert
       
    78 
       
    79 
       
    80   // ALERT NO CONFLICT
       
    81   // =================
       
    82 
       
    83   $.fn.alert.noConflict = function () {
       
    84     $.fn.alert = old
       
    85     return this
       
    86   }
       
    87 
       
    88 
       
    89   // ALERT DATA-API
       
    90   // ==============
       
    91 
       
    92   $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close)
       
    93 
       
    94 }(jQuery);