diff --git a/js/dist/alert.js b/js/dist/alert.js index 0dbfe767b..76b280a0c 100644 --- a/js/dist/alert.js +++ b/js/dist/alert.js @@ -4,167 +4,173 @@ var _createClass = (function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } -/** - * -------------------------------------------------------------------------- - * Constants - * -------------------------------------------------------------------------- - */ - -var NAME = 'alert'; -var VERSION = '4.0.0'; -var DATA_KEY = 'bs.alert'; -var JQUERY_NO_CONFLICT = $.fn[NAME]; -var TRANSITION_DURATION = 150; - -var Selector = { - DISMISS: '[data-dismiss="alert"]' -}; - -var Event = { - CLOSE: 'close.bs.alert', - CLOSED: 'closed.bs.alert', - CLICK: 'click.bs.alert.data-api' -}; - -var ClassName = { - ALERT: 'alert', - FADE: 'fade', - IN: 'in' -}; - -/** - * -------------------------------------------------------------------------- - * Class Definition - * -------------------------------------------------------------------------- - */ - -var Alert = (function () { - function Alert(element) { - _classCallCheck(this, Alert); - - if (element) { - this.element = element; - } - } - - _createClass(Alert, [{ - key: 'close', - - // public - - value: function close(element) { - var rootElement = this._getRootElement(element); - var customEvent = this._triggerCloseEvent(rootElement); - - if (customEvent.isDefaultPrevented()) { - return; - } - - this._removeElement(rootElement); - } - }, { - key: '_getRootElement', - - // private - - value: function _getRootElement(element) { - var parent = false; - var selector = Util.getSelectorFromElement(element); - - if (selector) { - parent = $(selector)[0]; - } - - if (!parent) { - parent = $(element).closest('.' + ClassName.ALERT)[0]; - } - - return parent; - } - }, { - key: '_triggerCloseEvent', - value: function _triggerCloseEvent(element) { - var closeEvent = $.Event(Event.CLOSE); - $(element).trigger(closeEvent); - return closeEvent; - } - }, { - key: '_removeElement', - value: function _removeElement(element) { - $(element).removeClass(ClassName.IN); - - if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) { - this._destroyElement(element); - return; - } - - $(element).one(Util.TRANSITION_END, this._destroyElement.bind(this, element)).emulateTransitionEnd(TRANSITION_DURATION); - } - }, { - key: '_destroyElement', - value: function _destroyElement(element) { - $(element).detach().trigger(Event.CLOSED).remove(); - } - }], [{ - key: '_jQueryInterface', - - // static - - value: function _jQueryInterface(config) { - return this.each(function () { - var $element = $(this); - var data = $element.data(DATA_KEY); - - if (!data) { - data = new Alert(this); - $element.data(DATA_KEY, data); - } - - if (config === 'close') { - data[config](this); - } - }); - } - }, { - key: '_handleDismiss', - value: function _handleDismiss(alertInstance) { - return function (event) { - if (event) { - event.preventDefault(); - } - - alertInstance.close(this); - }; - } - }]); - - return Alert; -})(); - -/** - * -------------------------------------------------------------------------- - * Data Api implementation - * -------------------------------------------------------------------------- - */ - -$(document).on(Event.CLICK, Selector.DISMISS, Alert._handleDismiss(new Alert())); - -/** - * -------------------------------------------------------------------------- - * jQuery - * -------------------------------------------------------------------------- - */ - -$.fn[NAME] = Alert._jQueryInterface; -$.fn[NAME].Constructor = Alert; -$.fn[NAME].noConflict = function () { - $.fn[NAME] = Alert._JQUERY_NO_CONFLICT; - return Alert._jQueryInterface; -}; /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ + +var Alert = (function () { + + /** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ + + var NAME = 'alert'; + var VERSION = '4.0.0'; + var DATA_KEY = 'bs.alert'; + var JQUERY_NO_CONFLICT = $.fn[NAME]; + var TRANSITION_DURATION = 150; + + var Selector = { + DISMISS: '[data-dismiss="alert"]' + }; + + var Event = { + CLOSE: 'close.bs.alert', + CLOSED: 'closed.bs.alert', + CLICK: 'click.bs.alert.data-api' + }; + + var ClassName = { + ALERT: 'alert', + FADE: 'fade', + IN: 'in' + }; + + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ + + var Alert = (function () { + function Alert(element) { + _classCallCheck(this, Alert); + + if (element) { + this.element = element; + } + } + + _createClass(Alert, [{ + key: 'close', + + // public + + value: function close(element) { + var rootElement = this._getRootElement(element); + var customEvent = this._triggerCloseEvent(rootElement); + + if (customEvent.isDefaultPrevented()) { + return; + } + + this._removeElement(rootElement); + } + }, { + key: '_getRootElement', + + // private + + value: function _getRootElement(element) { + var parent = false; + var selector = Util.getSelectorFromElement(element); + + if (selector) { + parent = $(selector)[0]; + } + + if (!parent) { + parent = $(element).closest('.' + ClassName.ALERT)[0]; + } + + return parent; + } + }, { + key: '_triggerCloseEvent', + value: function _triggerCloseEvent(element) { + var closeEvent = $.Event(Event.CLOSE); + $(element).trigger(closeEvent); + return closeEvent; + } + }, { + key: '_removeElement', + value: function _removeElement(element) { + $(element).removeClass(ClassName.IN); + + if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) { + this._destroyElement(element); + return; + } + + $(element).one(Util.TRANSITION_END, this._destroyElement.bind(this, element)).emulateTransitionEnd(TRANSITION_DURATION); + } + }, { + key: '_destroyElement', + value: function _destroyElement(element) { + $(element).detach().trigger(Event.CLOSED).remove(); + } + }], [{ + key: '_jQueryInterface', + + // static + + value: function _jQueryInterface(config) { + return this.each(function () { + var $element = $(this); + var data = $element.data(DATA_KEY); + + if (!data) { + data = new Alert(this); + $element.data(DATA_KEY, data); + } + + if (config === 'close') { + data[config](this); + } + }); + } + }, { + key: '_handleDismiss', + value: function _handleDismiss(alertInstance) { + return function (event) { + if (event) { + event.preventDefault(); + } + + alertInstance.close(this); + }; + } + }]); + + return Alert; + })(); + + /** + * ------------------------------------------------------------------------ + * Data Api implementation + * ------------------------------------------------------------------------ + */ + + $(document).on(Event.CLICK, Selector.DISMISS, Alert._handleDismiss(new Alert())); + + /** + * ------------------------------------------------------------------------ + * jQuery + * ------------------------------------------------------------------------ + */ + + $.fn[NAME] = Alert._jQueryInterface; + $.fn[NAME].Constructor = Alert; + $.fn[NAME].noConflict = function () { + $.fn[NAME] = Alert._JQUERY_NO_CONFLICT; + return Alert._jQueryInterface; + }; + + return Alert; +})(); //# sourceMappingURL=alert.js.map \ No newline at end of file diff --git a/js/dist/alert.js.map b/js/dist/alert.js.map index d2d9be6b6..f3bc7ad7f 100644 Binary files a/js/dist/alert.js.map and b/js/dist/alert.js.map differ diff --git a/js/dist/util.js b/js/dist/util.js index 48865c5d7..4c8c4e639 100644 --- a/js/dist/util.js +++ b/js/dist/util.js @@ -5,120 +5,119 @@ * -------------------------------------------------------------------------- */ -/** - * ------------------------------------------------------------------------ - * Public Util Api - * ------------------------------------------------------------------------ - */ - 'use strict'; -var Util = { +var Util = (function () { - TRANSITION_END: 'bsTransitionEnd', + /** + * ------------------------------------------------------------------------ + * Private TransitionEnd Helpers + * ------------------------------------------------------------------------ + */ - getUID: function getUID(prefix) { - do prefix += ~ ~(Math.random() * 1000000); while (document.getElementById(prefix)); - return prefix; - }, + var transition = false; - getSelectorFromElement: function getSelectorFromElement(element) { - var selector = element.getAttribute('data-target'); + var TransitionEndEvent = { + WebkitTransition: 'webkitTransitionEnd', + MozTransition: 'transitionend', + OTransition: 'oTransitionEnd otransitionend', + transition: 'transitionend' + }; - if (!selector) { - selector = element.getAttribute('href') || ''; - selector = /^#[a-z]/i.test(selector) ? selector : null; - } - - return selector; - }, - - reflow: function reflow(element) { - new Function('bs', 'return bs')(element.offsetHeight); - }, - - supportsTransitionEnd: function supportsTransitionEnd() { - return !!transition; + function getSpecialTransitionEndEvent() { + return { + bindType: transition.end, + delegateType: transition.end, + handle: function handle(event) { + if ($(event.target).is(this)) { + return event.handleObj.handler.apply(this, arguments); + } + } + }; } -}; + function transitionEndTest() { + if (window.QUnit) { + return false; + } -/** - * ------------------------------------------------------------------------ - * Private TransitionEnd Helpers - * ------------------------------------------------------------------------ - */ + var el = document.createElement('bootstrap'); -var transition = false; - -var TransitionEndEvent = { - WebkitTransition: 'webkitTransitionEnd', - MozTransition: 'transitionend', - OTransition: 'oTransitionEnd otransitionend', - transition: 'transitionend' -}; - -function getSpecialTransitionEndEvent() { - return { - bindType: transition.end, - delegateType: transition.end, - handle: function handle(event) { - if ($(event.target).is(this)) { - return event.handleObj.handler.apply(this, arguments); + for (var name in TransitionEndEvent) { + if (el.style[name] !== undefined) { + return { end: TransitionEndEvent[name] }; } } - }; -} -function transitionEndTest() { - if (window.QUnit) { return false; } - var el = document.createElement('bootstrap'); + function transitionEndEmulator(duration) { + var _this = this; - for (var name in TransitionEndEvent) { - if (el.style[name] !== undefined) { - return { end: TransitionEndEvent[name] }; + var called = false; + + $(this).one(Util.TRANSITION_END, function () { + called = true; + }); + + setTimeout(function () { + if (!called) { + $(_this).trigger(transition.end); + } + }, duration); + + return this; + } + + function setTransitionEndSupport() { + transition = transitionEndTest(); + + $.fn.emulateTransitionEnd = transitionEndEmulator; + + if (Util.supportsTransitionEnd()) { + $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent(); } } - return false; -} + /** + * -------------------------------------------------------------------------- + * Public Util Api + * -------------------------------------------------------------------------- + */ -function transitionEndEmulator(duration) { - var _this = this; + var Util = { - var called = false; + TRANSITION_END: 'bsTransitionEnd', - $(this).one(Util.TRANSITION_END, function () { - called = true; - }); + getUID: function getUID(prefix) { + do prefix += ~ ~(Math.random() * 1000000); while (document.getElementById(prefix)); + return prefix; + }, - setTimeout(function () { - if (!called) { - $(_this).trigger(transition.end); + getSelectorFromElement: function getSelectorFromElement(element) { + var selector = element.getAttribute('data-target'); + + if (!selector) { + selector = element.getAttribute('href') || ''; + selector = /^#[a-z]/i.test(selector) ? selector : null; + } + + return selector; + }, + + reflow: function reflow(element) { + new Function('bs', 'return bs')(element.offsetHeight); + }, + + supportsTransitionEnd: function supportsTransitionEnd() { + return !!transition; } - }, duration); - return this; -} + }; -function setTransitionEndSupport() { - transition = transitionEndTest(); + setTransitionEndSupport(); - $.fn.emulateTransitionEnd = transitionEndEmulator; - - if (Util.supportsTransitionEnd()) { - $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent(); - } -} - -setTransitionEndSupport(); - -/** - * ------------------------------------------------------------------------ - * Export Api - * ------------------------------------------------------------------------ - */ + return Util; +})(); //# sourceMappingURL=util.js.map \ No newline at end of file diff --git a/js/dist/util.js.map b/js/dist/util.js.map index 5de0badbd..71ad2163a 100644 Binary files a/js/dist/util.js.map and b/js/dist/util.js.map differ diff --git a/js/script-compiled.js b/js/script-compiled.js new file mode 100644 index 000000000..2a50eb3b3 --- /dev/null +++ b/js/script-compiled.js @@ -0,0 +1,305 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +/** + * -------------------------------------------------------------------------- + * Bootstrap (v4.0.0): alert.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * -------------------------------------------------------------------------- + */ + +var _util = require('util'); + +var _util2 = _interopRequireDefault(_util); + +/** + * -------------------------------------------------------------------------- + * Constants + * -------------------------------------------------------------------------- + */ + +var NAME = 'alert'; +var VERSION = '4.0.0'; +var DATA_KEY = 'bs.alert'; +var JQUERY_NO_CONFLICT = $.fn[NAME]; +var TRANSITION_DURATION = 150; + +var Selector = { + DISMISS: '[data-dismiss="alert"]' +}; + +var Event = { + CLOSE: 'close.bs.alert', + CLOSED: 'closed.bs.alert', + CLICK: 'click.bs.alert.data-api' +}; + +var ClassName = { + ALERT: 'alert', + FADE: 'fade', + IN: 'in' +}; + +/** + * -------------------------------------------------------------------------- + * Class Definition + * -------------------------------------------------------------------------- + */ + +var Alert = (function () { + function Alert(element) { + _classCallCheck(this, Alert); + + if (element) { + this.element = element; + } + } + + _createClass(Alert, [{ + key: 'close', + + // public + + value: function close(element) { + var rootElement = this._getRootElement(element); + var customEvent = this._triggerCloseEvent(rootElement); + + if (customEvent.isDefaultPrevented()) { + return; + } + + this._removeElement(rootElement); + } + }, { + key: '_getRootElement', + + // private + + value: function _getRootElement(element) { + var parent = false; + var selector = _util2['default'].getSelectorFromElement(element); + + if (selector) { + parent = $(selector)[0]; + } + + if (!parent) { + parent = $(element).closest('.' + ClassName.ALERT)[0]; + } + + return parent; + } + }, { + key: '_triggerCloseEvent', + value: function _triggerCloseEvent(element) { + var closeEvent = $.Event(Event.CLOSE); + $(element).trigger(closeEvent); + return closeEvent; + } + }, { + key: '_removeElement', + value: function _removeElement(element) { + $(element).removeClass(ClassName.IN); + + if (!_util2['default'].supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) { + this._destroyElement(element); + return; + } + + $(element).one(_util2['default'].TRANSITION_END, this._destroyElement.bind(this, element)).emulateTransitionEnd(TRANSITION_DURATION); + } + }, { + key: '_destroyElement', + value: function _destroyElement(element) { + $(element).detach().trigger(Event.CLOSED).remove(); + } + }], [{ + key: '_jQueryInterface', + + // static + + value: function _jQueryInterface(config) { + return this.each(function () { + var $element = $(this); + var data = $element.data(DATA_KEY); + + if (!data) { + data = new Alert(this); + $element.data(DATA_KEY, data); + } + + if (config === 'close') { + data[config](this); + } + }); + } + }, { + key: '_handleDismiss', + value: function _handleDismiss(alertInstance) { + return function (event) { + if (event) { + event.preventDefault(); + } + + alertInstance.close(this); + }; + } + }]); + + return Alert; +})(); + +exports.Alert = Alert; + +/** + * -------------------------------------------------------------------------- + * Data Api implementation + * -------------------------------------------------------------------------- + */ + +$(document).on(Event.CLICK, Selector.DISMISS, Alert._handleDismiss(new Alert())); + +/** + * -------------------------------------------------------------------------- + * jQuery + * -------------------------------------------------------------------------- + */ + +$.fn[NAME] = Alert._jQueryInterface; +$.fn[NAME].Constructor = Alert; +$.fn[NAME].noConflict = function () { + $.fn[NAME] = Alert._JQUERY_NO_CONFLICT; + return Alert._jQueryInterface; +}; +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +/** + * -------------------------------------------------------------------------- + * Bootstrap (v4.0.0): util.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * -------------------------------------------------------------------------- + */ + +/** + * -------------------------------------------------------------------------- + * Public Util Api + * -------------------------------------------------------------------------- + */ + +var Util = { + + TRANSITION_END: 'bsTransitionEnd', + + getUID: function getUID(prefix) { + do prefix += ~ ~(Math.random() * 1000000); while (document.getElementById(prefix)); + return prefix; + }, + + getSelectorFromElement: function getSelectorFromElement(element) { + var selector = element.getAttribute('data-target'); + + if (!selector) { + selector = element.getAttribute('href') || ''; + selector = /^#[a-z]/i.test(selector) ? selector : null; + } + + return selector; + }, + + reflow: function reflow(element) { + new Function('bs', 'return bs')(element.offsetHeight); + }, + + supportsTransitionEnd: function supportsTransitionEnd() { + return !!transition; + } + +}; + +exports['default'] = Util; + +/** + * -------------------------------------------------------------------------- + * Private TransitionEnd Helpers + * -------------------------------------------------------------------------- + */ + +var transition = false; + +var TransitionEndEvent = { + WebkitTransition: 'webkitTransitionEnd', + MozTransition: 'transitionend', + OTransition: 'oTransitionEnd otransitionend', + transition: 'transitionend' +}; + +function getSpecialTransitionEndEvent() { + return { + bindType: transition.end, + delegateType: transition.end, + handle: function handle(event) { + if ($(event.target).is(this)) { + return event.handleObj.handler.apply(this, arguments); + } + } + }; +} + +function transitionEndTest() { + if (window.QUnit) { + return false; + } + + var el = document.createElement('bootstrap'); + + for (var name in TransitionEndEvent) { + if (el.style[name] !== undefined) { + return { end: TransitionEndEvent[name] }; + } + } + + return false; +} + +function transitionEndEmulator(duration) { + var _this = this; + + var called = false; + + $(this).one(Util.TRANSITION_END, function () { + called = true; + }); + + setTimeout(function () { + if (!called) { + $(_this).trigger(transition.end); + } + }, duration); + + return this; +} + +function setTransitionEndSupport() { + transition = transitionEndTest(); + + $.fn.emulateTransitionEnd = transitionEndEmulator; + + if (Util.supportsTransitionEnd()) { + $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent(); + } +} + +setTransitionEndSupport(); +module.exports = exports['default']; diff --git a/js/src/alert.js b/js/src/alert.js index bd12b1a55..d69ad8910 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,3 +1,6 @@ +import Util from './util' + + /** * -------------------------------------------------------------------------- * Bootstrap (v4.0.0): alert.js @@ -5,164 +8,171 @@ * -------------------------------------------------------------------------- */ -import Util from 'util' +const Alert = (() => { -/** - * -------------------------------------------------------------------------- - * Constants - * -------------------------------------------------------------------------- - */ + /** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ -const NAME = 'alert' -const VERSION = '4.0.0' -const DATA_KEY = 'bs.alert' -const JQUERY_NO_CONFLICT = $.fn[NAME] -const TRANSITION_DURATION = 150 + const NAME = 'alert' + const VERSION = '4.0.0' + const DATA_KEY = 'bs.alert' + const JQUERY_NO_CONFLICT = $.fn[NAME] + const TRANSITION_DURATION = 150 -const Selector = { - DISMISS : '[data-dismiss="alert"]' -} + const Selector = { + DISMISS : '[data-dismiss="alert"]' + } -const Event = { - CLOSE : 'close.bs.alert', - CLOSED : 'closed.bs.alert', - CLICK : 'click.bs.alert.data-api' -} + const Event = { + CLOSE : 'close.bs.alert', + CLOSED : 'closed.bs.alert', + CLICK : 'click.bs.alert.data-api' + } -const ClassName = { - ALERT : 'alert', - FADE : 'fade', - IN : 'in' -} - - -/** - * -------------------------------------------------------------------------- - * Class Definition - * -------------------------------------------------------------------------- - */ - -export class Alert { - - constructor(element) { - if (element) { - this.element = element - } + const ClassName = { + ALERT : 'alert', + FADE : 'fade', + IN : 'in' } - // public + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - close(element) { - let rootElement = this._getRootElement(element) - let customEvent = this._triggerCloseEvent(rootElement) + class Alert { - if (customEvent.isDefaultPrevented()) { - return + constructor(element) { + if (element) { + this.element = element + } } - this._removeElement(rootElement) - } + // public - // private + close(element) { + let rootElement = this._getRootElement(element) + let customEvent = this._triggerCloseEvent(rootElement) - _getRootElement(element) { - let parent = false - let selector = Util.getSelectorFromElement(element) - - if (selector) { - parent = $(selector)[0] - } - - if (!parent) { - parent = $(element).closest('.' + ClassName.ALERT)[0] - } - - return parent - } - - _triggerCloseEvent(element) { - var closeEvent = $.Event(Event.CLOSE) - $(element).trigger(closeEvent) - return closeEvent - } - - _removeElement(element) { - $(element).removeClass(ClassName.IN) - - if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) { - this._destroyElement(element) - return - } - - $(element) - .one(Util.TRANSITION_END, this._destroyElement.bind(this, element)) - .emulateTransitionEnd(TRANSITION_DURATION) - } - - _destroyElement(element) { - $(element) - .detach() - .trigger(Event.CLOSED) - .remove() - } - - - // static - - static _jQueryInterface(config) { - return this.each(function () { - let $element = $(this) - let data = $element.data(DATA_KEY) - - if (!data) { - data = new Alert(this) - $element.data(DATA_KEY, data) + if (customEvent.isDefaultPrevented()) { + return } - if (config === 'close') { - data[config](this) - } - }) - } - - static _handleDismiss(alertInstance) { - return function (event) { - if (event) { - event.preventDefault() - } - - alertInstance.close(this) + this._removeElement(rootElement) } + + + // private + + _getRootElement(element) { + let parent = false + let selector = Util.getSelectorFromElement(element) + + if (selector) { + parent = $(selector)[0] + } + + if (!parent) { + parent = $(element).closest('.' + ClassName.ALERT)[0] + } + + return parent + } + + _triggerCloseEvent(element) { + var closeEvent = $.Event(Event.CLOSE) + $(element).trigger(closeEvent) + return closeEvent + } + + _removeElement(element) { + $(element).removeClass(ClassName.IN) + + if (!Util.supportsTransitionEnd() || + !$(element).hasClass(ClassName.FADE)) { + this._destroyElement(element) + return + } + + $(element) + .one(Util.TRANSITION_END, this._destroyElement.bind(this, element)) + .emulateTransitionEnd(TRANSITION_DURATION) + } + + _destroyElement(element) { + $(element) + .detach() + .trigger(Event.CLOSED) + .remove() + } + + + // static + + static _jQueryInterface(config) { + return this.each(function () { + let $element = $(this) + let data = $element.data(DATA_KEY) + + if (!data) { + data = new Alert(this) + $element.data(DATA_KEY, data) + } + + if (config === 'close') { + data[config](this) + } + }) + } + + static _handleDismiss(alertInstance) { + return function (event) { + if (event) { + event.preventDefault() + } + + alertInstance.close(this) + } + } + } -} + + /** + * ------------------------------------------------------------------------ + * Data Api implementation + * ------------------------------------------------------------------------ + */ + + $(document).on( + Event.CLICK, + Selector.DISMISS, + Alert._handleDismiss(new Alert()) + ) -/** - * -------------------------------------------------------------------------- - * Data Api implementation - * -------------------------------------------------------------------------- - */ + /** + * ------------------------------------------------------------------------ + * jQuery + * ------------------------------------------------------------------------ + */ -$(document).on( - Event.CLICK, - Selector.DISMISS, - Alert._handleDismiss(new Alert()) -) + $.fn[NAME] = Alert._jQueryInterface + $.fn[NAME].Constructor = Alert + $.fn[NAME].noConflict = function () { + $.fn[NAME] = Alert._JQUERY_NO_CONFLICT + return Alert._jQueryInterface + } + return Alert -/** - * -------------------------------------------------------------------------- - * jQuery - * -------------------------------------------------------------------------- - */ +})() -$.fn[NAME] = Alert._jQueryInterface -$.fn[NAME].Constructor = Alert -$.fn[NAME].noConflict = function () { - $.fn[NAME] = Alert._JQUERY_NO_CONFLICT - return Alert._jQueryInterface -} +export default Alert diff --git a/js/src/util.js b/js/src/util.js index e9542149e..68205edef 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -5,114 +5,120 @@ * -------------------------------------------------------------------------- */ +const Util = (() => { -/** - * -------------------------------------------------------------------------- - * Public Util Api - * -------------------------------------------------------------------------- - */ -var Util = { + /** + * ------------------------------------------------------------------------ + * Private TransitionEnd Helpers + * ------------------------------------------------------------------------ + */ - TRANSITION_END: 'bsTransitionEnd', + let transition = false - getUID(prefix) { - do prefix += ~~(Math.random() * 1000000) - while (document.getElementById(prefix)) - return prefix - }, - - getSelectorFromElement(element) { - let selector = element.getAttribute('data-target') - - if (!selector) { - selector = element.getAttribute('href') || '' - selector = /^#[a-z]/i.test(selector) ? selector : null - } - - return selector - }, - - reflow(element) { - new Function('bs', 'return bs')(element.offsetHeight) - }, - - supportsTransitionEnd() { - return !!transition + const TransitionEndEvent = { + WebkitTransition : 'webkitTransitionEnd', + MozTransition : 'transitionend', + OTransition : 'oTransitionEnd otransitionend', + transition : 'transitionend' } -} - -export default Util - - -/** - * -------------------------------------------------------------------------- - * Private TransitionEnd Helpers - * -------------------------------------------------------------------------- - */ - -let transition = false - -const TransitionEndEvent = { - WebkitTransition : 'webkitTransitionEnd', - MozTransition : 'transitionend', - OTransition : 'oTransitionEnd otransitionend', - transition : 'transitionend' -} - -function getSpecialTransitionEndEvent() { - return { - bindType: transition.end, - delegateType: transition.end, - handle: function (event) { - if ($(event.target).is(this)) { - return event.handleObj.handler.apply(this, arguments) + function getSpecialTransitionEndEvent() { + return { + bindType: transition.end, + delegateType: transition.end, + handle: function (event) { + if ($(event.target).is(this)) { + return event.handleObj.handler.apply(this, arguments) + } } } } -} -function transitionEndTest() { - if (window.QUnit) { + function transitionEndTest() { + if (window.QUnit) { + return false + } + + let el = document.createElement('bootstrap') + + for (var name in TransitionEndEvent) { + if (el.style[name] !== undefined) { + return { end: TransitionEndEvent[name] } + } + } + return false } - let el = document.createElement('bootstrap') + function transitionEndEmulator(duration) { + let called = false - for (var name in TransitionEndEvent) { - if (el.style[name] !== undefined) { - return { end: TransitionEndEvent[name] } + $(this).one(Util.TRANSITION_END, function () { + called = true + }) + + setTimeout(() => { + if (!called) { + $(this).trigger(transition.end) + } + }, duration) + + return this + } + + function setTransitionEndSupport() { + transition = transitionEndTest() + + $.fn.emulateTransitionEnd = transitionEndEmulator + + if (Util.supportsTransitionEnd()) { + $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent() } } - return false -} -function transitionEndEmulator(duration) { - let called = false + /** + * -------------------------------------------------------------------------- + * Public Util Api + * -------------------------------------------------------------------------- + */ - $(this).one(Util.TRANSITION_END, function () { - called = true - }) + let Util = { - setTimeout(() => { - if (!called) { - $(this).trigger(transition.end) + TRANSITION_END: 'bsTransitionEnd', + + getUID(prefix) { + do prefix += ~~(Math.random() * 1000000) + while (document.getElementById(prefix)) + return prefix + }, + + getSelectorFromElement(element) { + let selector = element.getAttribute('data-target') + + if (!selector) { + selector = element.getAttribute('href') || '' + selector = /^#[a-z]/i.test(selector) ? selector : null + } + + return selector + }, + + reflow(element) { + new Function('bs', 'return bs')(element.offsetHeight) + }, + + supportsTransitionEnd() { + return !!transition } - }, duration) - return this -} - -function setTransitionEndSupport() { - transition = transitionEndTest() - - $.fn.emulateTransitionEnd = transitionEndEmulator - - if (Util.supportsTransitionEnd()) { - $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent() } -} -setTransitionEndSupport() + setTransitionEndSupport() + + return Util + +})() + +export default Util