From 1dbcb35eb7a2f1d6d7790821da282df7254700d8 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 17 Mar 2017 20:45:47 -0700 Subject: [PATCH] wip --- ext/bg/js/templates.js | 8 ++++---- ext/mixed/js/display.js | 35 +++++++++++++++++++++-------------- tmpl/kanji.html | 4 ++-- tmpl/terms.html | 4 ++-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index ebff387b..fbdd2d11 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -284,7 +284,7 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "

\n

\n" + return "
\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n
" + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) @@ -296,7 +296,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n
\n" + ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(9, data, 0),"inverse":container.program(13, data, 0),"data":data})) != null ? stack1 : "") - + "
\n\n Back\n

\n"; + + "
\n\n Back\n
\n"; },"2":function(container,depth0,helpers,partials,data) { var helper; @@ -444,7 +444,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "

\n

\n" + return "
\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n\n" @@ -453,7 +453,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.grouped : depth0),{"name":"if","hash":{},"fn":container.program(26, data, 0),"inverse":container.program(32, data, 0),"data":data})) != null ? stack1 : "") - + "
\n

\n"; + + "
\n
\n"; },"13":function(container,depth0,helpers,partials,data) { var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; 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); } }); diff --git a/tmpl/kanji.html b/tmpl/kanji.html index f4c12041..00e4efd7 100644 --- a/tmpl/kanji.html +++ b/tmpl/kanji.html @@ -1,5 +1,5 @@ {{#*inline "kanji"}} -

+

{{#if addable}} @@ -48,7 +48,7 @@
Back -

+
{{/inline}} {{#if definitions}} diff --git a/tmpl/terms.html b/tmpl/terms.html index 04ba713d..22209f9b 100644 --- a/tmpl/terms.html +++ b/tmpl/terms.html @@ -18,7 +18,7 @@ {{/inline}} {{#*inline "term"}} -

+

{{#if addable}} @@ -58,7 +58,7 @@ {{> definition}} {{/if}}
-

+
{{/inline}} {{#if definitions}}