diff options
Diffstat (limited to 'js/src')
| -rw-r--r-- | js/src/alert.js | 9 | ||||
| -rw-r--r-- | js/src/button.js | 9 | ||||
| -rw-r--r-- | js/src/carousel.js | 15 | ||||
| -rw-r--r-- | js/src/collapse.js | 29 | ||||
| -rw-r--r-- | js/src/dropdown.js | 40 | ||||
| -rw-r--r-- | js/src/index.js | 46 | ||||
| -rw-r--r-- | js/src/modal.js | 28 | ||||
| -rw-r--r-- | js/src/popover.js | 14 | ||||
| -rw-r--r-- | js/src/scrollspy.js | 17 | ||||
| -rw-r--r-- | js/src/tab.js | 32 | ||||
| -rw-r--r-- | js/src/tooltip.js | 30 | ||||
| -rw-r--r-- | js/src/util.js | 26 |
12 files changed, 199 insertions, 96 deletions
diff --git a/js/src/alert.js b/js/src/alert.js index b30d0d3a0..9d6c498b9 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): alert.js + * Bootstrap (v4.0.0-beta): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Alert = (($) => { +const Alert = (() => { /** @@ -18,7 +19,7 @@ const Alert = (($) => { */ const NAME = 'alert' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.alert' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -188,6 +189,6 @@ const Alert = (($) => { return Alert -})(jQuery) +})($) export default Alert diff --git a/js/src/button.js b/js/src/button.js index 722fd489d..7bf5e87dd 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -1,11 +1,12 @@ +import $ from 'jquery' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): button.js + * Bootstrap (v4.0.0-beta): button.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Button = (($) => { +const Button = (() => { /** @@ -15,7 +16,7 @@ const Button = (($) => { */ const NAME = 'button' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.button' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -181,6 +182,6 @@ const Button = (($) => { return Button -})(jQuery) +})($) export default Button diff --git a/js/src/carousel.js b/js/src/carousel.js index 5993de256..3a6d7a4bc 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): carousel.js + * Bootstrap (v4.0.0-beta): carousel.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Carousel = (($) => { +const Carousel = (() => { /** @@ -18,7 +19,7 @@ const Carousel = (($) => { */ const NAME = 'carousel' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.carousel' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -131,7 +132,9 @@ const Carousel = (($) => { nextWhenVisible() { // Don't call next when the page isn't visible - if (!document.hidden) { + // or the carousel or its parent isn't visible + if (!document.hidden && + ($(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden')) { this.next() } } @@ -441,7 +444,7 @@ const Carousel = (($) => { if (typeof config === 'number') { data.to(config) } else if (typeof action === 'string') { - if (data[action] === undefined) { + if (typeof data[action] === 'undefined') { throw new Error(`No method named "${action}"`) } data[action]() @@ -516,6 +519,6 @@ const Carousel = (($) => { return Carousel -})(jQuery) +})($) export default Carousel diff --git a/js/src/collapse.js b/js/src/collapse.js index 78ed32906..d29e48722 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): collapse.js + * Bootstrap (v4.0.0-beta): collapse.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Collapse = (($) => { +const Collapse = (() => { /** @@ -18,7 +19,7 @@ const Collapse = (($) => { */ const NAME = 'collapse' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.collapse' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -32,7 +33,7 @@ const Collapse = (($) => { const DefaultType = { toggle : 'boolean', - parent : 'string' + parent : '(string|element)' } const Event = { @@ -288,7 +289,18 @@ const Collapse = (($) => { } _getParent() { - const parent = $(this._config.parent)[0] + let parent = null + if (Util.isElement(this._config.parent)) { + parent = this._config.parent + + // it's a jQuery object + if (typeof this._config.parent.jquery !== 'undefined') { + parent = this._config.parent[0] + } + } else { + parent = $(this._config.parent)[0] + } + const selector = `[data-toggle="collapse"][data-parent="${this._config.parent}"]` @@ -343,7 +355,7 @@ const Collapse = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() @@ -361,7 +373,8 @@ const Collapse = (($) => { */ $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) { - if (!/input|textarea/i.test(event.target.tagName)) { + // preventDefault only for <a> elements (which change the URL) not inside the collapsible element + if (event.currentTarget.tagName === 'A') { event.preventDefault() } @@ -391,6 +404,6 @@ const Collapse = (($) => { return Collapse -})(jQuery) +})($) export default Collapse diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 234d23447..3a910996b 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -1,16 +1,16 @@ -/* global Popper */ - +import $ from 'jquery' +import Popper from 'popper.js' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): dropdown.js + * Bootstrap (v4.0.0-beta): dropdown.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Dropdown = (($) => { +const Dropdown = (() => { /** * Check for Popper dependency @@ -27,7 +27,7 @@ const Dropdown = (($) => { */ const NAME = 'dropdown' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.dropdown' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -75,14 +75,12 @@ const Dropdown = (($) => { } const Default = { - placement : AttachmentMap.BOTTOM, offset : 0, flip : true } const DefaultType = { - placement : 'string', - offset : '(number|string)', + offset : '(number|string|function)', flip : 'boolean' } @@ -203,11 +201,6 @@ const Dropdown = (($) => { } _getConfig(config) { - const elementData = $(this._element).data() - if (elementData.placement !== undefined) { - elementData.placement = AttachmentMap[elementData.placement.toUpperCase()] - } - config = $.extend( {}, this.constructor.Default, @@ -234,10 +227,10 @@ const Dropdown = (($) => { _getPlacement() { const $parentDropdown = $(this._element).parent() - let placement = this._config.placement + let placement = AttachmentMap.BOTTOM // Handle dropup - if ($parentDropdown.hasClass(ClassName.DROPUP) || this._config.placement === AttachmentMap.TOP) { + if ($parentDropdown.hasClass(ClassName.DROPUP)) { placement = AttachmentMap.TOP if ($(this._menu).hasClass(ClassName.MENURIGHT)) { placement = AttachmentMap.TOPEND @@ -253,12 +246,19 @@ const Dropdown = (($) => { } _getPopperConfig() { + const offsetConf = {} + if (typeof this._config.offset === 'function') { + offsetConf.fn = (data) => { + data.offsets = $.extend({}, data.offsets, this._config.offset(data.offsets) || {}) + return data + } + } else { + offsetConf.offset = this._config.offset + } const popperConfig = { placement : this._getPlacement(), modifiers : { - offset : { - offset : this._config.offset - }, + offset : offsetConf, flip : { enabled : this._config.flip } @@ -287,7 +287,7 @@ const Dropdown = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() @@ -445,6 +445,6 @@ const Dropdown = (($) => { return Dropdown -})(jQuery) +})($, Popper) export default Dropdown diff --git a/js/src/index.js b/js/src/index.js new file mode 100644 index 000000000..2629e507f --- /dev/null +++ b/js/src/index.js @@ -0,0 +1,46 @@ +import $ from 'jquery' +import Alert from './alert' +import Button from './button' +import Carousel from './carousel' +import Collapse from './collapse' +import Dropdown from './dropdown' +import Modal from './modal' +import Popover from './popover' +import Scrollspy from './scrollspy' +import Tab from './tab' +import Tooltip from './tooltip' +import Util from './util' + +/** + * -------------------------------------------------------------------------- + * Bootstrap (v4.0.0-alpha.6): index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + * -------------------------------------------------------------------------- + */ + +(() => { + if (typeof $ === 'undefined') { + throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.') + } + + const version = $.fn.jquery.split(' ')[0].split('.') + const min = 3 + const max = 4 + if (version[0] < min || version[0] >= max) { + throw new Error('Bootstrap\'s JavaScript requires at least jQuery v3.0.0 but less than v4.0.0') + } +})($) + +export { + Util, + Alert, + Button, + Carousel, + Collapse, + Dropdown, + Modal, + Popover, + Scrollspy, + Tab, + Tooltip +} diff --git a/js/src/modal.js b/js/src/modal.js index 02d463945..fb787208d 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): modal.js + * Bootstrap (v4.0.0-beta): modal.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Modal = (($) => { +const Modal = (() => { /** @@ -18,7 +19,7 @@ const Modal = (($) => { */ const NAME = 'modal' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.modal' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -68,6 +69,7 @@ const Modal = (($) => { DATA_TOGGLE : '[data-toggle="modal"]', DATA_DISMISS : '[data-dismiss="modal"]', FIXED_CONTENT : '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top', + STICKY_CONTENT : '.sticky-top', NAVBAR_TOGGLER : '.navbar-toggler' } @@ -134,6 +136,8 @@ const Modal = (($) => { this._checkScrollbar() this._setScrollbar() + this._adjustDialog() + $(document.body).addClass(ClassName.OPEN) this._setEscapeEvent() @@ -425,7 +429,8 @@ const Modal = (($) => { } _checkScrollbar() { - this._isBodyOverflowing = document.body.clientWidth < window.innerWidth + const rect = document.body.getBoundingClientRect() + this._isBodyOverflowing = rect.left + rect.right < window.innerWidth this._scrollbarWidth = this._getScrollbarWidth() } @@ -441,6 +446,13 @@ const Modal = (($) => { $(element).data('padding-right', actualPadding).css('padding-right', `${parseFloat(calculatedPadding) + this._scrollbarWidth}px`) }) + // Adjust sticky content margin + $(Selector.STICKY_CONTENT).each((index, element) => { + const actualMargin = $(element)[0].style.marginRight + const calculatedMargin = $(element).css('margin-right') + $(element).data('margin-right', actualMargin).css('margin-right', `${parseFloat(calculatedMargin) - this._scrollbarWidth}px`) + }) + // Adjust navbar-toggler margin $(Selector.NAVBAR_TOGGLER).each((index, element) => { const actualMargin = $(element)[0].style.marginRight @@ -464,8 +476,8 @@ const Modal = (($) => { } }) - // Restore navbar-toggler margin - $(Selector.NAVBAR_TOGGLER).each((index, element) => { + // Restore sticky content and navbar-toggler margin + $(`${Selector.STICKY_CONTENT}, ${Selector.NAVBAR_TOGGLER}`).each((index, element) => { const margin = $(element).data('margin-right') if (typeof margin !== 'undefined') { $(element).css('margin-right', margin).removeData('margin-right') @@ -507,7 +519,7 @@ const Modal = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config](relatedTarget) @@ -573,6 +585,6 @@ const Modal = (($) => { return Modal -})(jQuery) +})($) export default Modal diff --git a/js/src/popover.js b/js/src/popover.js index 5c2b65b86..89c78f4fe 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Tooltip from './tooltip' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): popover.js + * Bootstrap (v4.0.0-beta): popover.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Popover = (($) => { +const Popover = (() => { /** @@ -18,7 +19,7 @@ const Popover = (($) => { */ const NAME = 'popover' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.popover' const EVENT_KEY = `.${DATA_KEY}` const JQUERY_NO_CONFLICT = $.fn[NAME] @@ -114,7 +115,8 @@ const Popover = (($) => { } getTipElement() { - return this.tip = this.tip || $(this.config.template)[0] + this.tip = this.tip || $(this.config.template)[0] + return this.tip } setContent() { @@ -162,7 +164,7 @@ const Popover = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() @@ -187,6 +189,6 @@ const Popover = (($) => { return Popover -})(jQuery) +})($) export default Popover diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js index 7ea9f2483..c844bd530 100644 --- a/js/src/scrollspy.js +++ b/js/src/scrollspy.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): scrollspy.js + * Bootstrap (v4.0.0-beta): scrollspy.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const ScrollSpy = (($) => { +const ScrollSpy = (() => { /** @@ -18,7 +19,7 @@ const ScrollSpy = (($) => { */ const NAME = 'scrollspy' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.scrollspy' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -53,6 +54,7 @@ const ScrollSpy = (($) => { ACTIVE : '.active', NAV_LIST_GROUP : '.nav, .list-group', NAV_LINKS : '.nav-link', + NAV_ITEMS : '.nav-item', LIST_ITEMS : '.list-group-item', DROPDOWN : '.dropdown', DROPDOWN_ITEMS : '.dropdown-item', @@ -231,7 +233,7 @@ const ScrollSpy = (($) => { for (let i = this._offsets.length; i--;) { const isActiveTarget = this._activeTarget !== this._targets[i] && scrollTop >= this._offsets[i] - && (this._offsets[i + 1] === undefined || + && (typeof this._offsets[i + 1] === 'undefined' || scrollTop < this._offsets[i + 1]) if (isActiveTarget) { @@ -246,6 +248,7 @@ const ScrollSpy = (($) => { this._clear() let queries = this._selector.split(',') + // eslint-disable-next-line arrow-body-style queries = queries.map((selector) => { return `${selector}[data-target="${target}"],` + `${selector}[href="${target}"]` @@ -262,6 +265,8 @@ const ScrollSpy = (($) => { // Set triggered links parents as active // With both <ul> and <nav> markup a parent is the previous sibling of any nav ancestor $link.parents(Selector.NAV_LIST_GROUP).prev(`${Selector.NAV_LINKS}, ${Selector.LIST_ITEMS}`).addClass(ClassName.ACTIVE) + // Handle special case when .nav-link is inside .nav-item + $link.parents(Selector.NAV_LIST_GROUP).prev(Selector.NAV_ITEMS).children(Selector.NAV_LINKS).addClass(ClassName.ACTIVE) } $(this._scrollElement).trigger(Event.ACTIVATE, { @@ -287,7 +292,7 @@ const ScrollSpy = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() @@ -330,6 +335,6 @@ const ScrollSpy = (($) => { return ScrollSpy -})(jQuery) +})($) export default ScrollSpy diff --git a/js/src/tab.js b/js/src/tab.js index c7bc520df..17699dfbe 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -1,14 +1,15 @@ +import $ from 'jquery' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): tab.js + * Bootstrap (v4.0.0-beta): tab.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Tab = (($) => { +const Tab = (() => { /** @@ -18,7 +19,7 @@ const Tab = (($) => { */ const NAME = 'tab' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.tab' const EVENT_KEY = `.${DATA_KEY}` const DATA_API_KEY = '.data-api' @@ -45,6 +46,7 @@ const Tab = (($) => { DROPDOWN : '.dropdown', NAV_LIST_GROUP : '.nav, .list-group', ACTIVE : '.active', + ACTIVE_UL : '> li > .active', DATA_TOGGLE : '[data-toggle="tab"], [data-toggle="pill"], [data-toggle="list"]', DROPDOWN_TOGGLE : '.dropdown-toggle', DROPDOWN_ACTIVE_CHILD : '> .dropdown-menu .active' @@ -87,7 +89,8 @@ const Tab = (($) => { const selector = Util.getSelectorFromElement(this._element) if (listElement) { - previous = $.makeArray($(listElement).find(Selector.ACTIVE)) + const itemSelector = listElement.nodeName === 'UL' ? Selector.ACTIVE_UL : Selector.ACTIVE + previous = $.makeArray($(listElement).find(itemSelector)) previous = previous[previous.length - 1] } @@ -148,7 +151,14 @@ const Tab = (($) => { // private _activate(element, container, callback) { - const active = $(container).find(Selector.ACTIVE)[0] + let activeElements + if (container.nodeName === 'UL') { + activeElements = $(container).find(Selector.ACTIVE_UL) + } else { + activeElements = $(container).children(Selector.ACTIVE) + } + + const active = activeElements[0] const isTransitioning = callback && Util.supportsTransitionEnd() && (active && $(active).hasClass(ClassName.FADE)) @@ -186,11 +196,15 @@ const Tab = (($) => { $(dropdownChild).removeClass(ClassName.ACTIVE) } - active.setAttribute('aria-expanded', false) + if (active.getAttribute('role') === 'tab') { + active.setAttribute('aria-selected', false) + } } $(element).addClass(ClassName.ACTIVE) - element.setAttribute('aria-expanded', true) + if (element.getAttribute('role') === 'tab') { + element.setAttribute('aria-selected', true) + } if (isTransitioning) { Util.reflow(element) @@ -229,7 +243,7 @@ const Tab = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() @@ -268,6 +282,6 @@ const Tab = (($) => { return Tab -})(jQuery) +})($) export default Tab diff --git a/js/src/tooltip.js b/js/src/tooltip.js index c7c7b9f9d..8d262f4ad 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -1,16 +1,16 @@ -/* global Popper */ - +import $ from 'jquery' +import Popper from 'popper.js' import Util from './util' /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): tooltip.js + * Bootstrap (v4.0.0-beta): tooltip.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Tooltip = (($) => { +const Tooltip = (() => { /** * Check for Popper dependency @@ -28,7 +28,7 @@ const Tooltip = (($) => { */ const NAME = 'tooltip' - const VERSION = '4.0.0-alpha.6' + const VERSION = '4.0.0-beta' const DATA_KEY = 'bs.tooltip' const EVENT_KEY = `.${DATA_KEY}` const JQUERY_NO_CONFLICT = $.fn[NAME] @@ -184,6 +184,10 @@ const Tooltip = (($) => { } toggle(event) { + if (!this._isEnabled) { + return + } + if (event) { const dataKey = this.constructor.DATA_KEY let context = $(event.currentTarget).data(dataKey) @@ -234,8 +238,8 @@ const Tooltip = (($) => { if (this._popper !== null) { this._popper.destroy() } - this._popper = null + this._popper = null this.element = null this.config = null this.tip = null @@ -415,7 +419,8 @@ const Tooltip = (($) => { } getTipElement() { - return this.tip = this.tip || $(this.config.template)[0] + this.tip = this.tip || $(this.config.template)[0] + return this.tip } setContent() { @@ -617,18 +622,18 @@ const Tooltip = (($) => { config ) - if (config.delay && typeof config.delay === 'number') { + if (typeof config.delay === 'number') { config.delay = { show : config.delay, hide : config.delay } } - if (config.title && typeof config.title === 'number') { + if (typeof config.title === 'number') { config.title = config.title.toString() } - if (config.content && typeof config.content === 'number') { + if (typeof config.content === 'number') { config.content = config.content.toString() } @@ -698,14 +703,13 @@ const Tooltip = (($) => { } if (typeof config === 'string') { - if (data[config] === undefined) { + if (typeof data[config] === 'undefined') { throw new Error(`No method named "${config}"`) } data[config]() } }) } - } @@ -724,6 +728,6 @@ const Tooltip = (($) => { return Tooltip -})(jQuery) +})($, Popper) export default Tooltip diff --git a/js/src/util.js b/js/src/util.js index 3c0d02251..a75660014 100644 --- a/js/src/util.js +++ b/js/src/util.js @@ -1,11 +1,13 @@ +import $ from 'jquery' + /** * -------------------------------------------------------------------------- - * Bootstrap (v4.0.0-alpha.6): util.js + * Bootstrap (v4.0.0-beta): util.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) * -------------------------------------------------------------------------- */ -const Util = (($) => { +const Util = (() => { /** @@ -30,10 +32,6 @@ const Util = (($) => { return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase() } - function isElement(obj) { - return (obj[0] || obj).nodeType - } - function getSpecialTransitionEndEvent() { return { bindType: transition.end, @@ -42,7 +40,7 @@ const Util = (($) => { if ($(event.target).is(this)) { return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params } - return undefined + return undefined // eslint-disable-line no-undefined } } } @@ -55,7 +53,7 @@ const Util = (($) => { const el = document.createElement('bootstrap') for (const name in TransitionEndEvent) { - if (el.style[name] !== undefined) { + if (typeof el.style[name] !== 'undefined') { return { end: TransitionEndEvent[name] } @@ -117,7 +115,7 @@ const Util = (($) => { } try { - const $selector = $(selector) + const $selector = $(document).find(selector) return $selector.length > 0 ? selector : null } catch (error) { return null @@ -136,12 +134,16 @@ const Util = (($) => { return Boolean(transition) }, + isElement(obj) { + return (obj[0] || obj).nodeType + }, + typeCheckConfig(componentName, config, configTypes) { for (const property in configTypes) { - if (configTypes.hasOwnProperty(property)) { + if (Object.prototype.hasOwnProperty.call(configTypes, property)) { const expectedTypes = configTypes[property] const value = config[property] - const valueType = value && isElement(value) ? + const valueType = value && Util.isElement(value) ? 'element' : toType(value) if (!new RegExp(expectedTypes).test(valueType)) { @@ -159,6 +161,6 @@ const Util = (($) => { return Util -})(jQuery) +})($) export default Util |
