mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-29 21:52:22 +01:00
remove old references to jquery and some fixes
This commit is contained in:
parent
0263d1742c
commit
7eddee286e
@ -114,8 +114,11 @@ class Alert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_destroyElement(element) {
|
_destroyElement(element) {
|
||||||
|
if (element.parentNode) {
|
||||||
|
element.parentNode.removeChild(element)
|
||||||
|
}
|
||||||
|
|
||||||
EventHandler.trigger(element, Event.CLOSED)
|
EventHandler.trigger(element, Event.CLOSED)
|
||||||
element.parentNode.removeChild(element)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static
|
// Static
|
||||||
@ -150,8 +153,8 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleD
|
|||||||
* add .alert to jQuery only if jQuery is present
|
* add .alert to jQuery only if jQuery is present
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof window.$ !== 'undefined' || typeof window.jQuery !== 'undefined') {
|
const $ = Util.jQuery
|
||||||
const $ = window.$ || window.jQuery
|
if (typeof $ !== 'undefined') {
|
||||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
$.fn[NAME] = Alert._jQueryInterface
|
$.fn[NAME] = Alert._jQueryInterface
|
||||||
$.fn[NAME].Constructor = Alert
|
$.fn[NAME].Constructor = Alert
|
||||||
|
@ -9,6 +9,7 @@ import Data from './dom/data'
|
|||||||
import EventHandler from './dom/eventHandler'
|
import EventHandler from './dom/eventHandler'
|
||||||
import Manipulator from './dom/manipulator'
|
import Manipulator from './dom/manipulator'
|
||||||
import SelectorEngine from './dom/selectorEngine'
|
import SelectorEngine from './dom/selectorEngine'
|
||||||
|
import Util from './util'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
@ -175,8 +176,8 @@ EventHandler.on(document, Event.BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, (eve
|
|||||||
* add .button to jQuery only if jQuery is present
|
* add .button to jQuery only if jQuery is present
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof window.$ !== 'undefined' || typeof window.jQuery !== 'undefined') {
|
const $ = Util.jQuery
|
||||||
const $ = window.$ || window.jQuery
|
if (typeof $ !== 'undefined') {
|
||||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
$.fn[NAME] = Button._jQueryInterface
|
$.fn[NAME] = Button._jQueryInterface
|
||||||
$.fn[NAME].Constructor = Button
|
$.fn[NAME].Constructor = Button
|
||||||
|
@ -571,7 +571,7 @@ class Carousel {
|
|||||||
config.interval = false
|
config.interval = false
|
||||||
}
|
}
|
||||||
|
|
||||||
Carousel._jQueryInterface.call($(target), config)
|
Carousel._carouselInterface(target, config)
|
||||||
|
|
||||||
if (slideIndex) {
|
if (slideIndex) {
|
||||||
Data.getData(target, DATA_KEY).to(slideIndex)
|
Data.getData(target, DATA_KEY).to(slideIndex)
|
||||||
@ -605,8 +605,8 @@ EventHandler.on(window, Event.LOAD_DATA_API, () => {
|
|||||||
* add .carousel to jQuery only if jQuery is present
|
* add .carousel to jQuery only if jQuery is present
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (typeof window.$ !== 'undefined' || typeof window.jQuery !== 'undefined') {
|
const $ = Util.jQuery
|
||||||
const $ = window.$ || window.jQuery
|
if (typeof $ !== 'undefined') {
|
||||||
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
||||||
$.fn[NAME] = Carousel._jQueryInterface
|
$.fn[NAME] = Carousel._jQueryInterface
|
||||||
$.fn[NAME].Constructor = Carousel
|
$.fn[NAME].Constructor = Carousel
|
||||||
|
@ -141,12 +141,11 @@ class Collapse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const container = SelectorEngine.findOne(this._selector)
|
||||||
if (actives) {
|
if (actives) {
|
||||||
const tempActiveData = actives.filter((elem) => {
|
const tempActiveData = actives.filter((elem) => container !== elem)
|
||||||
const container = SelectorEngine.findOne(this._selector)
|
|
||||||
return !container.contains(elem)
|
|
||||||
})
|
|
||||||
activesData = tempActiveData[0] ? Data.getData(tempActiveData[0], DATA_KEY) : null
|
activesData = tempActiveData[0] ? Data.getData(tempActiveData[0], DATA_KEY) : null
|
||||||
|
|
||||||
if (activesData && activesData._isTransitioning) {
|
if (activesData && activesData._isTransitioning) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -159,14 +158,14 @@ class Collapse {
|
|||||||
|
|
||||||
if (actives) {
|
if (actives) {
|
||||||
actives.forEach((elemActive) => {
|
actives.forEach((elemActive) => {
|
||||||
const container = SelectorEngine.findOne(this._selector)
|
if (container !== elemActive) {
|
||||||
if (!container.contains(elemActive)) {
|
|
||||||
Collapse._collapseInterface(elemActive, 'hide')
|
Collapse._collapseInterface(elemActive, 'hide')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!activesData) {
|
||||||
|
Data.setData(elemActive, DATA_KEY, null)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (!activesData) {
|
|
||||||
Data.setData(actives[0], DATA_KEY, null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dimension = this._getDimension()
|
const dimension = this._getDimension()
|
||||||
|
@ -23,10 +23,10 @@ const Data = (() => {
|
|||||||
key,
|
key,
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
id++
|
||||||
}
|
}
|
||||||
|
|
||||||
storeData[id] = data
|
storeData[element.key.id] = data
|
||||||
id++
|
|
||||||
},
|
},
|
||||||
get(element, key) {
|
get(element, key) {
|
||||||
if (typeof element === 'undefined' || typeof element.key === 'undefined') {
|
if (typeof element === 'undefined' || typeof element.key === 'undefined') {
|
||||||
|
@ -460,7 +460,7 @@ class Dropdown {
|
|||||||
if (/input|textarea/i.test(event.target.tagName)
|
if (/input|textarea/i.test(event.target.tagName)
|
||||||
? event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE &&
|
? event.which === SPACE_KEYCODE || event.which !== ESCAPE_KEYCODE &&
|
||||||
(event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE ||
|
(event.which !== ARROW_DOWN_KEYCODE && event.which !== ARROW_UP_KEYCODE ||
|
||||||
$(event.target).closest(Selector.MENU).length) : !REGEXP_KEYDOWN.test(event.which)) {
|
SelectorEngine.closest(event.target, Selector.MENU)) : !REGEXP_KEYDOWN.test(event.which)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,21 +17,6 @@ import Util from './util'
|
|||||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||||
* --------------------------------------------------------------------------
|
* --------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
(() => {
|
|
||||||
// only check jQuery version if jQuery is available
|
|
||||||
if (typeof window.$ !== 'undefined' || typeof window.jQuery !== 'undefined') {
|
|
||||||
const version = window.$.fn.jquery.split(' ')[0].split('.')
|
|
||||||
const minMajor = 1
|
|
||||||
const ltMajor = 2
|
|
||||||
const minMinor = 9
|
|
||||||
const minPatch = 1
|
|
||||||
const maxMajor = 4
|
|
||||||
|
|
||||||
if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) {
|
|
||||||
throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
Util,
|
Util,
|
||||||
|
@ -232,7 +232,7 @@ class Modal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_showElement(relatedTarget) {
|
_showElement(relatedTarget) {
|
||||||
const transition = $(this._element).hasClass(ClassName.FADE)
|
const transition = this._element.classList.contains(ClassName.FADE)
|
||||||
|
|
||||||
if (!this._element.parentNode ||
|
if (!this._element.parentNode ||
|
||||||
this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
|
this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
|
||||||
@ -295,14 +295,14 @@ class Modal {
|
|||||||
|
|
||||||
_setEscapeEvent() {
|
_setEscapeEvent() {
|
||||||
if (this._isShown && this._config.keyboard) {
|
if (this._isShown && this._config.keyboard) {
|
||||||
$(this._element).on(Event.KEYDOWN_DISMISS, (event) => {
|
EventHandler.on(this._element, Event.KEYDOWN_DISMISS, (event) => {
|
||||||
if (event.which === ESCAPE_KEYCODE) {
|
if (event.which === ESCAPE_KEYCODE) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
this.hide()
|
this.hide()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (!this._isShown) {
|
} else if (!this._isShown) {
|
||||||
$(this._element).off(Event.KEYDOWN_DISMISS)
|
EventHandler.off(this._element, Event.KEYDOWN_DISMISS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ const Util = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get transition-duration of the element
|
// Get transition-duration of the element
|
||||||
let transitionDuration = element.style.transitionDuration
|
let transitionDuration = window.getComputedStyle(element).transitionDuration
|
||||||
let transitionDelay = element.style.transitionDelay
|
let transitionDelay = window.getComputedStyle(element).transitionDelay
|
||||||
|
|
||||||
const floatTransitionDuration = parseFloat(transitionDuration)
|
const floatTransitionDuration = parseFloat(transitionDuration)
|
||||||
const floatTransitionDelay = parseFloat(transitionDelay)
|
const floatTransitionDelay = parseFloat(transitionDelay)
|
||||||
@ -92,7 +92,7 @@ const Util = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
triggerTransitionEnd(element) {
|
triggerTransitionEnd(element) {
|
||||||
EventHandler.trigger(element, Util.TRANSITION_END)
|
element.dispatchEvent(new Event(Util.TRANSITION_END))
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Remove in v5
|
// TODO: Remove in v5
|
||||||
|
@ -91,7 +91,7 @@ $(function () {
|
|||||||
var done = assert.async()
|
var done = assert.async()
|
||||||
var $el = $('<div/>')
|
var $el = $('<div/>')
|
||||||
var $alert = $el.bootstrapAlert()
|
var $alert = $el.bootstrapAlert()
|
||||||
var alertInstance = $alert.data('bs.alert')
|
var alertInstance = Data.getData($alert[0], 'bs.alert')
|
||||||
|
|
||||||
$alert.one('closed.bs.alert', function () {
|
$alert.one('closed.bs.alert', function () {
|
||||||
assert.ok('alert closed')
|
assert.ok('alert closed')
|
||||||
@ -107,11 +107,11 @@ $(function () {
|
|||||||
var $el = $('<div/>')
|
var $el = $('<div/>')
|
||||||
var $alert = $el.bootstrapAlert()
|
var $alert = $el.bootstrapAlert()
|
||||||
|
|
||||||
assert.ok(typeof $alert.data('bs.alert') !== 'undefined')
|
assert.ok(typeof Data.getData($alert[0], 'bs.alert') !== 'undefined')
|
||||||
|
|
||||||
$alert.data('bs.alert').dispose()
|
Data.getData($alert[0], 'bs.alert').dispose()
|
||||||
|
|
||||||
assert.ok(typeof $alert.data('bs.button') === 'undefined')
|
assert.ok(Data.getData($alert[0], 'bs.alert') === null)
|
||||||
})
|
})
|
||||||
|
|
||||||
QUnit.test('should return alert version', function (assert) {
|
QUnit.test('should return alert version', function (assert) {
|
||||||
|
@ -208,11 +208,11 @@ $(function () {
|
|||||||
var $el = $('<div/>')
|
var $el = $('<div/>')
|
||||||
var $button = $el.bootstrapButton()
|
var $button = $el.bootstrapButton()
|
||||||
|
|
||||||
assert.ok(typeof $button.data('bs.button') !== 'undefined')
|
assert.ok(typeof Data.getData($button[0], 'bs.button') !== 'undefined')
|
||||||
|
|
||||||
$button.data('bs.button').dispose()
|
Data.getData($button[0], 'bs.button').dispose()
|
||||||
|
|
||||||
assert.ok(typeof $button.data('bs.button') === 'undefined')
|
assert.ok(Data.getData($button[0], 'bs.button') === null)
|
||||||
})
|
})
|
||||||
|
|
||||||
QUnit.test('should return button version', function (assert) {
|
QUnit.test('should return button version', function (assert) {
|
||||||
|
@ -1025,7 +1025,7 @@ $(function () {
|
|||||||
.find('[data-toggle="dropdown"]')
|
.find('[data-toggle="dropdown"]')
|
||||||
.bootstrapDropdown()
|
.bootstrapDropdown()
|
||||||
|
|
||||||
var dropdown = $dropdown.data('bs.dropdown')
|
var dropdown = Data.getData($dropdown[0], 'bs.dropdown')
|
||||||
dropdown.toggle()
|
dropdown.toggle()
|
||||||
assert.ok(dropdown._popper)
|
assert.ok(dropdown._popper)
|
||||||
|
|
||||||
@ -1053,7 +1053,7 @@ $(function () {
|
|||||||
.find('[data-toggle="dropdown"]')
|
.find('[data-toggle="dropdown"]')
|
||||||
.bootstrapDropdown()
|
.bootstrapDropdown()
|
||||||
|
|
||||||
var dropdown = $dropdown.data('bs.dropdown')
|
var dropdown = Data.getData($dropdown[0], 'bs.dropdown')
|
||||||
var spyDetectNavbar = sinon.spy(dropdown, '_detectNavbar')
|
var spyDetectNavbar = sinon.spy(dropdown, '_detectNavbar')
|
||||||
|
|
||||||
dropdown.update()
|
dropdown.update()
|
||||||
@ -1078,7 +1078,7 @@ $(function () {
|
|||||||
.find('[data-toggle="dropdown"]')
|
.find('[data-toggle="dropdown"]')
|
||||||
.bootstrapDropdown()
|
.bootstrapDropdown()
|
||||||
|
|
||||||
var dropdown = $dropdown.data('bs.dropdown')
|
var dropdown = Data.getData($dropdown[0], 'bs.dropdown')
|
||||||
dropdown.toggle()
|
dropdown.toggle()
|
||||||
|
|
||||||
assert.ok(dropdown._popper)
|
assert.ok(dropdown._popper)
|
||||||
@ -1109,7 +1109,7 @@ $(function () {
|
|||||||
.find('[data-toggle="dropdown"]')
|
.find('[data-toggle="dropdown"]')
|
||||||
.bootstrapDropdown()
|
.bootstrapDropdown()
|
||||||
|
|
||||||
var dropdown = $dropdown.data('bs.dropdown')
|
var dropdown = Data.getData($dropdown[0], 'bs.dropdown')
|
||||||
|
|
||||||
assert.notOk(dropdown._popper)
|
assert.notOk(dropdown._popper)
|
||||||
assert.ok(dropdown._menu !== null)
|
assert.ok(dropdown._menu !== null)
|
||||||
|
@ -279,14 +279,14 @@ $(function () {
|
|||||||
})
|
})
|
||||||
.one('shown.bs.popover', function () {
|
.one('shown.bs.popover', function () {
|
||||||
assert.notEqual($('.popover').length, 0, 'popover was inserted')
|
assert.notEqual($('.popover').length, 0, 'popover was inserted')
|
||||||
$div.find('a').trigger('click')
|
EventHandler.trigger($div.find('a')[0], 'click')
|
||||||
})
|
})
|
||||||
.one('hidden.bs.popover', function () {
|
.one('hidden.bs.popover', function () {
|
||||||
assert.strictEqual($('.popover').length, 0, 'popover was removed')
|
assert.strictEqual($('.popover').length, 0, 'popover was removed')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
$div.find('a').trigger('click')
|
EventHandler.trigger($div.find('a')[0], 'click')
|
||||||
})
|
})
|
||||||
|
|
||||||
QUnit.test('should detach popover content rather than removing it so that event handlers are left intact', function (assert) {
|
QUnit.test('should detach popover content rather than removing it so that event handlers are left intact', function (assert) {
|
||||||
|
@ -1000,7 +1000,7 @@ $(function () {
|
|||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
.bootstrapTooltip()
|
.bootstrapTooltip()
|
||||||
|
|
||||||
var tooltip = $tooltip.data('bs.tooltip')
|
var tooltip = Data.getData($tooltip[0], 'bs.tooltip')
|
||||||
tooltip.show()
|
tooltip.show()
|
||||||
assert.ok(tooltip._popper)
|
assert.ok(tooltip._popper)
|
||||||
|
|
||||||
@ -1016,7 +1016,7 @@ $(function () {
|
|||||||
.appendTo('#qunit-fixture')
|
.appendTo('#qunit-fixture')
|
||||||
.bootstrapTooltip()
|
.bootstrapTooltip()
|
||||||
|
|
||||||
var tooltip = $tooltip.data('bs.tooltip')
|
var tooltip = Data.getData($tooltip[0], 'bs.tooltip')
|
||||||
tooltip.update()
|
tooltip.update()
|
||||||
|
|
||||||
assert.ok(tooltip._popper === null)
|
assert.ok(tooltip._popper === null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user