diff options
author | Alex Yatskov <alex@foosoft.net> | 2017-03-17 20:45:47 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2017-03-17 20:45:47 -0700 |
commit | 1dbcb35eb7a2f1d6d7790821da282df7254700d8 (patch) | |
tree | 060748dfdddf1c9fd9c61d21719b60dd6613104f /ext/mixed/js | |
parent | 231b471f45505a8b8fc4a8b25aa685f6f877953c (diff) |
wip
Diffstat (limited to 'ext/mixed/js')
-rw-r--r-- | ext/mixed/js/display.js | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index cab2cfea..07a9f0c1 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -66,20 +66,29 @@ class Display { this.spinner.hide(); this.templateRender('terms.html', params).then(content => { - window.scrollTo(0, 0); this.container.html(content); + if (context && context.hasOwnProperty('index') && context.index < definitions.length) { + const entry = $('.entry').eq(context.index); + window.scrollTo(0, entry.offset().top); + } else { + window.scrollTo(0, 0); + } $('.action-add-note').click(this.onActionAddNote.bind(this)); $('.action-play-audio').click(this.onActionPlayAudio.bind(this)); $('.kanji-link').click(e => { e.preventDefault(); - const character = $(e.target).text(); - this.kanjiFind(character).then(kanjiDefs => { - this.showKanjiDefs( - kanjiDefs, - options, - {definitions, sentence: context.sentence, url: context.url} - ); + + const link = $(e.target); + if (context) { + context.source = { + definitions, + index: $('.entry').index(link.closest('.entry')) + }; + } + + this.kanjiFind(link.text()).then(kanjiDefs => { + this.showKanjiDefs(kanjiDefs, options, context); }).catch(this.handleError.bind(this)); }); @@ -111,12 +120,10 @@ class Display { $('.action-add-note').click(this.onActionAddNote.bind(this)); $('.term-source').click(e => { e.preventDefault(); - if (context.definitions) { - this.showTermDefs( - context.definitions, - options, - {sentence: context.sentence, url: context.url} - ); + + if (context && context.source) { + context.index = context.source.index; + this.showTermDefs(context.source.definitions, options, context); } }); |