button.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery')) :
  3. typeof define === 'function' && define.amd ? define(['jquery'], factory) :
  4. (global.Button = factory(global.jQuery));
  5. }(this, (function ($) { 'use strict';
  6. $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  7. function _defineProperties(target, props) {
  8. for (var i = 0; i < props.length; i++) {
  9. var descriptor = props[i];
  10. descriptor.enumerable = descriptor.enumerable || false;
  11. descriptor.configurable = true;
  12. if ("value" in descriptor) descriptor.writable = true;
  13. Object.defineProperty(target, descriptor.key, descriptor);
  14. }
  15. }
  16. function _createClass(Constructor, protoProps, staticProps) {
  17. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  18. if (staticProps) _defineProperties(Constructor, staticProps);
  19. return Constructor;
  20. }
  21. /**
  22. * --------------------------------------------------------------------------
  23. * Bootstrap (v4.1.3): button.js
  24. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  25. * --------------------------------------------------------------------------
  26. */
  27. var Button = function ($$$1) {
  28. /**
  29. * ------------------------------------------------------------------------
  30. * Constants
  31. * ------------------------------------------------------------------------
  32. */
  33. var NAME = 'button';
  34. var VERSION = '4.1.3';
  35. var DATA_KEY = 'bs.button';
  36. var EVENT_KEY = "." + DATA_KEY;
  37. var DATA_API_KEY = '.data-api';
  38. var JQUERY_NO_CONFLICT = $$$1.fn[NAME];
  39. var ClassName = {
  40. ACTIVE: 'active',
  41. BUTTON: 'btn',
  42. FOCUS: 'focus'
  43. };
  44. var Selector = {
  45. DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
  46. DATA_TOGGLE: '[data-toggle="buttons"]',
  47. INPUT: 'input',
  48. ACTIVE: '.active',
  49. BUTTON: '.btn'
  50. };
  51. var Event = {
  52. CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY,
  53. FOCUS_BLUR_DATA_API: "focus" + EVENT_KEY + DATA_API_KEY + " " + ("blur" + EVENT_KEY + DATA_API_KEY)
  54. /**
  55. * ------------------------------------------------------------------------
  56. * Class Definition
  57. * ------------------------------------------------------------------------
  58. */
  59. };
  60. var Button =
  61. /*#__PURE__*/
  62. function () {
  63. function Button(element) {
  64. this._element = element;
  65. } // Getters
  66. var _proto = Button.prototype;
  67. // Public
  68. _proto.toggle = function toggle() {
  69. var triggerChangeEvent = true;
  70. var addAriaPressed = true;
  71. var rootElement = $$$1(this._element).closest(Selector.DATA_TOGGLE)[0];
  72. if (rootElement) {
  73. var input = this._element.querySelector(Selector.INPUT);
  74. if (input) {
  75. if (input.type === 'radio') {
  76. if (input.checked && this._element.classList.contains(ClassName.ACTIVE)) {
  77. triggerChangeEvent = false;
  78. } else {
  79. var activeElement = rootElement.querySelector(Selector.ACTIVE);
  80. if (activeElement) {
  81. $$$1(activeElement).removeClass(ClassName.ACTIVE);
  82. }
  83. }
  84. }
  85. if (triggerChangeEvent) {
  86. if (input.hasAttribute('disabled') || rootElement.hasAttribute('disabled') || input.classList.contains('disabled') || rootElement.classList.contains('disabled')) {
  87. return;
  88. }
  89. input.checked = !this._element.classList.contains(ClassName.ACTIVE);
  90. $$$1(input).trigger('change');
  91. }
  92. input.focus();
  93. addAriaPressed = false;
  94. }
  95. }
  96. if (addAriaPressed) {
  97. this._element.setAttribute('aria-pressed', !this._element.classList.contains(ClassName.ACTIVE));
  98. }
  99. if (triggerChangeEvent) {
  100. $$$1(this._element).toggleClass(ClassName.ACTIVE);
  101. }
  102. };
  103. _proto.dispose = function dispose() {
  104. $$$1.removeData(this._element, DATA_KEY);
  105. this._element = null;
  106. }; // Static
  107. Button._jQueryInterface = function _jQueryInterface(config) {
  108. return this.each(function () {
  109. var data = $$$1(this).data(DATA_KEY);
  110. if (!data) {
  111. data = new Button(this);
  112. $$$1(this).data(DATA_KEY, data);
  113. }
  114. if (config === 'toggle') {
  115. data[config]();
  116. }
  117. });
  118. };
  119. _createClass(Button, null, [{
  120. key: "VERSION",
  121. get: function get() {
  122. return VERSION;
  123. }
  124. }]);
  125. return Button;
  126. }();
  127. /**
  128. * ------------------------------------------------------------------------
  129. * Data Api implementation
  130. * ------------------------------------------------------------------------
  131. */
  132. $$$1(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
  133. event.preventDefault();
  134. var button = event.target;
  135. if (!$$$1(button).hasClass(ClassName.BUTTON)) {
  136. button = $$$1(button).closest(Selector.BUTTON);
  137. }
  138. Button._jQueryInterface.call($$$1(button), 'toggle');
  139. }).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
  140. var button = $$$1(event.target).closest(Selector.BUTTON)[0];
  141. $$$1(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
  142. });
  143. /**
  144. * ------------------------------------------------------------------------
  145. * jQuery
  146. * ------------------------------------------------------------------------
  147. */
  148. $$$1.fn[NAME] = Button._jQueryInterface;
  149. $$$1.fn[NAME].Constructor = Button;
  150. $$$1.fn[NAME].noConflict = function () {
  151. $$$1.fn[NAME] = JQUERY_NO_CONFLICT;
  152. return Button._jQueryInterface;
  153. };
  154. return Button;
  155. }($);
  156. return Button;
  157. })));
  158. //# sourceMappingURL=button.js.map