From 66cf7790b3f8d7660076e391dd974e3f88b53e69 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 8 Jul 2022 19:09:57 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20ContentsPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reader/ContentsPage/ContentsPage.vue | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/client/components/Reader/ContentsPage/ContentsPage.vue b/client/components/Reader/ContentsPage/ContentsPage.vue index 135657aa..4ade64d4 100644 --- a/client/components/Reader/ContentsPage/ContentsPage.vue +++ b/client/components/Reader/ContentsPage/ContentsPage.vue @@ -23,10 +23,10 @@
-
+
-
+
@@ -42,8 +42,12 @@
-
-
+
+
@@ -289,24 +293,24 @@ class ContentsPage { const item = this.contents[i]; const nextOffset = (i < this.contents.length - 1 ? this.contents[i + 1].offset : this.parsed.textLength); + if (bp >= item.offset && bp < nextOffset) { + item.isBookPos = true; + this.updateBookPosScrollTop(item); + } else if (item.isBookPos) { + item.isBookPos = false; + } + for (let j = 0; j < item.list.length; j++) { const subitem = item.list[j]; const nextSubOffset = (j < item.list.length - 1 ? item.list[j + 1].offset : nextOffset); if (bp >= subitem.offset && bp < nextSubOffset) { subitem.isBookPos = true; - this.contents[i] = Object.assign(item, {list: item.list}); + this.updateBookPosScrollTop(item, subitem, j); } else if (subitem.isBookPos) { subitem.isBookPos = false; - this.contents[i] = Object.assign(item, {list: item.list}); } } - - if (bp >= item.offset && bp < nextOffset) { - this.contents[i] = Object.assign(item, {isBookPos: true}); - } else if (item.isBookPos) { - this.contents[i] = Object.assign(item, {isBookPos: false}); - } } for (let i = 0; i < this.images.length; i++) { @@ -314,13 +318,35 @@ class ContentsPage { const nextOffset = (i < this.images.length - 1 ? this.images[i + 1].offset : this.parsed.textLength); if (bp >= img.offset && bp < nextOffset) { - this.images[i] = Object.assign(img, {isBookPos: true}); + this.images[i].isBookPos = true; } else if (img.isBookPos) { - this.images[i] = Object.assign(img, {isBookPos: false}); + this.images[i].isBookPos = false; } } } + updateBookPosScrollTop(item, subitem, i) { + try { + if (this.selectedTab == 'contents') { + let el = this.getFirstElem(this.$refs[`mainitem${item.key}`]); + let elShift = 0; + if (subitem && item.expanded) { + const subEl = this.getFirstElem(this.$refs[`subitem${subitem.key}`]); + elShift = el.offsetHeight - (0.5 + subEl.offsetHeight)*(i + 1); + } else { + elShift = el.offsetHeight; + } + + const halfH = this.$refs.tabPanel.clientHeight/2; + const newScrollTop = el.offsetTop - halfH - elShift; + if (newScrollTop < this.$refs.tabPanel.scrollTop - halfH || newScrollTop > this.$refs.tabPanel.scrollTop + halfH) + this.$refs.tabPanel.scrollTop = newScrollTop; + } + } catch (e) { + console.error(e); + } + } + getFirstElem(items) { return (Array.isArray(items) ? items[0] : items); } @@ -330,8 +356,8 @@ class ContentsPage { const expanded = !item.expanded; if (!expanded) { - let subitems = this.getFirstElem(this.$refs[`subitem${key}`]); - subitems.style.height = '0'; + let subdiv = this.getFirstElem(this.$refs[`subdiv${key}`]); + subdiv.style.height = '0'; await utils.sleep(200); } @@ -339,8 +365,8 @@ class ContentsPage { if (expanded) { await this.$nextTick(); - let subitems = this.getFirstElem(this.$refs[`subitem${key}`]); - subitems.style.height = subitems.scrollHeight + 'px'; + let subdiv = this.getFirstElem(this.$refs[`subdiv${key}`]); + subdiv.style.height = subdiv.scrollHeight + 'px'; } }