mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-17 19:21:23 +03:00
move getJquery function to another file
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getjQuery } from '../util/index'
|
import { getjQuery } from '../util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+1
-10
@@ -4,7 +4,7 @@
|
|||||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
import { getJqueryInterfaceForPlugin } from './jquery-stuff'
|
import { getjQuery, getJqueryInterfaceForPlugin } from './jquery-stuff'
|
||||||
|
|
||||||
const MAX_UID = 1_000_000
|
const MAX_UID = 1_000_000
|
||||||
const MILLISECONDS_MULTIPLIER = 1000
|
const MILLISECONDS_MULTIPLIER = 1000
|
||||||
@@ -204,14 +204,6 @@ const reflow = element => {
|
|||||||
element.offsetHeight // eslint-disable-line no-unused-expressions
|
element.offsetHeight // eslint-disable-line no-unused-expressions
|
||||||
}
|
}
|
||||||
|
|
||||||
const getjQuery = () => {
|
|
||||||
if (window.jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
|
|
||||||
return window.jQuery
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const DOMContentLoadedCallbacks = []
|
const DOMContentLoadedCallbacks = []
|
||||||
|
|
||||||
const onDOMContentLoaded = callback => {
|
const onDOMContentLoaded = callback => {
|
||||||
@@ -321,7 +313,6 @@ export {
|
|||||||
findShadowRoot,
|
findShadowRoot,
|
||||||
getElement,
|
getElement,
|
||||||
getElementFromSelector,
|
getElementFromSelector,
|
||||||
getjQuery,
|
|
||||||
getNextActiveElement,
|
getNextActiveElement,
|
||||||
getSelectorFromElement,
|
getSelectorFromElement,
|
||||||
getTransitionDurationFromElement,
|
getTransitionDurationFromElement,
|
||||||
|
|||||||
Vendored
+11
@@ -5,6 +5,16 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const getjQuery = () => {
|
||||||
|
const { jQuery } = window
|
||||||
|
|
||||||
|
if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
|
||||||
|
return jQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const defaultJQueryInterface = plugin => {
|
const defaultJQueryInterface = plugin => {
|
||||||
return function (config) {
|
return function (config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
@@ -26,5 +36,6 @@ const defaultJQueryInterface = plugin => {
|
|||||||
const getJqueryInterfaceForPlugin = plugin => plugin.jQueryInterface || defaultJQueryInterface(plugin)
|
const getJqueryInterfaceForPlugin = plugin => plugin.jQueryInterface || defaultJQueryInterface(plugin)
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
getjQuery,
|
||||||
getJqueryInterfaceForPlugin
|
getJqueryInterfaceForPlugin
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -538,39 +538,6 @@ describe('Util', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
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-bs-no-jquery', () => {
|
|
||||||
document.body.setAttribute('data-bs-no-jquery', '')
|
|
||||||
|
|
||||||
expect(window.jQuery).toEqual(fakejQuery)
|
|
||||||
expect(Util.getjQuery()).toBeNull()
|
|
||||||
|
|
||||||
document.body.removeAttribute('data-bs-no-jquery')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should not return jQuery if not present', () => {
|
|
||||||
window.jQuery = undefined
|
|
||||||
expect(Util.getjQuery()).toBeNull()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('onDOMContentLoaded', () => {
|
describe('onDOMContentLoaded', () => {
|
||||||
it('should execute callbacks when DOMContentLoaded is fired and should not add more than one listener', () => {
|
it('should execute callbacks when DOMContentLoaded is fired and should not add more than one listener', () => {
|
||||||
const spy = jasmine.createSpy()
|
const spy = jasmine.createSpy()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getJqueryInterfaceForPlugin } from '../../../src/util/jquery-stuff'
|
import * as jQueryUtil from '../../../src/util/jquery-stuff'
|
||||||
|
|
||||||
describe('Jquery Stuff', () => {
|
describe('Jquery Stuff', () => {
|
||||||
const fakejQuery = { fn: {} }
|
const fakejQuery = { fn: {} }
|
||||||
@@ -14,21 +14,54 @@ describe('Jquery Stuff', () => {
|
|||||||
window.jQuery = undefined
|
window.jQuery = undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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(jQueryUtil.getjQuery()).toEqual(fakejQuery)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not return jQuery object when present if data-bs-no-jquery', () => {
|
||||||
|
document.body.setAttribute('data-bs-no-jquery', '')
|
||||||
|
|
||||||
|
expect(window.jQuery).toEqual(fakejQuery)
|
||||||
|
expect(jQueryUtil.getjQuery()).toBeNull()
|
||||||
|
|
||||||
|
document.body.removeAttribute('data-bs-no-jquery')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not return jQuery if not present', () => {
|
||||||
|
window.jQuery = undefined
|
||||||
|
expect(jQueryUtil.getjQuery()).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('getJqueryInterfaceForPlugin', () => {
|
describe('getJqueryInterfaceForPlugin', () => {
|
||||||
it('should return a plugin jQueryInterface if exists', () => {
|
it('should return a plugin jQueryInterface if exists', () => {
|
||||||
const pluginMock = function () {}
|
const pluginMock = function () {}
|
||||||
pluginMock.NAME = 'test'
|
pluginMock.NAME = 'test'
|
||||||
pluginMock.jQueryInterface = function () {}
|
pluginMock.jQueryInterface = function () {}
|
||||||
|
|
||||||
expect(getJqueryInterfaceForPlugin(pluginMock)).toEqual(pluginMock.jQueryInterface)
|
expect(jQueryUtil.getJqueryInterfaceForPlugin(pluginMock)).toEqual(pluginMock.jQueryInterface)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return the default `defaultJQueryInterface`, if plugin jQueryInterface doesn\'t exists', () => {
|
it('should return the default `defaultJQueryInterface`, if plugin jQueryInterface doesn\'t exists', () => {
|
||||||
const pluginMock = function () {}
|
const pluginMock = function () {}
|
||||||
pluginMock.NAME = 'test'
|
pluginMock.NAME = 'test'
|
||||||
|
|
||||||
expect(getJqueryInterfaceForPlugin(pluginMock)).not.toEqual(pluginMock.jQueryInterface)
|
expect(jQueryUtil.getJqueryInterfaceForPlugin(pluginMock)).not.toEqual(pluginMock.jQueryInterface)
|
||||||
expect(getJqueryInterfaceForPlugin(pluginMock)).toEqual(jasmine.any(Function))
|
expect(jQueryUtil.getJqueryInterfaceForPlugin(pluginMock)).toEqual(jasmine.any(Function))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user