Files
PyRIGS/RIGS/static/js/button.js
2020-03-07 23:00:45 +00:00

1 line
1.9 KiB
JavaScript
Executable File

!function(o){"use strict";var i=function(t,e){this.$element=o(t),this.options=o.extend({},i.DEFAULTS,e),this.isLoading=!1};function n(s){return this.each(function(){var t=o(this),e=t.data("bs.button"),n="object"==typeof s&&s;e||t.data("bs.button",e=new i(this,n)),"toggle"==s?e.toggle():s&&e.setState(s)})}i.VERSION="3.3.7",i.DEFAULTS={loadingText:"loading..."},i.prototype.setState=function(t){var e="disabled",n=this.$element,s=n.is("input")?"val":"html",i=n.data();t+="Text",null==i.resetText&&n.data("resetText",n[s]()),setTimeout(o.proxy(function(){n[s](null==i[t]?this.options[t]:i[t]),"loadingText"==t?(this.isLoading=!0,n.addClass(e).attr(e,e).prop(e,!0)):this.isLoading&&(this.isLoading=!1,n.removeClass(e).removeAttr(e).prop(e,!1))},this),0)},i.prototype.toggle=function(){var t=!0,e=this.$element.closest('[data-toggle="buttons"]');if(e.length){var n=this.$element.find("input");"radio"==n.prop("type")?(n.prop("checked")&&(t=!1),e.find(".active").removeClass("active"),this.$element.addClass("active")):"checkbox"==n.prop("type")&&(n.prop("checked")!==this.$element.hasClass("active")&&(t=!1),this.$element.toggleClass("active")),n.prop("checked",this.$element.hasClass("active")),t&&n.trigger("change")}else this.$element.attr("aria-pressed",!this.$element.hasClass("active")),this.$element.toggleClass("active")};var t=o.fn.button;o.fn.button=n,o.fn.button.Constructor=i,o.fn.button.noConflict=function(){return o.fn.button=t,this},o(document).on("click.bs.button.data-api",'[data-toggle^="button"]',function(t){var e=o(t.target).closest(".btn");n.call(e,"toggle"),o(t.target).is('input[type="radio"], input[type="checkbox"]')||(t.preventDefault(),e.is("input,button")?e.trigger("focus"):e.find("input:visible,button:visible").first().trigger("focus"))}).on("focus.bs.button.data-api blur.bs.button.data-api",'[data-toggle^="button"]',function(t){o(t.target).closest(".btn").toggleClass("focus",/^focus(in)?$/.test(t.type))})}(jQuery);