aboutsummaryrefslogtreecommitdiff
path: root/dist/js/umd/button.js
diff options
context:
space:
mode:
authorfat <[email protected]>2015-05-13 10:13:34 -0700
committerfat <[email protected]>2015-05-13 10:13:34 -0700
commitdafdd180cd54a2e238fe715d8aeb83c07f385a18 (patch)
tree7db2949420f90040726e9f26dd5afc2c41364300 /dist/js/umd/button.js
parent6b251582d6c01dfe4e27062118a1af1811625ac5 (diff)
downloadbootstrap-dafdd180cd54a2e238fe715d8aeb83c07f385a18.tar.xz
bootstrap-dafdd180cd54a2e238fe715d8aeb83c07f385a18.zip
add umd module support in dist
Diffstat (limited to 'dist/js/umd/button.js')
-rw-r--r--dist/js/umd/button.js181
1 files changed, 181 insertions, 0 deletions
diff --git a/dist/js/umd/button.js b/dist/js/umd/button.js
new file mode 100644
index 000000000..7449af2c9
--- /dev/null
+++ b/dist/js/umd/button.js
@@ -0,0 +1,181 @@
+(function (global, factory) {
+ if (typeof define === 'function' && define.amd) {
+ define(['exports', 'module'], factory);
+ } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
+ factory(exports, module);
+ } else {
+ var mod = {
+ exports: {}
+ };
+ factory(mod.exports, mod);
+ global.button = mod.exports;
+ }
+})(this, function (exports, module) {
+ 'use strict';
+
+ var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
+
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
+
+ /**
+ * --------------------------------------------------------------------------
+ * Bootstrap (v4.0.0): button.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
+ * --------------------------------------------------------------------------
+ */
+
+ var Button = (function ($) {
+
+ /**
+ * ------------------------------------------------------------------------
+ * Constants
+ * ------------------------------------------------------------------------
+ */
+
+ var NAME = 'button';
+ var VERSION = '4.0.0';
+ var DATA_KEY = 'bs.button';
+ var JQUERY_NO_CONFLICT = $.fn[NAME];
+ var TRANSITION_DURATION = 150;
+
+ var ClassName = {
+ ACTIVE: 'active',
+ BUTTON: 'btn',
+ FOCUS: 'focus'
+ };
+
+ var Selector = {
+ DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
+ DATA_TOGGLE: '[data-toggle="buttons"]',
+ INPUT: 'input',
+ ACTIVE: '.active',
+ BUTTON: '.btn'
+ };
+
+ var Event = {
+ CLICK: 'click.bs.button.data-api',
+ FOCUS_BLUR: 'focus.bs.button.data-api blur.bs.button.data-api'
+ };
+
+ /**
+ * ------------------------------------------------------------------------
+ * Class Definition
+ * ------------------------------------------------------------------------
+ */
+
+ var Button = (function () {
+ function Button(element) {
+ _classCallCheck(this, Button);
+
+ this._element = element;
+ }
+
+ _createClass(Button, [{
+ key: 'toggle',
+
+ // public
+
+ value: function toggle() {
+ var triggerChangeEvent = true;
+ var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0];
+
+ if (rootElement) {
+ var input = $(this._element).find(Selector.INPUT)[0];
+
+ if (input) {
+ if (input.type === 'radio') {
+ if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) {
+ triggerChangeEvent = false;
+ } else {
+ var activeElement = $(rootElement).find(Selector.ACTIVE)[0];
+
+ if (activeElement) {
+ $(activeElement).removeClass(ClassName.ACTIVE);
+ }
+ }
+ }
+
+ if (triggerChangeEvent) {
+ input.checked = !$(this._element).hasClass(ClassName.ACTIVE);
+ $(this._element).trigger('change');
+ }
+ }
+ } else {
+ this._element.setAttribute('aria-pressed', !$(this._element).hasClass(ClassName.ACTIVE));
+ }
+
+ if (triggerChangeEvent) {
+ $(this._element).toggleClass(ClassName.ACTIVE);
+ }
+ }
+ }], [{
+ key: 'VERSION',
+
+ // getters
+
+ get: function () {
+ return VERSION;
+ }
+ }, {
+ key: '_jQueryInterface',
+
+ // static
+
+ value: function _jQueryInterface(config) {
+ return this.each(function () {
+ var data = $(this).data(DATA_KEY);
+
+ if (!data) {
+ data = new Button(this);
+ $(this).data(DATA_KEY, data);
+ }
+
+ if (config === 'toggle') {
+ data[config]();
+ }
+ });
+ }
+ }]);
+
+ return Button;
+ })();
+
+ /**
+ * ------------------------------------------------------------------------
+ * Data Api implementation
+ * ------------------------------------------------------------------------
+ */
+
+ $(document).on(Event.CLICK, Selector.DATA_TOGGLE_CARROT, function (event) {
+ event.preventDefault();
+
+ var button = event.target;
+
+ if (!$(button).hasClass(ClassName.BUTTON)) {
+ button = $(button).closest(Selector.BUTTON);
+ }
+
+ Button._jQueryInterface.call($(button), 'toggle');
+ }).on(Event.FOCUS_BLUR, Selector.DATA_TOGGLE_CARROT, function (event) {
+ var button = $(event.target).closest(Selector.BUTTON)[0];
+ $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
+ });
+
+ /**
+ * ------------------------------------------------------------------------
+ * jQuery
+ * ------------------------------------------------------------------------
+ */
+
+ $.fn[NAME] = Button._jQueryInterface;
+ $.fn[NAME].Constructor = Button;
+ $.fn[NAME].noConflict = function () {
+ $.fn[NAME] = JQUERY_NO_CONFLICT;
+ return Button._jQueryInterface;
+ };
+
+ return Button;
+ })(jQuery);
+
+ module.exports = Button;
+}); \ No newline at end of file