From 90610a5b3d5192496e45195df3782e78150f4221 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Thu, 11 Oct 2018 22:00:55 +0800 Subject: [PATCH 1/2] feat: the forceUseInfiniteWrapper could be a css selector --- src/components/InfiniteLoading.vue | 18 +++++++++----- test/unit/specs/InfiniteLoading.spec.js | 33 ++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/components/InfiniteLoading.vue b/src/components/InfiniteLoading.vue index f5f3496..8b1605e 100644 --- a/src/components/InfiniteLoading.vue +++ b/src/components/InfiniteLoading.vue @@ -295,12 +295,18 @@ export default { getScrollParent(elm = this.$el) { let result; - if (elm.tagName === 'BODY') { - result = window; - } else if (!this.forceUseInfiniteWrapper && ['scroll', 'auto'].indexOf(getComputedStyle(elm).overflowY) > -1) { - result = elm; - } else if (elm.hasAttribute('infinite-wrapper') || elm.hasAttribute('data-infinite-wrapper')) { - result = elm; + if (typeof this.forceUseInfiniteWrapper === 'string') { + result = elm.querySelector(this.forceUseInfiniteWrapper); + } + + if (!result) { + if (elm.tagName === 'BODY') { + result = window; + } else if (!this.forceUseInfiniteWrapper && ['scroll', 'auto'].indexOf(getComputedStyle(elm).overflowY) > -1) { + result = elm; + } else if (elm.hasAttribute('infinite-wrapper') || elm.hasAttribute('data-infinite-wrapper')) { + result = elm; + } } return result || this.getScrollParent(elm.parentNode); diff --git a/test/unit/specs/InfiniteLoading.spec.js b/test/unit/specs/InfiniteLoading.spec.js index 869bf01..f5f5830 100644 --- a/test/unit/specs/InfiniteLoading.spec.js +++ b/test/unit/specs/InfiniteLoading.spec.js @@ -460,7 +460,7 @@ describe('vue-infinite-loading', () => { vm.$mount('#app'); }); - it('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` property', (done) => { + it.only('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` property', (done) => { vm = new Vue(Object.assign({}, basicConfig, { template: `
@@ -566,4 +566,35 @@ describe('vue-infinite-loading', () => { vm.$mount('#app'); }); + + it('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` as seletor', (done) => { + vm = new Vue(Object.assign({}, basicConfig, { + template: ` +
+
+
+
    +
  • +
+ + +
+
+
+ `, + methods: { + infiniteHandler: function infiniteHandler() { + expect(this.$refs.infiniteLoading.scrollParent).to.equal(this.$el); + done(); + }, + }, + })); + + vm.$mount('#app'); + }); }); From f33402fe13784df4dcfc7e0334e3c8b0ec4fda13 Mon Sep 17 00:00:00 2001 From: Riceball LEE Date: Thu, 11 Oct 2018 22:04:31 +0800 Subject: [PATCH 2/2] chore: forget to remove only flag --- test/unit/specs/InfiniteLoading.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/specs/InfiniteLoading.spec.js b/test/unit/specs/InfiniteLoading.spec.js index f5f5830..2e86b8e 100644 --- a/test/unit/specs/InfiniteLoading.spec.js +++ b/test/unit/specs/InfiniteLoading.spec.js @@ -460,7 +460,7 @@ describe('vue-infinite-loading', () => { vm.$mount('#app'); }); - it.only('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` property', (done) => { + it('should find my forcible element as scroll wrapper when using `force-use-infinite-wrapper` property', (done) => { vm = new Vue(Object.assign({}, basicConfig, { template: `