import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
*/
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert()))
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* add .alert to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Alert.jQueryInterface
- $.fn[NAME].Constructor = Alert
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Alert.jQueryInterface
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Alert.jQueryInterface
+ $.fn[NAME].Constructor = Alert
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Alert.jQueryInterface
+ }
}
-}
+})
export default Alert
* --------------------------------------------------------------------------
*/
-import { getjQuery } from './util/index'
+import { getjQuery, onDOMContentLoaded } from './util/index'
import Data from './dom/data'
import EventHandler from './dom/event-handler'
data.toggle()
})
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .button to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Button.jQueryInterface
- $.fn[NAME].Constructor = Button
-
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Button.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Button.jQueryInterface
+ $.fn[NAME].Constructor = Button
+
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Button.jQueryInterface
+ }
}
-}
+})
export default Button
import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
}
})
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .carousel to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Carousel.jQueryInterface
- $.fn[NAME].Constructor = Carousel
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Carousel.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Carousel.jQueryInterface
+ $.fn[NAME].Constructor = Carousel
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Carousel.jQueryInterface
+ }
}
-}
+})
export default Carousel
import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
getSelectorFromElement,
})
})
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .collapse to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Collapse.jQueryInterface
- $.fn[NAME].Constructor = Collapse
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Collapse.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Collapse.jQueryInterface
+ $.fn[NAME].Constructor = Collapse
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Collapse.jQueryInterface
+ }
}
-}
+})
export default Collapse
* ------------------------------------------------------------------------
*/
-const $ = getjQuery()
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
const stripNameRegex = /\..*/
const stripUidRegex = /::\d+$/
return null
}
+ const $ = getjQuery()
const typeEvent = event.replace(stripNameRegex, '')
const inNamespace = event !== typeEvent
const isNative = nativeEvents.indexOf(typeEvent) > -1
import {
getjQuery,
+ onDOMContentLoaded,
getElementFromSelector,
isElement,
isVisible,
})
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_FORM_CHILD, e => e.stopPropagation())
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .dropdown to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Dropdown.jQueryInterface
- $.fn[NAME].Constructor = Dropdown
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Dropdown.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Dropdown.jQueryInterface
+ $.fn[NAME].Constructor = Dropdown
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Dropdown.jQueryInterface
+ }
}
-}
+})
export default Dropdown
import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
data.show(this)
})
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .modal to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Modal.jQueryInterface
- $.fn[NAME].Constructor = Modal
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Modal.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Modal.jQueryInterface
+ $.fn[NAME].Constructor = Modal
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Modal.jQueryInterface
+ }
}
-}
+})
export default Modal
* --------------------------------------------------------------------------
*/
-import { getjQuery } from './util/index'
+import { getjQuery, onDOMContentLoaded } from './util/index'
import Data from './dom/data'
import SelectorEngine from './dom/selector-engine'
import Tooltip from './tooltip'
}
}
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Popover.jQueryInterface
- $.fn[NAME].Constructor = Popover
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Popover.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Popover.jQueryInterface
+ $.fn[NAME].Constructor = Popover
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Popover.jQueryInterface
+ }
}
-}
+})
export default Popover
import {
getjQuery,
+ onDOMContentLoaded,
getSelectorFromElement,
getUID,
isElement,
.forEach(spy => new ScrollSpy(spy, Manipulator.getDataAttributes(spy)))
})
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = ScrollSpy.jQueryInterface
- $.fn[NAME].Constructor = ScrollSpy
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return ScrollSpy.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = ScrollSpy.jQueryInterface
+ $.fn[NAME].Constructor = ScrollSpy
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return ScrollSpy.jQueryInterface
+ }
}
-}
+})
export default ScrollSpy
import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
data.show()
})
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .tab to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Tab.jQueryInterface
- $.fn[NAME].Constructor = Tab
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Tab.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Tab.jQueryInterface
+ $.fn[NAME].Constructor = Tab
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Tab.jQueryInterface
+ }
}
-}
+})
export default Tab
import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
getTransitionDurationFromElement,
}
}
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .toast to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Toast.jQueryInterface
- $.fn[NAME].Constructor = Toast
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Toast.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Toast.jQueryInterface
+ $.fn[NAME].Constructor = Toast
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Toast.jQueryInterface
+ }
}
-}
+})
export default Toast
import {
getjQuery,
+ onDOMContentLoaded,
TRANSITION_END,
emulateTransitionEnd,
findShadowRoot,
}
}
-const $ = getjQuery()
-
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .tooltip to jQuery only if jQuery is present
*/
-/* istanbul ignore if */
-if ($) {
- const JQUERY_NO_CONFLICT = $.fn[NAME]
- $.fn[NAME] = Tooltip.jQueryInterface
- $.fn[NAME].Constructor = Tooltip
- $.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Tooltip.jQueryInterface
+
+onDOMContentLoaded(() => {
+ const $ = getjQuery()
+ /* istanbul ignore if */
+ if ($) {
+ const JQUERY_NO_CONFLICT = $.fn[NAME]
+ $.fn[NAME] = Tooltip.jQueryInterface
+ $.fn[NAME].Constructor = Tooltip
+ $.fn[NAME].noConflict = () => {
+ $.fn[NAME] = JQUERY_NO_CONFLICT
+ return Tooltip.jQueryInterface
+ }
}
-}
+})
export default Tooltip
return null
}
+const onDOMContentLoaded = callback => {
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', callback)
+ } else {
+ callback()
+ }
+}
+
export {
- getjQuery,
TRANSITION_END,
getUID,
getSelectorFromElement,
isVisible,
findShadowRoot,
noop,
- reflow
+ reflow,
+ getjQuery,
+ onDOMContentLoaded
}
expect(Util.getjQuery()).toEqual(null)
})
})
+
+ describe('onDOMContentLoaded', () => {
+ it('should execute callback when DOMContentLoaded is fired', () => {
+ const spy = jasmine.createSpy()
+ spyOnProperty(document, 'readyState').and.returnValue('loading')
+ Util.onDOMContentLoaded(spy)
+ window.document.dispatchEvent(new Event('DOMContentLoaded', {
+ bubbles: true,
+ cancelable: true
+ }))
+ expect(spy).toHaveBeenCalled()
+ })
+
+ it('should execute callback if readyState is not "loading"', () => {
+ const spy = jasmine.createSpy()
+ Util.onDOMContentLoaded(spy)
+ expect(spy).toHaveBeenCalled()
+ })
+ })
})