OSDN Git Service

843b39c9d2fbf0fc113e625eec7bdfa7bec3f40c
[bytom/vapor.git] / tools / side_chain_tool / web / node_modules / bootstrap / js / button.js
1 /* ========================================================================
2  * Bootstrap: button.js v3.3.7
3  * http://getbootstrap.com/javascript/#buttons
4  * ========================================================================
5  * Copyright 2011-2016 Twitter, Inc.
6  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7  * ======================================================================== */
8
9
10 +function ($) {
11   'use strict';
12
13   // BUTTON PUBLIC CLASS DEFINITION
14   // ==============================
15
16   var Button = function (element, options) {
17     this.$element  = $(element)
18     this.options   = $.extend({}, Button.DEFAULTS, options)
19     this.isLoading = false
20   }
21
22   Button.VERSION  = '3.3.7'
23
24   Button.DEFAULTS = {
25     loadingText: 'loading...'
26   }
27
28   Button.prototype.setState = function (state) {
29     var d    = 'disabled'
30     var $el  = this.$element
31     var val  = $el.is('input') ? 'val' : 'html'
32     var data = $el.data()
33
34     state += 'Text'
35
36     if (data.resetText == null) $el.data('resetText', $el[val]())
37
38     // push to event loop to allow forms to submit
39     setTimeout($.proxy(function () {
40       $el[val](data[state] == null ? this.options[state] : data[state])
41
42       if (state == 'loadingText') {
43         this.isLoading = true
44         $el.addClass(d).attr(d, d).prop(d, true)
45       } else if (this.isLoading) {
46         this.isLoading = false
47         $el.removeClass(d).removeAttr(d).prop(d, false)
48       }
49     }, this), 0)
50   }
51
52   Button.prototype.toggle = function () {
53     var changed = true
54     var $parent = this.$element.closest('[data-toggle="buttons"]')
55
56     if ($parent.length) {
57       var $input = this.$element.find('input')
58       if ($input.prop('type') == 'radio') {
59         if ($input.prop('checked')) changed = false
60         $parent.find('.active').removeClass('active')
61         this.$element.addClass('active')
62       } else if ($input.prop('type') == 'checkbox') {
63         if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false
64         this.$element.toggleClass('active')
65       }
66       $input.prop('checked', this.$element.hasClass('active'))
67       if (changed) $input.trigger('change')
68     } else {
69       this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
70       this.$element.toggleClass('active')
71     }
72   }
73
74
75   // BUTTON PLUGIN DEFINITION
76   // ========================
77
78   function Plugin(option) {
79     return this.each(function () {
80       var $this   = $(this)
81       var data    = $this.data('bs.button')
82       var options = typeof option == 'object' && option
83
84       if (!data) $this.data('bs.button', (data = new Button(this, options)))
85
86       if (option == 'toggle') data.toggle()
87       else if (option) data.setState(option)
88     })
89   }
90
91   var old = $.fn.button
92
93   $.fn.button             = Plugin
94   $.fn.button.Constructor = Button
95
96
97   // BUTTON NO CONFLICT
98   // ==================
99
100   $.fn.button.noConflict = function () {
101     $.fn.button = old
102     return this
103   }
104
105
106   // BUTTON DATA-API
107   // ===============
108
109   $(document)
110     .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
111       var $btn = $(e.target).closest('.btn')
112       Plugin.call($btn, 'toggle')
113       if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) {
114         // Prevent double click on radios, and the double selections (so cancellation) on checkboxes
115         e.preventDefault()
116         // The target component still receive the focus
117         if ($btn.is('input,button')) $btn.trigger('focus')
118         else $btn.find('input:visible,button:visible').first().trigger('focus')
119       }
120     })
121     .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
122       $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
123     })
124
125 }(jQuery);