";
+ "
";
stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"kanjiLinks","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; }
@@ -494,13 +479,13 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"22":function(container,depth0,helpers,partials,data) {
var stack1;
- return "
\n"
+ return "
\n"
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.reasons : depth0),{"name":"each","hash":{},"fn":container.program(23, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "
\n";
+ + "
\n";
},"23":function(container,depth0,helpers,partials,data) {
var stack1;
- return "
"
+ return " "
+ container.escapeExpression(container.lambda(depth0, depth0))
+ " "
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(24, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
@@ -520,13 +505,13 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"28":function(container,depth0,helpers,partials,data) {
var stack1;
- return " "
+ return " "
+ ((stack1 = container.invokePartial(partials.definition,depth0,{"name":"definition","data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "")
+ "\n";
},"30":function(container,depth0,helpers,partials,data) {
var stack1;
- return ((stack1 = container.invokePartial(partials.definition,((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["0"] : stack1),{"name":"definition","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
+ return ((stack1 = container.invokePartial(partials.definition,((stack1 = (depth0 != null ? depth0.definitions : depth0)) != null ? stack1["0"] : stack1),{"name":"definition","data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"32":function(container,depth0,helpers,partials,data) {
var stack1;
@@ -538,14 +523,13 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
},"35":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1;
- return " "
- + ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.first),{"name":"unless","hash":{},"fn":container.program(36, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\n"
- + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1])},"data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
+ + ((stack1 = container.invokePartial(partials.term,depth0,{"name":"term","hash":{"playback":(depths[1] != null ? depths[1].playback : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"grouped":(depths[1] != null ? depths[1].grouped : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
},"36":function(container,depth0,helpers,partials,data) {
return "
";
},"38":function(container,depth0,helpers,partials,data) {
- return " No results found.
\n";
+ return "No results found.
\n";
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1;
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index 57c9b882..6ce84626 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -47,6 +47,9 @@ class Display {
}
showTermDefs(definitions, options, context) {
+ this.spinner.hide();
+ this.definitions = definitions;
+
const sequence = ++this.sequence;
const params = {
definitions,
@@ -56,26 +59,29 @@ class Display {
};
if (context) {
- definitions.forEach(definition => {
+ for (const definition of definitions) {
definition.sentence = context.sentence;
definition.url = context.url;
- });
+ }
}
- this.definitions = definitions;
- this.spinner.hide();
-
this.templateRender('terms.html', params).then(content => {
this.container.html(content);
+
+ let offset = 0;
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);
+ offset = entry.offset().top;
}
+ window.scrollTo(0, offset);
+
$('.action-add-note').click(this.onActionAddNote.bind(this));
- $('.action-play-audio').click(this.onActionPlayAudio.bind(this));
+ $('.action-play-audio').click(e => {
+ e.preventDefault();
+ const index = Display.entryIndexFind($(e.currentTarget));
+ Display.audioPlay(this.definitions[index], this.audioCache);
+ });
$('.kanji-link').click(e => {
e.preventDefault();
@@ -83,7 +89,7 @@ class Display {
if (context) {
context.source = {
definitions,
- index: $('.entry').index(link.closest('.entry'))
+ index: Display.entryIndexFind(link)
};
}
@@ -97,6 +103,9 @@ class Display {
}
showKanjiDefs(definitions, options, context) {
+ this.spinner.hide();
+ this.definitions = definitions;
+
const sequence = ++this.sequence;
const params = {
definitions,
@@ -105,18 +114,15 @@ class Display {
};
if (context) {
- definitions.forEach(definition => {
+ for (const definition of definitions) {
definition.sentence = context.sentence;
definition.url = context.url;
- });
+ }
}
- this.definitions = definitions;
- this.spinner.hide();
-
this.templateRender('kanji.html', params).then(content => {
- window.scrollTo(0, 0);
this.container.html(content);
+ window.scrollTo(0, 0);
$('.action-add-note').click(this.onActionAddNote.bind(this));
$('.source-term').click(e => {
@@ -132,10 +138,6 @@ class Display {
}).catch(this.handleError.bind(this));
}
- adderButtonFind(index, mode) {
- return $(`.action-add-note[data-index="${index}"][data-mode="${mode}"]`);
- }
-
adderButtonsUpdate(modes, sequence) {
return this.definitionsAddable(this.definitions, modes).then(states => {
if (states === null || sequence !== this.sequence) {
@@ -144,7 +146,7 @@ class Display {
states.forEach((state, index) => {
for (const mode in state) {
- const button = this.adderButtonFind(index, mode);
+ const button = Display.adderButtonFind(index, mode);
if (state[mode]) {
button.removeClass('disabled');
} else {
@@ -157,21 +159,15 @@ class Display {
});
}
- onActionPlayAudio(e) {
- e.preventDefault();
- const index = $(e.currentTarget).data('index');
- this.audioPlay(this.definitions[index]);
- }
-
onActionAddNote(e) {
e.preventDefault();
this.spinner.show();
const link = $(e.currentTarget);
- const index = link.data('index');
const mode = link.data('mode');
-
+ const index = Display.entryIndexFind(link);
const definition = this.definitions[index];
+
if (mode !== 'kanji') {
const url = Display.audioBuildUrl(definition);
const filename = Display.audioBuildFilename(definition);
@@ -182,17 +178,16 @@ class Display {
this.definitionAdd(definition, mode).then(success => {
if (success) {
- const button = this.adderButtonFind(index, mode);
- button.addClass('disabled');
+ Display.adderButtonFind(index, mode).addClass('disabled');
} else {
this.handleError('note could not be added');
}
}).catch(this.handleError.bind(this)).then(() => this.spinner.hide());
}
- audioPlay(definition) {
- for (const key in this.audioCache) {
- const audio = this.audioCache[key];
+ static audioPlay(definition, cache) {
+ for (const key in cache) {
+ const audio = cache[key];
if (audio !== null) {
audio.pause();
}
@@ -203,7 +198,7 @@ class Display {
return;
}
- let audio = this.audioCache[url];
+ let audio = cache[url];
if (audio) {
audio.currentTime = 0;
audio.play();
@@ -214,12 +209,20 @@ class Display {
audio = new Audio('/mixed/mp3/button.mp3');
}
- this.audioCache[url] = audio;
+ cache[url] = audio;
audio.play();
};
}
}
+ static entryIndexFind(element) {
+ return $('.entry').index(element.closest('.entry'));
+ }
+
+ static adderButtonFind(index, mode) {
+ return $('.entry').eq(index).find(`.action-add-note[data-mode="${mode}"]`);
+ }
+
static audioBuildUrl(definition) {
let kana = definition.reading;
let kanji = definition.expression;
diff --git a/tmpl/kanji.html b/tmpl/kanji.html
index 8f52eb4a..4bb524cf 100644
--- a/tmpl/kanji.html
+++ b/tmpl/kanji.html
@@ -2,10 +2,10 @@
{{#if addable}}
-
+
{{/if}}
{{#if source}}
-
+
{{/if}}
@@ -17,7 +17,7 @@
Kunyomi: |
{{#each kunyomi}}
- {{.}}{{#unless @last}}, {{/unless}}
+ {{.}}{{#unless @last}}, {{/unless}}
{{/each}}
|
@@ -25,7 +25,7 @@
Onyomi: |
{{#each onyomi}}
- {{.}}{{#unless @last}}, {{/unless}}
+ {{.}}{{#unless @last}}, {{/unless}}
{{/each}}
|
@@ -34,29 +34,29 @@
{{#each tags}}
- {{name}}
+ {{name}}
{{/each}}
{{#if glossary.[1]}}
-
- {{#each glossary}}
- - {{#multiLine}}{{.}}{{/multiLine}}
- {{/each}}
-
+
+ {{#each glossary}}
+ - {{#multiLine}}{{.}}{{/multiLine}}
+ {{/each}}
+
{{else}}
-
{{#multiLine}}{{glossary.[0]}}{{/multiLine}}
+
{{#multiLine}}{{glossary.[0]}}{{/multiLine}}
{{/if}}
{{/inline}}
{{#if definitions}}
- {{#each definitions}}
- {{#unless @first}}
{{/unless}}
- {{> kanji addable=../addable source=../source root=../root}}
- {{/each}}
+{{#each definitions}}
+{{#unless @first}}
{{/unless}}
+{{> kanji addable=../addable source=../source root=../root}}
+{{/each}}
{{else}}
- No results found.
+No results found.
{{/if}}
diff --git a/tmpl/model.html b/tmpl/model.html
index acff44a0..94772316 100644
--- a/tmpl/model.html
+++ b/tmpl/model.html
@@ -9,7 +9,7 @@
diff --git a/tmpl/terms.html b/tmpl/terms.html
index 22209f9b..fa32cea1 100644
--- a/tmpl/terms.html
+++ b/tmpl/terms.html
@@ -1,71 +1,71 @@
{{#*inline "definition"}}
- {{#if tags}}
-
- {{#each tags}}
- {{name}}
- {{/each}}
-
- {{/if}}
- {{#if glossary.[1]}}
-
- {{#each glossary}}
- - {{#multiLine}}{{.}}{{/multiLine}}
- {{/each}}
-
- {{else}}
-
{{#multiLine}}{{glossary.[0]}}{{/multiLine}}
- {{/if}}
+{{#if tags}}
+
+ {{#each tags}}
+ {{name}}
+ {{/each}}
+
+{{/if}}
+{{#if glossary.[1]}}
+
+ {{#each glossary}}
+ - {{#multiLine}}{{.}}{{/multiLine}}
+ {{/each}}
+
+{{else}}
+
{{#multiLine}}{{glossary.[0]}}{{/multiLine}}
+{{/if}}
{{/inline}}
{{#*inline "term"}}
{{#if addable}}
-
-
+
+
{{/if}}
{{#if playback}}
-
+
{{/if}}
{{#if reading}}
-
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}
+
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}
{{else}}
-
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}
+
{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}
{{/if}}
{{#if reasons}}
-
- {{#each reasons}}
- {{.}} {{#unless @last}}«{{/unless}}
- {{/each}}
-
+
+ {{#each reasons}}
+ {{.}} {{#unless @last}}«{{/unless}}
+ {{/each}}
+
{{/if}}
- {{#if grouped}}
+ {{#if grouped}}
{{#if definitions.[1]}}
{{#each definitions}}
- - {{> definition}}
+ - {{> definition}}
{{/each}}
{{else}}
- {{> definition definitions.[0]}}
+ {{> definition definitions.[0]}}
{{/if}}
- {{else}}
+ {{else}}
{{> definition}}
- {{/if}}
+ {{/if}}
{{/inline}}
{{#if definitions}}
- {{#each definitions}}
- {{#unless @first}}
{{/unless}}
- {{> term grouped=../grouped addable=../addable playback=../playback}}
- {{/each}}
+{{#each definitions}}
+{{#unless @first}}
{{/unless}}
+{{> term grouped=../grouped addable=../addable playback=../playback}}
+{{/each}}
{{else}}
-
No results found.
+
No results found.
{{/if}}