Skip to content

Commit

Permalink
Merge branch 'master' into master-xmr-hugo-2
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Aug 4, 2019
2 parents 61a02f6 + 2be5f03 commit 519888d
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 59 deletions.
6 changes: 4 additions & 2 deletions js/src/alert/alert.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
Expand Down Expand Up @@ -165,6 +165,8 @@ class Alert {
EventHandler
.on(document, Event.CLICK_DATA_API, Selector.DISMISS, Alert.handleDismiss(new Alert()))

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
Expand All @@ -173,7 +175,7 @@ EventHandler
*/

/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Alert.jQueryInterface
$.fn[NAME].Constructor = Alert
Expand Down
6 changes: 4 additions & 2 deletions js/src/button/button.js
Expand Up @@ -5,7 +5,7 @@
* --------------------------------------------------------------------------
*/

import { jQuery as $ } from '../util/index'
import { getjQuery } from '../util/index'
import Data from '../dom/data'
import EventHandler from '../dom/event-handler'
import SelectorEngine from '../dom/selector-engine'
Expand Down Expand Up @@ -179,14 +179,16 @@ EventHandler.on(document, Event.BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, even
}
})

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .button to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Button.jQueryInterface
$.fn[NAME].Constructor = Button
Expand Down
6 changes: 4 additions & 2 deletions js/src/carousel/carousel.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
Expand Down Expand Up @@ -615,14 +615,16 @@ EventHandler.on(window, Event.LOAD_DATA_API, () => {
}
})

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .carousel to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Carousel.jQueryInterface
$.fn[NAME].Constructor = Carousel
Expand Down
6 changes: 4 additions & 2 deletions js/src/collapse/collapse.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
getSelectorFromElement,
Expand Down Expand Up @@ -419,14 +419,16 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (
})
})

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .collapse to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Collapse.jQueryInterface
$.fn[NAME].Constructor = Collapse
Expand Down
5 changes: 3 additions & 2 deletions js/src/dom/event-handler.js
Expand Up @@ -5,7 +5,7 @@
* --------------------------------------------------------------------------
*/

import { jQuery as $ } from '../util/index'
import { getjQuery } from '../util/index'
import { createCustomEvent, defaultPreventedPreservedOnDispatch } from './polyfill'

/**
Expand All @@ -14,6 +14,7 @@ import { createCustomEvent, defaultPreventedPreservedOnDispatch } from './polyfi
* ------------------------------------------------------------------------
*/

