cleanup
This commit is contained in:
parent
a55b74c92e
commit
f39323126d
@ -299,13 +299,9 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
+ ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.program(15, data, 0),"data":data})) != null ? stack1 : "")
|
||||
+ " </div>\n</div>\n";
|
||||
},"2":function(container,depth0,helpers,partials,data) {
|
||||
var helper;
|
||||
|
||||
return " <a href=\"#\" title=\"Add Kanji\" class=\"action-add-note pending disabled\" data-mode=\"kanji\" data-index=\""
|
||||
+ container.escapeExpression(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"index","hash":{},"data":data}) : helper)))
|
||||
+ "\"><img src=\"/mixed/img/add-kanji.png\"></a>\n";
|
||||
return " <a href=\"#\" title=\"Add Kanji\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" alt></a>\n";
|
||||
},"4":function(container,depth0,helpers,partials,data) {
|
||||
return " <a href=\"#\" title=\"Source term\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\"></a>\n";
|
||||
return " <a href=\"#\" title=\"Source term\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" alt></a>\n";
|
||||
},"6":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
@ -358,10 +354,9 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
},"19":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(20, 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(20, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1])},"data":data,"indent":" ","helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
||||
+ ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
||||
},"20":function(container,depth0,helpers,partials,data) {
|
||||
return "<hr>";
|
||||
},"22":function(container,depth0,helpers,partials,data) {
|
||||
@ -458,19 +453,9 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
+ ((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</div>\n";
|
||||
},"13":function(container,depth0,helpers,partials,data) {
|
||||
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
|
||||
|
||||
return " <a href=\"#\" title=\"Add term as expression\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\" data-index=\""
|
||||
+ alias4(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"index","hash":{},"data":data}) : helper)))
|
||||
+ "\"><img src=\"/mixed/img/add-term-kanji.png\"></a>\n <a href=\"#\" title=\"Add term as reading\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\" data-index=\""
|
||||
+ alias4(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"index","hash":{},"data":data}) : helper)))
|
||||
+ "\"><img src=\"/mixed/img/add-term-kana.png\"></a>\n";
|
||||
return " <a href=\"#\" title=\"Add expression\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" alt></a>\n <a href=\"#\" title=\"Add reading\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" alt></a>\n";
|
||||
},"15":function(container,depth0,helpers,partials,data) {
|
||||
var helper;
|
||||
|
||||
return " <a href=\"#\" title=\"Play audio\" class=\"action-play-audio\" data-index=\""
|
||||
+ container.escapeExpression(((helper = (helper = helpers.index || (data && data.index)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"index","hash":{},"data":data}) : helper)))
|
||||
+ "\"><img src=\"/mixed/img/play-audio.png\"></a>\n";
|
||||
return " <a href=\"#\" title=\"Play audio\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" alt></a>\n";
|
||||
},"17":function(container,depth0,helpers,partials,data) {
|
||||
var stack1, helper, options, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", buffer =
|
||||
" <div class=\"expression\"><ruby>";
|
||||
@ -538,10 +523,9 @@ 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 "<hr>";
|
||||
},"38":function(container,depth0,helpers,partials,data) {
|
||||
|
@ -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;
|
||||
|
@ -2,10 +2,10 @@
|
||||
<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>
|
||||
<a href="#" title="Add Kanji" class="action-add-note pending disabled" data-mode="kanji"><img src="/mixed/img/add-kanji.png" alt></a>
|
||||
{{/if}}
|
||||
{{#if source}}
|
||||
<a href="#" title="Source term" class="source-term"><img src="/mixed/img/source-term.png"></a>
|
||||
<a href="#" title="Source term" class="source-term"><img src="/mixed/img/source-term.png" alt></a>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
|
@ -21,11 +21,11 @@
|
||||
<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>
|
||||
<a href="#" title="Add term as reading" class="action-add-note pending disabled" data-mode="term-kana" data-index="{{@index}}"><img src="/mixed/img/add-term-kana.png"></a>
|
||||
<a href="#" title="Add expression" class="action-add-note pending disabled" data-mode="term-kanji"><img src="/mixed/img/add-term-kanji.png" alt></a>
|
||||
<a href="#" title="Add reading" class="action-add-note pending disabled" data-mode="term-kana"><img src="/mixed/img/add-term-kana.png" alt></a>
|
||||
{{/if}}
|
||||
{{#if playback}}
|
||||
<a href="#" title="Play audio" class="action-play-audio" data-index="{{@index}}"><img src="/mixed/img/play-audio.png"></a>
|
||||
<a href="#" title="Play audio" class="action-play-audio"><img src="/mixed/img/play-audio.png" alt></a>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user