Policy 1707 commit to LF
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / CSS / bootstrap / js / button.js
1 /* ========================================================================
2  * Bootstrap: button.js v3.3.4
3  * http://getbootstrap.com/javascript/#buttons
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   // 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.4'
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 = 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)
45       } else if (this.isLoading) {
46         this.isLoading = false
47         $el.removeClass(d).removeAttr(d)
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') && this.$element.hasClass('active')) changed = false
60         else $parent.find('.active').removeClass('active')
61       }
62       if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
63     } else {
64       this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
65     }
66
67     if (changed) this.$element.toggleClass('active')
68   }
69
70
71   // BUTTON PLUGIN DEFINITION
72   // ========================
73
74   function Plugin(option) {
75     return this.each(function () {
76       var $this   = $(this)
77       var data    = $this.data('bs.button')
78       var options = typeof option == 'object' && option
79
80       if (!data) $this.data('bs.button', (data = new Button(this, options)))
81
82       if (option == 'toggle') data.toggle()
83       else if (option) data.setState(option)
84     })
85   }
86
87   var old = $.fn.button
88
89   $.fn.button             = Plugin
90   $.fn.button.Constructor = Button
91
92
93   // BUTTON NO CONFLICT
94   // ==================
95
96   $.fn.button.noConflict = function () {
97     $.fn.button = old
98     return this
99   }
100
101
102   // BUTTON DATA-API
103   // ===============
104
105   $(document)
106     .on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
107       var $btn = $(e.target)
108       if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
109       Plugin.call($btn, 'toggle')
110       e.preventDefault()
111     })
112     .on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
113       $(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
114     })
115
116 }(jQuery);