Skip to content

Commit 88598b3

Browse files
committed
Merge branch 'feature/dynamic-modal' into feature/zh-Hant
2 parents a42e927 + b248d0b commit 88598b3

File tree

10 files changed

+51
-50
lines changed

10 files changed

+51
-50
lines changed

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@nuxt/content-theme-docs": "^0.8.2",
1313
"nuxt": "^2.14.12",
14-
"vue-final-modal": "^0.21.3"
14+
"vue-final-modal": "^0.21.5"
1515
},
1616
"devDependencies": {
1717
"@nuxtjs/google-analytics": "^2.4.0",

docs/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10619,10 +10619,10 @@ vue-client-only@^2.0.0:
1061910619
resolved "https://registry.yarnpkg.com/vue-client-only/-/vue-client-only-2.0.0.tgz#ddad8d675ee02c761a14229f0e440e219de1da1c"
1062010620
integrity sha512-arhk1wtWAfLsJyxGMoEYhoBowM87/i6HLSG2LH/03Yog6i2d9JEN1peMP0Ceis+/n9DxdenGYZZTxbPPJyHciA==
1062110621

10622-
vue-final-modal@^0.21.3:
10623-
version "0.21.3"
10624-
resolved "https://registry.yarnpkg.com/vue-final-modal/-/vue-final-modal-0.21.3.tgz#74a2ae88d6d0c7afc9f822c3bfbe7a99c4c8014d"
10625-
integrity sha512-8l1uMi+k8TSFtIJobtl1J3pYabD4AjgtavTxflDHckVI+XI7nwvMWotMbWCAs+rHQ83Hnz4QGq/Z1JefA/ZsqA==
10622+
vue-final-modal@^0.21.5:
10623+
version "0.21.5"
10624+
resolved "https://registry.yarnpkg.com/vue-final-modal/-/vue-final-modal-0.21.5.tgz#e992a7f82a511d0c852fa84d83d9b6ca8578e41b"
10625+
integrity sha512-2Yby+hhy6qer0Yfk1QVT1p6XqaeoxqMJBuvcMHE8pHAIbVo9pfjJu1cehb5SVBH0QJzTeVPdhcKOBVXOjLl67A==
1062610626

1062710627
vue-hot-reload-api@^2.3.0:
1062810628
version "2.3.4"

lib/VueFinalModal.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@
4040
tabindex="-1"
4141
@click.self="onClickContainer"
4242
>
43-
<div
44-
ref="vfmContent"
45-
class="vfm__content"
46-
:class="[contentClass, { 'vfm--prevent-auto': preventClick }]"
47-
:style="contentStyle"
48-
>
43+
<div class="vfm__content" :class="[contentClass, { 'vfm--prevent-auto': preventClick }]" :style="contentStyle">
4944
<slot v-bind:params="params" />
5045
</div>
5146
</div>
@@ -177,7 +172,7 @@ export default {
177172
},
178173
beforeDestroy() {
179174
this.close()
180-
this.lockScroll && enableBodyScroll(this.$refs.vfmContent)
175+
this.lockScroll && enableBodyScroll(this.$refs.vfmContainer)
181176
this?.$el?.remove()
182177
183178
let index = this.api.modals.findIndex(vm => vm === this)
@@ -249,11 +244,11 @@ export default {
249244
handleLockScroll() {
250245
if (this.value) {
251246
if (this.lockScroll) {
252-
disableBodyScroll(this.$refs.vfmContent, {
247+
disableBodyScroll(this.$refs.vfmContainer, {
253248
reserveScrollBarGap: true
254249
})
255250
} else {
256-
enableBodyScroll(this.$refs.vfmContent)
251+
enableBodyScroll(this.$refs.vfmContainer)
257252
}
258253
}
259254
},
@@ -309,7 +304,7 @@ export default {
309304
afterModalLeave() {
310305
this.modalTransitionState = TransitionState.Leave
311306
this.modalStackIndex = null
312-
this.lockScroll && enableBodyScroll(this.$refs.vfmContent)
307+
this.lockScroll && enableBodyScroll(this.$refs.vfmContainer)
313308
314309
let stopEvent = false
315310
const event = this.createModalEvent({

lib/utils/bodyScrollLock.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,47 @@ const isIosDevice =
2222

2323
let locks = []
2424
let documentListenerAdded = false
25+
let clientY = 0
2526
let initialClientY = -1
2627
let previousBodyOverflowSetting
2728
let previousBodyPaddingRight
2829

29-
// returns true if `el` should be allowed to receive touchmove events.
30-
const allowTouchMove = el =>
31-
locks.some(lock => {
32-
if (lock.options.allowTouchMove && lock.options.allowTouchMove(el)) {
33-
return true
34-
}
30+
const hasScrollbar = el => {
31+
if (!el || el.nodeType !== Node.ELEMENT_NODE) return false
3532

36-
return false
33+
const style = window.getComputedStyle(el)
34+
return ['auto', 'scroll'].includes(style.overflowY) && el.scrollHeight > el.clientHeight
35+
}
36+
37+
const shouldScroll = (el, delta) => {
38+
if (el.scrollTop === 0 && delta < 0) return false
39+
if (el.scrollTop + el.clientHeight + delta >= el.scrollHeight && delta > 0) return false
40+
return true
41+
}
42+
43+
const composedPath = el => {
44+
const path = []
45+
while (el) {
46+
path.push(el)
47+
if (el.classList.contains('vfm')) return path
48+
el = el.parentElement
49+
}
50+
return path
51+
}
52+
53+
const hasAnyScrollableEl = (el, delta) => {
54+
let hasAnyScrollableEl = false
55+
const path = composedPath(el)
56+
path.forEach(el => {
57+
if (hasScrollbar(el) && shouldScroll(el, delta)) {
58+
hasAnyScrollableEl = true
59+
}
3760
})
61+
return hasAnyScrollableEl
62+
}
63+
64+
// returns true if `el` should be allowed to receive touchmove events.
65+
const allowTouchMove = el => locks.some(() => hasAnyScrollableEl(el, -clientY))
3866

3967
const preventDefault = rawEvent => {
4068
const e = rawEvent || window.event
@@ -95,7 +123,7 @@ const isTargetElementTotallyScrolled = targetElement =>
95123
targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false
96124

97125
const handleScroll = (event, targetElement) => {
98-
const clientY = event.targetTouches[0].clientY - initialClientY
126+
clientY = event.targetTouches[0].clientY - initialClientY
99127

100128
if (allowTouchMove(event.target)) {
101129
return false
@@ -160,27 +188,6 @@ export const disableBodyScroll = (targetElement, options) => {
160188
}
161189
}
162190

163-
export const clearAllBodyScrollLocks = () => {
164-
if (isIosDevice) {
165-
// Clear all locks ontouchstart/ontouchmove handlers, and the references.
166-
locks.forEach(lock => {
167-
lock.targetElement.ontouchstart = null
168-
lock.targetElement.ontouchmove = null
169-
})
170-
171-
if (documentListenerAdded) {
172-
document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined)
173-
documentListenerAdded = false
174-
}
175-
// Reset initial clientY.
176-
initialClientY = -1
177-
} else {
178-
restoreOverflowSetting()
179-
}
180-
181-
locks = []
182-
}
183-
184191
export const enableBodyScroll = targetElement => {
185192
if (!targetElement) {
186193
// eslint-disable-next-line no-console

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-final-modal",
3-
"version": "0.21.3",
3+
"version": "0.21.5",
44
"description": "Vue Final Modal is a renderless, stackable, detachable and lightweight modal component.",
55
"private": false,
66
"main": "dist/VueFinalModal.umd.js",

types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import './lib'
44
export class VueFinalModalComponant extends Vue {
55
$refs: {
66
vfmContainer: HTMLDivElement,
7-
vfmContent: HTMLDivElement
87
}
98
}
109

0 commit comments

Comments
 (0)