mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-26 23:54:23 +01:00
Js - use a default JQueryInterface in js components
This commit is contained in:
parent
88a6610895
commit
dd9f2b31d0
@ -53,23 +53,6 @@ class Alert extends BaseComponent {
|
||||
EventHandler.trigger(this._element, EVENT_CLOSED)
|
||||
this.dispose()
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Alert.getOrCreateInstance(this)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config](this)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,17 +37,6 @@ class Button extends BaseComponent {
|
||||
// Toggle class and sync the `aria-pressed` attribute with the return value of the `.toggle()` method
|
||||
this._element.setAttribute('aria-pressed', this._element.classList.toggle(CLASS_NAME_ACTIVE))
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Button.getOrCreateInstance(this)
|
||||
|
||||
if (config === 'toggle') {
|
||||
data[config]()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,13 +264,15 @@ class Collapse extends BaseComponent {
|
||||
return this.each(function () {
|
||||
const data = Collapse.getOrCreateInstance(this, _config)
|
||||
|
||||
if (typeof config === 'string') {
|
||||
if (typeof data[config] === 'undefined') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -333,22 +333,6 @@ class Dropdown extends BaseComponent {
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Dropdown.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof data[config] === 'undefined') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
|
||||
static clearMenus(event) {
|
||||
if (event.button === RIGHT_MOUSE_BUTTON || (event.type === 'keyup' && event.key !== TAB_KEY)) {
|
||||
return
|
||||
|
@ -5,7 +5,7 @@
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
import { defineJQueryPlugin, getElementFromSelector, isRTL, isVisible, reflow } from './util/index'
|
||||
import { defineJQueryPlugin, getElementFromSelector, isRTL, isVisible, reflow, typeCheckConfig } from './util/index'
|
||||
import EventHandler from './dom/event-handler'
|
||||
import SelectorEngine from './dom/selector-engine'
|
||||
import ScrollBarHelper from './util/scrollbar'
|
||||
@ -30,6 +30,7 @@ const EVENT_HIDDEN = `hidden${EVENT_KEY}`
|
||||
const EVENT_SHOW = `show${EVENT_KEY}`
|
||||
const EVENT_SHOWN = `shown${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_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
||||
|
||||
@ -307,21 +308,6 @@ class Modal extends BaseComponent {
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config, relatedTarget) {
|
||||
return this.each(function () {
|
||||
const data = Modal.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof data[config] === 'undefined') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config](relatedTarget)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,23 +207,6 @@ class Offcanvas extends BaseComponent {
|
||||
this.hide()
|
||||
})
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Offcanvas.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config](this)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,23 +69,6 @@ class Popover extends Tooltip {
|
||||
_getContent() {
|
||||
return this._resolvePossibleFunction(this._config.content)
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Popover.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof data[config] === 'undefined') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,23 +252,6 @@ class ScrollSpy extends BaseComponent {
|
||||
node.classList.remove(CLASS_NAME_ACTIVE)
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = ScrollSpy.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,23 +263,6 @@ class Tab extends BaseComponent {
|
||||
_getOuterElement(elem) {
|
||||
return elem.closest(SELECTOR_OUTER) || elem
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Tab.getOrCreateInstance(this)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,21 +188,6 @@ class Toast extends BaseComponent {
|
||||
clearTimeout(this._timeout)
|
||||
this._timeout = null
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Toast.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config === 'string') {
|
||||
if (typeof data[config] === 'undefined') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config](this)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -625,23 +625,6 @@ class Tooltip extends BaseComponent {
|
||||
this._popper = null
|
||||
}
|
||||
}
|
||||
|
||||
// Static
|
||||
static jQueryInterface(config) {
|
||||
return this.each(function () {
|
||||
const data = Tooltip.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof data[config] === 'undefined') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
import { getJqueryInterfaceForPlugin } from './jquery-stuff'
|
||||
|
||||
const MAX_UID = 1_000_000
|
||||
const MILLISECONDS_MULTIPLIER = 1000
|
||||
@ -235,15 +236,16 @@ 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] = plugin.jQueryInterface
|
||||
$.fn[name] = callback
|
||||
$.fn[name].Constructor = plugin
|
||||
$.fn[name].noConflict = () => {
|
||||
$.fn[name] = JQUERY_NO_CONFLICT
|
||||
return plugin.jQueryInterface
|
||||
return callback
|
||||
}
|
||||
}
|
||||
})
|
||||
|
30
js/src/util/jquery-stuff.js
vendored
Normal file
30
js/src/util/jquery-stuff.js
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.1.3): util/jquery-stuff.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const defaultJQueryInterface = plugin => {
|
||||
return function (config) {
|
||||
return this.each(function () {
|
||||
const data = plugin.getOrCreateInstance(this, config)
|
||||
|
||||
if (typeof config !== 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
|
||||
throw new TypeError(`No method named "${config}"`)
|
||||
}
|
||||
|
||||
data[config]()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const getJqueryInterfaceForPlugin = plugin => plugin.jQueryInterface || defaultJQueryInterface(plugin)
|
||||
|
||||
export {
|
||||
getJqueryInterfaceForPlugin
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import Alert from '../../src/alert'
|
||||
import { getTransitionDurationFromElement } from '../../src/util/index'
|
||||
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Alert', () => {
|
||||
let fixtureEl
|
||||
@ -150,7 +151,7 @@ describe('Alert', () => {
|
||||
|
||||
spyOn(alert, 'close')
|
||||
|
||||
jQueryMock.fn.alert = Alert.jQueryInterface
|
||||
jQueryMock.fn.alert = getJqueryInterfaceForPlugin(Alert)
|
||||
jQueryMock.elements = [alertEl]
|
||||
|
||||
jQueryMock.fn.alert.call(jQueryMock, 'close')
|
||||
@ -163,7 +164,7 @@ describe('Alert', () => {
|
||||
|
||||
const alertEl = fixtureEl.querySelector('.alert')
|
||||
|
||||
jQueryMock.fn.alert = Alert.jQueryInterface
|
||||
jQueryMock.fn.alert = getJqueryInterfaceForPlugin(Alert)
|
||||
jQueryMock.elements = [alertEl]
|
||||
|
||||
expect(Alert.getInstance(alertEl)).toBeNull()
|
||||
@ -177,7 +178,7 @@ describe('Alert', () => {
|
||||
|
||||
const alertEl = fixtureEl.querySelector('.alert')
|
||||
|
||||
jQueryMock.fn.alert = Alert.jQueryInterface
|
||||
jQueryMock.fn.alert = getJqueryInterfaceForPlugin(Alert)
|
||||
jQueryMock.elements = [alertEl]
|
||||
|
||||
jQueryMock.fn.alert.call(jQueryMock)
|
||||
@ -192,7 +193,7 @@ describe('Alert', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.alert = Alert.jQueryInterface
|
||||
jQueryMock.fn.alert = getJqueryInterfaceForPlugin(Alert)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -206,7 +207,7 @@ describe('Alert', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = '_getConfig'
|
||||
|
||||
jQueryMock.fn.alert = Alert.jQueryInterface
|
||||
jQueryMock.fn.alert = getJqueryInterfaceForPlugin(Alert)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Button from '../../src/button'
|
||||
import { getFixture, clearFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Button', () => {
|
||||
let fixtureEl
|
||||
@ -102,7 +103,7 @@ describe('Button', () => {
|
||||
|
||||
spyOn(button, 'toggle')
|
||||
|
||||
jQueryMock.fn.button = Button.jQueryInterface
|
||||
jQueryMock.fn.button = getJqueryInterfaceForPlugin(Button)
|
||||
jQueryMock.elements = [btnEl]
|
||||
|
||||
jQueryMock.fn.button.call(jQueryMock, 'toggle')
|
||||
@ -115,7 +116,7 @@ describe('Button', () => {
|
||||
|
||||
const btnEl = fixtureEl.querySelector('.btn')
|
||||
|
||||
jQueryMock.fn.button = Button.jQueryInterface
|
||||
jQueryMock.fn.button = getJqueryInterfaceForPlugin(Button)
|
||||
jQueryMock.elements = [btnEl]
|
||||
|
||||
jQueryMock.fn.button.call(jQueryMock, 'toggle')
|
||||
@ -129,7 +130,7 @@ describe('Button', () => {
|
||||
|
||||
const btnEl = fixtureEl.querySelector('.btn')
|
||||
|
||||
jQueryMock.fn.button = Button.jQueryInterface
|
||||
jQueryMock.fn.button = getJqueryInterfaceForPlugin(Button)
|
||||
jQueryMock.elements = [btnEl]
|
||||
|
||||
jQueryMock.fn.button.call(jQueryMock)
|
||||
|
@ -3,6 +3,7 @@ import EventHandler from '../../src/dom/event-handler'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { isRTL, noop } from '../../src/util/index'
|
||||
import Swipe from '../../src/util/swipe'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Carousel', () => {
|
||||
const { Simulator, PointerEvent } = window
|
||||
@ -1385,7 +1386,7 @@ describe('Carousel', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.carousel = Carousel.jQueryInterface
|
||||
jQueryMock.fn.carousel = getJqueryInterfaceForPlugin(Carousel)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.carousel.call(jQueryMock)
|
||||
@ -1399,7 +1400,7 @@ describe('Carousel', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const carousel = new Carousel(div)
|
||||
|
||||
jQueryMock.fn.carousel = Carousel.jQueryInterface
|
||||
jQueryMock.fn.carousel = getJqueryInterfaceForPlugin(Carousel)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.carousel.call(jQueryMock)
|
||||
@ -1416,7 +1417,7 @@ describe('Carousel', () => {
|
||||
|
||||
spyOn(carousel, 'to')
|
||||
|
||||
jQueryMock.fn.carousel = Carousel.jQueryInterface
|
||||
jQueryMock.fn.carousel = getJqueryInterfaceForPlugin(Carousel)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.carousel.call(jQueryMock, slideTo)
|
||||
@ -1430,7 +1431,7 @@ describe('Carousel', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.carousel = Carousel.jQueryInterface
|
||||
jQueryMock.fn.carousel = getJqueryInterfaceForPlugin(Carousel)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import Collapse from '../../src/collapse'
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Collapse', () => {
|
||||
let fixtureEl
|
||||
@ -949,7 +950,7 @@ describe('Collapse', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.collapse = Collapse.jQueryInterface
|
||||
jQueryMock.fn.collapse = getJqueryInterfaceForPlugin(Collapse)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.collapse.call(jQueryMock)
|
||||
@ -963,7 +964,7 @@ describe('Collapse', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const collapse = new Collapse(div)
|
||||
|
||||
jQueryMock.fn.collapse = Collapse.jQueryInterface
|
||||
jQueryMock.fn.collapse = getJqueryInterfaceForPlugin(Collapse)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.collapse.call(jQueryMock)
|
||||
@ -977,7 +978,7 @@ describe('Collapse', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.collapse = Collapse.jQueryInterface
|
||||
jQueryMock.fn.collapse = getJqueryInterfaceForPlugin(Collapse)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -2,6 +2,7 @@ import Dropdown from '../../src/dropdown'
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
import { noop } from '../../src/util/index'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Dropdown', () => {
|
||||
let fixtureEl
|
||||
@ -2135,7 +2136,7 @@ describe('Dropdown', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.dropdown = Dropdown.jQueryInterface
|
||||
jQueryMock.fn.dropdown = getJqueryInterfaceForPlugin(Dropdown)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.dropdown.call(jQueryMock)
|
||||
@ -2149,7 +2150,7 @@ describe('Dropdown', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const dropdown = new Dropdown(div)
|
||||
|
||||
jQueryMock.fn.dropdown = Dropdown.jQueryInterface
|
||||
jQueryMock.fn.dropdown = getJqueryInterfaceForPlugin(Dropdown)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.dropdown.call(jQueryMock)
|
||||
@ -2163,7 +2164,7 @@ describe('Dropdown', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.dropdown = Dropdown.jQueryInterface
|
||||
jQueryMock.fn.dropdown = getJqueryInterfaceForPlugin(Dropdown)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -12,7 +12,8 @@ import ScrollSpy from '../../src/scrollspy'
|
||||
import Tab from '../../src/tab'
|
||||
import Toast from '../../src/toast'
|
||||
import Tooltip from '../../src/tooltip'
|
||||
import { clearFixture, getFixture } from '../helpers/fixture'
|
||||
import { getFixture, clearFixture } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('jQuery', () => {
|
||||
let fixtureEl
|
||||
@ -26,18 +27,18 @@ describe('jQuery', () => {
|
||||
})
|
||||
|
||||
it('should add all plugins in jQuery', () => {
|
||||
expect(Alert.jQueryInterface).toEqual(jQuery.fn.alert)
|
||||
expect(Button.jQueryInterface).toEqual(jQuery.fn.button)
|
||||
expect(Carousel.jQueryInterface).toEqual(jQuery.fn.carousel)
|
||||
expect(Collapse.jQueryInterface).toEqual(jQuery.fn.collapse)
|
||||
expect(Dropdown.jQueryInterface).toEqual(jQuery.fn.dropdown)
|
||||
expect(Modal.jQueryInterface).toEqual(jQuery.fn.modal)
|
||||
expect(Offcanvas.jQueryInterface).toEqual(jQuery.fn.offcanvas)
|
||||
expect(Popover.jQueryInterface).toEqual(jQuery.fn.popover)
|
||||
expect(ScrollSpy.jQueryInterface).toEqual(jQuery.fn.scrollspy)
|
||||
expect(Tab.jQueryInterface).toEqual(jQuery.fn.tab)
|
||||
expect(Toast.jQueryInterface).toEqual(jQuery.fn.toast)
|
||||
expect(Tooltip.jQueryInterface).toEqual(jQuery.fn.tooltip)
|
||||
expect(getJqueryInterfaceForPlugin(Alert)).toEqual(jQuery.fn.alert)
|
||||
expect(getJqueryInterfaceForPlugin(Button)).toEqual(jQuery.fn.button)
|
||||
expect(getJqueryInterfaceForPlugin(Carousel)).toEqual(jQuery.fn.carousel)
|
||||
expect(getJqueryInterfaceForPlugin(Collapse)).toEqual(jQuery.fn.collapse)
|
||||
expect(getJqueryInterfaceForPlugin(Dropdown)).toEqual(jQuery.fn.dropdown)
|
||||
expect(getJqueryInterfaceForPlugin(Modal)).toEqual(jQuery.fn.modal)
|
||||
expect(getJqueryInterfaceForPlugin(Offcanvas)).toEqual(jQuery.fn.offcanvas)
|
||||
expect(getJqueryInterfaceForPlugin(Popover)).toEqual(jQuery.fn.popover)
|
||||
expect(getJqueryInterfaceForPlugin(ScrollSpy)).toEqual(jQuery.fn.scrollspy)
|
||||
expect(getJqueryInterfaceForPlugin(Tab)).toEqual(jQuery.fn.tab)
|
||||
expect(getJqueryInterfaceForPlugin(Toast)).toEqual(jQuery.fn.toast)
|
||||
expect(getJqueryInterfaceForPlugin(Tooltip)).toEqual(jQuery.fn.tooltip)
|
||||
})
|
||||
|
||||
it('should use jQuery event system', () => {
|
||||
|
@ -2,6 +2,7 @@ import Modal from '../../src/modal'
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
import ScrollBarHelper from '../../src/util/scrollbar'
|
||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Modal', () => {
|
||||
let fixtureEl
|
||||
@ -1100,7 +1101,7 @@ describe('Modal', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.modal = Modal.jQueryInterface
|
||||
jQueryMock.fn.modal = getJqueryInterfaceForPlugin(Modal)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.modal.call(jQueryMock)
|
||||
@ -1113,7 +1114,7 @@ describe('Modal', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.modal = Modal.jQueryInterface
|
||||
jQueryMock.fn.modal = getJqueryInterfaceForPlugin(Modal)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.modal.call(jQueryMock, { keyboard: false })
|
||||
@ -1131,7 +1132,7 @@ describe('Modal', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const modal = new Modal(div)
|
||||
|
||||
jQueryMock.fn.modal = Modal.jQueryInterface
|
||||
jQueryMock.fn.modal = getJqueryInterfaceForPlugin(Modal)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.modal.call(jQueryMock)
|
||||
@ -1145,7 +1146,7 @@ describe('Modal', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.modal = Modal.jQueryInterface
|
||||
jQueryMock.fn.modal = getJqueryInterfaceForPlugin(Modal)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -1159,7 +1160,7 @@ describe('Modal', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const modal = new Modal(div)
|
||||
|
||||
jQueryMock.fn.modal = Modal.jQueryInterface
|
||||
jQueryMock.fn.modal = getJqueryInterfaceForPlugin(Modal)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
spyOn(modal, 'show')
|
||||
@ -1174,7 +1175,7 @@ describe('Modal', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.modal = Modal.jQueryInterface
|
||||
jQueryMock.fn.modal = getJqueryInterfaceForPlugin(Modal)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
spyOn(Modal.prototype, 'show')
|
||||
|
@ -3,6 +3,7 @@ import EventHandler from '../../src/dom/event-handler'
|
||||
import { clearBodyAndDocument, clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { isVisible } from '../../src/util/index'
|
||||
import ScrollBarHelper from '../../src/util/scrollbar'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Offcanvas', () => {
|
||||
let fixtureEl
|
||||
@ -722,7 +723,7 @@ describe('Offcanvas', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.offcanvas.call(jQueryMock)
|
||||
@ -736,7 +737,7 @@ describe('Offcanvas', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const offCanvas = new Offcanvas(div)
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.offcanvas.call(jQueryMock)
|
||||
@ -750,7 +751,7 @@ describe('Offcanvas', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -764,7 +765,7 @@ describe('Offcanvas', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = '_getConfig'
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -778,7 +779,7 @@ describe('Offcanvas', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'constructor'
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -793,7 +794,7 @@ describe('Offcanvas', () => {
|
||||
|
||||
spyOn(Offcanvas.prototype, 'show')
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.offcanvas.call(jQueryMock, 'show')
|
||||
@ -805,7 +806,7 @@ describe('Offcanvas', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.offcanvas = Offcanvas.jQueryInterface
|
||||
jQueryMock.fn.offcanvas = getJqueryInterfaceForPlugin(Offcanvas)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.offcanvas.call(jQueryMock, { scroll: true })
|
||||
|
@ -1,6 +1,7 @@
|
||||
import Popover from '../../src/popover'
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
import { clearFixture, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Popover', () => {
|
||||
let fixtureEl
|
||||
@ -269,7 +270,7 @@ describe('Popover', () => {
|
||||
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
|
||||
jQueryMock.fn.popover = Popover.jQueryInterface
|
||||
jQueryMock.fn.popover = getJqueryInterfaceForPlugin(Popover)
|
||||
jQueryMock.elements = [popoverEl]
|
||||
|
||||
jQueryMock.fn.popover.call(jQueryMock)
|
||||
@ -282,7 +283,7 @@ describe('Popover', () => {
|
||||
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
|
||||
jQueryMock.fn.popover = Popover.jQueryInterface
|
||||
jQueryMock.fn.popover = getJqueryInterfaceForPlugin(Popover)
|
||||
jQueryMock.elements = [popoverEl]
|
||||
|
||||
jQueryMock.fn.popover.call(jQueryMock, {
|
||||
@ -298,7 +299,7 @@ describe('Popover', () => {
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
const popover = new Popover(popoverEl)
|
||||
|
||||
jQueryMock.fn.popover = Popover.jQueryInterface
|
||||
jQueryMock.fn.popover = getJqueryInterfaceForPlugin(Popover)
|
||||
jQueryMock.elements = [popoverEl]
|
||||
|
||||
jQueryMock.fn.popover.call(jQueryMock)
|
||||
@ -312,7 +313,7 @@ describe('Popover', () => {
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.popover = Popover.jQueryInterface
|
||||
jQueryMock.fn.popover = getJqueryInterfaceForPlugin(Popover)
|
||||
jQueryMock.elements = [popoverEl]
|
||||
|
||||
expect(() => {
|
||||
@ -326,7 +327,7 @@ describe('Popover', () => {
|
||||
const popoverEl = fixtureEl.querySelector('a')
|
||||
const popover = new Popover(popoverEl)
|
||||
|
||||
jQueryMock.fn.popover = Popover.jQueryInterface
|
||||
jQueryMock.fn.popover = getJqueryInterfaceForPlugin(Popover)
|
||||
jQueryMock.elements = [popoverEl]
|
||||
|
||||
spyOn(popover, 'show')
|
||||
|
@ -1,8 +1,8 @@
|
||||
import ScrollSpy from '../../src/scrollspy'
|
||||
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
/** Test helpers */
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
|
||||
describe('ScrollSpy', () => {
|
||||
let fixtureEl
|
||||
@ -610,7 +610,7 @@ describe('ScrollSpy', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('.content')
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.scrollspy.call(jQueryMock, { target: '#navBar' })
|
||||
@ -623,7 +623,7 @@ describe('ScrollSpy', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('.content')
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.scrollspy.call(jQueryMock, { rootMargin: '100px' })
|
||||
@ -641,7 +641,7 @@ describe('ScrollSpy', () => {
|
||||
const div = fixtureEl.querySelector('.content')
|
||||
const scrollSpy = new ScrollSpy(div)
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.scrollspy.call(jQueryMock)
|
||||
@ -657,7 +657,7 @@ describe('ScrollSpy', () => {
|
||||
|
||||
spyOn(scrollSpy, 'refresh')
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.scrollspy.call(jQueryMock, 'refresh')
|
||||
@ -672,7 +672,7 @@ describe('ScrollSpy', () => {
|
||||
const div = fixtureEl.querySelector('.content')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -686,7 +686,7 @@ describe('ScrollSpy', () => {
|
||||
const div = fixtureEl.querySelector('.content')
|
||||
const action = '_getConfig'
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
@ -700,7 +700,7 @@ describe('ScrollSpy', () => {
|
||||
const div = fixtureEl.querySelector('.content')
|
||||
const action = 'constructor'
|
||||
|
||||
jQueryMock.fn.scrollspy = ScrollSpy.jQueryInterface
|
||||
jQueryMock.fn.scrollspy = getJqueryInterfaceForPlugin(ScrollSpy)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Tab from '../../src/tab'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Tab', () => {
|
||||
let fixtureEl
|
||||
@ -622,7 +623,7 @@ describe('Tab', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('.nav > div')
|
||||
|
||||
jQueryMock.fn.tab = Tab.jQueryInterface
|
||||
jQueryMock.fn.tab = getJqueryInterfaceForPlugin(Tab)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.tab.call(jQueryMock)
|
||||
@ -636,7 +637,7 @@ describe('Tab', () => {
|
||||
const div = fixtureEl.querySelector('.nav > div')
|
||||
const tab = new Tab(div)
|
||||
|
||||
jQueryMock.fn.tab = Tab.jQueryInterface
|
||||
jQueryMock.fn.tab = getJqueryInterfaceForPlugin(Tab)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.tab.call(jQueryMock)
|
||||
@ -652,7 +653,7 @@ describe('Tab', () => {
|
||||
|
||||
spyOn(tab, 'show')
|
||||
|
||||
jQueryMock.fn.tab = Tab.jQueryInterface
|
||||
jQueryMock.fn.tab = getJqueryInterfaceForPlugin(Tab)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.tab.call(jQueryMock, 'show')
|
||||
@ -667,7 +668,7 @@ describe('Tab', () => {
|
||||
const div = fixtureEl.querySelector('.nav > div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.tab = Tab.jQueryInterface
|
||||
jQueryMock.fn.tab = getJqueryInterfaceForPlugin(Tab)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Toast from '../../src/toast'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getFixture, clearFixture, createEvent, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Toast', () => {
|
||||
let fixtureEl
|
||||
@ -540,7 +541,7 @@ describe('Toast', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.toast = Toast.jQueryInterface
|
||||
jQueryMock.fn.toast = getJqueryInterfaceForPlugin(Toast)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.toast.call(jQueryMock)
|
||||
@ -554,7 +555,7 @@ describe('Toast', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const toast = new Toast(div)
|
||||
|
||||
jQueryMock.fn.toast = Toast.jQueryInterface
|
||||
jQueryMock.fn.toast = getJqueryInterfaceForPlugin(Toast)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.toast.call(jQueryMock)
|
||||
@ -570,7 +571,7 @@ describe('Toast', () => {
|
||||
|
||||
spyOn(toast, 'show')
|
||||
|
||||
jQueryMock.fn.toast = Toast.jQueryInterface
|
||||
jQueryMock.fn.toast = getJqueryInterfaceForPlugin(Toast)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.toast.call(jQueryMock, 'show')
|
||||
@ -585,7 +586,7 @@ describe('Toast', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.toast = Toast.jQueryInterface
|
||||
jQueryMock.fn.toast = getJqueryInterfaceForPlugin(Toast)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
@ -2,6 +2,7 @@ import Tooltip from '../../src/tooltip'
|
||||
import EventHandler from '../../src/dom/event-handler'
|
||||
import { noop } from '../../src/util/index'
|
||||
import { clearFixture, createEvent, getFixture, jQueryMock } from '../helpers/fixture'
|
||||
import { getJqueryInterfaceForPlugin } from '../../src/util/jquery-stuff'
|
||||
|
||||
describe('Tooltip', () => {
|
||||
let fixtureEl
|
||||
@ -1455,7 +1456,7 @@ describe('Tooltip', () => {
|
||||
|
||||
const div = fixtureEl.querySelector('div')
|
||||
|
||||
jQueryMock.fn.tooltip = Tooltip.jQueryInterface
|
||||
jQueryMock.fn.tooltip = getJqueryInterfaceForPlugin(Tooltip)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.tooltip.call(jQueryMock)
|
||||
@ -1469,7 +1470,7 @@ describe('Tooltip', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const tooltip = new Tooltip(div)
|
||||
|
||||
jQueryMock.fn.tooltip = Tooltip.jQueryInterface
|
||||
jQueryMock.fn.tooltip = getJqueryInterfaceForPlugin(Tooltip)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.tooltip.call(jQueryMock)
|
||||
@ -1485,7 +1486,7 @@ describe('Tooltip', () => {
|
||||
|
||||
spyOn(tooltip, 'show')
|
||||
|
||||
jQueryMock.fn.tooltip = Tooltip.jQueryInterface
|
||||
jQueryMock.fn.tooltip = getJqueryInterfaceForPlugin(Tooltip)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
jQueryMock.fn.tooltip.call(jQueryMock, 'show')
|
||||
@ -1500,7 +1501,7 @@ describe('Tooltip', () => {
|
||||
const div = fixtureEl.querySelector('div')
|
||||
const action = 'undefinedMethod'
|
||||
|
||||
jQueryMock.fn.tooltip = Tooltip.jQueryInterface
|
||||
jQueryMock.fn.tooltip = getJqueryInterfaceForPlugin(Tooltip)
|
||||
jQueryMock.elements = [div]
|
||||
|
||||
expect(() => {
|
||||
|
34
js/tests/unit/util/jquery-stuff.spec.js
Normal file
34
js/tests/unit/util/jquery-stuff.spec.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { getJqueryInterfaceForPlugin } from '../../../src/util/jquery-stuff'
|
||||
|
||||
describe('Jquery Stuff', () => {
|
||||
const fakejQuery = { fn: {} }
|
||||
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(window, 'jQuery', {
|
||||
value: fakejQuery,
|
||||
writable: true
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
window.jQuery = undefined
|
||||
})
|
||||
|
||||
describe('getJqueryInterfaceForPlugin', () => {
|
||||
it('should return a plugin jQueryInterface if exists', () => {
|
||||
const pluginMock = function () {}
|
||||
pluginMock.NAME = 'test'
|
||||
pluginMock.jQueryInterface = function () {}
|
||||
|
||||
expect(getJqueryInterfaceForPlugin(pluginMock)).toEqual(pluginMock.jQueryInterface)
|
||||
})
|
||||
|
||||
it('should return the default `defaultJQueryInterface`, if plugin jQueryInterface doesn\'t exists', () => {
|
||||
const pluginMock = function () {}
|
||||
pluginMock.NAME = 'test'
|
||||
|
||||
expect(getJqueryInterfaceForPlugin(pluginMock)).not.toEqual(pluginMock.jQueryInterface)
|
||||
expect(getJqueryInterfaceForPlugin(pluginMock)).toEqual(jasmine.any(Function))
|
||||
})
|
||||
})
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user