mirror of
https://github.com/tenrok/bootstrap.git
synced 2026-06-17 19:21:23 +03:00
transfer defineJQueryPlugin to jquery-stuff.js file
This commit is contained in:
+1
-1
@@ -5,10 +5,10 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin } from './util/index'
|
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
import { enableDismissTrigger } from './util/component-functions'
|
import { enableDismissTrigger } from './util/component-functions'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+1
-1
@@ -5,9 +5,9 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin } from './util/index'
|
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
defineJQueryPlugin,
|
|
||||||
getElementFromSelector,
|
getElementFromSelector,
|
||||||
getNextActiveElement,
|
getNextActiveElement,
|
||||||
isRTL,
|
isRTL,
|
||||||
@@ -19,6 +18,7 @@ import Manipulator from './dom/manipulator'
|
|||||||
import SelectorEngine from './dom/selector-engine'
|
import SelectorEngine from './dom/selector-engine'
|
||||||
import Swipe from './util/swipe'
|
import Swipe from './util/swipe'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
defineJQueryPlugin,
|
|
||||||
getElement,
|
getElement,
|
||||||
getElementFromSelector,
|
getElementFromSelector,
|
||||||
getSelectorFromElement,
|
getSelectorFromElement,
|
||||||
@@ -15,6 +14,7 @@ import {
|
|||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import SelectorEngine from './dom/selector-engine'
|
import SelectorEngine from './dom/selector-engine'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
import * as Popper from '@popperjs/core'
|
import * as Popper from '@popperjs/core'
|
||||||
import {
|
import {
|
||||||
defineJQueryPlugin,
|
|
||||||
getElement,
|
getElement,
|
||||||
getNextActiveElement,
|
getNextActiveElement,
|
||||||
isDisabled,
|
isDisabled,
|
||||||
@@ -20,6 +19,7 @@ import EventHandler from './dom/event-handler'
|
|||||||
import Manipulator from './dom/manipulator'
|
import Manipulator from './dom/manipulator'
|
||||||
import SelectorEngine from './dom/selector-engine'
|
import SelectorEngine from './dom/selector-engine'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin, getElementFromSelector, isRTL, isVisible, reflow, typeCheckConfig } from './util/index'
|
import { getElementFromSelector, isRTL, isVisible, reflow } from './util/index'
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import SelectorEngine from './dom/selector-engine'
|
import SelectorEngine from './dom/selector-engine'
|
||||||
import ScrollBarHelper from './util/scrollbar'
|
import ScrollBarHelper from './util/scrollbar'
|
||||||
@@ -13,6 +13,7 @@ import BaseComponent from './base-component'
|
|||||||
import Backdrop from './util/backdrop'
|
import Backdrop from './util/backdrop'
|
||||||
import FocusTrap from './util/focustrap'
|
import FocusTrap from './util/focustrap'
|
||||||
import { enableDismissTrigger } from './util/component-functions'
|
import { enableDismissTrigger } from './util/component-functions'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
@@ -30,7 +31,6 @@ const EVENT_HIDDEN = `hidden${EVENT_KEY}`
|
|||||||
const EVENT_SHOW = `show${EVENT_KEY}`
|
const EVENT_SHOW = `show${EVENT_KEY}`
|
||||||
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
||||||
const EVENT_RESIZE = `resize${EVENT_KEY}`
|
const EVENT_RESIZE = `resize${EVENT_KEY}`
|
||||||
const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
|
|
||||||
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
|
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
|
||||||
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
defineJQueryPlugin,
|
|
||||||
getElementFromSelector,
|
getElementFromSelector,
|
||||||
isDisabled,
|
isDisabled,
|
||||||
isVisible
|
isVisible
|
||||||
@@ -18,6 +17,7 @@ import SelectorEngine from './dom/selector-engine'
|
|||||||
import Backdrop from './util/backdrop'
|
import Backdrop from './util/backdrop'
|
||||||
import FocusTrap from './util/focustrap'
|
import FocusTrap from './util/focustrap'
|
||||||
import { enableDismissTrigger } from './util/component-functions'
|
import { enableDismissTrigger } from './util/component-functions'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+1
-1
@@ -5,8 +5,8 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin } from './util/index'
|
|
||||||
import Tooltip from './tooltip'
|
import Tooltip from './tooltip'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+2
-1
@@ -5,10 +5,11 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin, getElement, isDisabled, isVisible } from './util/index'
|
import { getElement, isDisabled, isVisible } from './util/index'
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import SelectorEngine from './dom/selector-engine'
|
import SelectorEngine from './dom/selector-engine'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+2
-1
@@ -5,10 +5,11 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin, getElementFromSelector, getNextActiveElement, isDisabled } from './util/index'
|
import { getElementFromSelector, getNextActiveElement, isDisabled } from './util/index'
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import SelectorEngine from './dom/selector-engine'
|
import SelectorEngine from './dom/selector-engine'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+2
-1
@@ -5,10 +5,11 @@
|
|||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { defineJQueryPlugin, reflow } from './util/index'
|
import { reflow } from './util/index'
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
import { enableDismissTrigger } from './util/component-functions'
|
import { enableDismissTrigger } from './util/component-functions'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
+2
-1
@@ -6,12 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Popper from '@popperjs/core'
|
import * as Popper from '@popperjs/core'
|
||||||
import { defineJQueryPlugin, findShadowRoot, getElement, getUID, isRTL, noop } from './util/index'
|
import { findShadowRoot, getElement, getUID, isRTL, noop } from './util/index'
|
||||||
import { DefaultAllowlist } from './util/sanitizer'
|
import { DefaultAllowlist } from './util/sanitizer'
|
||||||
import EventHandler from './dom/event-handler'
|
import EventHandler from './dom/event-handler'
|
||||||
import Manipulator from './dom/manipulator'
|
import Manipulator from './dom/manipulator'
|
||||||
import BaseComponent from './base-component'
|
import BaseComponent from './base-component'
|
||||||
import TemplateFactory from './util/template-factory'
|
import TemplateFactory from './util/template-factory'
|
||||||
|
import { defineJQueryPlugin } from './util/jquery-stuff'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants
|
* Constants
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
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
|
||||||
const TRANSITION_END = 'transitionend'
|
const TRANSITION_END = 'transitionend'
|
||||||
@@ -225,24 +223,6 @@ const onDOMContentLoaded = callback => {
|
|||||||
|
|
||||||
const isRTL = () => document.documentElement.dir === 'rtl'
|
const isRTL = () => document.documentElement.dir === 'rtl'
|
||||||
|
|
||||||
const defineJQueryPlugin = plugin => {
|
|
||||||
onDOMContentLoaded(() => {
|
|
||||||
const $ = getjQuery()
|
|
||||||
const callback = getJqueryInterfaceForPlugin(plugin)
|
|
||||||
/* istanbul ignore if */
|
|
||||||
if ($) {
|
|
||||||
const name = plugin.NAME
|
|
||||||
const JQUERY_NO_CONFLICT = $.fn[name]
|
|
||||||
$.fn[name] = callback
|
|
||||||
$.fn[name].Constructor = plugin
|
|
||||||
$.fn[name].noConflict = () => {
|
|
||||||
$.fn[name] = JQUERY_NO_CONFLICT
|
|
||||||
return callback
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const execute = callback => {
|
const execute = callback => {
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback()
|
callback()
|
||||||
@@ -307,7 +287,6 @@ const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed
|
|||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
defineJQueryPlugin,
|
|
||||||
execute,
|
execute,
|
||||||
executeAfterTransition,
|
executeAfterTransition,
|
||||||
findShadowRoot,
|
findShadowRoot,
|
||||||
|
|||||||
Vendored
+20
@@ -4,6 +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 { onDOMContentLoaded } from './index'
|
||||||
|
|
||||||
const getjQuery = () => {
|
const getjQuery = () => {
|
||||||
const { jQuery } = window
|
const { jQuery } = window
|
||||||
@@ -15,6 +16,24 @@ const getjQuery = () => {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defineJQueryPlugin = plugin => {
|
||||||
|
onDOMContentLoaded(() => {
|
||||||
|
const $ = getjQuery()
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if ($) {
|
||||||
|
const callback = getJqueryInterfaceForPlugin(plugin)
|
||||||
|
const name = plugin.NAME
|
||||||
|
const JQUERY_NO_CONFLICT = $.fn[name]
|
||||||
|
$.fn[name] = callback
|
||||||
|
$.fn[name].Constructor = plugin
|
||||||
|
$.fn[name].noConflict = () => {
|
||||||
|
$.fn[name] = JQUERY_NO_CONFLICT
|
||||||
|
return callback
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const defaultJQueryInterface = plugin => {
|
const defaultJQueryInterface = plugin => {
|
||||||
return function (config) {
|
return function (config) {
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
@@ -36,6 +55,7 @@ const defaultJQueryInterface = plugin => {
|
|||||||
const getJqueryInterfaceForPlugin = plugin => plugin.jQueryInterface || defaultJQueryInterface(plugin)
|
const getJqueryInterfaceForPlugin = plugin => plugin.jQueryInterface || defaultJQueryInterface(plugin)
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
defineJQueryPlugin,
|
||||||
getjQuery,
|
getjQuery,
|
||||||
getJqueryInterfaceForPlugin
|
getJqueryInterfaceForPlugin
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -566,32 +566,6 @@ describe('Util', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('defineJQueryPlugin', () => {
|
|
||||||
const fakejQuery = { fn: {} }
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
Object.defineProperty(window, 'jQuery', {
|
|
||||||
value: fakejQuery,
|
|
||||||
writable: true
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
window.jQuery = undefined
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should define a plugin on the jQuery instance', () => {
|
|
||||||
const pluginMock = Util.noop
|
|
||||||
pluginMock.NAME = 'test'
|
|
||||||
pluginMock.jQueryInterface = Util.noop
|
|
||||||
|
|
||||||
Util.defineJQueryPlugin(pluginMock)
|
|
||||||
expect(fakejQuery.fn.test).toEqual(pluginMock.jQueryInterface)
|
|
||||||
expect(fakejQuery.fn.test.Constructor).toEqual(pluginMock)
|
|
||||||
expect(fakejQuery.fn.test.noConflict).toEqual(jasmine.any(Function))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('execute', () => {
|
describe('execute', () => {
|
||||||
it('should execute if arg is function', () => {
|
it('should execute if arg is function', () => {
|
||||||
const spy = jasmine.createSpy('spy')
|
const spy = jasmine.createSpy('spy')
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as jQueryUtil from '../../../src/util/jquery-stuff'
|
import * as jQueryUtil from '../../../src/util/jquery-stuff'
|
||||||
|
import { noop } from '../../../src/util/index'
|
||||||
|
|
||||||
describe('Jquery Stuff', () => {
|
describe('Jquery Stuff', () => {
|
||||||
const fakejQuery = { fn: {} }
|
const fakejQuery = { fn: {} }
|
||||||
@@ -15,7 +16,9 @@ describe('Jquery Stuff', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('getjQuery', () => {
|
describe('getjQuery', () => {
|
||||||
const fakejQuery = { trigger() {} }
|
const fakejQuery = {
|
||||||
|
trigger: noop
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
Object.defineProperty(window, 'jQuery', {
|
Object.defineProperty(window, 'jQuery', {
|
||||||
@@ -47,20 +50,32 @@ describe('Jquery Stuff', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('defineJQueryPlugin', () => {
|
||||||
|
it('should define a plugin on the jQuery instance', () => {
|
||||||
|
const pluginMock = noop
|
||||||
|
pluginMock.NAME = 'test'
|
||||||
|
pluginMock.jQueryInterface = noop
|
||||||
|
|
||||||
|
jQueryUtil.defineJQueryPlugin(pluginMock)
|
||||||
|
expect(fakejQuery.fn.test).toEqual(pluginMock.jQueryInterface)
|
||||||
|
expect(fakejQuery.fn.test.Constructor).toEqual(pluginMock)
|
||||||
|
expect(fakejQuery.fn.test.noConflict).toEqual(jasmine.any(Function))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
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 = noop
|
||||||
pluginMock.NAME = 'test'
|
pluginMock.NAME = 'test'
|
||||||
pluginMock.jQueryInterface = function () {}
|
pluginMock.jQueryInterface = noop
|
||||||
|
|
||||||
expect(jQueryUtil.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 = noop
|
||||||
pluginMock.NAME = 'test'
|
pluginMock.NAME = 'test'
|
||||||
|
|
||||||
expect(jQueryUtil.getJqueryInterfaceForPlugin(pluginMock)).not.toEqual(pluginMock.jQueryInterface)
|
|
||||||
expect(jQueryUtil.getJqueryInterfaceForPlugin(pluginMock)).toEqual(jasmine.any(Function))
|
expect(jQueryUtil.getJqueryInterfaceForPlugin(pluginMock)).toEqual(jasmine.any(Function))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user