|
| 1 | +/* ======================================================================== |
| 2 | + * Bootstrap: button.js v3.3.5 |
| 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 | ++function ($) { |
| 10 | + 'use strict'; |
| 11 | + |
| 12 | + // BUTTON PUBLIC CLASS DEFINITION |
| 13 | + // ============================== |
| 14 | + |
| 15 | + var Button = function (element, options) { |
| 16 | + this.$element = $(element) |
| 17 | + this.options = $.extend({}, Button.DEFAULTS, options) |
| 18 | + this.isLoading = false |
| 19 | + } |
| 20 | + |
| 21 | + Button.VERSION = '3.3.5' |
| 22 | + |
| 23 | + Button.DEFAULTS = { |
| 24 | + loadingText: 'loading...' |
| 25 | + } |
| 26 | + |
| 27 | + Button.prototype.setState = function (state) { |
| 28 | + var d = 'disabled' |
| 29 | + var $el = this.$element |
| 30 | + var val = $el.is('input') ? 'val' : 'html' |
| 31 | + var data = $el.data() |
| 32 | + |
| 33 | + state += 'Text' |
| 34 | + |
| 35 | + if (data.resetText == null) $el.data('resetText', $el[val]()) |
| 36 | + |
| 37 | + // push to event loop to allow forms to submit |
| 38 | + setTimeout($.proxy(function () { |
| 39 | + $el[val](data[state] == null ? this.options[state] : data[state]) |
| 40 | + |
| 41 | + if (state == 'loadingText') { |
| 42 | + this.isLoading = true |
| 43 | + $el.addClass(d).attr(d, d) |
| 44 | + } else if (this.isLoading) { |
| 45 | + this.isLoading = false |
| 46 | + $el.removeClass(d).removeAttr(d) |
| 47 | + } |
| 48 | + }, this), 0) |
| 49 | + } |
| 50 | + |
| 51 | + Button.prototype.toggle = $.noop; |
| 52 | + |
| 53 | + // BUTTON PLUGIN DEFINITION |
| 54 | + // ======================== |
| 55 | + |
| 56 | + function Plugin(option) { |
| 57 | + return this.each(function () { |
| 58 | + var $this = $(this) |
| 59 | + var data = $this.data('bs.button') |
| 60 | + var options = typeof option == 'object' && option |
| 61 | + |
| 62 | + if (!data) $this.data('bs.button', (data = new Button(this, options))) |
| 63 | + |
| 64 | + if (option == 'toggle') data.toggle() |
| 65 | + else if (option) data.setState(option) |
| 66 | + }) |
| 67 | + } |
| 68 | + |
| 69 | + var old = $.fn.button |
| 70 | + |
| 71 | + $.fn.button = Plugin |
| 72 | + $.fn.button.Constructor = Button |
| 73 | + |
| 74 | + |
| 75 | + // BUTTON NO CONFLICT |
| 76 | + // ================== |
| 77 | + |
| 78 | + $.fn.button.noConflict = function () { |
| 79 | + $.fn.button = old |
| 80 | + return this |
| 81 | + } |
| 82 | + |
| 83 | +}(jQuery); |
| 84 | ++function (yii) { |
| 85 | + function showLoading() { |
| 86 | + var $self = $(this), |
| 87 | + data = $self.data('yiiActiveForm'), |
| 88 | + $submit = data.submitObject; |
| 89 | + if (!$submit) { |
| 90 | + $submit = $self.find('[type=submit]'); |
| 91 | + } |
| 92 | + $submit.button('loading'); |
| 93 | + } |
| 94 | + function resetLoading() { |
| 95 | + var $self = $(this), |
| 96 | + $submit = $self.data('yiiActiveForm').submitObject; |
| 97 | + if (!$submit) { |
| 98 | + $submit = $self.find('[type=submit]'); |
| 99 | + } |
| 100 | + $submit.button('reset'); |
| 101 | + } |
| 102 | + |
| 103 | + yii.lock = { |
| 104 | + init: function () { |
| 105 | + $('body') |
| 106 | + .on('beforeSubmit', 'form', showLoading) |
| 107 | + .on('ajaxComplete', 'form', resetLoading); |
| 108 | + } |
| 109 | + }; |
| 110 | +}(yii); |
0 commit comments