aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-03-17 20:45:47 -0700
committerAlex Yatskov <alex@foosoft.net>2017-03-17 20:45:47 -0700
commit1dbcb35eb7a2f1d6d7790821da282df7254700d8 (patch)
tree060748dfdddf1c9fd9c61d21719b60dd6613104f
parent231b471f45505a8b8fc4a8b25aa685f6f877953c (diff)
wip
-rw-r--r--ext/bg/js/templates.js8
-rw-r--r--ext/mixed/js/display.js35
-rw-r--r--tmpl/kanji.html4
-rw-r--r--tmpl/terms.html4
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 "<p>\n <div class=\"actions\">\n"
+ return "<div class=\"entry\">\n <div class=\"actions\">\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 : "")
+ " </div>\n\n <div class=\"glyph\">"
+ 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 : "")
+ " </div>\n\n <div class=\"glossary\">\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 : "")
- + " </div>\n\n <a href=\"#\" class=\"term-source\">Back</a>\n</p>\n";
+ + " </div>\n\n <a href=\"#\" class=\"term-source\">Back</a>\n</div>\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 "<p>\n <div class=\"actions\">\n"
+ return "<div class=\"entry\">\n <div class=\"actions\">\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 : "")
+ " </div>\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 <div class=\"glossary\">\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 : "")
- + " </div>\n</p>\n";
+ + " </div>\n</div>\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"}}
-<p>
+<div class="entry">
<div class="actions">
{{#if addable}}
<a href="#" title="Add Kanji" class="action-add-note pending disabled" data-mode="kanji" data-index="{{@index}}"><img src="/mixed/img/add-kanji.png"></a>
@@ -48,7 +48,7 @@
</div>
<a href="#" class="term-source">Back</a>
-</p>
+</div>
{{/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"}}
-<p>
+<div class="entry">
<div class="actions">
{{#if addable}}
<a href="#" title="Add term as expression" class="action-add-note pending disabled" data-mode="term-kanji" data-index="{{@index}}"><img src="/mixed/img/add-term-kanji.png"></a>
@@ -58,7 +58,7 @@
{{> definition}}
{{/if}}
</div>
-</p>
+</div>
{{/inline}}
{{#if definitions}}