aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2016-12-04 21:05:19 -0800
committerMark Otto <[email protected]>2016-12-04 21:05:19 -0800
commit1e3ec8935520e2d118d9d7742abd80183d34beb2 (patch)
tree3a2e940d7d91d578db4fe86675fa9d2a11bb9512 /js/src
parent6782dd6e92637f85e3778584ec417a775d01243f (diff)
parent5a19d4870537ca85ba38beeb7eabe80858417b72 (diff)
downloadbootstrap-1e3ec8935520e2d118d9d7742abd80183d34beb2.tar.xz
bootstrap-1e3ec8935520e2d118d9d7742abd80183d34beb2.zip
Merge branch 'v4-dev' into carousel
Diffstat (limited to 'js/src')
-rw-r--r--js/src/button.js2
-rw-r--r--js/src/carousel.js24
-rw-r--r--js/src/collapse.js14
-rw-r--r--js/src/dropdown.js6
-rw-r--r--js/src/modal.js35
-rw-r--r--js/src/popover.js4
-rw-r--r--js/src/scrollspy.js2
-rw-r--r--js/src/tooltip.js46
8 files changed, 81 insertions, 52 deletions
diff --git a/js/src/button.js b/js/src/button.js
index 8b9511765..45e1424ff 100644
--- a/js/src/button.js
+++ b/js/src/button.js
@@ -90,7 +90,7 @@ const Button = (($) => {
if (triggerChangeEvent) {
input.checked = !$(this._element).hasClass(ClassName.ACTIVE)
- $(this._element).trigger('change')
+ $(input).trigger('change')
}
input.focus()
diff --git a/js/src/carousel.js b/js/src/carousel.js
index c0d572f0a..a8c16283e 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -120,9 +120,10 @@ const Carousel = (($) => {
// public
next() {
- if (!this._isSliding) {
- this._slide(Direction.NEXT)
+ if (this._isSliding) {
+ throw new Error('Carousel is sliding')
}
+ this._slide(Direction.NEXT)
}
nextWhenVisible() {
@@ -133,9 +134,10 @@ const Carousel = (($) => {
}
prev() {
- if (!this._isSliding) {
- this._slide(Direction.PREVIOUS)
+ if (this._isSliding) {
+ throw new Error('Carousel is sliding')
}
+ this._slide(Direction.PREVIOUS)
}
pause(event) {
@@ -236,11 +238,10 @@ const Carousel = (($) => {
}
_keydown(event) {
- event.preventDefault()
-
if (/input|textarea/i.test(event.target.tagName)) {
return
}
+ event.preventDefault()
switch (event.which) {
case ARROW_LEFT_KEYCODE:
@@ -372,15 +373,10 @@ const Carousel = (($) => {
$(activeElement)
.one(Util.TRANSITION_END, () => {
$(nextElement)
- .removeClass(directionalClassName)
- .removeClass(orderClassName)
-
- $(nextElement).addClass(ClassName.ACTIVE)
+ .removeClass(`${directionalClassName} ${orderClassName}`)
+ .addClass(ClassName.ACTIVE)
- $(activeElement)
- .removeClass(ClassName.ACTIVE)
- .removeClass(orderClassName)
- .removeClass(directionalClassName)
+ $(activeElement).removeClass(`${ClassName.ACTIVE} ${orderClassName} ${directionalClassName}`)
this._isSliding = false
diff --git a/js/src/collapse.js b/js/src/collapse.js
index ebc3e24cf..1e4730ff7 100644
--- a/js/src/collapse.js
+++ b/js/src/collapse.js
@@ -112,8 +112,11 @@ const Collapse = (($) => {
}
show() {
- if (this._isTransitioning ||
- $(this._element).hasClass(ClassName.ACTIVE)) {
+ if (this._isTransitioning) {
+ throw new Error('Collapse is transitioning')
+ }
+
+ if ($(this._element).hasClass(ClassName.ACTIVE)) {
return
}
@@ -193,8 +196,11 @@ const Collapse = (($) => {
}
hide() {
- if (this._isTransitioning ||
- !$(this._element).hasClass(ClassName.ACTIVE)) {
+ if (this._isTransitioning) {
+ throw new Error('Collapse is transitioning')
+ }
+
+ if (!$(this._element).hasClass(ClassName.ACTIVE)) {
return
}
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 644659266..8b2164aa9 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -239,11 +239,7 @@ const Dropdown = (($) => {
return
}
- let items = $.makeArray($(Selector.VISIBLE_ITEMS))
-
- items = items.filter((item) => {
- return item.offsetWidth || item.offsetHeight
- })
+ const items = $(parent).find(Selector.VISIBLE_ITEMS).get()
if (!items.length) {
return
diff --git a/js/src/modal.js b/js/src/modal.js
index 5c2c0208a..70bb68e42 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -87,6 +87,7 @@ const Modal = (($) => {
this._isShown = false
this._isBodyOverflowing = false
this._ignoreBackdropClick = false
+ this._isTransitioning = false
this._originalBodyPadding = 0
this._scrollbarWidth = 0
}
@@ -110,6 +111,14 @@ const Modal = (($) => {
}
show(relatedTarget) {
+ if (this._isTransitioning) {
+ throw new Error('Modal is transitioning')
+ }
+
+ if (Util.supportsTransitionEnd() &&
+ $(this._element).hasClass(ClassName.FADE)) {
+ this._isTransitioning = true
+ }
const showEvent = $.Event(Event.SHOW, {
relatedTarget
})
@@ -152,8 +161,17 @@ const Modal = (($) => {
event.preventDefault()
}
- const hideEvent = $.Event(Event.HIDE)
+ if (this._isTransitioning) {
+ throw new Error('Modal is transitioning')
+ }
+ const transition = Util.supportsTransitionEnd() &&
+ $(this._element).hasClass(ClassName.FADE)
+ if (transition) {
+ this._isTransitioning = true
+ }
+
+ const hideEvent = $.Event(Event.HIDE)
$(this._element).trigger(hideEvent)
if (!this._isShown || hideEvent.isDefaultPrevented()) {
@@ -172,9 +190,7 @@ const Modal = (($) => {
$(this._element).off(Event.CLICK_DISMISS)
$(this._dialog).off(Event.MOUSEDOWN_DISMISS)
- if (Util.supportsTransitionEnd() &&
- $(this._element).hasClass(ClassName.FADE)) {
-
+ if (transition) {
$(this._element)
.one(Util.TRANSITION_END, (event) => this._hideModal(event))
.emulateTransitionEnd(TRANSITION_DURATION)
@@ -186,10 +202,7 @@ const Modal = (($) => {
dispose() {
$.removeData(this._element, DATA_KEY)
- $(window).off(EVENT_KEY)
- $(document).off(EVENT_KEY)
- $(this._element).off(EVENT_KEY)
- $(this._backdrop).off(EVENT_KEY)
+ $(window, document, this._element, this._backdrop).off(EVENT_KEY)
this._config = null
this._element = null
@@ -243,6 +256,7 @@ const Modal = (($) => {
if (this._config.focus) {
this._element.focus()
}
+ this._isTransitioning = false
$(this._element).trigger(shownEvent)
}
@@ -290,7 +304,8 @@ const Modal = (($) => {
_hideModal() {
this._element.style.display = 'none'
- this._element.setAttribute('aria-hidden', true)
+ this._element.setAttribute('aria-hidden', 'true')
+ this._isTransitioning = false
this._showBackdrop(() => {
$(document.body).removeClass(ClassName.OPEN)
this._resetAdjustments()
@@ -489,7 +504,7 @@ const Modal = (($) => {
const config = $(target).data(DATA_KEY) ?
'toggle' : $.extend({}, $(target).data(), $(this).data())
- if (this.tagName === 'A') {
+ if (this.tagName === 'A' || this.tagName === 'AREA') {
event.preventDefault()
}
diff --git a/js/src/popover.js b/js/src/popover.js
index 01804eda6..a08ed4de9 100644
--- a/js/src/popover.js
+++ b/js/src/popover.js
@@ -117,9 +117,7 @@ const Popover = (($) => {
this.setElementContent($tip.find(Selector.TITLE), this.getTitle())
this.setElementContent($tip.find(Selector.CONTENT), this._getContent())
- $tip
- .removeClass(ClassName.FADE)
- .removeClass(ClassName.ACTIVE)
+ $tip.removeClass(`${ClassName.FADE} ${ClassName.ACTIVE}`)
this.cleanupTether()
}
diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js
index 9b39acd36..9cb1438ca 100644
--- a/js/src/scrollspy.js
+++ b/js/src/scrollspy.js
@@ -221,7 +221,7 @@ const ScrollSpy = (($) => {
return
}
- if (this._activeTarget && scrollTop < this._offsets[0]) {
+ if (this._activeTarget && scrollTop < this._offsets[0] && this._offsets[0] > 0) {
this._activeTarget = null
this._clear()
return
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 822ae3652..dc291a72c 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -46,7 +46,8 @@ const Tooltip = (($) => {
selector : false,
placement : 'top',
offset : '0 0',
- constraints : []
+ constraints : [],
+ container : false
}
const DefaultType = {
@@ -59,7 +60,8 @@ const Tooltip = (($) => {
selector : '(string|boolean)',
placement : '(string|function)',
offset : 'string',
- constraints : 'array'
+ constraints : 'array',
+ container : '(string|element|boolean)'
}
const AttachmentMap = {
@@ -121,11 +123,12 @@ const Tooltip = (($) => {
constructor(element, config) {
// private
- this._isEnabled = true
- this._timeout = 0
- this._hoverState = ''
- this._activeTrigger = {}
- this._tether = null
+ this._isEnabled = true
+ this._timeout = 0
+ this._hoverState = ''
+ this._activeTrigger = {}
+ this._isTransitioning = false
+ this._tether = null
// protected
this.element = element
@@ -222,6 +225,7 @@ const Tooltip = (($) => {
$.removeData(this.element, this.constructor.DATA_KEY)
$(this.element).off(this.constructor.EVENT_KEY)
+ $(this.element).closest('.modal').off('hide.bs.modal')
if (this.tip) {
$(this.tip).remove()
@@ -242,9 +246,12 @@ const Tooltip = (($) => {
if ($(this.element).css('display') === 'none') {
throw new Error('Please use show on visible elements')
}
- const showEvent = $.Event(this.constructor.Event.SHOW)
+ const showEvent = $.Event(this.constructor.Event.SHOW)
if (this.isWithContent() && this._isEnabled) {
+ if (this._isTransitioning) {
+ throw new Error('Tooltip is transitioning')
+ }
$(this.element).trigger(showEvent)
const isInTheDom = $.contains(
@@ -274,9 +281,11 @@ const Tooltip = (($) => {
const attachment = this._getAttachment(placement)
+ const container = this.config.container === false ? document.body : $(this.config.container)
+
$(tip)
.data(this.constructor.DATA_KEY, this)
- .appendTo(document.body)
+ .appendTo(container)
$(this.element).trigger(this.constructor.Event.INSERTED)
@@ -298,7 +307,8 @@ const Tooltip = (($) => {
const complete = () => {
const prevHoverState = this._hoverState
- this._hoverState = null
+ this._hoverState = null
+ this._isTransitioning = false
$(this.element).trigger(this.constructor.Event.SHOWN)
@@ -308,6 +318,7 @@ const Tooltip = (($) => {
}
if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
+ this._isTransitioning = true
$(this.tip)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(Tooltip._TRANSITION_DURATION)
@@ -321,6 +332,9 @@ const Tooltip = (($) => {
hide(callback) {
const tip = this.getTipElement()
const hideEvent = $.Event(this.constructor.Event.HIDE)
+ if (this._isTransitioning) {
+ throw new Error('Tooltip is transitioning')
+ }
const complete = () => {
if (this._hoverState !== HoverState.ACTIVE && tip.parentNode) {
tip.parentNode.removeChild(tip)
@@ -328,6 +342,7 @@ const Tooltip = (($) => {
this.element.removeAttribute('aria-describedby')
$(this.element).trigger(this.constructor.Event.HIDDEN)
+ this._isTransitioning = false
this.cleanupTether()
if (callback) {
@@ -345,7 +360,7 @@ const Tooltip = (($) => {
if (Util.supportsTransitionEnd() &&
$(this.tip).hasClass(ClassName.FADE)) {
-
+ this._isTransitioning = true
$(tip)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
@@ -373,9 +388,7 @@ const Tooltip = (($) => {
this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle())
- $tip
- .removeClass(ClassName.FADE)
- .removeClass(ClassName.ACTIVE)
+ $tip.removeClass(`${ClassName.FADE} ${ClassName.ACTIVE}`)
this.cleanupTether()
}
@@ -452,6 +465,11 @@ const Tooltip = (($) => {
(event) => this._leave(event)
)
}
+
+ $(this.element).closest('.modal').on(
+ 'hide.bs.modal',
+ () => this.hide()
+ )
})
if (this.config.selector) {