aboutsummaryrefslogtreecommitdiff
path: root/js/src
diff options
context:
space:
mode:
authorGijs Boddeus <[email protected]>2017-08-25 23:29:40 +0200
committerGitHub <[email protected]>2017-08-25 23:29:40 +0200
commit4356d08abb4d94785af15f3cc9be0e553f1c1c03 (patch)
treece649fd410b7e9a38758ef8318e1d9aba5eef3e8 /js/src
parenta103958975787653b4ba84f80d1d1e8f7be302c3 (diff)
parentba6a6f13691000ffaf22ef8e731513737659447f (diff)
downloadbootstrap-4356d08abb4d94785af15f3cc9be0e553f1c1c03.tar.xz
bootstrap-4356d08abb4d94785af15f3cc9be0e553f1c1c03.zip
Merge pull request #3 from twbs/v4-dev
update from official repo
Diffstat (limited to 'js/src')
-rw-r--r--js/src/carousel.js6
-rw-r--r--js/src/collapse.js5
-rw-r--r--js/src/dropdown.js4
-rw-r--r--js/src/modal.js14
-rw-r--r--js/src/popover.js5
-rw-r--r--js/src/scrollspy.js5
-rw-r--r--js/src/tab.js2
-rw-r--r--js/src/tooltip.js12
-rw-r--r--js/src/util.js6
9 files changed, 38 insertions, 21 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index a5d5f143a..873660519 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -131,7 +131,9 @@ const Carousel = (($) => {
nextWhenVisible() {
// Don't call next when the page isn't visible
- if (!document.hidden) {
+ // or the carousel or its parent isn't visible
+ if (!document.hidden &&
+ ($(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden')) {
this.next()
}
}
@@ -441,7 +443,7 @@ const Carousel = (($) => {
if (typeof config === 'number') {
data.to(config)
} else if (typeof action === 'string') {
- if (data[action] === undefined) {
+ if (typeof data[action] === 'undefined') {
throw new Error(`No method named "${action}"`)
}
data[action]()
diff --git a/js/src/collapse.js b/js/src/collapse.js
index 2f00b98cb..7d1ba4c54 100644
--- a/js/src/collapse.js
+++ b/js/src/collapse.js
@@ -343,7 +343,7 @@ const Collapse = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
@@ -361,7 +361,8 @@ const Collapse = (($) => {
*/
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
- if (!/input|textarea/i.test(event.target.tagName)) {
+ // preventDefault only for <a> elements (which change the URL) not inside the collapsible element
+ if (event.target.tagName === 'A' && !$.contains(this, event.target)) {
event.preventDefault()
}
diff --git a/js/src/dropdown.js b/js/src/dropdown.js
index 5e792a527..e1c48ac6e 100644
--- a/js/src/dropdown.js
+++ b/js/src/dropdown.js
@@ -204,7 +204,7 @@ const Dropdown = (($) => {
_getConfig(config) {
const elementData = $(this._element).data()
- if (elementData.placement !== undefined) {
+ if (typeof elementData.placement !== 'undefined') {
elementData.placement = AttachmentMap[elementData.placement.toUpperCase()]
}
@@ -287,7 +287,7 @@ const Dropdown = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
diff --git a/js/src/modal.js b/js/src/modal.js
index 9f17fafc8..ab73230c8 100644
--- a/js/src/modal.js
+++ b/js/src/modal.js
@@ -68,6 +68,7 @@ const Modal = (($) => {
DATA_TOGGLE : '[data-toggle="modal"]',
DATA_DISMISS : '[data-dismiss="modal"]',
FIXED_CONTENT : '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
+ STICKY_CONTENT : '.sticky-top',
NAVBAR_TOGGLER : '.navbar-toggler'
}
@@ -441,6 +442,13 @@ const Modal = (($) => {
$(element).data('padding-right', actualPadding).css('padding-right', `${parseFloat(calculatedPadding) + this._scrollbarWidth}px`)
})
+ // Adjust sticky content margin
+ $(Selector.STICKY_CONTENT).each((index, element) => {
+ const actualMargin = $(element)[0].style.marginRight
+ const calculatedMargin = $(element).css('margin-right')
+ $(element).data('margin-right', actualMargin).css('margin-right', `${parseFloat(calculatedMargin) - this._scrollbarWidth}px`)
+ })
+
// Adjust navbar-toggler margin
$(Selector.NAVBAR_TOGGLER).each((index, element) => {
const actualMargin = $(element)[0].style.marginRight
@@ -464,8 +472,8 @@ const Modal = (($) => {
}
})
- // Restore navbar-toggler margin
- $(Selector.NAVBAR_TOGGLER).each((index, element) => {
+ // Restore sticky content and navbar-toggler margin
+ $(`${Selector.STICKY_CONTENT}, ${Selector.NAVBAR_TOGGLER}`).each((index, element) => {
const margin = $(element).data('margin-right')
if (typeof margin !== 'undefined') {
$(element).css('margin-right', margin).removeData('margin-right')
@@ -507,7 +515,7 @@ const Modal = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config](relatedTarget)
diff --git a/js/src/popover.js b/js/src/popover.js
index 0e8953f77..f5820ecbe 100644
--- a/js/src/popover.js
+++ b/js/src/popover.js
@@ -114,7 +114,8 @@ const Popover = (($) => {
}
getTipElement() {
- return this.tip = this.tip || $(this.config.template)[0]
+ this.tip = this.tip || $(this.config.template)[0]
+ return this.tip
}
setContent() {
@@ -162,7 +163,7 @@ const Popover = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
diff --git a/js/src/scrollspy.js b/js/src/scrollspy.js
index b70b7e477..588f65298 100644
--- a/js/src/scrollspy.js
+++ b/js/src/scrollspy.js
@@ -231,7 +231,7 @@ const ScrollSpy = (($) => {
for (let i = this._offsets.length; i--;) {
const isActiveTarget = this._activeTarget !== this._targets[i]
&& scrollTop >= this._offsets[i]
- && (this._offsets[i + 1] === undefined ||
+ && (typeof this._offsets[i + 1] === 'undefined' ||
scrollTop < this._offsets[i + 1])
if (isActiveTarget) {
@@ -246,6 +246,7 @@ const ScrollSpy = (($) => {
this._clear()
let queries = this._selector.split(',')
+ // eslint-disable-next-line arrow-body-style
queries = queries.map((selector) => {
return `${selector}[data-target="${target}"],` +
`${selector}[href="${target}"]`
@@ -287,7 +288,7 @@ const ScrollSpy = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
diff --git a/js/src/tab.js b/js/src/tab.js
index 4c3091495..c32cd3776 100644
--- a/js/src/tab.js
+++ b/js/src/tab.js
@@ -238,7 +238,7 @@ const Tab = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 2060cebbb..37573cf49 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -184,6 +184,10 @@ const Tooltip = (($) => {
}
toggle(event) {
+ if (!this._isEnabled) {
+ return
+ }
+
if (event) {
const dataKey = this.constructor.DATA_KEY
let context = $(event.currentTarget).data(dataKey)
@@ -234,8 +238,8 @@ const Tooltip = (($) => {
if (this._popper !== null) {
this._popper.destroy()
}
- this._popper = null
+ this._popper = null
this.element = null
this.config = null
this.tip = null
@@ -415,7 +419,8 @@ const Tooltip = (($) => {
}
getTipElement() {
- return this.tip = this.tip || $(this.config.template)[0]
+ this.tip = this.tip || $(this.config.template)[0]
+ return this.tip
}
setContent() {
@@ -698,14 +703,13 @@ const Tooltip = (($) => {
}
if (typeof config === 'string') {
- if (data[config] === undefined) {
+ if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
}
data[config]()
}
})
}
-
}
diff --git a/js/src/util.js b/js/src/util.js
index 387c7d2ed..69fb8283c 100644
--- a/js/src/util.js
+++ b/js/src/util.js
@@ -42,7 +42,7 @@ const Util = (($) => {
if ($(event.target).is(this)) {
return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params
}
- return undefined
+ return undefined // eslint-disable-line no-undefined
}
}
}
@@ -55,7 +55,7 @@ const Util = (($) => {
const el = document.createElement('bootstrap')
for (const name in TransitionEndEvent) {
- if (el.style[name] !== undefined) {
+ if (typeof el.style[name] !== 'undefined') {
return {
end: TransitionEndEvent[name]
}
@@ -138,7 +138,7 @@ const Util = (($) => {
typeCheckConfig(componentName, config, configTypes) {
for (const property in configTypes) {
- if (configTypes.hasOwnProperty(property)) {
+ if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
const expectedTypes = configTypes[property]
const value = config[property]
const valueType = value && isElement(value) ?