const $ = getjQuery()
const namespaceRegex = /[^.]*(?=\..*)\.|.*/
const stripNameRegex = /\..*/
const keyEventRegex = /^key/
Expand Down Expand Up @@ -293,7 +294,7 @@ const EventHandler = {
let defaultPrevented = false
let evt = null

if (inNamespace && typeof $ !== 'undefined') {
if (inNamespace && $) {
jQueryEvent = $.Event(event, args)

$(element).trigger(jQueryEvent)
Expand Down
6 changes: 4 additions & 2 deletions js/src/dropdown/dropdown.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
getElementFromSelector,
isElement,
makeArray,
Expand Down Expand Up @@ -526,14 +526,16 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (
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 (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Dropdown.jQueryInterface
$.fn[NAME].Constructor = Dropdown
Expand Down
6 changes: 4 additions & 2 deletions js/src/modal/modal.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
Expand Down Expand Up @@ -582,14 +582,16 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (
data.show(this)
})

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .modal to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Modal.jQueryInterface
$.fn[NAME].Constructor = Modal
Expand Down
6 changes: 4 additions & 2 deletions js/src/popover/popover.js
Expand Up @@ -5,7 +5,7 @@
* --------------------------------------------------------------------------
*/

import { jQuery as $ } from '../util/index'
import { getjQuery } from '../util/index'
import Data from '../dom/data'
import SelectorEngine from '../dom/selector-engine'
import Tooltip from '../tooltip/tooltip'
Expand Down Expand Up @@ -173,13 +173,15 @@ class Popover extends Tooltip {
}
}

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Popover.jQueryInterface
$.fn[NAME].Constructor = Popover
Expand Down
6 changes: 4 additions & 2 deletions js/src/scrollspy/scrollspy.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
getSelectorFromElement,
getUID,
makeArray,
Expand Down Expand Up @@ -336,13 +336,15 @@ EventHandler.on(window, Event.LOAD_DATA_API, () => {
.forEach(spy => new ScrollSpy(spy, Manipulator.getDataAttributes(spy)))
})

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = ScrollSpy.jQueryInterface
$.fn[NAME].Constructor = ScrollSpy
Expand Down
6 changes: 4 additions & 2 deletions js/src/tab/tab.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
getElementFromSelector,
Expand Down Expand Up @@ -242,14 +242,16 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (
data.show()
})

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .tab to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Tab.jQueryInterface
$.fn[NAME].Constructor = Tab
Expand Down
6 changes: 4 additions & 2 deletions js/src/toast/toast.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
getTransitionDurationFromElement,
Expand Down Expand Up @@ -222,14 +222,16 @@ class Toast {
}
}

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .toast to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Toast.jQueryInterface
$.fn[NAME].Constructor = Toast
Expand Down
6 changes: 4 additions & 2 deletions js/src/tooltip/tooltip.js
Expand Up @@ -6,7 +6,7 @@
*/

import {
jQuery as $,
getjQuery,
TRANSITION_END,
emulateTransitionEnd,
findShadowRoot,
Expand Down Expand Up @@ -798,14 +798,16 @@ class Tooltip {
}
}

const $ = getjQuery()

/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
* add .tooltip to jQuery only if jQuery is present
*/
/* istanbul ignore if */
if (typeof $ !== 'undefined') {
if ($) {
const JQUERY_NO_CONFLICT = $.fn[NAME]
$.fn[NAME] = Tooltip.jQueryInterface
$.fn[NAME].Constructor = Tooltip
Expand Down
13 changes: 11 additions & 2 deletions js/src/util/index.js
Expand Up @@ -8,7 +8,6 @@
const MAX_UID = 1000000
const MILLISECONDS_MULTIPLIER = 1000
const TRANSITION_END = 'transitionend'
const { jQuery } = window

// Shoutout AngusCroll (https://goo.gl/pxwQGp)
const toType = obj => ({}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase())
Expand Down Expand Up @@ -176,8 +175,18 @@ const noop = () => function () {}

const reflow = element => element.offsetHeight

const getjQuery = () => {
const { jQuery } = window

if (jQuery && !document.body.hasAttribute('data-no-jquery')) {
return jQuery
}

return null
}

export {
jQuery,
getjQuery,
TRANSITION_END,
getUID,
getSelectorFromElement,
Expand Down
33 changes: 33 additions & 0 deletions js/src/util/index.spec.js
Expand Up @@ -346,4 +346,37 @@ describe('Util', () => {
expect(Util.reflow(div)).toEqual(0)
})
})

describe('getjQuery', () => {
const fakejQuery = { trigger() {} }

beforeEach(() => {
Object.defineProperty(window, 'jQuery', {
value: fakejQuery,
writable: true
})
})

afterEach(() => {
window.jQuery = undefined
})

it('should return jQuery object when present', () => {
expect(Util.getjQuery()).toEqual(fakejQuery)
})

it('should not return jQuery object when present if data-no-jquery', () => {
document.body.setAttribute('data-no-jquery', '')

expect(window.jQuery).toEqual(fakejQuery)
expect(Util.getjQuery()).toEqual(null)

document.body.removeAttribute('data-no-jquery')
})

it('should not return jQuery if not present', () => {
window.jQuery = undefined
expect(Util.getjQuery()).toEqual(null)
})
})
})

0 comments on commit 519888d

Please sign in to comment.