js/bootstrap-alert.js
changeset 0 ba8ab09f730e
equal deleted inserted replaced
-1:000000000000 0:ba8ab09f730e
       
     1 /* ==========================================================
       
     2  * bootstrap-alert.js v2.3.1
       
     3  * http://twitter.github.com/bootstrap/javascript.html#alerts
       
     4  * ==========================================================
       
     5  * Copyright 2012 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 
       
    20 
       
    21 !function ($) {
       
    22 
       
    23   "use strict"; // jshint ;_;
       
    24 
       
    25 
       
    26  /* ALERT CLASS DEFINITION
       
    27   * ====================== */
       
    28 
       
    29   var dismiss = '[data-dismiss="alert"]'
       
    30     , Alert = function (el) {
       
    31         $(el).on('click', dismiss, this.close)
       
    32       }
       
    33 
       
    34   Alert.prototype.close = function (e) {
       
    35     var $this = $(this)
       
    36       , selector = $this.attr('data-target')
       
    37       , $parent
       
    38 
       
    39     if (!selector) {
       
    40       selector = $this.attr('href')
       
    41       selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
       
    42     }
       
    43 
       
    44     $parent = $(selector)
       
    45 
       
    46     e && e.preventDefault()
       
    47 
       
    48     $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
       
    49 
       
    50     $parent.trigger(e = $.Event('close'))
       
    51 
       
    52     if (e.isDefaultPrevented()) return
       
    53 
       
    54     $parent.removeClass('in')
       
    55 
       
    56     function removeElement() {
       
    57       $parent
       
    58         .trigger('closed')
       
    59         .remove()
       
    60     }
       
    61 
       
    62     $.support.transition && $parent.hasClass('fade') ?
       
    63       $parent.on($.support.transition.end, removeElement) :
       
    64       removeElement()
       
    65   }
       
    66 
       
    67 
       
    68  /* ALERT PLUGIN DEFINITION
       
    69   * ======================= */
       
    70 
       
    71   var old = $.fn.alert
       
    72 
       
    73   $.fn.alert = function (option) {
       
    74     return this.each(function () {
       
    75       var $this = $(this)
       
    76         , data = $this.data('alert')
       
    77       if (!data) $this.data('alert', (data = new Alert(this)))
       
    78       if (typeof option == 'string') data[option].call($this)
       
    79     })
       
    80   }
       
    81 
       
    82   $.fn.alert.Constructor = Alert
       
    83 
       
    84 
       
    85  /* ALERT NO CONFLICT
       
    86   * ================= */
       
    87 
       
    88   $.fn.alert.noConflict = function () {
       
    89     $.fn.alert = old
       
    90     return this
       
    91   }
       
    92 
       
    93 
       
    94  /* ALERT DATA-API
       
    95   * ============== */
       
    96 
       
    97   $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)
       
    98 
       
    99 }(window.jQuery);