aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-08-03 19:46:54 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2019-08-03 19:46:54 +0300
commit683bb5b620759c71297ca6d8fe24aa8c3ff56a18 (patch)
treeb2d0803392820cc648be93b808816a4a8ab5d5f6 /ext/mixed/js
parentec1441434f35ad7ac2d1feb4eae1cee12bf00609 (diff)
scroll back to exact position in source term view
Diffstat (limited to 'ext/mixed/js')
-rw-r--r--ext/mixed/js/display.js39
1 files changed, 25 insertions, 14 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 9a178a1f..650372d3 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -55,7 +55,8 @@ class Display {
const context = {
source: {
definitions: this.definitions,
- index: Display.entryIndexFind(link)
+ index: Display.entryIndexFind(link),
+ scroll: $('html,body').scrollTop()
}
};
@@ -94,7 +95,8 @@ class Display {
const context = {
source: {
definitions: this.definitions,
- index: Display.entryIndexFind(clickedElement)
+ index: Display.entryIndexFind(clickedElement),
+ scroll: $('html,body').scrollTop()
}
};
@@ -155,42 +157,42 @@ class Display {
33: /* page up */ () => {
if (e.altKey) {
- this.entryScrollIntoView(this.index - 3, true);
+ this.entryScrollIntoView(this.index - 3, null, true);
return true;
}
},
34: /* page down */ () => {
if (e.altKey) {
- this.entryScrollIntoView(this.index + 3, true);
+ this.entryScrollIntoView(this.index + 3, null, true);
return true;
}
},
35: /* end */ () => {
if (e.altKey) {
- this.entryScrollIntoView(this.definitions.length - 1, true);
+ this.entryScrollIntoView(this.definitions.length - 1, null, true);
return true;
}
},
36: /* home */ () => {
if (e.altKey) {
- this.entryScrollIntoView(0, true);
+ this.entryScrollIntoView(0, null, true);
return true;
}
},
38: /* up */ () => {
if (e.altKey) {
- this.entryScrollIntoView(this.index - 1, true);
+ this.entryScrollIntoView(this.index - 1, null, true);
return true;
}
},
40: /* down */ () => {
if (e.altKey) {
- this.entryScrollIntoView(this.index + 1, true);
+ this.entryScrollIntoView(this.index + 1, null, true);
return true;
}
},
@@ -251,10 +253,10 @@ class Display {
const handler = () => {
if (event.altKey) {
if (event.deltaY < 0) { // scroll up
- this.entryScrollIntoView(this.index - 1, true);
+ this.entryScrollIntoView(this.index - 1, null, true);
return true;
} else if (event.deltaY > 0) { // scroll down
- this.entryScrollIntoView(this.index + 1, true);
+ this.entryScrollIntoView(this.index + 1, null, true);
return true;
}
}
@@ -296,7 +298,8 @@ class Display {
const content = await apiTemplateRender('terms.html', params);
this.container.html(content);
- this.entryScrollIntoView(context && context.index || 0);
+ const {index, scroll} = context || {};
+ this.entryScrollIntoView(index || 0, scroll);
if (this.options.general.autoPlayAudio && this.options.general.audioSource !== 'disabled') {
this.autoPlayAudio();
@@ -342,7 +345,8 @@ class Display {
const content = await apiTemplateRender('kanji.html', params);
this.container.html(content);
- this.entryScrollIntoView(context && context.index || 0);
+ const {index, scroll} = context || {};
+ this.entryScrollIntoView(index || 0, scroll);
$('.action-add-note').click(this.onNoteAdd.bind(this));
$('.action-view-note').click(this.onNoteView.bind(this));
@@ -383,7 +387,7 @@ class Display {
}
}
- entryScrollIntoView(index, smooth) {
+ entryScrollIntoView(index, scroll, smooth) {
index = Math.min(index, this.definitions.length - 1);
index = Math.max(index, 0);
@@ -391,7 +395,13 @@ class Display {
const container = $('html,body').stop();
const entry = $('.entry').eq(index);
- const target = index === 0 ? 0 : entry.offset().top;
+ let target;
+
+ if (scroll) {
+ target = scroll;
+ } else {
+ target = index === 0 ? 0 : entry.offset().top;
+ }
if (smooth) {
container.animate({scrollTop: target}, 200);
@@ -408,6 +418,7 @@ class Display {
url: this.context.source.url,
sentence: this.context.source.sentence,
index: this.context.source.index,
+ scroll: this.context.source.scroll,
source: this.context.source.source
};