Blame view

app/bower_components/bootstrap/js/button.js 3.73 KB
f986e111b   TRUONG   add libs
1
  /* ========================================================================
87c93a029   Dang YoungWorld   add modal
2
   * Bootstrap: button.js v3.3.7
f986e111b   TRUONG   add libs
3
4
   * http://getbootstrap.com/javascript/#buttons
   * ========================================================================
87c93a029   Dang YoungWorld   add modal
5
6
   * Copyright 2011-2016 Twitter, Inc.
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
f986e111b   TRUONG   add libs
7
   * ======================================================================== */
87c93a029   Dang YoungWorld   add modal
8
9
  +function ($) {
    'use strict';
f986e111b   TRUONG   add libs
10
11
12
13
14
  
    // BUTTON PUBLIC CLASS DEFINITION
    // ==============================
  
    var Button = function (element, options) {
87c93a029   Dang YoungWorld   add modal
15
16
17
      this.$element  = $(element)
      this.options   = $.extend({}, Button.DEFAULTS, options)
      this.isLoading = false
f986e111b   TRUONG   add libs
18
    }
87c93a029   Dang YoungWorld   add modal
19
    Button.VERSION  = '3.3.7'
f986e111b   TRUONG   add libs
20
21
22
23
24
25
26
27
28
    Button.DEFAULTS = {
      loadingText: 'loading...'
    }
  
    Button.prototype.setState = function (state) {
      var d    = 'disabled'
      var $el  = this.$element
      var val  = $el.is('input') ? 'val' : 'html'
      var data = $el.data()
87c93a029   Dang YoungWorld   add modal
29
      state += 'Text'
f986e111b   TRUONG   add libs
30

87c93a029   Dang YoungWorld   add modal
31
      if (data.resetText == null) $el.data('resetText', $el[val]())
f986e111b   TRUONG   add libs
32
33
  
      // push to event loop to allow forms to submit
87c93a029   Dang YoungWorld   add modal
34
35
36
37
38
39
40
41
42
43
44
      setTimeout($.proxy(function () {
        $el[val](data[state] == null ? this.options[state] : data[state])
  
        if (state == 'loadingText') {
          this.isLoading = true
          $el.addClass(d).attr(d, d).prop(d, true)
        } else if (this.isLoading) {
          this.isLoading = false
          $el.removeClass(d).removeAttr(d).prop(d, false)
        }
      }, this), 0)
f986e111b   TRUONG   add libs
45
46
47
    }
  
    Button.prototype.toggle = function () {
f986e111b   TRUONG   add libs
48
      var changed = true
87c93a029   Dang YoungWorld   add modal
49
      var $parent = this.$element.closest('[data-toggle="buttons"]')
f986e111b   TRUONG   add libs
50
51
52
  
      if ($parent.length) {
        var $input = this.$element.find('input')
87c93a029   Dang YoungWorld   add modal
53
54
55
56
57
58
59
        if ($input.prop('type') == 'radio') {
          if ($input.prop('checked')) changed = false
          $parent.find('.active').removeClass('active')
          this.$element.addClass('active')
        } else if ($input.prop('type') == 'checkbox') {
          if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false
          this.$element.toggleClass('active')
f986e111b   TRUONG   add libs
60
        }
87c93a029   Dang YoungWorld   add modal
61
62
63
64
65
        $input.prop('checked', this.$element.hasClass('active'))
        if (changed) $input.trigger('change')
      } else {
        this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
        this.$element.toggleClass('active')
f986e111b   TRUONG   add libs
66
      }
f986e111b   TRUONG   add libs
67
68
69
70
71
    }
  
  
    // BUTTON PLUGIN DEFINITION
    // ========================
87c93a029   Dang YoungWorld   add modal
72
    function Plugin(option) {
f986e111b   TRUONG   add libs
73
74
75
76
77
78
79
80
81
82
83
      return this.each(function () {
        var $this   = $(this)
        var data    = $this.data('bs.button')
        var options = typeof option == 'object' && option
  
        if (!data) $this.data('bs.button', (data = new Button(this, options)))
  
        if (option == 'toggle') data.toggle()
        else if (option) data.setState(option)
      })
    }
87c93a029   Dang YoungWorld   add modal
84
85
86
    var old = $.fn.button
  
    $.fn.button             = Plugin
f986e111b   TRUONG   add libs
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    $.fn.button.Constructor = Button
  
  
    // BUTTON NO CONFLICT
    // ==================
  
    $.fn.button.noConflict = function () {
      $.fn.button = old
      return this
    }
  
  
    // BUTTON DATA-API
    // ===============
87c93a029   Dang YoungWorld   add modal
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    $(document)
      .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
        var $btn = $(e.target).closest('.btn')
        Plugin.call($btn, 'toggle')
        if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) {
          // Prevent double click on radios, and the double selections (so cancellation) on checkboxes
          e.preventDefault()
          // The target component still receive the focus
          if ($btn.is('input,button')) $btn.trigger('focus')
          else $btn.find('input:visible,button:visible').first().trigger('focus')
        }
      })
      .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
        $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
      })
f986e111b   TRUONG   add libs
116
117
  
  }(jQuery);